OrderItemController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. 'sjShopName2' => $sjShopName,
  71. 'productName' => $productName,
  72. 'dishNum' => $dishNum,
  73. 'itemNum' => $itemNum,
  74. 'saleName'=>'销售单',
  75. ];
  76. $info = [];
  77. $info['printData'] = $printData;
  78. $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":79.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":"sjShopName2","testData":"小向花卉","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":21,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":424.5,"top":25.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":14.25,"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":85,"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":238.5,"top":148.5,"height":16,"width":178,"title":"客户","field":"customName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":16.5,"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":150,"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":28.5,"height":16,"width":143,"title":"名称","field":"productName","testData":"高原红","coordinateSync":false,"widthHeightSync":false,"fontFamily":"STHeitiSC-Light","fontSize":14.25,"fontWeight":"bold","qrCodeLevel":0,"right":141.75,"bottom":36,"vCenter":81.75,"hCenter":31.125},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":106.5,"top":148.5,"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":148.5,"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"}},{"options":{"left":241.5,"top":54,"height":20,"width":120,"title":"文本","field":"saleName","testData":"销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":19.5,"textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":363,"bottom":68,"vCenter":303,"hCenter":58},"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}}]}';
  79. $info['template'] = $template;
  80. util::success($info);
  81. }
  82. public function actionPrintItemWlLabel()
  83. {
  84. $get = Yii::$app->request->get();
  85. $orderSn = $get['orderSn'] ?? '';
  86. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  87. if (empty($order)) {
  88. util::fail('没有找到订单');
  89. }
  90. if ($order->mainId != $this->mainId) {
  91. util::fail('不是你的订单');
  92. }
  93. $id = $get['id'] ?? 0;
  94. $orderItem = OrderItemClass::getById($id, true);
  95. if (empty($orderItem)) {
  96. util::fail('没有花材信息');
  97. }
  98. if (empty($orderItem->productId)) {
  99. util::fail('花材信息缺失');
  100. }
  101. $productId = $orderItem->productId;
  102. if ($orderItem->orderSn != $orderSn) {
  103. util::fail('你不能操作');
  104. }
  105. $product = ProductClass::getById($productId, true);
  106. if (empty($product)) {
  107. util::fail('花材信息没有找到');
  108. }
  109. $shop = $this->shop;
  110. $ext = $this->shopExt;
  111. $num = $get['num'] ?? 0;
  112. if ($num <= 0) {
  113. util::fail('请填写数量');
  114. }
  115. $boxNum = $get['boxNum'] ?? 0;
  116. if ($boxNum <= 0) {
  117. util::fail('请填写装箱数');
  118. }
  119. OrderClass::printItemLabel($order, $shop, $ext, $product, $num, $boxNum, $orderItem);
  120. util::complete('打印成功');
  121. }
  122. //过滤名称 ssh 20240430
  123. public function actionFilterName()
  124. {
  125. $get = Yii::$app->request->get();
  126. $id = $get['id'] ?? 0;
  127. $info = OrderItemClass::getById($id, true);
  128. $name = $info->name ?? '';
  129. $num = $info->xhNum ?? 0;
  130. $name = strtolower($name);
  131. $name = preg_replace('/\d/', '', $name);
  132. $arr = ['cm', '箱', '个', 'a', 'b', 'c', 'd', 'e', 'o', '梦金鹏', '拍市', '七彩', '市场', '(', ')', '(', ')', '-', '级', '红', '黄', '绿', '橙', '蓝', '基地', '支', '枝', '*', '张良', '配色', '混色', '浅粉', '粉', '玫红', '青铜', '深紫', '浅紫', '紫', '色', '重瓣', ' ', ' '];
  133. foreach ($arr as $it) {
  134. $name = str_replace($it, '', $name);
  135. }
  136. util::success(['name' => $name, 'num' => $num]);
  137. }
  138. //修改预订单花材的数量和价格
  139. public function actionModifyBookItem()
  140. {
  141. $post = Yii::$app->request->post();
  142. $id = $post['id'] ?? 0;
  143. $data = $post['data'] ?? [];
  144. $packCost = $post['packCost'] ?? 0;
  145. $sendCost = $post['sendCost'] ?? 0;
  146. if (empty($data)) {
  147. util::fail('没有花材数据');
  148. }
  149. $order = OrderClass::getById($id, true);
  150. if (empty($order)) {
  151. util::fail('没有订单');
  152. }
  153. if ($order->mainId != $this->mainId) {
  154. util::fail('不是你的订单哦');
  155. }
  156. if ($order->stockChange == 1) {
  157. util::fail('已经入库,不能修改');
  158. }
  159. if ($order->status != 2) {
  160. util::fail('待发货订单才能修改');
  161. }
  162. $connection = Yii::$app->db;
  163. $transaction = $connection->beginTransaction();
  164. try {
  165. $addData = [];
  166. $delData = [];
  167. foreach ($data as $item) {
  168. $id = $item['id'] ?? 0;
  169. $xhNum = $item['xhNum'] ?? 0;
  170. $xhUnitPrice = $item['xhUnitPrice'] ?? 0;
  171. $info = OrderItemClass::getById($id, true);
  172. if (empty($info)) {
  173. continue;
  174. }
  175. if ($info->orderSn != $order->orderSn) {
  176. continue;
  177. }
  178. $productId = $info->productId ?? 0;
  179. $preNum = $info->xhNum ?? 0;
  180. //新增预订花材
  181. if ($xhNum > $preNum) {
  182. $diffNum = bcsub($xhNum, $preNum);
  183. $addData[] = [
  184. 'productId' => $productId,
  185. 'num' => $diffNum,
  186. 'lastNum' => $xhNum,
  187. ];
  188. }
  189. //删除预订花材
  190. if ($preNum > $xhNum) {
  191. $diffNum = bcsub($preNum, $xhNum);
  192. $delData[] = [
  193. 'productId' => $productId,
  194. 'num' => $diffNum,
  195. 'lastNum' => $xhNum,
  196. ];
  197. }
  198. $info->xhNum = $xhNum;
  199. $info->xhPreNum = $xhNum;
  200. $info->xhUnitPrice = $xhUnitPrice;
  201. $info->xhPreUnitPrice = $xhUnitPrice;
  202. $info->save();
  203. }
  204. $order->packCost = $packCost;
  205. $order->sendCost = $sendCost;
  206. $order->save();
  207. $staff = $this->shopAdmin;
  208. $staffId = $staff->id ?? 0;
  209. $staffName = $staff->name ?? '';
  210. $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
  211. if (!empty($addData)) {
  212. BookItemClass::addBatchItem($addData, $order, $params);
  213. }
  214. if (!empty($delData)) {
  215. BookItemClass::delBathItem($delData, $order, $params);
  216. }
  217. $transaction->commit();
  218. util::complete('保存成功');
  219. } catch (\Exception $e) {
  220. $transaction->rollBack();
  221. Yii::info("保存出错了:" . $e->getMessage());
  222. util::fail('保存出错了');
  223. }
  224. }
  225. //更换花材 ssh 20240430
  226. public function actionChangeItem()
  227. {
  228. $post = Yii::$app->request->post();
  229. $delId = $post['delId'] ?? 0;
  230. $orderSn = $post['orderSn'] ?? '';
  231. $num = $post['num'] ?? 0;
  232. $price = $post['price'] ?? 0;
  233. $productId = $post['productId'] ?? 0;
  234. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  235. if (empty($order)) {
  236. util::fail('订单没有找到哦');
  237. }
  238. if ($order->mainId != $this->mainId) {
  239. util::fail('不是你的订单');
  240. }
  241. $delInfo = OrderItemClass::getById($delId, true);
  242. if (empty($delInfo)) {
  243. util::fail('没有找到要删除的花材');
  244. }
  245. if ($delInfo->orderSn != $orderSn) {
  246. util::fail('这个花材你不能删除');
  247. }
  248. $connection = Yii::$app->db;
  249. $transaction = $connection->beginTransaction();
  250. try {
  251. OrderItemClass::delBookItem($order, $delId);
  252. $new = [];
  253. $new[$productId] = ['num' => $num, 'productId' => $productId, 'price' => $price];
  254. OrderItemClass::addBookItemFn($order, $new);
  255. $transaction->commit();
  256. util::complete('更换成功');
  257. } catch (\Exception $e) {
  258. $transaction->rollBack();
  259. Yii::info("出错了:" . $e->getMessage());
  260. util::fail('出错了');
  261. }
  262. }
  263. //删除花材 ssh 20240123
  264. public function actionDelItem()
  265. {
  266. $post = Yii::$app->request->post();
  267. $id = $post['id'] ?? 0;
  268. $smallId = $post['smallId'] ?? 0;
  269. $order = OrderClass::getById($id, true);
  270. if (empty($order)) {
  271. util::fail('没有订单');
  272. }
  273. if ($order->status != 2) {
  274. util::fail('待发货才能添加');
  275. }
  276. if ($order->book == 0) {
  277. util::fail('不是预订单');
  278. }
  279. if ($order->mainId != $this->mainId) {
  280. util::fail('不是你的订单');
  281. }
  282. if (floatval($order->actPrice) != 0) {
  283. util::fail('订单金额不是0');
  284. }
  285. $connection = Yii::$app->db;
  286. $transaction = $connection->beginTransaction();
  287. try {
  288. $staff = $this->shopAdmin;
  289. $staffId = $staff->id ?? 0;
  290. $staffName = $staff->name ?? '';
  291. $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
  292. OrderItemClass::delBookItem($order, $smallId, $params);
  293. $transaction->commit();
  294. util::complete('删除成功');
  295. } catch (\Exception $e) {
  296. $transaction->rollBack();
  297. Yii::info("删除出错了:" . $e->getMessage());
  298. util::fail('删除出错了');
  299. }
  300. }
  301. //添加花材
  302. public function actionAddItem()
  303. {
  304. $post = Yii::$app->request->post();
  305. $id = $post['id'] ?? 0;
  306. $data = $post['data'] ?? 0;
  307. $arr = json_decode($data, true);
  308. $order = OrderClass::getById($id, true);
  309. if (empty($order)) {
  310. util::fail('没有订单');
  311. }
  312. if ($order->status != 2) {
  313. util::fail('待发货才能添加');
  314. }
  315. if ($order->book == 0) {
  316. util::fail('不是预订单');
  317. }
  318. if (floatval($order->actPrice) != 0) {
  319. util::fail('订单金额不是0');
  320. }
  321. if (empty($arr)) {
  322. util::fail('请选花材');
  323. }
  324. $new = [];
  325. foreach ($arr as $val) {
  326. $id = $val['id'] ?? 0;
  327. $num = $val['bigCount'] ?? 0;
  328. $name = $val['name'] ?? '';
  329. $price = $val['price'] ?? 0;
  330. if ($num <= 0) {
  331. util::fail($name . ' 数量要大于0');
  332. }
  333. $new[$id] = ['num' => $num, 'productId' => $id, 'price' => $price];
  334. }
  335. $connection = Yii::$app->db;
  336. $transaction = $connection->beginTransaction();
  337. try {
  338. $staff = $this->shopAdmin;
  339. $staffId = $staff->id ?? 0;
  340. $staffName = $staff->name ?? '';
  341. $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
  342. OrderItemClass::addBookItemFn($order, $new, $params);
  343. $transaction->commit();
  344. util::complete('添加成功');
  345. } catch (\Exception $e) {
  346. $transaction->rollBack();
  347. Yii::info("添加出错了:" . $e->getMessage());
  348. util::fail('添加出错了');
  349. }
  350. }
  351. //赠送花材 ssh 20230411
  352. public function actionGiveItem()
  353. {
  354. $post = Yii::$app->request->post();
  355. $id = $post['id'] ?? 0;
  356. $num = $post['num'] ?? 0;
  357. if (is_numeric($num) == false || $num <= 0) {
  358. util::fail('请填写赠送数量');
  359. }
  360. $orderItem = OrderItemClass::getById($id, true);
  361. if (empty($orderItem)) {
  362. util::fail('没有找到花材');
  363. }
  364. if ($orderItem->mainId != $this->mainId) {
  365. util::fail('无法操作');
  366. }
  367. if (!in_array($this->mainId, [1496])) {
  368. util::fail('开发中');
  369. }
  370. $connection = Yii::$app->db;
  371. $transaction = $connection->beginTransaction();
  372. try {
  373. $staff = $this->shopAdmin;
  374. $staffName = $staff->name ?? '';
  375. $staffId = $staff->id ?? 0;
  376. $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId];
  377. $respond = OrderItemService::giveProduct($data, $orderItem, $num);
  378. $transaction->commit();
  379. util::success(['info' => $respond], '赠送成功');
  380. } catch (\Exception $e) {
  381. $transaction->rollBack();
  382. Yii::info("赠送出错了:" . $e->getMessage());
  383. util::fail('出错了');
  384. }
  385. }
  386. //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
  387. public function actionGetOrderProduct()
  388. {
  389. $id = Yii::$app->request->get('id', 0);
  390. $order = OrderClass::getById($id, true);
  391. OrderClass::valid($order, $this->shopId);
  392. $orderSn = $order->orderSn ?? '';
  393. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
  394. $ids = array_column($itemList, 'productId');
  395. if (empty($ids)) {
  396. util::fail('没有找到花材');
  397. }
  398. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  399. if (empty($productList)) {
  400. util::fail('没有找到花材信息');
  401. }
  402. foreach ($productList as $key => $product) {
  403. $productId = $product['id'] ?? 0;
  404. $currentItem = $itemList[$productId] ?? [];
  405. $bigCount = $currentItem['bigNum'] ?? 0;
  406. $smallCount = $currentItem['smallNum'] ?? 0;
  407. $userPrice = $currentItem['userPrice'] ?? 0;
  408. $productList[$key]['bigCount'] = $bigCount;
  409. $productList[$key]['smallCount'] = $smallCount;
  410. $productList[$key]['userPrice'] = $userPrice;
  411. $cover = imgUtil::groupImg($product['cover']);
  412. $productList[$key]['cover'] = $cover;
  413. $bigPrice = $product['unitPrice'] ?? 0;
  414. $smallPrice = $product['smallUnitPrice'] ?? 0;
  415. $productList[$key]['bigPrice'] = $bigPrice;
  416. $productList[$key]['smallPrice'] = $smallPrice;
  417. $productList[$key]['cover'] = $cover;
  418. }
  419. util::success(['productList' => array_values($productList)]);
  420. }
  421. //根据花材id取订单列表 ssh 20211011
  422. public function actionGetOrderInfoList()
  423. {
  424. $get = Yii::$app->request->get();
  425. $productId = $get['productId'] ?? 0;
  426. $product = ProductClass::getById($productId, true);
  427. ProductClass::check($product, $this->mainId);
  428. $where = ['productId' => $productId];
  429. $respond = OrderItemClass::getOrderInfoList($where);
  430. util::success($respond);
  431. }
  432. //修改花材的备注 ssh 20240514
  433. public function actionUpdateItemRemark()
  434. {
  435. $get = Yii::$app->request->get();
  436. $id = $get['id'] ?? 0;
  437. $remark = $get['remark'] ?? '';
  438. $info = OrderItemClass::getById($id, true);
  439. if (empty($info)) {
  440. util::fail('没有找到');
  441. }
  442. if ($info->mainId != $this->mainId) {
  443. util::fail('不是你的花材');
  444. }
  445. $info->remark = $remark;
  446. $info->save();
  447. $orderSn = $info->orderSn ?? '';
  448. $productId = $info->productId ?? 0;
  449. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  450. if (empty($order)) {
  451. util::fail('没有找订单');
  452. }
  453. $customId = $order->customId ?? 0;
  454. $shop = $this->shop;
  455. $bookSn = $shop->bookSn ?? 0;
  456. if (!empty($bookSn) && !empty($remark)) {
  457. $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $productId], true);
  458. if (!empty($bookItemRes)) {
  459. $bookItemRes->hasRemark = 1;
  460. $bookItemRes->save();
  461. }
  462. $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
  463. if (!empty($bookCustomRes)) {
  464. $bookCustomRes->hasRemark = 1;
  465. $bookCustomRes->save();
  466. }
  467. $bookItemCustomRes = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $productId], true);
  468. if (!empty($bookItemCustomRes)) {
  469. $bookItemCustomRes->hasRemark = 1;
  470. $bookItemCustomRes->remark = $remark;
  471. $bookItemCustomRes->save();
  472. }
  473. }
  474. util::complete();
  475. }
  476. //下载excel ssh 20241127
  477. public function actionGetDownExcel()
  478. {
  479. $get = Yii::$app->request->get();
  480. $id = $get['id'] ?? 0;
  481. $order = OrderClass::getById($id, true);
  482. if (empty($order)) {
  483. util::fail('没有找到订单');
  484. }
  485. if ($order->mainId != $this->mainId) {
  486. util::fail('不是你的订单');
  487. }
  488. $orderSn = $order->orderSn ?? '';
  489. $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  490. OrderItemClass::exportExcel($order, $list, $this->mainId);
  491. }
  492. }