OrderItemController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\book\classes\BookCustomClass;
  4. use bizGhs\book\classes\BookItemClass;
  5. use bizGhs\book\classes\BookItemCustomClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\order\classes\OrderClass;
  8. use bizGhs\order\classes\OrderItemClass;
  9. use bizGhs\order\classes\OrderTreeClass;
  10. use bizGhs\order\services\OrderItemService;
  11. use bizGhs\order\services\OrderService;
  12. use bizGhs\product\classes\ProductClass;
  13. use common\components\imgUtil;
  14. use common\components\util;
  15. use Yii;
  16. class OrderItemController extends BaseController
  17. {
  18. public $guestAccess = [];
  19. //针式打印 筛数
  20. public function actionPrintTreePin()
  21. {
  22. $get = Yii::$app->request->get();
  23. $id = $get['id'] ?? 0;
  24. $orderItem = OrderItemClass::getById($id, true);
  25. if (empty($orderItem)) {
  26. util::fail('没有找到');
  27. }
  28. if ($orderItem->kind != 2) {
  29. util::fail('不需要打印');
  30. }
  31. $orderSn = $orderItem->orderSn ?? '';
  32. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  33. if (empty($order)) {
  34. util::fail('没有找到订单');
  35. }
  36. if ($order->mainId != $this->mainId) {
  37. util::fail('不是你的订单哦!');
  38. }
  39. $customId = $order->customId ?? '';
  40. $custom = CustomClass::getById($customId, true);
  41. $customName = $custom->name ?? '';
  42. $productId = $orderItem->productId ?? '';
  43. $productName = $orderItem->name ?? '';
  44. $dishNum = $orderItem->dishNum ?? 0;
  45. $itemNum = $orderItem->num ?? 0;
  46. $itemNum = floatval($itemNum);
  47. $treeList = OrderTreeClass::getAllByCondition(['orderSn' => $orderSn, 'productId' => $productId], 'id asc', '*');
  48. if (empty($treeList)) {
  49. util::fail('没有需要打印');
  50. }
  51. $table = [];
  52. $numList = array_column($treeList, 'num');
  53. foreach (array_chunk($numList, 10) as $numChunk) {
  54. $row = [];
  55. for ($i = 1; $i <= 10; $i++) {
  56. $row['num' . $i] = $numChunk[$i - 1] ?? '';
  57. }
  58. $table[] = $row;
  59. }
  60. $shop = $this->shop;
  61. $sjName = $shop->merchantName ?? '';
  62. $shopName = $shop->shopName ?? '';
  63. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  64. $printData = [
  65. 'table' => $table,
  66. 'staffName' => '',
  67. 'orderSn' => $orderSn,
  68. 'customName' => $customName,
  69. 'sjShopName' => $sjShopName . ' 销售单',
  70. 'productName' => $productName,
  71. 'dishNum' => $dishNum,
  72. 'itemNum' => $itemNum,
  73. ];
  74. $info = [];
  75. $info['printData'] = $printData;
  76. $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":49.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName","testData":"小向花卉 采购单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":424.5,"top":21,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":568.75,"bottom":43.5,"vCenter":496.25,"hCenter":33,"fontFamily":"SimSun","textAlign":"right"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":55,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","tableHeaderRepeat":"none","tableBorder":"noBorder","tableHeaderBorder":"noBorder","tableHeaderCellBorder":"noBorder","columns":[[{"width":56.70171229595743,"title":"","field":"num1","checked":true,"columnId":"num1","fixed":false,"rowspan":1,"colspan":1},{"width":59.07977608328001,"title":"","field":"num2","checked":true,"columnId":"num2","fixed":false,"rowspan":1,"colspan":1},{"width":57.094134615384505,"title":"","field":"num3","checked":true,"columnId":"num3","fixed":false,"rowspan":1,"colspan":1},{"width":52.07663313609472,"title":"","field":"num4","checked":true,"columnId":"num4","fixed":false,"rowspan":1,"colspan":1},{"width":57.083112653618585,"title":"","field":"num5","checked":true,"columnId":"num5","fixed":false,"rowspan":1,"colspan":1},{"width":53.10106937445619,"title":"","field":"num6","checked":true,"columnId":"num6","fixed":false,"rowspan":1,"colspan":1},{"width":56.05950964586556,"title":"","field":"num7","checked":true,"columnId":"num7","fixed":false,"rowspan":1,"colspan":1},{"width":47.09117873148696,"title":"","field":"num8","checked":true,"columnId":"num8","fixed":false,"rowspan":1,"colspan":1},{"width":54.07419941532827,"title":"","field":"num9","checked":true,"columnId":"num9","fixed":false,"rowspan":1,"colspan":1},{"width":57.63867404852769,"title":"","field":"num9","checked":true,"columnId":"num9","fixed":false,"rowspan":1,"colspan":1},{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":false,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":false,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":false,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":false,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":false,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":false,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":false,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":256.5,"top":112.5,"height":16,"width":178,"title":"客户","field":"customName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":12.75,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":428.5,"bottom":127.75,"vCenter":339.5,"hCenter":119.75},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":424.5,"top":112.5,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":12.75,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571,"bottom":128.5,"vCenter":497,"hCenter":120.5},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":25.5,"height":16,"width":143,"title":"名称","field":"productName","testData":"高原红","coordinateSync":false,"widthHeightSync":false,"fontFamily":"STHeitiSC-Light","fontSize":12.75,"fontWeight":"bold","qrCodeLevel":0,"right":141.75,"bottom":36,"vCenter":81.75,"hCenter":31.125},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":106.5,"top":111,"height":14,"width":112,"title":"株数","field":"itemNum","testData":"200","coordinateSync":false,"widthHeightSync":false,"fontSize":12.75,"textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":22.5,"top":111,"height":15,"width":85,"title":"筛数","field":"dishNum","testData":"3","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"qrCodeLevel":0,"right":108.25,"bottom":126,"vCenter":65.75,"hCenter":118.5},"printElementType":{"title":"这是更新后的元素","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  77. $info['template'] = $template;
  78. util::success($info);
  79. }
  80. public function actionPrintItemWlLabel()
  81. {
  82. $get = Yii::$app->request->get();
  83. $orderSn = $get['orderSn'] ?? '';
  84. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  85. if (empty($order)) {
  86. util::fail('没有找到订单');
  87. }
  88. if ($order->mainId != $this->mainId) {
  89. util::fail('不是你的订单');
  90. }
  91. $id = $get['id'] ?? 0;
  92. $orderItem = OrderItemClass::getById($id, true);
  93. if (empty($orderItem)) {
  94. util::fail('没有花材信息');
  95. }
  96. if (empty($orderItem->productId)) {
  97. util::fail('花材信息缺失');
  98. }
  99. $productId = $orderItem->productId;
  100. if ($orderItem->orderSn != $orderSn) {
  101. util::fail('你不能操作');
  102. }
  103. $product = ProductClass::getById($productId, true);
  104. if (empty($product)) {
  105. util::fail('花材信息没有找到');
  106. }
  107. $shop = $this->shop;
  108. $ext = $this->shopExt;
  109. $num = $get['num'] ?? 0;
  110. if ($num <= 0) {
  111. util::fail('请填写数量');
  112. }
  113. $boxNum = $get['boxNum'] ?? 0;
  114. if ($boxNum <= 0) {
  115. util::fail('请填写装箱数');
  116. }
  117. OrderClass::printItemLabel($order, $shop, $ext, $product, $num, $boxNum, $orderItem);
  118. util::complete('打印成功');
  119. }
  120. //过滤名称 ssh 20240430
  121. public function actionFilterName()
  122. {
  123. $get = Yii::$app->request->get();
  124. $id = $get['id'] ?? 0;
  125. $info = OrderItemClass::getById($id, true);
  126. $name = $info->name ?? '';
  127. $num = $info->xhNum ?? 0;
  128. $name = strtolower($name);
  129. $name = preg_replace('/\d/', '', $name);
  130. $arr = ['cm', '箱', '个', 'a', 'b', 'c', 'd', 'e', 'o', '梦金鹏', '拍市', '七彩', '市场', '(', ')', '(', ')', '-', '级', '红', '黄', '绿', '橙', '蓝', '基地', '支', '枝', '*', '张良', '配色', '混色', '浅粉', '粉', '玫红', '青铜', '深紫', '浅紫', '紫', '色', '重瓣', ' ', ' '];
  131. foreach ($arr as $it) {
  132. $name = str_replace($it, '', $name);
  133. }
  134. util::success(['name' => $name, 'num' => $num]);
  135. }
  136. //修改预订单花材的数量和价格
  137. public function actionModifyBookItem()
  138. {
  139. $post = Yii::$app->request->post();
  140. $id = $post['id'] ?? 0;
  141. $data = $post['data'] ?? [];
  142. $packCost = $post['packCost'] ?? 0;
  143. $sendCost = $post['sendCost'] ?? 0;
  144. if (empty($data)) {
  145. util::fail('没有花材数据');
  146. }
  147. $order = OrderClass::getById($id, true);
  148. if (empty($order)) {
  149. util::fail('没有订单');
  150. }
  151. if ($order->mainId != $this->mainId) {
  152. util::fail('不是你的订单哦');
  153. }
  154. if ($order->stockChange == 1) {
  155. util::fail('已经入库,不能修改');
  156. }
  157. if ($order->status != 2) {
  158. util::fail('待发货订单才能修改');
  159. }
  160. $connection = Yii::$app->db;
  161. $transaction = $connection->beginTransaction();
  162. try {
  163. $addData = [];
  164. $delData = [];
  165. foreach ($data as $item) {
  166. $id = $item['id'] ?? 0;
  167. $xhNum = $item['xhNum'] ?? 0;
  168. $xhUnitPrice = $item['xhUnitPrice'] ?? 0;
  169. $info = OrderItemClass::getById($id, true);
  170. if (empty($info)) {
  171. continue;
  172. }
  173. if ($info->orderSn != $order->orderSn) {
  174. continue;
  175. }
  176. $productId = $info->productId ?? 0;
  177. $preNum = $info->xhNum ?? 0;
  178. //新增预订花材
  179. if ($xhNum > $preNum) {
  180. $diffNum = bcsub($xhNum, $preNum);
  181. $addData[] = [
  182. 'productId' => $productId,
  183. 'num' => $diffNum,
  184. 'lastNum' => $xhNum,
  185. ];
  186. }
  187. //删除预订花材
  188. if ($preNum > $xhNum) {
  189. $diffNum = bcsub($preNum, $xhNum);
  190. $delData[] = [
  191. 'productId' => $productId,
  192. 'num' => $diffNum,
  193. 'lastNum' => $xhNum,
  194. ];
  195. }
  196. $info->xhNum = $xhNum;
  197. $info->xhPreNum = $xhNum;
  198. $info->xhUnitPrice = $xhUnitPrice;
  199. $info->xhPreUnitPrice = $xhUnitPrice;
  200. $info->save();
  201. }
  202. $order->packCost = $packCost;
  203. $order->sendCost = $sendCost;
  204. $order->save();
  205. $staff = $this->shopAdmin;
  206. $staffId = $staff->id ?? 0;
  207. $staffName = $staff->name ?? '';
  208. $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
  209. if (!empty($addData)) {
  210. BookItemClass::addBatchItem($addData, $order, $params);
  211. }
  212. if (!empty($delData)) {
  213. BookItemClass::delBathItem($delData, $order, $params);
  214. }
  215. $transaction->commit();
  216. util::complete('保存成功');
  217. } catch (\Exception $e) {
  218. $transaction->rollBack();
  219. Yii::info("保存出错了:" . $e->getMessage());
  220. util::fail('保存出错了');
  221. }
  222. }
  223. //更换花材 ssh 20240430
  224. public function actionChangeItem()
  225. {
  226. $post = Yii::$app->request->post();
  227. $delId = $post['delId'] ?? 0;
  228. $orderSn = $post['orderSn'] ?? '';
  229. $num = $post['num'] ?? 0;
  230. $price = $post['price'] ?? 0;
  231. $productId = $post['productId'] ?? 0;
  232. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  233. if (empty($order)) {
  234. util::fail('订单没有找到哦');
  235. }
  236. if ($order->mainId != $this->mainId) {
  237. util::fail('不是你的订单');
  238. }
  239. $delInfo = OrderItemClass::getById($delId, true);
  240. if (empty($delInfo)) {
  241. util::fail('没有找到要删除的花材');
  242. }
  243. if ($delInfo->orderSn != $orderSn) {
  244. util::fail('这个花材你不能删除');
  245. }
  246. $connection = Yii::$app->db;
  247. $transaction = $connection->beginTransaction();
  248. try {
  249. OrderItemClass::delBookItem($order, $delId);
  250. $new = [];
  251. $new[$productId] = ['num' => $num, 'productId' => $productId, 'price' => $price];
  252. OrderItemClass::addBookItemFn($order, $new);
  253. $transaction->commit();
  254. util::complete('更换成功');
  255. } catch (\Exception $e) {
  256. $transaction->rollBack();
  257. Yii::info("出错了:" . $e->getMessage());
  258. util::fail('出错了');
  259. }
  260. }
  261. //删除花材 ssh 20240123
  262. public function actionDelItem()
  263. {
  264. $post = Yii::$app->request->post();
  265. $id = $post['id'] ?? 0;
  266. $smallId = $post['smallId'] ?? 0;
  267. $order = OrderClass::getById($id, true);
  268. if (empty($order)) {
  269. util::fail('没有订单');
  270. }
  271. if ($order->status != 2) {
  272. util::fail('待发货才能添加');
  273. }
  274. if ($order->book == 0) {
  275. util::fail('不是预订单');
  276. }
  277. if ($order->mainId != $this->mainId) {
  278. util::fail('不是你的订单');
  279. }
  280. if (floatval($order->actPrice) != 0) {
  281. util::fail('订单金额不是0');
  282. }
  283. $connection = Yii::$app->db;
  284. $transaction = $connection->beginTransaction();
  285. try {
  286. $staff = $this->shopAdmin;
  287. $staffId = $staff->id ?? 0;
  288. $staffName = $staff->name ?? '';
  289. $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
  290. OrderItemClass::delBookItem($order, $smallId, $params);
  291. $transaction->commit();
  292. util::complete('删除成功');
  293. } catch (\Exception $e) {
  294. $transaction->rollBack();
  295. Yii::info("删除出错了:" . $e->getMessage());
  296. util::fail('删除出错了');
  297. }
  298. }
  299. //添加花材
  300. public function actionAddItem()
  301. {
  302. $post = Yii::$app->request->post();
  303. $id = $post['id'] ?? 0;
  304. $data = $post['data'] ?? 0;
  305. $arr = json_decode($data, true);
  306. $order = OrderClass::getById($id, true);
  307. if (empty($order)) {
  308. util::fail('没有订单');
  309. }
  310. if ($order->status != 2) {
  311. util::fail('待发货才能添加');
  312. }
  313. if ($order->book == 0) {
  314. util::fail('不是预订单');
  315. }
  316. if (floatval($order->actPrice) != 0) {
  317. util::fail('订单金额不是0');
  318. }
  319. if (empty($arr)) {
  320. util::fail('请选花材');
  321. }
  322. $new = [];
  323. foreach ($arr as $val) {
  324. $id = $val['id'] ?? 0;
  325. $num = $val['bigCount'] ?? 0;
  326. $name = $val['name'] ?? '';
  327. $price = $val['price'] ?? 0;
  328. if ($num <= 0) {
  329. util::fail($name . ' 数量要大于0');
  330. }
  331. $new[$id] = ['num' => $num, 'productId' => $id, 'price' => $price];
  332. }
  333. $connection = Yii::$app->db;
  334. $transaction = $connection->beginTransaction();
  335. try {
  336. $staff = $this->shopAdmin;
  337. $staffId = $staff->id ?? 0;
  338. $staffName = $staff->name ?? '';
  339. $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
  340. OrderItemClass::addBookItemFn($order, $new, $params);
  341. $transaction->commit();
  342. util::complete('添加成功');
  343. } catch (\Exception $e) {
  344. $transaction->rollBack();
  345. Yii::info("添加出错了:" . $e->getMessage());
  346. util::fail('添加出错了');
  347. }
  348. }
  349. //赠送花材 ssh 20230411
  350. public function actionGiveItem()
  351. {
  352. $post = Yii::$app->request->post();
  353. $id = $post['id'] ?? 0;
  354. $num = $post['num'] ?? 0;
  355. if (is_numeric($num) == false || $num <= 0) {
  356. util::fail('请填写赠送数量');
  357. }
  358. $orderItem = OrderItemClass::getById($id, true);
  359. if (empty($orderItem)) {
  360. util::fail('没有找到花材');
  361. }
  362. if ($orderItem->mainId != $this->mainId) {
  363. util::fail('无法操作');
  364. }
  365. if (!in_array($this->mainId, [1496])) {
  366. util::fail('开发中');
  367. }
  368. $connection = Yii::$app->db;
  369. $transaction = $connection->beginTransaction();
  370. try {
  371. $staff = $this->shopAdmin;
  372. $staffName = $staff->name ?? '';
  373. $staffId = $staff->id ?? 0;
  374. $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId];
  375. $respond = OrderItemService::giveProduct($data, $orderItem, $num);
  376. $transaction->commit();
  377. util::success(['info' => $respond], '赠送成功');
  378. } catch (\Exception $e) {
  379. $transaction->rollBack();
  380. Yii::info("赠送出错了:" . $e->getMessage());
  381. util::fail('出错了');
  382. }
  383. }
  384. //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
  385. public function actionGetOrderProduct()
  386. {
  387. $id = Yii::$app->request->get('id', 0);
  388. $order = OrderClass::getById($id, true);
  389. OrderClass::valid($order, $this->shopId);
  390. $orderSn = $order->orderSn ?? '';
  391. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
  392. $ids = array_column($itemList, 'productId');
  393. if (empty($ids)) {
  394. util::fail('没有找到花材');
  395. }
  396. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  397. if (empty($productList)) {
  398. util::fail('没有找到花材信息');
  399. }
  400. foreach ($productList as $key => $product) {
  401. $productId = $product['id'] ?? 0;
  402. $currentItem = $itemList[$productId] ?? [];
  403. $bigCount = $currentItem['bigNum'] ?? 0;
  404. $smallCount = $currentItem['smallNum'] ?? 0;
  405. $userPrice = $currentItem['userPrice'] ?? 0;
  406. $productList[$key]['bigCount'] = $bigCount;
  407. $productList[$key]['smallCount'] = $smallCount;
  408. $productList[$key]['userPrice'] = $userPrice;
  409. $cover = imgUtil::groupImg($product['cover']);
  410. $productList[$key]['cover'] = $cover;
  411. $bigPrice = $product['unitPrice'] ?? 0;
  412. $smallPrice = $product['smallUnitPrice'] ?? 0;
  413. $productList[$key]['bigPrice'] = $bigPrice;
  414. $productList[$key]['smallPrice'] = $smallPrice;
  415. $productList[$key]['cover'] = $cover;
  416. }
  417. util::success(['productList' => array_values($productList)]);
  418. }
  419. //根据花材id取订单列表 ssh 20211011
  420. public function actionGetOrderInfoList()
  421. {
  422. $get = Yii::$app->request->get();
  423. $productId = $get['productId'] ?? 0;
  424. $product = ProductClass::getById($productId, true);
  425. ProductClass::check($product, $this->mainId);
  426. $where = ['productId' => $productId];
  427. $respond = OrderItemClass::getOrderInfoList($where);
  428. util::success($respond);
  429. }
  430. //修改花材的备注 ssh 20240514
  431. public function actionUpdateItemRemark()
  432. {
  433. $get = Yii::$app->request->get();
  434. $id = $get['id'] ?? 0;
  435. $remark = $get['remark'] ?? '';
  436. $info = OrderItemClass::getById($id, true);
  437. if (empty($info)) {
  438. util::fail('没有找到');
  439. }
  440. if ($info->mainId != $this->mainId) {
  441. util::fail('不是你的花材');
  442. }
  443. $info->remark = $remark;
  444. $info->save();
  445. $orderSn = $info->orderSn ?? '';
  446. $productId = $info->productId ?? 0;
  447. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  448. if (empty($order)) {
  449. util::fail('没有找订单');
  450. }
  451. $customId = $order->customId ?? 0;
  452. $shop = $this->shop;
  453. $bookSn = $shop->bookSn ?? 0;
  454. if (!empty($bookSn) && !empty($remark)) {
  455. $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $productId], true);
  456. if (!empty($bookItemRes)) {
  457. $bookItemRes->hasRemark = 1;
  458. $bookItemRes->save();
  459. }
  460. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  461. if (!empty($bookCustomRes)) {
  462. $bookCustomRes->hasRemark = 1;
  463. $bookCustomRes->save();
  464. }
  465. $bookItemCustomRes = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $productId], true);
  466. if (!empty($bookItemCustomRes)) {
  467. $bookItemCustomRes->hasRemark = 1;
  468. $bookItemCustomRes->remark = $remark;
  469. $bookItemCustomRes->save();
  470. }
  471. }
  472. util::complete();
  473. }
  474. //下载excel ssh 20241127
  475. public function actionGetDownExcel()
  476. {
  477. $get = Yii::$app->request->get();
  478. $id = $get['id'] ?? 0;
  479. $order = OrderClass::getById($id, true);
  480. if (empty($order)) {
  481. util::fail('没有找到订单');
  482. }
  483. if ($order->mainId != $this->mainId) {
  484. util::fail('不是你的订单');
  485. }
  486. $orderSn = $order->orderSn ?? '';
  487. $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  488. OrderItemClass::exportExcel($order, $list, $this->mainId);
  489. }
  490. }