CloudForm.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\Cloud;
  9. use yii\base\Model;
  10. use yii\helpers\Json;
  11. class CloudForm extends Model
  12. {
  13. public $id;
  14. public $mch_id = 0;
  15. public $name;
  16. public $cloud_setting;
  17. public $cloud_type;
  18. /**
  19. * @return array
  20. */
  21. public function rules()
  22. {
  23. return [
  24. [[ 'name'], 'required'],
  25. [['id', 'mch_id'], 'integer'],
  26. [['cloud_type', 'name'], 'string', 'max' => 255],
  27. [['cloud_setting'], 'safe'],
  28. ];
  29. }
  30. public function attributeLabels()
  31. {
  32. return [
  33. 'name' => '名称'
  34. ];
  35. }
  36. /**
  37. * 保存运费规则
  38. * @return array
  39. */
  40. public function save()
  41. {
  42. if (!$this->validate()) {
  43. return [
  44. 'code' => 1,
  45. 'msg' => $this->getErrorSummary(false)[0],
  46. ];
  47. }
  48. $cloud = Cloud::findOne($this->id) ?: new Cloud();
  49. $cloud->store_id = get_store_id();
  50. $cloud->mch_id = $this->mch_id;
  51. $cloud->name = $this->name;
  52. $cloud->cloud_setting = Json::encode($this->cloud_setting);
  53. $cloud->cloud_type = $this->cloud_type;
  54. $cloud->is_delete = 0;//有客户添加云打印报错is_delete字段不能为null
  55. cache()->delete('admin_cloud_setting_' . get_store_id() . '_' . get_mch_id());
  56. if ($cloud->save()) {
  57. return [
  58. 'code' => 0,
  59. 'msg' => '保存成功'
  60. ];
  61. } else {
  62. return [
  63. 'code' => 1,
  64. 'msg' => '保存失败',
  65. 'err' => $cloud->errors
  66. ];
  67. }
  68. }
  69. }