SupplierSettingForm.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\SupplierSetting;
  9. use yii\base\Model;
  10. use yii\helpers\Json;
  11. class SupplierSettingForm extends Model
  12. {
  13. public $id;
  14. public $store_id = 1;
  15. public $mch_id = 0;
  16. public $repertory_warning;
  17. public $repertory_purchase;
  18. public $address;
  19. public $name;
  20. public $mobile;
  21. public $province;
  22. public $city;
  23. public $district;
  24. /**
  25. * @return array
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [[ 'name'], 'required'],
  31. [['id', 'mch_id'], 'integer'],
  32. [['SupplierSetting_type', 'name'], 'string', 'max' => 255],
  33. [['SupplierSetting_setting'], 'safe'],
  34. ];
  35. }
  36. public function attributeLabels()
  37. {
  38. return [
  39. 'id' => 'ID',
  40. 'store_id' => 'Store ID',
  41. 'mch_id' => '入驻商id',
  42. 'address' => '平台供货收货地址',
  43. 'name' => '收货人名字',
  44. 'mobile' => '收货人电话',
  45. 'repertory_warning' => '库存警告',
  46. 'repertory_purchase' => '采购库存',
  47. 'province' => '省id',
  48. 'city' => '市id',
  49. 'district' => '区id',
  50. 'longitude' => '经度',
  51. 'latitude' => '纬度',
  52. ];
  53. }
  54. /**
  55. * 保存运费规则
  56. * @return array
  57. */
  58. public function save()
  59. {
  60. if(!$this->validate()) {
  61. return [
  62. 'code' => 1,
  63. 'msg' => $this->getErrorSummary(false)[0],
  64. ];
  65. }
  66. $SupplierSetting = SupplierSetting::findOne($this->id) ?: new SupplierSetting();
  67. $SupplierSetting->store_id = get_store_id();
  68. $SupplierSetting->mch_id = $this->mch_id;
  69. $SupplierSetting->name = $this->name;
  70. $SupplierSetting->SupplierSetting_setting = Json::encode($this->SupplierSetting_setting);
  71. $SupplierSetting->SupplierSetting_type = $this->SupplierSetting_type;
  72. if ($SupplierSetting->save()) {
  73. return [
  74. 'code' => 0,
  75. 'msg' => '保存成功'
  76. ];
  77. } else {
  78. return [
  79. 'code' => 1,
  80. 'msg' => '保存失败',
  81. 'err' => $SupplierSetting->errors
  82. ];
  83. }
  84. }
  85. }