IntelligentMatchForm.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 yii\base\Model;
  9. class IntelligentMatchForm extends Model
  10. {
  11. public $store_id = 1;
  12. public $parent_id;
  13. public $sort;
  14. public $cat_name;
  15. public $is_show;
  16. public $model;
  17. /**
  18. * @return array
  19. */
  20. public function rules()
  21. {
  22. return [
  23. [['parent_id', 'store_id', 'sort'], 'integer'],
  24. [['cat_name'], 'string', 'max' => 60],
  25. [['sort'], 'default', 'value' => 100],
  26. [['is_show'], 'default', 'value' => 1],
  27. [['is_delete'], 'default', 'value' => 0]
  28. ];
  29. }
  30. /**
  31. * 保存分类
  32. * @return array
  33. */
  34. public function save()
  35. {
  36. $this->model->parent_id = $this->parent_id;
  37. $this->model->is_show = $this->is_show;
  38. if ($this->is_show == 0) {
  39. // 产品分类隐藏同时下架该分类下所有商品
  40. /*$goods_ids = GoodsCat::find()->where(['is_delete' => 0, 'store_id' => get_store_id(),
  41. 'cat_id' => post_params('id')])->select('goods_id')->asArray()->all();
  42. Goods::updateAll(['status' => Goods::STATUS_DISABLE],['in', 'id', array_column($goods_ids, 'goods_id')]);*/
  43. }
  44. $this->model->cat_name = $this->cat_name;
  45. $this->model->sort = $this->sort;
  46. $this->model->store_id = $this->store_id;
  47. if ($this->model->save()) {
  48. return [
  49. 'code' => 0,
  50. 'msg' => '提交成功'
  51. ];
  52. } else {
  53. return [
  54. 'code' => 0,
  55. 'msg' => '保存失败'
  56. ];
  57. }
  58. }
  59. }