| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace addons\SecondaryCard\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_secondary_card_relate_store".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $create_source_type 创建来源类型:0:平台;1:门店
- * @property int $store_type 店铺类型:1:o2o门店
- * @property int $secondary_card_id 次卡id
- * @property int $store_id 门店id
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $created_at 创建时间
- * @property int $updated_at
- */
- class SecondaryCardRelateStore extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_secondary_card_relate_store}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'create_source_type', 'store_type', 'secondary_card_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'create_source_type' => '创建来源类型:0:平台;1:门店',
- 'store_type' => '店铺类型:1:o2o门店',
- 'secondary_card_id' => '次卡id',
- 'store_id' => '门店id',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'created_at' => '创建时间',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($mall_id, $secondary_card_id, $store_ids, $create_source_type, $store_type)
- {
- try {
- foreach ($store_ids as $store_id) {
- $model = self::findOne(['mall_id' => $mall_id, 'secondary_card_id' => $secondary_card_id, 'store_id' => $store_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- $params = [
- 'mall_id' => $mall_id,
- 'secondary_card_id' => $secondary_card_id,
- 'create_source_type' => $create_source_type,
- 'store_type' => $store_type,
- 'store_id' => $store_id,
- ];
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- }
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|