'save' ], [ [ 'store_id', 'change_shop', 'pay_wechat', 'pay_alipay', 'pay_bank', 'pay_lg', 'pay_remaining', 'member_price_clerk_commission', 'single_md_goods_risk' ], 'integer', 'on' => 'save' ], [ [ 'min_money', 'cash_max_day', 'cash_max_single_day', 'cash_service_charge' ], 'number', 'on' => 'save' ], [ [ 'md_banner', 'md_agreement' ], 'safe', 'on' => 'save' ] ]; } /** * 获取门店设置信息 * @return MdSetting|array|\yii\db\ActiveRecord|null * @author: hankaige * @Time: 2024/3/18 14:36 */ public function getSetting() { $store = Store::findOne($this->store_id); $pics = $store->md_banner ? Json::decode($store->md_banner) : []; $model = MdSetting::find()->where(['store_id' => $this->store_id])->one(); if (!$model) { $model = new MdSetting(); $model->store_id = $this->store_id; $model->save(); } $model = ArrayHelper::toArray($model); $model['md_agreement'] = $store->md_agreement; $model['md_banner'] = $pics; $model['single_md_goods_risk'] = intval($model['single_md_goods_risk']); $model['member_price_clerk_commission'] = intval($model['member_price_clerk_commission']) ?? 1; return $model; } /** * 保存配置信息 * @return array * @author: hankaige * @Time: 2024/3/19 09:38 */ public function saveSetting() { if (!$this->validate()) { return [ 'code' => 1, "msg" => $this->getErrorSummary(FALSE)[0] ]; } $t = \Yii::$app->db->beginTransaction(); $store = Store::findOne($this->store_id); try { $store->md_banner = Json::encode($this->md_banner); $store->md_agreement = $this->md_agreement; if (!$store->save()) { $t->rollBack(); return [ 'code' => 1, 'msg' => '保存配置信息失败' ]; } $model = MdSetting::findOne(['store_id' => $this->store_id]); $model->change_shop = $this->change_shop; $model->pay_wechat = $this->pay_wechat; $model->pay_alipay = $this->pay_alipay; $model->pay_bank = $this->pay_bank; $model->pay_lg = $this->pay_lg; $model->pay_remaining = $this->pay_remaining; $model->min_money = $this->min_money; $model->cash_max_day = $this->cash_max_day; $model->cash_max_single_day = $this->cash_max_single_day; $model->cash_service_charge = $this->cash_service_charge; //会员价产品是否计算核销佣金 $model->member_price_clerk_commission = $this->member_price_clerk_commission ?? 1; $model->single_md_goods_risk = $this->single_md_goods_risk ?? 0; if (!$model->save()) { $t->rollBack(); return [ 'code' => 1, 'msg' => '保存配置信息失败' ]; } $t->commit(); return [ 'code' => 0, 'msg' => '设置成功' ]; } catch (\Throwable $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }