ItemController.php 8.6 KB

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