AttrLibraryController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\models\AttrLibrary;
  9. use app\modules\admin\models\AttrLibraryForm;
  10. /**
  11. * Class AttrLibraryController
  12. * @package app\modules\admin\controllers
  13. */
  14. class AttrLibraryController extends BaseController
  15. {
  16. /**
  17. * 保存分类
  18. * @return \yii\web\Response
  19. */
  20. public function actionSave()
  21. {
  22. $data = post_params();
  23. $form = new AttrLibraryForm();
  24. $attr = $data['id'] ? (AttrLibrary::findOne($data['id']) ?: new AttrLibrary()) : new AttrLibrary();
  25. $form->model = $attr;
  26. $form->store_id = get_store_id();
  27. $form->supplier_id = get_supplier_id();
  28. $form->attributes = $data;
  29. return $this->asJson($form->save());
  30. }
  31. /**
  32. * 获取规格库列表
  33. * @return \yii\web\Response
  34. */
  35. public function actionList()
  36. {
  37. $store_id = get_store_id();
  38. $supplier_id = get_supplier_id();
  39. $list = AttrLibrary::getList($store_id, 0, $supplier_id);
  40. return $this->asJson([
  41. 'code' => 0,
  42. 'data' => [
  43. 'list' => $list
  44. ]
  45. ]);
  46. }
  47. /**
  48. * 批量删除
  49. * @return \yii\web\Response
  50. */
  51. public function actionStatus()
  52. {
  53. $res = AttrLibrary::updateAll(['is_delete' => 1], ['id' => get_params('id',[])]);
  54. return $this->asJson([
  55. 'code' => 0,
  56. 'data' => [
  57. 'updateCount' => $res
  58. ]
  59. ]);
  60. }
  61. /**
  62. * 删除分类
  63. * @return \yii\web\Response
  64. */
  65. public function actionDel()
  66. {
  67. $attr = AttrLibrary::findOne(get_params('id'));
  68. if (empty($attr)) {
  69. return $this->asJson([
  70. 'code' => 1,
  71. 'msg' => '查无此分类'
  72. ]);
  73. }
  74. $attr->is_delete = 1;
  75. if ($attr->save()) {
  76. return $this->asJson([
  77. 'code' => 0,
  78. 'msg' => '删除成功'
  79. ]);
  80. }else {
  81. return $this->asJson([
  82. 'code' => 1,
  83. 'msg' => '删除失败'
  84. ]);
  85. }
  86. }
  87. }