AttrLibraryForm.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Cat;
  9. use yii\base\Model;
  10. class AttrLibraryForm extends Model
  11. {
  12. public $store_id = 1;
  13. public $supplier_id = 0;
  14. public $parent_id;
  15. public $sort;
  16. public $name;
  17. public $type;
  18. public $model;
  19. /**
  20. * @return array
  21. */
  22. public function rules()
  23. {
  24. return [
  25. [['parent_id', 'store_id', 'sort', 'supplier_id'], 'integer'],
  26. [['name'], 'string', 'max' => 60],
  27. [['type'], 'default', 'value' => 0],
  28. [['is_delete'], 'default', 'value' => 0]
  29. ];
  30. }
  31. /**
  32. * 保存分类
  33. * @return array
  34. */
  35. public function save()
  36. {
  37. if ($this->supplier_id > 0) {
  38. $this->store_id = 0;
  39. }
  40. $this->model->parent_id = $this->parent_id;
  41. $this->model->type = $this->type;
  42. $this->model->name = $this->name;
  43. $this->model->sort = $this->sort;
  44. $this->model->store_id = $this->store_id;
  45. $this->model->supplier_id = $this->supplier_id;
  46. if ($this->model->save()) {
  47. return [
  48. 'code' => 0,
  49. 'msg' => '提交成功'
  50. ];
  51. } else {
  52. return [
  53. 'code' => 0,
  54. 'msg' => '保存失败'
  55. ];
  56. }
  57. }
  58. }