['save']], [['poster', 'payment_type', 'price_type', 'first', 'second', 'third', 'mch'], 'safe'], ]; } public function scenarios() { return [ 'search' => ['store_id','mch'], 'save' => ['store_id', 'is_scan_code_pay', 'is_share', 'is_sms', 'is_mail', 'is_print', 'payment_type', 'price_type', 'first', 'second', 'third', 'mch'], ]; } public function save() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } try { $model = ScanCodePaySetting::findOne(['store_id' => $this->store_id, 'mch' => $this->mch, 'is_delete' => 0]); if (!$model) { $model = new ScanCodePaySetting(); $model->store_id = $this->store_id; } $model->is_scan_code_pay = $this->is_scan_code_pay; $model->payment_type = json_encode($this->payment_type ? $this->payment_type : []); $model->is_share = $this->is_share; $model->is_sms = $this->is_sms; $model->is_mail = $this->is_mail; $model->is_print = $this->is_print; $model->poster = json_encode($this->poster); $model->price_type = $this->price_type; $model->first = $this->first; $model->second = $this->second; $model->third = $this->third; $model->mch = $this->mch; $res = $model->save(); if (!$res) { throw new \Exception((new Model())->getErrorResponse($model)->msg); } return [ 'code' => 0, 'msg' => "保存成功" ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function search() { $setting = ScanCodePaySetting::find()->where(['store_id' => $this->store_id, 'mch' => $this->mch, 'is_delete' => 0])->asArray()->one(); $setting['payment_type'] = json_decode($setting['payment_type'], true); return $setting; } }