ItemController.php 8.0 KB

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