| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\scanCodePay\models\form;
- use app\plugins\scanCodePay\models\ScanCodePaySetting;
- use yii\base\Model;
- class ScanCodePaySettingForm extends Model
- {
- public $store_id;
- public $is_scan_code_pay;
- public $payment_type;
- public $is_share;
- public $is_sms;
- public $is_mail;
- public $is_print;
- public $poster;
- public $price_type;
- public $first;
- public $second;
- public $third;
- public $mch;
- public function rules()
- {
- return [
- [['store_id', 'is_scan_code_pay', 'payment_type', 'is_share', 'is_sms', 'is_mail', 'is_print'], 'required', 'on' => ['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;
- }
- }
|