PurchaseOrderController.php 57 KB

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