| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\SupplierSetting;
- use yii\base\Model;
- use yii\helpers\Json;
- class SupplierSettingForm extends Model
- {
- public $id;
- public $store_id = 1;
- public $mch_id = 0;
- public $repertory_warning;
- public $repertory_purchase;
- public $address;
- public $name;
- public $mobile;
- public $province;
- public $city;
- public $district;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [[ 'name'], 'required'],
- [['id', 'mch_id'], 'integer'],
- [['SupplierSetting_type', 'name'], 'string', 'max' => 255],
- [['SupplierSetting_setting'], 'safe'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'mch_id' => '入驻商id',
- 'address' => '平台供货收货地址',
- 'name' => '收货人名字',
- 'mobile' => '收货人电话',
- 'repertory_warning' => '库存警告',
- 'repertory_purchase' => '采购库存',
- 'province' => '省id',
- 'city' => '市id',
- 'district' => '区id',
- 'longitude' => '经度',
- 'latitude' => '纬度',
- ];
- }
- /**
- * 保存运费规则
- * @return array
- */
- public function save()
- {
- if(!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $SupplierSetting = SupplierSetting::findOne($this->id) ?: new SupplierSetting();
- $SupplierSetting->store_id = get_store_id();
- $SupplierSetting->mch_id = $this->mch_id;
- $SupplierSetting->name = $this->name;
- $SupplierSetting->SupplierSetting_setting = Json::encode($this->SupplierSetting_setting);
- $SupplierSetting->SupplierSetting_type = $this->SupplierSetting_type;
- if ($SupplierSetting->save()) {
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => '保存失败',
- 'err' => $SupplierSetting->errors
- ];
- }
- }
- }
|