CatForm.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: your name
  9. * @Date: 2021-05-08 17:28:23
  10. * @LastEditTime: 2021-05-12 16:35:15
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\client\models\v1\admin\CatForm.php
  14. */
  15. namespace app\modules\client\models\v1\admin;
  16. use app\models\Cat;
  17. use yii\base\Model;
  18. class CatForm extends Model
  19. {
  20. public $store_id = 1;
  21. public $parent_id;
  22. public $sort;
  23. public $name;
  24. public $pic_url;
  25. public $is_show;
  26. public $model;
  27. public $is_delete;
  28. /**
  29. * @return array
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['parent_id', 'store_id', 'sort'], 'integer'],
  35. [['name'], 'string', 'max' => 60],
  36. [['pic_url'], 'string'],
  37. [['is_show'], 'default', 'value' => 1],
  38. [['is_delete'], 'default', 'value' => 0]
  39. ];
  40. }
  41. /**
  42. * 保存分类
  43. * @return array
  44. */
  45. public function save()
  46. {
  47. $this->model->parent_id = $this->parent_id;
  48. $this->model->is_show = $this->is_show;
  49. $this->model->name = $this->name;
  50. $this->model->pic_url = $this->pic_url;
  51. $this->model->sort = $this->sort;
  52. $this->model->store_id = $this->store_id;
  53. if ($this->model->save()) {
  54. return [
  55. 'code' => 0,
  56. 'msg' => '提交成功'
  57. ];
  58. } else {
  59. return [
  60. 'code' => 0,
  61. 'msg' => '保存失败'
  62. ];
  63. }
  64. }
  65. /**
  66. * Undocumented function
  67. *
  68. * @Author LGL 24963@qq.com
  69. * @DateTime 2021-01-18
  70. * @desc: 根据id获取分类列表
  71. * @param array $id
  72. * @return void
  73. */
  74. public static function getCatListById ($id = [])
  75. {
  76. if (empty($id) && !is_array($id)) {
  77. return [];
  78. }
  79. return Cat::find()->where(['in', 'id', $id])->select('id, name, pic_url')->asArray()->all();
  80. }
  81. }