| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\Community\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- /**
- * This is the model class for table "qimall_addons_community_goods_setting".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $goods_id Goods ID
- * @property int $enable 是否开启社区社区团购[0关闭,1开启]
- * @property string $supported_logistics 支持物流方式[1:快递配送; 2:站点自提; 3送货上门]
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class CommunityGoodsSetting extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_community_goods_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'goods_id', 'enable', 'status', 'created_at', 'updated_at', 'enable_refund'], 'integer'],
- [['supported_logistics'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'goods_id' => '商品id',
- 'enable' => '是否开启社区社区团购[0关闭,1开启]',
- 'supported_logistics' => '支持物流方式[1:快递配送; 2:站点自提; 3送货上门]',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'goods_id' => $params['goods_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile();
- return false;
- }
- }
- /**
- * 商品是否开启社区团购
- * @param $mall_id
- * @param $goods_id
- * @return bool
- */
- public static function getEnable($mall_id, $goods_id)
- {
- return self::find()
- ->where(['status' => StatusEnum::ENABLED, 'goods_id' => $goods_id, 'enable' => StatusEnum::ENABLED, 'mall_id' => $mall_id])
- ->exists();
- }
- }
|