ItemController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use bizGhs\item\services\ItemService;
  6. use common\components\util;
  7. use bizGhs\product\classes\ProductClass;
  8. use Yii;
  9. class ItemController extends BaseController
  10. {
  11. //是否有C级价格大于B级的 ssh 20221204
  12. public function actionGetErrorPrice()
  13. {
  14. $shop = $this->shop;
  15. $list = ItemClass::errorPrice($shop);
  16. util::success(['list' => $list]);
  17. }
  18. //列出所有花材,包括特价花材列表 ssh 20220315
  19. public function actionShowList()
  20. {
  21. $where['mainId'] = $this->mainId;
  22. $where['delStatus'] = 0;
  23. $list = ItemClass::getShowList($where);
  24. util::success(['list' => $list]);
  25. }
  26. public function actionAdd()
  27. {
  28. $post = Yii::$app->request->post();
  29. $post['adminId'] = $this->adminId;
  30. $post['sjId'] = $this->sjId;
  31. $connection = Yii::$app->db;//事务处理
  32. $transaction = $connection->beginTransaction();
  33. try {
  34. ItemService::addGhsItem($post);
  35. $transaction->commit();
  36. util::complete('添加成功');
  37. } catch (Exception $e) {
  38. $transaction->rollBack();
  39. util::fail('添加失败');
  40. }
  41. }
  42. //批量添加花材
  43. public function actionBatchAdd()
  44. {
  45. $shopAdmin = $this->shopAdmin;
  46. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  47. util::fail('超管才能操作');
  48. }
  49. $post = Yii::$app->request->post();
  50. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  51. $data = $post['data'];
  52. if (empty($data)) {
  53. util::fail("请选花材");
  54. }
  55. $data = json_decode($data, true);
  56. if (!is_array($data) || empty($data)) {
  57. util::fail("请选花材");
  58. }
  59. $sjId = $this->sjId;
  60. $ids = array_column($data, 'itemId');
  61. $ids = array_unique(array_filter($ids));
  62. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
  63. if (!empty($has)) {
  64. util::fail("有花材已经添加过了");
  65. }
  66. $connection = Yii::$app->db;//事务处理
  67. $transaction = $connection->beginTransaction();
  68. try {
  69. foreach ($data as $v) {
  70. $v['adminId'] = $this->adminId;
  71. $v['sjId'] = $sjId;
  72. ItemService::addGhsItem($v);
  73. }
  74. $transaction->commit();
  75. util::complete('添加成功');
  76. } catch (Exception $e) {
  77. $transaction->rollBack();
  78. util::fail();
  79. }
  80. }
  81. public function actionDelete()
  82. {
  83. util::fail('不能删除哦!');
  84. }
  85. //获取平台里的花材信息
  86. public function actionPlatformItem()
  87. {
  88. $py = Yii::$app->request->get('py', '');
  89. $where = [];
  90. if ($py) {
  91. $where = ['py' => $py];
  92. }
  93. $list = PtItemClass::getItemList($where);
  94. util::success($list);
  95. }
  96. //列出需要进行颜色管理的花材 ssh 20220820
  97. public function actionColorList()
  98. {
  99. $mainId = $this->mainId ?? 0;
  100. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  101. util::success(['list' => $list]);
  102. }
  103. }