| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace addons\Store\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_store_extra".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $store_id 门店id
- * @property string|null $give_setting 赠送设置
- * @property string|null $deduct_setting 抵扣设置
- * @property int $status 状态[1正常 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class StoreExtra extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_extra}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['give_setting', 'deduct_setting'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => 'Store ID',
- 'give_setting' => 'Give Setting',
- 'deduct_setting' => 'Deduct Setting',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($params)
- {
- try{
- // 根据商品id获取商品信息
- $model = self::findOne(['store_id' => $params['store_id'],'status'=>StatusEnum::ENABLED]);
- if (empty($model)) {
- // 初始化商品额外参数
- $model = new self();
- $model->loadDefaultValues();
- }
- $model->store_id = $params['store_id'];
- $params['give_setting'] = json_encode($params['give_setting']);
- $params['deduct_setting'] = json_encode($params['deduct_setting']);
- if(!$model->load($params,'') || !$model->save(false)) throw new \Exception($model->getErrorMessage());
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|