ItemController.php 3.6 KB

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