ItemController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\miniUtil;
  12. use common\components\stringUtil;
  13. use common\components\util;
  14. use Yii;
  15. class ItemController extends BaseController
  16. {
  17. //列出所有花材 ssh 20240222
  18. public function actionGetItemList()
  19. {
  20. $get = Yii::$app->request->get();
  21. $search = $get['search'] ?? '';
  22. $requestType = $get['requestType'] ?? 'kd';
  23. $classId = $get['classId'] ?? 0;
  24. $lookStock = $get['lookStock'] ?? 0;
  25. $where['mainId'] = $this->mainId;
  26. if ($requestType == 'kd') {
  27. $where['delStatus'] = 0;
  28. $where['status'] = 1;
  29. } elseif ($requestType == 'itemList') {
  30. $where['delStatus'] = 0;
  31. if ($lookStock == 1) {
  32. $where['stock>'] = 0;
  33. }
  34. if ($lookStock == 2) {
  35. $where['stock'] = 0;
  36. }
  37. unset($where['status']);
  38. } elseif ($requestType == 'changePrice') {
  39. $where['delStatus'] = 0;
  40. $where['stock>'] = 0;
  41. } elseif ($requestType == 'hasStockList') {
  42. $where['delStatus'] = 0;
  43. $where['stock>'] = 0;
  44. } elseif ($requestType == 'book') {
  45. $where['delStatus'] = 0;
  46. unset($where['status']);
  47. } elseif ($requestType == 'outList') {
  48. $where['delStatus'] = 0;
  49. $where['status'] = 2;
  50. $where['removeStatus'] = 0;
  51. } elseif ($requestType == 'stopList') {
  52. $where['delStatus'] = 1;
  53. unset($where['status']);
  54. $where['removeStatus'] = 0;
  55. } elseif ($requestType == 'removeList') {
  56. $where['delStatus'] = 1;
  57. unset($where['status']);
  58. $where['removeStatus'] = 1;
  59. } elseif ($requestType == 'cg') {
  60. $where['delStatus'] = 0;
  61. unset($where['status']);
  62. } elseif ($requestType == 'changeStock') {
  63. $where['delStatus'] = 0;
  64. unset($where['status']);
  65. } elseif ($requestType == 'check') {
  66. $where['delStatus'] = 0;
  67. unset($where['status']);
  68. } elseif ($requestType == 'stockOut') {
  69. $where['delStatus'] = 0;
  70. $where['status'] = 1;
  71. } elseif ($requestType == 'break') {
  72. $where['delStatus'] = 0;
  73. $where['status'] = 1;
  74. } elseif ($requestType == 'part') {
  75. $where['delStatus'] = 0;
  76. $where['status'] = 1;
  77. } else {
  78. util::fail('没有定义的请求方式');
  79. }
  80. if (!empty($search)) {
  81. if (stringUtil::isLetter($search)) {
  82. $search = strtolower($search);
  83. $where['py'] = ['like', $search];
  84. } else {
  85. $where['name'] = ['like', $search];
  86. }
  87. } else {
  88. if (!empty($classId)) {
  89. if ($classId == -1) {
  90. $where['discountPrice>'] = 0;
  91. } elseif ($classId == -2) {
  92. $where['reachNum>'] = 0;
  93. } elseif ($classId == -3) {
  94. $where['presell'] = 1;
  95. } else {
  96. $where['classId'] = $classId;
  97. }
  98. }
  99. }
  100. $customId = $get['customId'] ?? 0;
  101. $custom = CustomClass::getById($customId, true);
  102. if (!empty($custom)) {
  103. if ($custom->shopId != $this->shopId) {
  104. util::fail('不是你的客户哦,编号55236');
  105. }
  106. }
  107. $level = $custom->level ?? 1;
  108. $field = '*';
  109. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  110. $list = $result['list'] ?? [];
  111. if ($requestType == 'kd') {
  112. $list = ProductClass::kdItemGroup($list, $level);
  113. } elseif ($requestType == 'itemList') {
  114. $list = ProductClass::itemListGroup($list, $level);
  115. } elseif ($requestType == 'changePrice') {
  116. $list = ProductClass::changePriceGroup($list, $level);
  117. } elseif ($requestType == 'break') {
  118. $list = ProductClass::breakItemGroup($list, $level);
  119. } elseif ($requestType == 'part') {
  120. $list = ProductClass::partItemGroup($list, $level);
  121. } elseif ($requestType == 'check') {
  122. $list = ProductClass::checkItemGroup($list, $level);
  123. } elseif ($requestType == 'changeStock') {
  124. $list = ProductClass::changeStockGroup($list, $level);
  125. } elseif ($requestType == 'stockOut') {
  126. $list = ProductClass::stockOutGroup($list, $level);
  127. } else {
  128. util::fail('没有数据');
  129. }
  130. $result['list'] = $list;
  131. util::success($result);
  132. }
  133. //增加和减少半扎 ssh 20250417
  134. public function actionChangeHalf()
  135. {
  136. util::fail('此功能已停用');
  137. $post = Yii::$app->request->post();
  138. $productId = $post['productId'] ?? '';
  139. $add = $post['add'] ?? 0;
  140. $remark = $post['remark'] ?? '';
  141. $product = ProductClass::getLockById($productId);
  142. if (empty($product)) {
  143. util::fail('没有找到花材');
  144. }
  145. if ($product->mainId != $this->mainId) {
  146. util::fail('不是你的花材');
  147. }
  148. if ($product->ratioType == 1) {
  149. util::fail('若干扎的花材不能减半份');
  150. }
  151. //避免重复提交
  152. util::checkRepeatCommit($this->adminId, 4);
  153. $connection = Yii::$app->db;
  154. $transaction = $connection->beginTransaction();
  155. try {
  156. $shop = $this->shop;
  157. $staff = $this->shopAdmin;
  158. $staffName = $staff->name ?? '';
  159. $staffId = $staff->id;
  160. $adminId = $this->adminId;
  161. $params = [
  162. 'staffId' => $staffId,
  163. 'staffName' => $staffName,
  164. 'adminId' => $adminId,
  165. 'remark' => $remark,
  166. ];
  167. ItemClass::modifyHalf($shop, $product, $params, $add);
  168. $product = ProductClass::getLockById($productId);
  169. $stock = $product->stock;
  170. $stock = floatval($stock);
  171. $transaction->commit();
  172. util::success(['stock' => $stock]);
  173. } catch (\Exception $e) {
  174. $transaction->rollBack();
  175. Yii::info("加减半份失败原因:" . $e->getMessage());
  176. util::fail('加减半份失败');
  177. }
  178. }
  179. //检测是否要刷新
  180. public function actionCheckRefresh()
  181. {
  182. $mainId = $this->mainId;
  183. $staffId = $this->shopAdminId;
  184. $respond = Yii::$app->redis->executeCommand('GET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  185. if ($respond == 'yes') {
  186. util::success(['remind' => 1]);
  187. }
  188. util::complete();
  189. }
  190. //列出所有花材,包括特价花材列表 ssh 20220315
  191. public function actionShowList()
  192. {
  193. $headers = Yii::$app->getRequest()->getHeaders();
  194. $requestVersion = $headers->get('appVersion');
  195. $currentVersion = dict::getDict('appVersion');
  196. if ($requestVersion < $currentVersion) {
  197. util::fail('请先升级系统');
  198. }
  199. $get = Yii::$app->request->get();
  200. $isCashier = $get['isCashier'] ?? 0;
  201. $mainId = $this->mainId;
  202. if ($isCashier == 1) {
  203. //去掉收银台提示价格更新
  204. $staffId = $this->shopAdminId;
  205. Yii::$app->redis->executeCommand('DEL', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  206. }
  207. $where['mainId'] = $mainId;
  208. $where['delStatus'] = 0;
  209. $where['status'] = 1;
  210. $list = \bizHd\item\classes\ItemClass::getShowList($where);
  211. $productList = [];
  212. if (!empty($list)) {
  213. foreach ($list as $key => $item) {
  214. if (!empty($item)) {
  215. $productList = array_merge($productList, $item);
  216. }
  217. }
  218. }
  219. util::success(['list' => $list, 'productList' => $productList]);
  220. }
  221. public function actionAdd()
  222. {
  223. util::fail('开发中');
  224. }
  225. public function actionBatchAdd()
  226. {
  227. util::fail('开发中');
  228. }
  229. public function actionDelete()
  230. {
  231. util::fail('不能删除哦!');
  232. }
  233. //获取平台里的花材信息
  234. public function actionPlatformItem()
  235. {
  236. $py = Yii::$app->request->get('py', '');
  237. $where = [];
  238. if ($py) {
  239. $where = ['py' => $py];
  240. }
  241. $list = PtItemClass::getItemList($where);
  242. util::success($list);
  243. }
  244. //获取给散客下单的花材海报 ssh 20220111
  245. public function actionGetPoster()
  246. {
  247. $get = Yii::$app->request->get();
  248. $id = $get['id'] ?? 0;
  249. $item = ItemClass::getById($id, true);
  250. if (empty($item) || $item->mainId != $this->mainId) {
  251. util::fail('获取失败');
  252. }
  253. $cover = $item->cover ?? '';
  254. if (empty($cover)) {
  255. util::fail('获取失败');
  256. }
  257. $merchant = WxOpenClass::getMallWxInfo();
  258. $page = 'pages/item/detail';
  259. $ptStyle = dict::getDict('ptStyle', 'mall');
  260. $shop = $this->shop;
  261. $shopId = $shop->id ?? 0;
  262. //scene不能超过32个字条
  263. $scene = "id=" . $id . '&a=' . $shopId;
  264. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  265. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  266. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  267. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  268. $prefix = imgUtil::getPrefix();
  269. $price = $item->skPrice ?? 0;
  270. if ($item->discountPrice > 0) {
  271. $skMore = $item->skMore ?? 0;
  272. $price = bcadd($item->discountPrice, $skMore, 2);
  273. }
  274. $newPrice = '¥' . floatval($price);
  275. $priceBase64 = stringUtil::ossBase64($newPrice);
  276. $name = $item->name ?? '';
  277. $nameBase64 = stringUtil::ossBase64($name);
  278. $staff = $this->shopAdmin;
  279. $staffName = $staff->name ?? '';
  280. $newStaffName = $staffName . ' 为您推荐';
  281. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  282. //花材主图
  283. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  284. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  285. $logoBase64 = '';
  286. if (in_array($this->mainId, [52, 1459, 13495])) {
  287. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  288. if ($this->mainId == 1459) {
  289. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  290. }
  291. if ($this->mainId == 13495) {
  292. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  293. }
  294. $logoBase64 = stringUtil::ossBase64($logo);
  295. }
  296. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  297. //花材主图
  298. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  299. //小程序码
  300. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  301. if (!empty($logoBase64)) {
  302. //logo
  303. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  304. }
  305. //为你推荐
  306. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  307. //标题
  308. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  309. //价格
  310. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  311. $respond = ['imgUrl' => $url];
  312. util::success($respond);
  313. }
  314. }