PurchaseOrderController.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\cg\classes\CgPurchaseNextDayClass;
  4. use biz\ghs\classes\GhsClass;
  5. use biz\sj\classes\SjClass;
  6. use bizGhs\book\classes\BookItemClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\order\classes\PurchaseOrderClass;
  9. use bizGhs\order\classes\PurchaseOrderItemClass;
  10. use bizGhs\product\classes\ProductClass;
  11. use bizGhs\shop\classes\ShopClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use common\components\dateUtil;
  14. use common\components\dirUtil;
  15. use common\components\noticeUtil;
  16. use common\components\printUtil;
  17. use common\components\stringUtil;
  18. use common\components\util;
  19. use Yii;
  20. class PurchaseOrderController extends BaseController
  21. {
  22. public $guestAccess = ['detail', 'check-seat-update', 'assign-seat'];
  23. //打印多联 ssh 2024509
  24. public function actionPrintPaper()
  25. {
  26. $get = Yii::$app->request->get();
  27. $id = $get['id'] ?? 0;
  28. $cg = PurchaseOrderClass::getById($id, true);
  29. if (empty($cg)) {
  30. util::fail('没有找到采购信息');
  31. }
  32. if ($cg->mainId != $this->mainId) {
  33. util::fail('不是你的采购单哦');
  34. }
  35. if ($cg->status != 4) {
  36. util::fail('请先确认入库');
  37. }
  38. $orderSn = $cg->orderSn ?? '';
  39. //增加打印次数
  40. PurchaseOrderClass::addPrintNum($cg);
  41. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  42. $table = [];
  43. $totalItemNum = 0;
  44. $kind = 0;
  45. if (!empty($itemList)) {
  46. foreach ($itemList as $key => $val) {
  47. $kind++;
  48. $currentName = $val['name'] ?? '';
  49. $preNum = $val['itemNum'] ?? 0;
  50. $preNum = floatval($preNum);
  51. $refundNum = $val['refundNum'] ?? 0;
  52. $num = bcsub($preNum, $refundNum);
  53. $totalItemNum = bcadd($totalItemNum, $num);
  54. $unitPrice = $val['bigPrice'] ?? 0;
  55. $unitPrice = floatval($unitPrice);
  56. $orderNum = bcadd($key, 1);
  57. $currentPrice = $val['totalPrice'] ?? 0;
  58. $currentPrice = floatval($currentPrice);
  59. $table[] = [
  60. 'orderNum' => $orderNum,
  61. 'name' => $currentName,
  62. 'num' => $preNum,
  63. 'unitPrice' => '¥' . $unitPrice,
  64. 'refundNum' => $refundNum,
  65. 'remark' => '',
  66. 'price' => '¥' . $currentPrice,
  67. ];
  68. }
  69. }
  70. $shortOrderSn = substr($orderSn, -4);
  71. $ghsName = $cg->ghsName ?? '';
  72. $entryTime = $cg->entryTime ?? '';
  73. $entryTime = substr($entryTime, 0, 16);
  74. $addTime = $cg->addTime ?? '';
  75. $addTime = substr($addTime, 0, 16);
  76. $shopAdminName = $cg->shopAdminName ?? '';
  77. $shopId = $cg->shopId ?? 0;
  78. $shop = ShopClass::getById($shopId, true);
  79. $telephone = $shop->telephone ?? '';
  80. $shopName = $shop->shopName ?? '';
  81. $sjId = $shop->sjId ?? 0;
  82. $sj = SjClass::getById($sjId, true);
  83. $sjName = $sj->name ?? '';
  84. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  85. $prePrice = $cg->prePrice ?? 0;
  86. $prePrice = floatval($prePrice);
  87. $tkPrice = $cg->tkPrice ?? 0;
  88. $tkPrice = floatval($tkPrice);
  89. $realPrice = $cg->realPrice ?? 0;
  90. $realPrice = floatval($realPrice);
  91. $printData = [
  92. 'table' => $table,
  93. 'addTime' => $addTime,
  94. 'entryTime' => $entryTime,
  95. 'ghsName' => $ghsName,
  96. 'clearCode' => $shortOrderSn,
  97. 'staffName' => $shopAdminName,
  98. 'telephone' => '-',
  99. 'kind' => $kind,
  100. 'orderSn' => $orderSn,
  101. 'sjShopName' => $sjShopName . ' 采购单',
  102. 'prePrice' => '¥' . $prePrice,
  103. 'tkPrice' => '¥' . $tkPrice,
  104. 'realPrice' => '¥' . $realPrice,
  105. 'totalItemNum' => $totalItemNum,
  106. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  107. ];
  108. $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":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"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","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"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":192.5,"top":120,"height":16,"width":178,"title":"制单时间","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":365,"top":120,"height":16,"width":178,"title":"供货商","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"入库时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":170,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"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}}]}';
  109. if (getenv('YII_ENV') == 'production') {
  110. //集花舍 三等分
  111. if ($this->mainId == 42490) {
  112. $template = '{"panels":[{"index":0,"name":1,"height":94,"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":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"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","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"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":192.5,"top":120,"height":16,"width":178,"title":"制单时间","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":365,"top":120,"height":16,"width":178,"title":"供货商","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"入库时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":170,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"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}}]}';
  113. }
  114. }
  115. util::success(['template' => $template, 'printData' => $printData]);
  116. }
  117. //修改货位号 ssh 20240410
  118. public function actionModifySeatSn()
  119. {
  120. $get = Yii::$app->request->get();
  121. $id = $get['id'] ?? 0;
  122. $seatSn = $get['seatSn'] ?? '';
  123. $cg = PurchaseOrderClass::getById($id, true);
  124. if (empty($cg)) {
  125. util::fail('没有找到采购单');
  126. }
  127. if ($cg->mainId != $this->mainId) {
  128. util::fail('没有权限');
  129. }
  130. $cg->seatSn = $seatSn;
  131. $cg->save();
  132. }
  133. //获取零售端在进行中的订单 ssh 20231201
  134. public function actionGetLsRunningOrderNum()
  135. {
  136. $lsFhNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 2]);
  137. $lsShNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 3]);
  138. util::success(['lsFhNum' => $lsFhNum, 'lsShNum' => $lsShNum]);
  139. }
  140. //打印小票 ssh 20230608
  141. public function actionPrintBill()
  142. {
  143. $get = Yii::$app->request->get();
  144. $id = $get['id'] ?? 0;
  145. $order = $get['order'] ?? 1;
  146. $cg = PurchaseOrderClass::getById($id, true);
  147. if (empty($cg)) {
  148. util::fail('没有找到采购单');
  149. }
  150. if ($cg->mainId != $this->mainId) {
  151. util::fail('没有权限');
  152. }
  153. if (getenv('YII_ENV') == 'production') {
  154. //小向的采购单要打印二张
  155. if ($this->mainId == 23390) {
  156. //PurchaseOrderClass::printTicket($cg, false, $order);
  157. }
  158. }
  159. PurchaseOrderClass::printTicket($cg, false, $order);
  160. util::complete();
  161. }
  162. //增加打印次数 ssh 20240511
  163. public function actionAddPrintNum()
  164. {
  165. util::complete();
  166. }
  167. //打印全部 ssh 20220602
  168. public function actionPrintAll()
  169. {
  170. $get = Yii::$app->request->get();
  171. $orderSn = $get['orderSn'] ?? 0;
  172. $type = $get['type'] ?? 0;
  173. $priceOption = $get['priceOption'] ?? 0;
  174. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  175. if (empty($itemList)) {
  176. util::fail('没有商品');
  177. }
  178. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  179. $mainId = $order->mainId ?? 0;
  180. $ext = $this->shopExt;
  181. $printLabelSn = $ext->printLabelSn ?? '';
  182. if (empty($printLabelSn)) {
  183. util::fail('请设置标签打印机');
  184. }
  185. $p = new printUtil($printLabelSn);
  186. $ids = [];
  187. foreach ($itemList as $key => $item) {
  188. $productId = $item->productId ?? 0;
  189. $ids[] = $productId;
  190. }
  191. $ids = array_unique($ids);
  192. $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  193. $priceMap = CustomClass::$levelPriceKeyMap;
  194. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  195. foreach ($itemList as $key => $item) {
  196. $name = $item->name ?? '';
  197. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  198. if (empty($num)) {
  199. util::fail('没有花材数量');
  200. }
  201. $ptItemId = $item->itemId ?? '';
  202. $productId = $item->productId ?? 0;
  203. $p->times = $num;
  204. $smallUnit = $item->smallUnit ?? '';
  205. $ratio = $item->ratio ?? 0;
  206. $unit = $ratio . $smallUnit . '装';
  207. if (isset($item->ratioType) && $item->ratioType == 1) {
  208. $unit = '若干' . $smallUnit . '装';
  209. }
  210. $price = 0;
  211. $hyPrice = 0;
  212. if (isset($infoList[$productId])) {
  213. $currentInfo = $infoList[$productId];
  214. $price = ProductClass::getFinalPrice($currentInfo, 0, $priceMap, $addPriceMap);
  215. $price = floatval($price);
  216. $hyPrice = ProductClass::getFinalPrice($currentInfo, 1, $priceMap, $addPriceMap);
  217. $hyPrice = floatval($hyPrice);
  218. }
  219. if ($priceOption == 2) {
  220. // 每7个汉字截取一次(支持汉字、字母、数字混合),多处需要同步修改,关键词 label_print_substr
  221. $content = '';
  222. $len = mb_strlen($name, 'UTF-8');
  223. $baseNum = 30;
  224. $u = 0;
  225. for ($i = 0; $i < $len; $i += 6) {
  226. $currentName = mb_substr($name, $i, 6, 'UTF-8');
  227. $number = $baseNum + 90 * $u;
  228. $u++;
  229. $content .= '<TEXT x="10" y="' . $number . '" font="12" w="3" h="3" r="0">' . $currentName . '</TEXT>';
  230. }
  231. } else {
  232. if (stringUtil::getWordNum($name) > 8) {
  233. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  234. } else {
  235. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  236. }
  237. if ($key % 2 == 1) {
  238. $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="0">.</TEXT>';
  239. }
  240. }
  241. if ($type == 0) {
  242. if ($priceOption != 2) {
  243. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  244. if (in_array($mainId, [52, 1459])) {
  245. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  246. } elseif ($mainId == 16948) {
  247. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里鲜花</TEXT>';
  248. } elseif ($mainId == 72057) {
  249. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里小榄店</TEXT>';
  250. } else {
  251. if ($priceOption == 0) {
  252. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  253. } else {
  254. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . ' ' . $price . '元</TEXT>';
  255. }
  256. }
  257. }
  258. } else {
  259. if (getenv('YII_ENV') == 'production') {
  260. $doublePrice = [52, 1459];
  261. } else {
  262. $doublePrice = [];
  263. }
  264. if (in_array($this->mainId, $doublePrice)) {
  265. //惠雅鲜花,打价格,显示正价和会员价,多处同步修改,关键词 hy_print_label_price ssh 20260101
  266. $content .= '<TEXT x="35" y="90" font="12" w="2" h="2" r="0">----------</TEXT>';
  267. $content .= '<TEXT x="35" y="150" font="12" w="2" h="2" r="0">正价 ' . $price . '元</TEXT>';
  268. $content .= '<TEXT x="35" y="230" font="12" w="2" h="2" r="0">会员价 ' . $hyPrice . '元</TEXT>';
  269. } elseif ($this->mainId == 4556) {
  270. //打价格,显示零售价,并且不带元,杭州斗南鲜花不要带元
  271. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '</TEXT>';
  272. } else {
  273. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '元</TEXT>';
  274. }
  275. }
  276. $p->printLabelMsg($content);
  277. }
  278. util::complete();
  279. }
  280. //取消入库单 ssh 20221211
  281. public function actionCancel()
  282. {
  283. $get = Yii::$app->request->get();
  284. $id = $get['id'] ?? 0;
  285. $cg = PurchaseOrderClass::getLockById($id);
  286. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  287. util::fail('请确认是否您的采购单');
  288. }
  289. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
  290. util::fail('已取消过了');
  291. }
  292. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
  293. util::fail('已入库,无法取消');
  294. }
  295. try {
  296. util::runWithDbConcurrencyRetry(function () use ($cg) {
  297. $connection = Yii::$app->db;
  298. $transaction = $connection->beginTransaction();
  299. try {
  300. $shop = $this->shop;
  301. $staff = $this->shopAdmin;
  302. $staffId = $staff->id ?? 0;
  303. $staffName = $staff->name ?? '';
  304. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  305. PurchaseOrderClass::cancel($cg, $shop, $params);
  306. $transaction->commit();
  307. } catch (\Exception $exception) {
  308. if ($transaction->isActive) {
  309. $transaction->rollBack();
  310. }
  311. throw $exception;
  312. }
  313. });
  314. util::complete();
  315. } catch (\Exception $e) {
  316. if (util::isDbConcurrencyException($e)) {
  317. util::fail('系统繁忙中,请稍后再试');
  318. } else {
  319. util::fail('取消失败');
  320. }
  321. }
  322. }
  323. //确认入库 sssh 20221211
  324. public function actionConfirmPutIn()
  325. {
  326. ini_set('memory_limit', '2045M');
  327. set_time_limit(0);
  328. $shopAdmin = $this->shopAdmin;
  329. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  330. util::fail('超管才能修改');
  331. }
  332. try {
  333. $get = Yii::$app->request->get();
  334. $id = $get['id'] ?? 0;
  335. //解决重复请求问题
  336. $cacheKey = 'confirm_put_in_action_' . $id;
  337. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  338. if (!empty($has)) {
  339. util::fail('请5秒后操作');
  340. }
  341. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  342. $return = util::runWithDbConcurrencyRetry(function () use ($id) {
  343. $connection = Yii::$app->db;
  344. $transaction = $connection->beginTransaction();
  345. try {
  346. $cg = PurchaseOrderClass::getLockById($id);
  347. if (!isset($cg->mainId) || $cg->mainId != $this->mainId) {
  348. util::fail('请确认是否您的采购单');
  349. }
  350. $staff = $this->shopAdmin;
  351. $data = [];
  352. $data['staffId'] = $staff->id ?? 0;
  353. $data['staffName'] = $staff->name ?? '';
  354. $data['adminId'] = $this->adminId ?? 0;
  355. $data['shop'] = $this->shop;
  356. $return = PurchaseOrderClass::putIn($cg, $data);
  357. $transaction->commit();
  358. return $return;
  359. } catch (\Exception $exception) {
  360. if ($transaction->isActive) {
  361. $transaction->rollBack();
  362. }
  363. throw $exception;
  364. }
  365. });
  366. //入库成功通知相关人员,关键词 put_in_notice
  367. //$shop = $this->shop;
  368. //WxMessageClass::ghsCgEntryInform($shop, $cg);
  369. util::success($return);
  370. } catch (\Exception $e) {
  371. noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
  372. Yii::error("确认入库失败,原因:" . $e->getMessage());
  373. if (util::isDbConcurrencyException($e)) {
  374. util::fail('系统繁忙中,请稍后再试');
  375. } else {
  376. util::fail('确认失败');
  377. }
  378. }
  379. }
  380. //新增采购订单
  381. public function actionCreateOrder()
  382. {
  383. ini_set('memory_limit', '2045M');
  384. set_time_limit(0);
  385. //避免重复提交
  386. $adminId = $this->adminId;
  387. util::checkRepeatCommit($adminId, 10);
  388. $post = Yii::$app->request->post();
  389. $post['sjId'] = $this->sjId;
  390. $post['shopId'] = $this->shopId;
  391. $post['adminId'] = $this->adminId;
  392. $post['mainId'] = $this->mainId;
  393. $staff = $this->shopAdmin;
  394. //以下二个都需要保留
  395. $post['staffId'] = $staff->id ?? 0;
  396. $post['staffName'] = $staff->name ?? '';
  397. $post['shopAdminId'] = $staff->id ?? 0;
  398. $post['shopAdminName'] = $staff->name ?? '';
  399. $shopAdmin = $this->shopAdmin;
  400. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  401. util::fail('超管才能修改');
  402. }
  403. if (getenv('YII_ENV') == 'production') {
  404. //小向花卉采购控制
  405. if ($this->mainId == 23390) {
  406. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
  407. util::fail('你不能采购哦');
  408. }
  409. }
  410. }
  411. $shop = $this->shop;
  412. $carSale = $shop->carSale ?? 0;
  413. if ($carSale == 1) {
  414. util::fail('车销不能采购');
  415. }
  416. try {
  417. $result = util::runWithDbConcurrencyRetry(function () use ($post, $staff, $shop, $shopAdmin) {
  418. $connection = Yii::$app->db;
  419. $transaction = $connection->beginTransaction();
  420. try {
  421. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  422. $ghsItemInfo = $post['itemInfo'] ?? '';
  423. if (empty($ghsItemInfo)) {
  424. util::fail('请选择花材');
  425. }
  426. $ghsItemInfo = json_decode($ghsItemInfo, true);
  427. if (!is_array($ghsItemInfo)) {
  428. util::fail('花材格式不正确');
  429. }
  430. //合并
  431. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  432. //判断花材格式,是否属于当前门店
  433. ProductClass::valid($ghsItemInfo, $this->mainId);
  434. $cgStaffId = $post['cgStaffId'] ?? 0;
  435. if (empty($cgStaffId)) {
  436. $mainId = $this->mainId;
  437. if (getenv('YII_ENV') == 'production') {
  438. //花大苪、鹏诚康乃馨 采购入库必须选择采购人
  439. if (in_array($mainId, [8164, 19606])) {
  440. util::fail('请选择采购人');
  441. }
  442. } else {
  443. if (in_array($mainId, [])) {
  444. util::fail('请选择采购人');
  445. }
  446. }
  447. }
  448. //获取供货商信息
  449. $ghsId = $post['ghsId'];
  450. if (empty($ghsId)) {
  451. util::fail("请选择供货商");
  452. }
  453. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  454. GhsClass::valid($ghsInfo, $this->shopId);
  455. $post['ghsInfo'] = json_encode($ghsInfo);
  456. $post['ghsName'] = $ghsInfo['name'] ?? '';
  457. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  458. $shop = $this->shop;
  459. $bookSn = $shop->bookSn ?? 0;
  460. if (!empty($bookSn)) {
  461. if (empty($cgStaffId)) {
  462. util::fail('请选择采购人哦');
  463. }
  464. }
  465. //只查我负责的花材
  466. $globalCgMyCharge = $post['globalCgMyCharge'] ?? 0;
  467. $needCgList = [];
  468. if ($globalCgMyCharge == 1) {
  469. $staffId = $staff->id ?? 0;
  470. if (!empty($bookSn)) {
  471. $bList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
  472. if (!empty($bList)) {
  473. $myIds = [];
  474. foreach ($bList as $bInfo) {
  475. $biProductId = $bInfo->itemId ?? 0;
  476. if ($bInfo->needCgNum > 0) {
  477. $myIds[] = $biProductId;
  478. $needCgList[$biProductId] = $bInfo->needCgNum;
  479. }
  480. }
  481. }
  482. }
  483. }
  484. //判断花材里的信息
  485. foreach ($ghsItemInfo as $v) {
  486. $bigNum = $v['bigNum'] ?? 0;
  487. $productId = $v['productId'] ?? 0;
  488. $smallNum = $v['smallNum'] ?? 0;
  489. $name = $v['name'] ?? '';
  490. if (!isset($v['itemPrice'])) {
  491. util::fail('采购价格不能为空');
  492. }
  493. if (!$productId) {
  494. util::fail('花材不存在');
  495. }
  496. if ($bigNum <= 0 && $smallNum <= 0) {
  497. util::fail('花材数量不能为0');
  498. }
  499. //城市批发店限制不能让其录小单位,太多人录错,昆明批发不知道有没人录,暂时不限制。 ssh 20250308
  500. if ($shop->pfLevel == 0) {
  501. if ($smallNum > 0) {
  502. //util::fail('不能录小单位:' . $name);
  503. }
  504. }
  505. if ($globalCgMyCharge == 1) {
  506. if (!isset($needCgList[$productId])) {
  507. util::fail($name . ' 不需要采购');
  508. }
  509. $needNum = $needCgList[$productId];
  510. if ($bigNum > $needNum) {
  511. util::fail($name . ' 只要采' . $needNum . '份');
  512. }
  513. }
  514. }
  515. $post['itemInfo'] = $ghsItemInfo;
  516. //0稍后入库 1直接入库
  517. $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
  518. if (!empty($bookSn)) {
  519. //有预订,不要直接入库
  520. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  521. $post['inType'] = $inType;
  522. }
  523. if ($shop->pfLevel == 1) {
  524. //昆明批发,不要直接入库
  525. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  526. $post['inType'] = $inType;
  527. }
  528. $post['bookSn'] = $bookSn;
  529. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  530. $post['debt'] = $debtStatus;
  531. $order = PurchaseOrderClass::addOrder($post);
  532. //如果是附近供货商,则采购单标记为外采单
  533. if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
  534. $order->location = 1;
  535. $order->save();
  536. }
  537. $transaction->commit();
  538. return ['order' => $order, 'bookSn' => $bookSn, 'inType' => $inType];
  539. } catch (\Exception $exception) {
  540. if ($transaction->isActive) {
  541. $transaction->rollBack();
  542. }
  543. throw $exception;
  544. }
  545. });
  546. $order = $result['order'];
  547. $bookSn = $result['bookSn'];
  548. $inType = $result['inType'];
  549. if (isset($order->needPrint) && $order->needPrint == 1) {
  550. PurchaseOrderClass::printTicket($order);
  551. }
  552. if (!empty($bookSn) && $inType == 0) {
  553. //如果是昆明批发,有开启预订则直接分配货位
  554. $key = 'ghs_cg_order_scan_seat_' . $order->id;
  555. $noLock = util::lock($key);
  556. if ($noLock) {
  557. //没有锁定,即没有在分配货位,可以进行货位分配
  558. $params = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name];
  559. PurchaseOrderClass::assign($order, $shop, $params);
  560. util::unlock($key);
  561. }
  562. }
  563. util::success($order);
  564. } catch (\Exception $e) {
  565. noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
  566. Yii::error("操作失败原因:" . $e->getMessage());
  567. if (util::isDbConcurrencyException($e)) {
  568. util::fail('系统繁忙中,请稍后再试');
  569. } else {
  570. util::fail('操作失败');
  571. }
  572. }
  573. }
  574. //分配货位号 ssh 20240619
  575. public function actionAssignSeat()
  576. {
  577. $get = Yii::$app->request->get();
  578. $id = $get['id'] ?? 0;
  579. $salt = $get['salt'] ?? '';
  580. $cg = PurchaseOrderClass::getById($id, true);
  581. if (empty($cg)) {
  582. util::fail('没有找到采购单');
  583. }
  584. //不是待入库状态不需要分配
  585. if ($cg->status != 3) {
  586. util::success(['assign' => 0, 'hint' => 'cg is no wait for entry']);
  587. }
  588. $cgBookSn = $cg->bookSn ?? 0;
  589. if (empty($cgBookSn)) {
  590. util::success(['assign' => 0, 'hint' => 'cg bookSn is empty']);
  591. }
  592. $adminId = $this->adminId;
  593. if (!empty($adminId) && empty($salt)) {
  594. if ($cg->mainId != $this->mainId) {
  595. util::success(['assign' => 0, 'hint' => 'cg mainId != this mainId']);
  596. }
  597. $shop = $this->shop;
  598. $bookSn = $shop->bookSn ?? 0;
  599. if ($bookSn != $cgBookSn) {
  600. util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn']);
  601. }
  602. $staff = $this->shopAdmin;
  603. $staffId = $staff->id ?? 0;
  604. $staffName = $staff->name ?? '';
  605. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  606. } else {
  607. if ($cg->salt != $salt) {
  608. util::success(['assign' => 0, 'hint' => 'cg salt != post salt']);
  609. }
  610. $shopId = $cg->shopId ?? 0;
  611. $shop = ShopClass::getById($shopId, true);
  612. if (empty($shop)) {
  613. util::success(['assign' => 0, 'hint' => 'shop empty']);
  614. }
  615. if ($shop->bookSn != $cgBookSn) {
  616. util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn o']);
  617. }
  618. $staffId = $cg->shopAdminId ?? 0;
  619. $staffName = $cg->shopAdminName ?? '';
  620. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  621. }
  622. $connection = Yii::$app->db;
  623. $transaction = $connection->beginTransaction();
  624. try {
  625. PurchaseOrderClass::assign($cg, $shop, $params);
  626. $transaction->commit();
  627. util::success(['assign' => 1]);
  628. } catch (\Exception $e) {
  629. $transaction->rollBack();
  630. util::fail('获取失败');
  631. }
  632. }
  633. //订单列表
  634. public function actionList()
  635. {
  636. $where = [];
  637. $get = Yii::$app->request->get();
  638. $export = $get['export'] ?? 0;
  639. $where['shopId'] = $this->shopId;
  640. $orderStatus = $get['status'] ?? '';
  641. if ($orderStatus) {
  642. $where['status'] = $orderStatus;
  643. }
  644. $ghsId = $get['ghsId'] ?? 0;
  645. if (!empty($ghsId)) {
  646. $where['ghsId'] = $ghsId;
  647. }
  648. $search = '';
  649. $name1 = $get['search'] ?? '';
  650. if (!empty($name1)) {
  651. $search = $name1;
  652. }
  653. $name2 = $get['name'] ?? '';
  654. if (!empty($name2)) {
  655. $search = $name2;
  656. }
  657. if (!empty($search)) {
  658. $ret = strstr($search, 'PH');
  659. if (is_numeric($search) && strlen($search) == 4) {
  660. $where['checkCode'] = $search;
  661. } elseif (!empty($ret)) {
  662. $where['orderSn'] = $search;
  663. } else {
  664. $where['ghsName'] = ['like', $search];
  665. }
  666. }
  667. $searchTime = $get['searchTime'] ?? '';
  668. if (!empty($searchTime)) {
  669. $startTime = $get['startTime'] ?? '';
  670. $endTime = $get['endTime'] ?? '';
  671. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  672. $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
  673. }
  674. $cgStaffId = $get['cgStaffId'] ?? 0;
  675. if (!empty($cgStaffId)) {
  676. $where['cgStaffId'] = $cgStaffId;
  677. }
  678. if ($export == 1) {
  679. ini_set('memory_limit', '2045M');
  680. set_time_limit(0);
  681. if (isset($where['entryTime']) == false) {
  682. util::fail('请选时间段');
  683. }
  684. $start = $where['entryTime'][1][0];
  685. $end = $where['entryTime'][1][1];
  686. $monthTime = bcmul(31, 86400);
  687. $startArea = strtotime($start);
  688. $endArea = strtotime($end);
  689. $diff = bcsub($endArea, $startArea);
  690. if ($diff > $monthTime) {
  691. util::fail('最长可导出一个月');
  692. }
  693. }
  694. $adminId = $this->adminId;
  695. $mainId = $this->mainId;
  696. //采购限制访问,有多处要同步修改,权限管理问题,关键词cg_limit_access
  697. if (getenv('YII_ENV') == 'production') {
  698. //纯彩花艺
  699. if ($this->mainId == 10) {
  700. if (!in_array($this->adminId, [37, 988, 14346])) {
  701. util::fail('没有数据哦,编号1792');
  702. }
  703. }
  704. //天天鲜花十堰店
  705. if ($this->mainId == 7184) {
  706. if (!in_array($this->adminId, [8340, 8345, 9433])) {
  707. util::fail('没有数据哦,编号1592');
  708. }
  709. }
  710. //小向花卉采购控制
  711. if ($this->mainId == 23390) {
  712. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
  713. util::fail('没有数据哦,编号2292');
  714. }
  715. }
  716. //中山淘花里采购控制,多处要修改,搜索关键词 thl_cg_control
  717. if ($mainId == 16948) {
  718. if (!in_array($adminId, [55494, 55445, 17908, 55459, 55707, 4, 55709])) {
  719. util::fail('暂时不能查看哦,编号6811');
  720. }
  721. }
  722. //贴心鲜花批发,只有老板可以查看
  723. if ($mainId == 15144) {
  724. if (!in_array($adminId, [16163])) {
  725. util::fail('暂时不能查看哦,编号6818');
  726. }
  727. }
  728. //捷芳鲜花批发,限制不能查看采购权限的人
  729. if ($mainId == 45354) {
  730. if (in_array($adminId, [47094, 47130])) {
  731. util::fail('暂时不能查看哦,编号6822');
  732. }
  733. }
  734. }
  735. $data = PurchaseOrderClass::getOrderList($where);
  736. if ($export == 1) {
  737. PurchaseOrderClass::exportOrderData($data, $this->mainId);
  738. }
  739. //状态统计,很慢,暂时隐藏
  740. //$statData = PurchaseOrderClass::statNum($this->shopId);
  741. $statData = [
  742. 'allNum' => 0,
  743. 'unPayNum' => 0,
  744. 'unSendNum' => 0,
  745. 'sendingNum' => 0,
  746. 'finishNum' => 0,
  747. ];
  748. $data = array_merge($data, $statData);
  749. util::success($data);
  750. }
  751. //订单详情
  752. public function actionDetail()
  753. {
  754. $get = Yii::$app->request->get();
  755. $orderSn = $get['orderSn'] ?? '';
  756. $salt = $get['salt'] ?? '';
  757. $adminId = $this->adminId ?? 0;
  758. $onBooking = 0;
  759. if (!empty($adminId) && empty($salt)) {
  760. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  761. $shop = $this->shop;
  762. $bookSn = $orderData['bookSn'] ?? 0;
  763. $shopBookSn = $shop->bookSn ?? 0;
  764. if (!empty($shopBookSn) && $shopBookSn == $bookSn) {
  765. $onBooking = 1;
  766. }
  767. $pfLevel = $shop->pfLevel ?? 0;
  768. } else {
  769. $info = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  770. if (empty($info)) {
  771. util::fail('没有找到采购单');
  772. }
  773. if ($info->salt != $salt) {
  774. util::fail('不是你的采购单');
  775. }
  776. $shopId = $info->shopId ?? 0;
  777. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $shopId);
  778. $shop = ShopClass::getById($shopId, true);
  779. $pfLevel = $shop->pfLevel ?? 0;
  780. }
  781. $mainId = $this->mainId;
  782. $staff = $this->shopAdmin;
  783. $addTime = $orderData['addTime'] ?? '';
  784. $currentTime = time();
  785. $hasOver = false;
  786. $overTime = $currentTime - strtotime($addTime);
  787. $overDay = ceil($overTime / 86400);
  788. if ($overDay > 3) {
  789. $hasOver = true;
  790. }
  791. if (getenv('YII_ENV') == 'production') {
  792. //花大苪没有财务权限的人,采购单只能看最近3天
  793. if ($mainId == 8164) {
  794. if (!isset($staff->finance) || $staff->finance == 0) {
  795. if ($hasOver) {
  796. util::fail('超过3天,暂时无法查看');
  797. }
  798. }
  799. }
  800. //中山淘花里采购控制,多处要修改,搜索关键词 thl_cg_control
  801. if ($mainId == 16948) {
  802. if (!in_array($adminId, [55494, 55445, 17908, 55459, 55707, 4, 55709])) {
  803. util::fail('暂时不能查看哦,编号6892');
  804. }
  805. }
  806. }
  807. $orderData['onBooking'] = $onBooking;
  808. $orderData['pfLevel'] = $pfLevel;
  809. util::success($orderData);
  810. }
  811. //采购页,定时检测货位有没更新 ssh 20240709
  812. public function actionCheckSeatUpdate()
  813. {
  814. $get = Yii::$app->request->get();
  815. $orderSn = $get['orderSn'] ?? '';
  816. $salt = $get['salt'] ?? '';
  817. if (empty($orderSn)) {
  818. util::success(['need' => 0, 'hint' => 'empty orderSn']);
  819. }
  820. $cg = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  821. if (empty($cg)) {
  822. util::success(['need' => 0, 'hint' => 'empty cg info']);
  823. }
  824. $adminId = $this->adminId ?? 0;
  825. $cgId = $cg->id ?? 0;
  826. $cgBookSn = $cg->bookSn ?? 0;
  827. if (!empty($adminId) && empty($salt)) {
  828. if ($cg->mainId != $this->mainId) {
  829. util::success(['need' => 0, 'hint' => 'cgMainId != thisMainId']);
  830. }
  831. $shop = $this->shop;
  832. $shopBookSn = $shop->bookSn ?? 0;
  833. if (empty($shopBookSn)) {
  834. util::success(['need' => 0, 'hint' => 'empty shopBookSn']);
  835. }
  836. if ($shopBookSn != $cgBookSn) {
  837. util::success(['need' => 0, 'hint' => 'shopBookSn!=cgBookSn']);
  838. }
  839. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $cgBookSn;
  840. $staff = $this->shopAdmin;
  841. $staffId = $staff->id ?? 0;
  842. $element = $cgId . '-' . $staffId;
  843. $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $element]);
  844. if (!empty($exists)) {
  845. Yii::$app->redis->executeCommand('SREM', [$cacheKey, $element]);
  846. util::success(['need' => 1]);
  847. }
  848. } else {
  849. if ($cg->salt != $salt) {
  850. util::success(['need' => 0, 'hint' => 'cg salt != post salt']);
  851. }
  852. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $cgBookSn;
  853. $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $cgId]);
  854. if (!empty($exists)) {
  855. Yii::$app->redis->executeCommand('SREM', [$cacheKey, $cgId]);
  856. util::success(['need' => 1]);
  857. }
  858. }
  859. util::success(['need' => 0, 'hint' => 'real no need']);
  860. }
  861. //修改备注
  862. public function actionUpdateRemark()
  863. {
  864. $remark = Yii::$app->request->post('remark', '');
  865. $id = Yii::$app->request->post('id', '');
  866. $cg = PurchaseOrderClass::getById($id, true);
  867. if (empty($cg)) {
  868. util::fail('没有找到订单');
  869. }
  870. if ($cg->shopId != $this->shopId) {
  871. util::fail('没有权限修改');
  872. }
  873. $cg->remark = $remark;
  874. $cg->save();
  875. util::complete('修改成功');
  876. }
  877. /**
  878. * 应付统计:按入库日汇总。
  879. * originAmount=未扣隔天;nextDayAmount=隔天售后;amount=已扣隔天(净额)。
  880. */
  881. public function actionDueList()
  882. {
  883. $get = Yii::$app->request->get();
  884. $mainId = $this->mainId;
  885. $export = $get['export'] ?? 0;
  886. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : 0;
  887. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  888. $startTime = $get['startTime'] ?? '';
  889. $endTime = $get['endTime'] ?? '';
  890. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  891. $start = $period['startTime'];
  892. $end = $period['endTime'];
  893. $ghsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, 'id,name', 'id');
  894. $currentStartDate = date('Y-m-d', strtotime($start));
  895. $currentEndDate = date('Y-m-d', strtotime($end));
  896. $currentStartTime = $currentStartDate . ' 00:00:00';
  897. $currentEndTime = $currentEndDate . ' 23:59:59';
  898. $cgWhere = ['mainId' => $mainId, 'status' => 4];
  899. if ($debt > 0) {
  900. $cgWhere['debt'] = $debt;
  901. }
  902. $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
  903. $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
  904. $list = [];
  905. $totalOriginAmount = 0;
  906. $totalAmount = 0;
  907. $nextDayDeduct = '0.00';
  908. if (!empty($cgList)) {
  909. foreach ($cgList as $cgInfo) {
  910. $actPrice = $cgInfo['actPrice'] ?? 0;
  911. $ghsId = $cgInfo['ghsId'] ?? 0;
  912. if (isset($list[$ghsId])) {
  913. $list[$ghsId]['originAmount'] = bcadd($list[$ghsId]['originAmount'], $actPrice, 2);
  914. $list[$ghsId]['amount'] = bcadd($list[$ghsId]['amount'], $actPrice, 2);
  915. $list[$ghsId]['num'] = bcadd($list[$ghsId]['num'], 1);
  916. } else {
  917. $name = $ghsList[$ghsId] && $ghsList[$ghsId]['name'] ? $ghsList[$ghsId]['name'] : '未命名';
  918. $list[$ghsId] = [
  919. 'id' => $ghsId,
  920. 'name' => $name,
  921. 'originAmount' => $actPrice,
  922. 'amount' => $actPrice,
  923. 'num' => 1,
  924. 'nextDayAmount' => '0.00',
  925. ];
  926. }
  927. $totalOriginAmount = bcadd($totalOriginAmount, $actPrice, 2);
  928. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  929. }
  930. }
  931. // 隔天售后:只扣 amount,originAmount 保持未扣口径
  932. $nextMap = CgPurchaseNextDayClass::sumAmountGroupByGhs($mainId, $currentStartTime, $currentEndTime);
  933. foreach ($nextMap as $ghsId => $amt) {
  934. if (bccomp((string)$amt, '0', 2) <= 0) {
  935. continue;
  936. }
  937. if (!isset($list[$ghsId])) {
  938. $list[$ghsId] = [
  939. 'id' => $ghsId,
  940. 'name' => $ghsList[$ghsId]['name'] ?? '未命名',
  941. 'originAmount' => '0.00',
  942. 'amount' => '0.00',
  943. 'num' => 0,
  944. 'nextDayAmount' => '0.00',
  945. ];
  946. }
  947. if (!isset($list[$ghsId]['originAmount'])) {
  948. $list[$ghsId]['originAmount'] = (string)($list[$ghsId]['amount'] ?? '0');
  949. }
  950. if (!isset($list[$ghsId]['nextDayAmount'])) {
  951. $list[$ghsId]['nextDayAmount'] = '0.00';
  952. }
  953. $list[$ghsId]['amount'] = bcsub((string)$list[$ghsId]['amount'], (string)$amt, 2);
  954. $list[$ghsId]['nextDayAmount'] = bcadd((string)$list[$ghsId]['nextDayAmount'], (string)$amt, 2);
  955. $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
  956. $nextDayDeduct = bcadd($nextDayDeduct, (string)$amt, 2);
  957. }
  958. $list = array_values($list);
  959. if ($export == 1) {
  960. if (empty($list)) {
  961. util::fail('没有数据需要导出');
  962. }
  963. ini_set('memory_limit', '2045M');
  964. set_time_limit(0);
  965. PurchaseOrderClass::exportDueList($list, $mainId);
  966. util::stop();
  967. }
  968. util::success([
  969. 'list' => $list,
  970. 'totalOriginAmount' => $totalOriginAmount,
  971. 'totalAmount' => $totalAmount,
  972. 'nextDayDeduct' => floatval($nextDayDeduct),
  973. ]);
  974. }
  975. //修改入库时间 ssh 20240511
  976. public function actionModifyEntryTime()
  977. {
  978. $get = Yii::$app->request->get();
  979. $id = $get['id'] ?? 0;
  980. $date = $get['date'] ?? '';
  981. if (empty($date)) {
  982. util::fail('请选择日期');
  983. }
  984. $cg = PurchaseOrderClass::getById($id, true);
  985. if (empty($cg)) {
  986. util::fail('没有找到订单');
  987. }
  988. if ($cg->mainId != $this->mainId) {
  989. util::fail('不是你的订单');
  990. }
  991. $mainId = $this->mainId;
  992. //超管或者约定的人可以修改日期
  993. if (getenv('YII_ENV') == 'production') {
  994. if (in_array($mainId, [23390])) {
  995. if (!in_array($this->adminId, [24586, 23960])) {
  996. util::fail('你不能修改哦');
  997. }
  998. }
  999. } else {
  1000. if (in_array($mainId, [644])) {
  1001. if (!in_array($this->adminId, [919])) {
  1002. }
  1003. }
  1004. }
  1005. $entryTime = $cg->entryTime;
  1006. $time = strtotime($entryTime);
  1007. $after = date("H:i:s", $time);
  1008. $new = $date . ' ' . $after;
  1009. $cg->entryTime = $new;
  1010. $cg->save();
  1011. util::complete('修改成功');
  1012. }
  1013. //导入采购 ssh 20241126
  1014. public function actionImportCreate()
  1015. {
  1016. $get = Yii::$app->request->get();
  1017. $connection = Yii::$app->db;
  1018. $transaction = $connection->beginTransaction();
  1019. try {
  1020. $ghsId = $get['id'] ?? '';
  1021. $file = $_FILES['file'];
  1022. if (!is_uploaded_file($file['tmp_name'])) {
  1023. util::fail('please upload img');
  1024. }
  1025. $mainId = $this->sjId;
  1026. $shopId = $this->shopId;
  1027. $month = date("Ym");
  1028. $date = date("d");
  1029. $path = dirUtil::getImgUploadDir() . "/{$mainId}/cg/{$shopId}/{$month}/{$date}/";
  1030. if (!file_exists($path)) {
  1031. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1032. mkdir($path, 0700, true);
  1033. }
  1034. $preFileName = stringUtil::uniqueFileName();
  1035. $newFile = $preFileName . ".xls";
  1036. $fullPathFile = $path . $newFile;
  1037. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  1038. $arr = [];
  1039. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  1040. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  1041. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  1042. // 获取活动工作表
  1043. $worksheet = $spreadsheet->getActiveSheet();
  1044. // 遍历每一行
  1045. foreach ($worksheet->getRowIterator() as $key => $row) {
  1046. $cellIterator = $row->getCellIterator();
  1047. // 这里设置为迭代所有单元格,包括空单元格
  1048. $cellIterator->setIterateOnlyExistingCells(FALSE);
  1049. // 遍历每列
  1050. $rowData = [];
  1051. foreach ($cellIterator as $cell) {
  1052. $option = $cell->getValue();
  1053. $rowData[] = trim($option);
  1054. }
  1055. $arr[] = $rowData;
  1056. }
  1057. array_shift($arr);
  1058. $productIds = [];
  1059. foreach ($arr as $k => $v) {
  1060. $productId = $v[0] ?? 0;
  1061. $productId = trim($productId);
  1062. if (is_numeric($productId) && $productId > 0) {
  1063. $productIds[] = $productId;
  1064. }
  1065. }
  1066. if (empty($productIds)) {
  1067. util::fail('没有识别出花材');
  1068. }
  1069. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  1070. if (empty($productInfo)) {
  1071. util::fail('没有找到有效花材');
  1072. }
  1073. $ghsItemInfo = [];
  1074. foreach ($arr as $k => $v) {
  1075. $productId = $v[0] ?? 0;
  1076. $productId = trim($productId);
  1077. $num = $v[2] ?? 0;
  1078. $num = trim($num);
  1079. $unitPrice = $v[3] ?? 0;
  1080. $unitPrice = trim($unitPrice);
  1081. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  1082. $price = bcmul($unitPrice, $num, 2);
  1083. $product = $productInfo[$productId] ?? [];
  1084. $ptItemId = $product['itemId'] ?? 0;
  1085. $ratio = $product['ratio'] ?? 20;
  1086. $ratioType = $product['ratioType'] ?? 0;
  1087. $ghsItemInfo[] = [
  1088. 'productId' => $productId,
  1089. 'bigNum' => $num,
  1090. 'smallNum' => 0,
  1091. 'itemId' => $ptItemId,
  1092. 'itemPrice' => $unitPrice,
  1093. 'totalPrice' => $price,
  1094. 'assignSeat' => 0,
  1095. 'ratio' => $ratio,
  1096. 'ratioType' => $ratioType,
  1097. 'aboutPrice' => 0,
  1098. ];
  1099. }
  1100. }
  1101. ini_set('memory_limit', '2045M');
  1102. set_time_limit(0);
  1103. $post = [];
  1104. $post['sjId'] = $this->sjId;
  1105. $post['shopId'] = $this->shopId;
  1106. $post['adminId'] = $this->adminId;
  1107. $post['mainId'] = $this->mainId;
  1108. $staff = $this->shopAdmin;
  1109. //以下二个都需要保留
  1110. $post['staffId'] = $staff->id ?? 0;
  1111. $post['staffName'] = $staff->name ?? '';
  1112. $post['shopAdminId'] = $staff->id ?? 0;
  1113. $post['shopAdminName'] = $staff->name ?? '';
  1114. $shopAdmin = $this->shopAdmin;
  1115. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1116. util::fail('没有权限导入库存');
  1117. }
  1118. if (getenv('YII_ENV') == 'production') {
  1119. //小向花卉采购控制
  1120. if ($this->mainId == 23390) {
  1121. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
  1122. util::fail('你不能采购哦');
  1123. }
  1124. }
  1125. }
  1126. $shop = $this->shop;
  1127. $carSale = $shop->carSale ?? 0;
  1128. if ($carSale == 1) {
  1129. util::fail('车销不能采购');
  1130. }
  1131. //合并
  1132. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  1133. //判断花材格式,是否属于当前门店
  1134. ProductClass::valid($ghsItemInfo, $this->mainId);
  1135. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  1136. GhsClass::valid($ghsInfo, $this->shopId);
  1137. $post['ghsId'] = $ghsId;
  1138. $post['ghsInfo'] = json_encode($ghsInfo);
  1139. $post['ghsName'] = $ghsInfo['name'] ?? '';
  1140. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  1141. $shop = $this->shop;
  1142. $post['itemInfo'] = $ghsItemInfo;
  1143. //0稍后入库
  1144. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  1145. $post['inType'] = $inType;
  1146. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  1147. $post['debt'] = $debtStatus;
  1148. $order = PurchaseOrderClass::addOrder($post);
  1149. $transaction->commit();
  1150. util::success($order);
  1151. } else {
  1152. util::fail('导入失败了哦!');
  1153. }
  1154. } catch (\Exception $e) {
  1155. $transaction->rollBack();
  1156. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  1157. Yii::error("导入失败原因:" . $e->getMessage());
  1158. $msg = $e->getMessage();
  1159. util::fail('导入失败:' . $msg);
  1160. }
  1161. }
  1162. }