| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\RefundAddress;
- use yii\base\Model;
- class RefundAddressForm extends Model
- {
- public $id;
- public $name;
- public $address;
- public $mobile;
- public $mch_id;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [[ 'name'], 'required'],
- [['id', 'mch_id'], 'integer'],
- [['address', 'mobile', 'name'], 'string', 'max' => 255],
- [['mch_id'], 'default', 'value' => 0]
- ];
- }
- public function attributeLabels()
- {
- return [
- 'name' => '名称',
- 'mobile' => '电话',
- 'address' => '收货地址'
- ];
- }
- /**
- * 保存运费规则
- * @return array
- */
- public function save()
- {
- if(!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $refund = RefundAddress::findOne($this->id)?: new RefundAddress();
- $refund->store_id = get_store_id();
- $refund->name = $this->name;
- $refund->address = $this->address;
- $refund->mobile = $this->mobile;
- $refund->mch_id = $this->mch_id;
- if ($refund->save()) {
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => '保存失败',
- 'err' => $refund->errors
- ];
- }
- }
- }
|