ScanCodePaySendIntegralForm.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\scanCodePay\models\form;
  8. use app\plugins\scanCodePay\models\ScanCodePaySetting;
  9. use yii\base\Model;
  10. class ScanCodePaySendIntegralForm extends Model
  11. {
  12. public $store_id;
  13. public $send_integral;
  14. public $mch;
  15. public function rules()
  16. {
  17. return [
  18. [['store_id', 'send_integral'], 'required'],
  19. ];
  20. }
  21. public function save()
  22. {
  23. if (!$this->validate()) {
  24. return [
  25. 'code' => 1,
  26. 'msg' => $this->getErrorSummary(false)[0],
  27. ];
  28. }
  29. try {
  30. $model = ScanCodePaySetting::findOne(['store_id' => $this->store_id, 'mch' => $this->mch, 'is_delete' => 0]);
  31. if (!$model) {
  32. $model = new ScanCodePaySetting();
  33. $model->store_id = $this->store_id;
  34. $model->is_scan_code_pay = 0;
  35. $model->payment_type = json_encode([]);
  36. $model->is_share = 0;
  37. $model->is_sms = 0;
  38. $model->is_mail = 0;
  39. $model->is_print = 0;
  40. $model->poster = json_encode([]);
  41. $model->price_type = 0;
  42. $model->first = 0;
  43. $model->second = 0;
  44. $model->third = 0;
  45. $model->mch = $this->mch;
  46. }
  47. $model->send_integral = $this->send_integral;
  48. $res = $model->save();
  49. if (!$res) {
  50. throw new \Exception($model->getErrors($model));
  51. }
  52. return [
  53. 'code' => 0,
  54. 'msg' => "保存成功"
  55. ];
  56. } catch (\Exception $e) {
  57. return [
  58. 'code' => 1,
  59. 'msg' => $e->getMessage()
  60. ];
  61. }
  62. }
  63. }