RefundAddressForm.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\RefundAddress;
  9. use yii\base\Model;
  10. class RefundAddressForm extends Model
  11. {
  12. public $id;
  13. public $name;
  14. public $address;
  15. public $mobile;
  16. public $mch_id;
  17. /**
  18. * @return array
  19. */
  20. public function rules()
  21. {
  22. return [
  23. [[ 'name'], 'required'],
  24. [['id', 'mch_id'], 'integer'],
  25. [['address', 'mobile', 'name'], 'string', 'max' => 255],
  26. [['mch_id'], 'default', 'value' => 0]
  27. ];
  28. }
  29. public function attributeLabels()
  30. {
  31. return [
  32. 'name' => '名称',
  33. 'mobile' => '电话',
  34. 'address' => '收货地址'
  35. ];
  36. }
  37. /**
  38. * 保存运费规则
  39. * @return array
  40. */
  41. public function save()
  42. {
  43. if(!$this->validate()) {
  44. return [
  45. 'code' => 1,
  46. 'msg' => $this->getErrorSummary(false)[0],
  47. ];
  48. }
  49. $refund = RefundAddress::findOne($this->id)?: new RefundAddress();
  50. $refund->store_id = get_store_id();
  51. $refund->name = $this->name;
  52. $refund->address = $this->address;
  53. $refund->mobile = $this->mobile;
  54. $refund->mch_id = $this->mch_id;
  55. if ($refund->save()) {
  56. return [
  57. 'code' => 0,
  58. 'msg' => '保存成功'
  59. ];
  60. } else {
  61. return [
  62. 'code' => 1,
  63. 'msg' => '保存失败',
  64. 'err' => $refund->errors
  65. ];
  66. }
  67. }
  68. }