| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\Cloud;
- use yii\base\Model;
- use yii\helpers\Json;
- class CloudForm extends Model
- {
- public $id;
- public $mch_id = 0;
- public $name;
- public $cloud_setting;
- public $cloud_type;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [[ 'name'], 'required'],
- [['id', 'mch_id'], 'integer'],
- [['cloud_type', 'name'], 'string', 'max' => 255],
- [['cloud_setting'], 'safe'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'name' => '名称'
- ];
- }
- /**
- * 保存运费规则
- * @return array
- */
- public function save()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $cloud = Cloud::findOne($this->id) ?: new Cloud();
- $cloud->store_id = get_store_id();
- $cloud->mch_id = $this->mch_id;
- $cloud->name = $this->name;
- $cloud->cloud_setting = Json::encode($this->cloud_setting);
- $cloud->cloud_type = $this->cloud_type;
- $cloud->is_delete = 0;//有客户添加云打印报错is_delete字段不能为null
- cache()->delete('admin_cloud_setting_' . get_store_id() . '_' . get_mch_id());
- if ($cloud->save()) {
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => '保存失败',
- 'err' => $cloud->errors
- ];
- }
- }
- }
|