PurchaseOrderController.php 60 KB

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