| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?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 ScanCodePaySendIntegralForm extends Model
- {
- public $store_id;
- public $send_integral;
- public $mch;
- public function rules()
- {
- return [
- [['store_id', 'send_integral'], 'required'],
- ];
- }
- 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 = 0;
- $model->payment_type = json_encode([]);
- $model->is_share = 0;
- $model->is_sms = 0;
- $model->is_mail = 0;
- $model->is_print = 0;
- $model->poster = json_encode([]);
- $model->price_type = 0;
- $model->first = 0;
- $model->second = 0;
- $model->third = 0;
- $model->mch = $this->mch;
- }
- $model->send_integral = $this->send_integral;
- $res = $model->save();
- if (!$res) {
- throw new \Exception($model->getErrors($model));
- }
- return [
- 'code' => 0,
- 'msg' => "保存成功"
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- }
|