PurchaseOrderController.php 58 KB

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