ItemController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. } elseif ($requestType == 'part') {
  72. $where['delStatus'] = 0;
  73. $where['status'] = 1;
  74. } else {
  75. util::fail('没有定义的请求方式');
  76. }
  77. if (!empty($search)) {
  78. if (stringUtil::isLetter($search)) {
  79. $search = strtolower($search);
  80. $where['py'] = ['like', $search];
  81. } else {
  82. $where['name'] = ['like', $search];
  83. }
  84. } else {
  85. if (!empty($classId)) {
  86. if ($classId == -1) {
  87. $where['discountPrice>'] = 0;
  88. } elseif ($classId == -2) {
  89. $where['reachNum>'] = 0;
  90. } elseif ($classId == -3) {
  91. $where['presell'] = 1;
  92. } else {
  93. $where['classId'] = $classId;
  94. }
  95. }
  96. }
  97. $customId = $get['customId'] ?? 0;
  98. $custom = CustomClass::getById($customId, true);
  99. if (!empty($custom)) {
  100. if ($custom->shopId != $this->shopId) {
  101. util::fail('不是你的客户哦,编号55236');
  102. }
  103. }
  104. $level = $custom->level ?? 1;
  105. $field = '*';
  106. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  107. $list = $result['list'] ?? [];
  108. if ($requestType == 'kd') {
  109. $list = ProductClass::kdItemGroup($list, $level);
  110. } elseif ($requestType == 'itemList') {
  111. $list = ProductClass::itemListGroup($list, $level);
  112. } elseif ($requestType == 'changePrice') {
  113. $list = ProductClass::changePriceGroup($list, $level);
  114. } elseif ($requestType == 'break') {
  115. $list = ProductClass::breakItemGroup($list, $level);
  116. } elseif ($requestType == 'part') {
  117. $list = ProductClass::partItemGroup($list, $level);
  118. } elseif ($requestType == 'check') {
  119. $list = ProductClass::checkItemGroup($list, $level);
  120. } elseif ($requestType == 'changeStock') {
  121. $list = ProductClass::changeStockGroup($list, $level);
  122. } elseif ($requestType == 'stockOut') {
  123. $list = ProductClass::stockOutGroup($list, $level);
  124. } else {
  125. util::fail('没有数据');
  126. }
  127. $result['list'] = $list;
  128. util::success($result);
  129. }
  130. //增加和减少半扎 ssh 20250417
  131. public function actionChangeHalf()
  132. {
  133. util::fail('此功能已停用');
  134. $post = Yii::$app->request->post();
  135. $productId = $post['productId'] ?? '';
  136. $add = $post['add'] ?? 0;
  137. $remark = $post['remark'] ?? '';
  138. $product = ProductClass::getLockById($productId);
  139. if (empty($product)) {
  140. util::fail('没有找到花材');
  141. }
  142. if ($product->mainId != $this->mainId) {
  143. util::fail('不是你的花材');
  144. }
  145. if ($product->ratioType == 1) {
  146. util::fail('若干扎的花材不能减半份');
  147. }
  148. //避免重复提交
  149. util::checkRepeatCommit($this->adminId, 4);
  150. $connection = Yii::$app->db;
  151. $transaction = $connection->beginTransaction();
  152. try {
  153. $shop = $this->shop;
  154. $staff = $this->shopAdmin;
  155. $staffName = $staff->name ?? '';
  156. $staffId = $staff->id;
  157. $adminId = $this->adminId;
  158. $params = [
  159. 'staffId' => $staffId,
  160. 'staffName' => $staffName,
  161. 'adminId' => $adminId,
  162. 'remark' => $remark,
  163. ];
  164. ItemClass::modifyHalf($shop, $product, $params, $add);
  165. $product = ProductClass::getLockById($productId);
  166. $stock = $product->stock;
  167. $stock = floatval($stock);
  168. $transaction->commit();
  169. util::success(['stock' => $stock]);
  170. } catch (\Exception $e) {
  171. $transaction->rollBack();
  172. Yii::info("加减半份失败原因:" . $e->getMessage());
  173. util::fail('加减半份失败');
  174. }
  175. }
  176. //检测是否要刷新
  177. public function actionCheckRefresh()
  178. {
  179. $mainId = $this->mainId;
  180. $staffId = $this->shopAdminId;
  181. $respond = Yii::$app->redis->executeCommand('GET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  182. if ($respond == 'yes') {
  183. util::success(['remind' => 1]);
  184. }
  185. util::complete();
  186. }
  187. //列出所有花材,包括特价花材列表 ssh 20220315
  188. public function actionShowList()
  189. {
  190. $headers = Yii::$app->getRequest()->getHeaders();
  191. $requestVersion = $headers->get('appVersion');
  192. $currentVersion = dict::getDict('appVersion');
  193. if ($requestVersion < $currentVersion) {
  194. util::fail('请先升级系统');
  195. }
  196. $get = Yii::$app->request->get();
  197. $isCashier = $get['isCashier'] ?? 0;
  198. $mainId = $this->mainId;
  199. if ($isCashier == 1) {
  200. //去掉收银台提示价格更新
  201. $staffId = $this->shopAdminId;
  202. Yii::$app->redis->executeCommand('DEL', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  203. }
  204. $where['mainId'] = $mainId;
  205. $where['delStatus'] = 0;
  206. $where['status'] = 1;
  207. $list = \bizHd\item\classes\ItemClass::getShowList($where);
  208. $productList = [];
  209. if (!empty($list)) {
  210. foreach ($list as $key => $item) {
  211. if (!empty($item)) {
  212. $productList = array_merge($productList, $item);
  213. }
  214. }
  215. }
  216. util::success(['list' => $list, 'productList' => $productList]);
  217. }
  218. public function actionAdd()
  219. {
  220. util::fail('开发中');
  221. }
  222. public function actionBatchAdd()
  223. {
  224. util::fail('开发中');
  225. }
  226. public function actionDelete()
  227. {
  228. util::fail('不能删除哦!');
  229. }
  230. //获取平台里的花材信息
  231. public function actionPlatformItem()
  232. {
  233. $py = Yii::$app->request->get('py', '');
  234. $where = [];
  235. if ($py) {
  236. $where = ['py' => $py];
  237. }
  238. $list = PtItemClass::getItemList($where);
  239. util::success($list);
  240. }
  241. }