PurchaseOrderController.php 60 KB

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