'ID', 'mall_id' => 'Mall ID', 'store_id' => 'Store ID', 'coupon_give_item_setting_id' => 'Coupon Give Item Setting ID', 'coupon_id' => 'Coupon ID', 'from_type' => 'From Type', 'num' => 'Num', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getCoupon() { return $this->hasOne(StoreCoupon::class, ['id' => 'coupon_id'])->where(['status' => StatusEnum::ENABLED]); } public static function setData($params, $data) { try{ $coupon_id_arr = array_column($data,'coupon_id'); self::updateAll(['status'=>StatusEnum::DELETE],[ 'and', ['coupon_give_item_setting_id'=>$params['coupon_give_item_setting_id']], ['from_type'=>$params['from_type']], ['not in','coupon_id',$coupon_id_arr], ]); foreach ($data as $item) { $where = [ 'mall_id' => $params['mall_id'], 'coupon_id' => $item['coupon_id'], 'store_id' => $params['store_id'], 'from_type' => $params['from_type'], 'coupon_give_item_setting_id' => $params['coupon_give_item_setting_id'], 'status' => [StatusEnum::ENABLED]]; $model = self::findOne($where); if (empty($model)) { $model = new self(); $model->mall_id = $params['mall_id']; $model->store_id = $params['store_id']; $model->from_type = $params['from_type']; $model->coupon_give_item_setting_id = $params['coupon_give_item_setting_id']; $model->loadDefaultValues(); } if(!$model->load($item,'') || !$model->save()){ throw new \Exception($model->getErrorMessage()); } } return true; }catch(\Exception $e){ self::$static_error = $e->getMessage(); return false; } } }