ItemController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace hd\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use bizGhs\item\services\ItemService;
  6. use bizHd\custom\classes\CustomClass;
  7. use bizHd\product\classes\ProductClass;
  8. use common\components\dict;
  9. use common\components\stringUtil;
  10. use common\components\util;
  11. use Yii;
  12. class ItemController extends BaseController
  13. {
  14. //列出所有花材 ssh 20240222
  15. public function actionGetItemList()
  16. {
  17. $get = Yii::$app->request->get();
  18. $search = $get['search'] ?? '';
  19. $requestType = $get['requestType'] ?? 'kd';
  20. $classId = $get['classId'] ?? 0;
  21. $lookStock = $get['lookStock'] ?? 0;
  22. $where['mainId'] = $this->mainId;
  23. if ($requestType == 'kd') {
  24. $where['delStatus'] = 0;
  25. $where['status'] = 1;
  26. } elseif ($requestType == 'itemList') {
  27. $where['delStatus'] = 0;
  28. if ($lookStock == 1) {
  29. $where['stock>'] = 0;
  30. }
  31. if ($lookStock == 2) {
  32. $where['stock'] = 0;
  33. }
  34. unset($where['status']);
  35. } elseif ($requestType == 'changePrice') {
  36. $where['delStatus'] = 0;
  37. $where['stock>'] = 0;
  38. } elseif ($requestType == 'hasStockList') {
  39. $where['delStatus'] = 0;
  40. $where['stock>'] = 0;
  41. } elseif ($requestType == 'book') {
  42. $where['delStatus'] = 0;
  43. unset($where['status']);
  44. } elseif ($requestType == 'outList') {
  45. $where['delStatus'] = 0;
  46. $where['status'] = 2;
  47. $where['removeStatus'] = 0;
  48. } elseif ($requestType == 'stopList') {
  49. $where['delStatus'] = 1;
  50. unset($where['status']);
  51. $where['removeStatus'] = 0;
  52. } elseif ($requestType == 'removeList') {
  53. $where['delStatus'] = 1;
  54. unset($where['status']);
  55. $where['removeStatus'] = 1;
  56. } elseif ($requestType == 'cg') {
  57. $where['delStatus'] = 0;
  58. unset($where['status']);
  59. } elseif ($requestType == 'changeStock') {
  60. $where['delStatus'] = 0;
  61. unset($where['status']);
  62. } elseif ($requestType == 'check') {
  63. $where['delStatus'] = 0;
  64. unset($where['status']);
  65. } elseif ($requestType == 'stockOut') {
  66. $where['delStatus'] = 0;
  67. $where['status'] = 1;
  68. } elseif ($requestType == 'break') {
  69. $where['delStatus'] = 0;
  70. $where['status'] = 1;
  71. } else {
  72. util::fail('没有定义的请求方式');
  73. }
  74. if (!empty($search)) {
  75. if (stringUtil::isLetter($search)) {
  76. $search = strtolower($search);
  77. $where['py'] = ['like', $search];
  78. } else {
  79. $where['name'] = ['like', $search];
  80. }
  81. } else {
  82. if (!empty($classId)) {
  83. if ($classId == -1) {
  84. $where['discountPrice>'] = 0;
  85. } elseif ($classId == -2) {
  86. $where['reachNum>'] = 0;
  87. } elseif ($classId == -3) {
  88. $where['presell'] = 1;
  89. } else {
  90. $where['classId'] = $classId;
  91. }
  92. }
  93. }
  94. $customId = $get['customId'] ?? 0;
  95. $custom = CustomClass::getById($customId, true);
  96. if (!empty($custom)) {
  97. if ($custom->shopId != $this->shopId) {
  98. util::fail('不是你的客户哦,编号55236');
  99. }
  100. }
  101. $level = $custom->level ?? 1;
  102. $field = '*';
  103. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  104. $list = $result['list'] ?? [];
  105. if ($requestType == 'kd') {
  106. $list = ProductClass::kdItemGroup($list, $level);
  107. } elseif ($requestType == 'itemList') {
  108. $list = ProductClass::itemListGroup($list, $level);
  109. } else {
  110. util::fail('没有数据');
  111. }
  112. $result['list'] = $list;
  113. util::success($result);
  114. }
  115. //增加和减少半扎 ssh 20250417
  116. public function actionChangeHalf()
  117. {
  118. util::fail('此功能已停用');
  119. $post = Yii::$app->request->post();
  120. $productId = $post['productId'] ?? '';
  121. $add = $post['add'] ?? 0;
  122. $remark = $post['remark'] ?? '';
  123. $product = ProductClass::getLockById($productId);
  124. if (empty($product)) {
  125. util::fail('没有找到花材');
  126. }
  127. if ($product->mainId != $this->mainId) {
  128. util::fail('不是你的花材');
  129. }
  130. if ($product->ratioType == 1) {
  131. util::fail('若干扎的花材不能减半份');
  132. }
  133. //避免重复提交
  134. util::checkRepeatCommit($this->adminId, 4);
  135. $connection = Yii::$app->db;
  136. $transaction = $connection->beginTransaction();
  137. try {
  138. $shop = $this->shop;
  139. $staff = $this->shopAdmin;
  140. $staffName = $staff->name ?? '';
  141. $staffId = $staff->id;
  142. $adminId = $this->adminId;
  143. $params = [
  144. 'staffId' => $staffId,
  145. 'staffName' => $staffName,
  146. 'adminId' => $adminId,
  147. 'remark' => $remark,
  148. ];
  149. ItemClass::modifyHalf($shop, $product, $params, $add);
  150. $product = ProductClass::getLockById($productId);
  151. $stock = $product->stock;
  152. $stock = floatval($stock);
  153. $transaction->commit();
  154. util::success(['stock' => $stock]);
  155. } catch (\Exception $e) {
  156. $transaction->rollBack();
  157. Yii::info("加减半份失败原因:" . $e->getMessage());
  158. util::fail('加减半份失败');
  159. }
  160. }
  161. //检测是否要刷新
  162. public function actionCheckRefresh()
  163. {
  164. $mainId = $this->mainId;
  165. $staffId = $this->shopAdminId;
  166. $respond = Yii::$app->redis->executeCommand('GET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  167. if ($respond == 'yes') {
  168. util::success(['remind' => 1]);
  169. }
  170. util::complete();
  171. }
  172. //列出所有花材,包括特价花材列表 ssh 20220315
  173. public function actionShowList()
  174. {
  175. $headers = Yii::$app->getRequest()->getHeaders();
  176. $requestVersion = $headers->get('appVersion');
  177. $currentVersion = dict::getDict('appVersion');
  178. if ($requestVersion < $currentVersion) {
  179. util::fail('请先升级系统');
  180. }
  181. $get = Yii::$app->request->get();
  182. $isCashier = $get['isCashier'] ?? 0;
  183. $mainId = $this->mainId;
  184. if ($isCashier == 1) {
  185. //去掉收银台提示价格更新
  186. $staffId = $this->shopAdminId;
  187. Yii::$app->redis->executeCommand('DEL', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  188. }
  189. $where['mainId'] = $mainId;
  190. $where['delStatus'] = 0;
  191. $where['status'] = 1;
  192. $list = \bizHd\item\classes\ItemClass::getShowList($where);
  193. $productList = [];
  194. if (!empty($list)) {
  195. foreach ($list as $key => $item) {
  196. if (!empty($item)) {
  197. $productList = array_merge($productList, $item);
  198. }
  199. }
  200. }
  201. util::success(['list' => $list, 'productList' => $productList]);
  202. }
  203. public function actionAdd()
  204. {
  205. util::fail('开发中');
  206. }
  207. public function actionBatchAdd()
  208. {
  209. util::fail('开发中');
  210. }
  211. public function actionDelete()
  212. {
  213. util::fail('不能删除哦!');
  214. }
  215. //获取平台里的花材信息
  216. public function actionPlatformItem()
  217. {
  218. $py = Yii::$app->request->get('py', '');
  219. $where = [];
  220. if ($py) {
  221. $where = ['py' => $py];
  222. }
  223. $list = PtItemClass::getItemList($where);
  224. util::success($list);
  225. }
  226. }