PurchaseOrderController.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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. if ($globalCgMyCharge == 1) {
  473. if (isset($needCgList[$productId]) == false) {
  474. util::fail($name . ' 不需要采购');
  475. }
  476. $needNum = $needCgList[$productId];
  477. if ($bigNum > $needNum) {
  478. util::fail($name . ' 只要采' . $needNum . '份');
  479. }
  480. }
  481. }
  482. $post['itemInfo'] = $ghsItemInfo;
  483. //0稍后入库 1直接入库
  484. $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
  485. if (!empty($bookSn)) {
  486. //有预订,不要直接入库
  487. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  488. $post['inType'] = $inType;
  489. }
  490. if ($shop->pfLevel == 1) {
  491. //昆明批发,不要直接入库
  492. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  493. $post['inType'] = $inType;
  494. }
  495. $post['bookSn'] = $bookSn;
  496. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  497. $post['debt'] = $debtStatus;
  498. $order = PurchaseOrderClass::addOrder($post);
  499. //如果是附近供货商,则采购单标记为外采单
  500. if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
  501. $order->location = 1;
  502. $order->save();
  503. }
  504. $transaction->commit();
  505. if (isset($order->needPrint) && $order->needPrint == 1) {
  506. PurchaseOrderClass::printTicket($order);
  507. }
  508. if (!empty($bookSn) && $inType == 0) {
  509. //如果是昆明批发,有开启预订则直接分配货位
  510. $key = 'ghs_cg_order_scan_seat_' . $order->id;
  511. $noLock = util::lock($key);
  512. if ($noLock) {
  513. //没有锁定,即没有在分配货位,可以进行货位分配
  514. $params = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name];
  515. PurchaseOrderClass::assign($order, $shop, $params);
  516. util::unlock($key);
  517. }
  518. }
  519. util::success($order);
  520. } catch (\Exception $e) {
  521. $transaction->rollBack();
  522. noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
  523. Yii::error("操作失败原因:" . $e->getMessage());
  524. util::fail('操作失败');
  525. }
  526. }
  527. //分配货位号 ssh 20240619
  528. public function actionAssignSeat()
  529. {
  530. $get = Yii::$app->request->get();
  531. $id = $get['id'] ?? 0;
  532. $salt = $get['salt'] ?? '';
  533. $cg = PurchaseOrderClass::getById($id, true);
  534. if (empty($cg)) {
  535. util::fail('没有找到采购单');
  536. }
  537. //不是待入库状态不需要分配
  538. if ($cg->status != 3) {
  539. util::success(['assign' => 0, 'hint' => 'cg is no wait for entry']);
  540. }
  541. $cgBookSn = $cg->bookSn ?? 0;
  542. if (empty($cgBookSn)) {
  543. util::success(['assign' => 0, 'hint' => 'cg bookSn is empty']);
  544. }
  545. $adminId = $this->adminId;
  546. if (!empty($adminId) && empty($salt)) {
  547. if ($cg->mainId != $this->mainId) {
  548. util::success(['assign' => 0, 'hint' => 'cg mainId != this mainId']);
  549. }
  550. $shop = $this->shop;
  551. $bookSn = $shop->bookSn ?? 0;
  552. if ($bookSn != $cgBookSn) {
  553. util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn']);
  554. }
  555. $staff = $this->shopAdmin;
  556. $staffId = $staff->id ?? 0;
  557. $staffName = $staff->name ?? '';
  558. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  559. } else {
  560. if ($cg->salt != $salt) {
  561. util::success(['assign' => 0, 'hint' => 'cg salt != post salt']);
  562. }
  563. $shopId = $cg->shopId ?? 0;
  564. $shop = ShopClass::getById($shopId, true);
  565. if (empty($shop)) {
  566. util::success(['assign' => 0, 'hint' => 'shop empty']);
  567. }
  568. if ($shop->bookSn != $cgBookSn) {
  569. util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn o']);
  570. }
  571. $staffId = $cg->shopAdminId ?? 0;
  572. $staffName = $cg->shopAdminName ?? '';
  573. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  574. }
  575. $connection = Yii::$app->db;
  576. $transaction = $connection->beginTransaction();
  577. try {
  578. PurchaseOrderClass::assign($cg, $shop, $params);
  579. $transaction->commit();
  580. util::success(['assign' => 1]);
  581. } catch (\Exception $e) {
  582. $transaction->rollBack();
  583. util::fail('获取失败');
  584. }
  585. }
  586. //订单列表
  587. public function actionList()
  588. {
  589. $where = [];
  590. $get = Yii::$app->request->get();
  591. $export = $get['export'] ?? 0;
  592. $where['shopId'] = $this->shopId;
  593. $orderStatus = $get['status'] ?? '';
  594. if ($orderStatus) {
  595. $where['status'] = $orderStatus;
  596. }
  597. $ghsId = $get['ghsId'] ?? 0;
  598. if (!empty($ghsId)) {
  599. $where['ghsId'] = $ghsId;
  600. }
  601. $search = '';
  602. $name1 = $get['search'] ?? '';
  603. if (!empty($name1)) {
  604. $search = $name1;
  605. }
  606. $name2 = $get['name'] ?? '';
  607. if (!empty($name2)) {
  608. $search = $name2;
  609. }
  610. if (!empty($search)) {
  611. $ret = strstr($search, 'PH');
  612. if (is_numeric($search) && strlen($search) == 4) {
  613. $where['checkCode'] = $search;
  614. } elseif (!empty($ret)) {
  615. $where['orderSn'] = $search;
  616. } else {
  617. $where['ghsName'] = ['like', $search];
  618. }
  619. }
  620. $searchTime = $get['searchTime'] ?? '';
  621. if (!empty($searchTime)) {
  622. $startTime = $get['startTime'] ?? '';
  623. $endTime = $get['endTime'] ?? '';
  624. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  625. $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
  626. }
  627. $cgStaffId = $get['cgStaffId'] ?? 0;
  628. if (!empty($cgStaffId)) {
  629. $where['cgStaffId'] = $cgStaffId;
  630. }
  631. if ($export == 1) {
  632. ini_set('memory_limit', '2045M');
  633. set_time_limit(0);
  634. if (isset($where['entryTime']) == false) {
  635. util::fail('请选时间段');
  636. }
  637. $start = $where['entryTime'][1][0];
  638. $end = $where['entryTime'][1][1];
  639. $monthTime = bcmul(31, 86400);
  640. $startArea = strtotime($start);
  641. $endArea = strtotime($end);
  642. $diff = bcsub($endArea, $startArea);
  643. if ($diff > $monthTime) {
  644. util::fail('最长可导出一个月');
  645. }
  646. }
  647. //采购限制访问,有多处要同步修改,关键词cg_limit_access
  648. if (getenv('YII_ENV') == 'production') {
  649. //纯彩花艺
  650. if ($this->mainId == 10) {
  651. if (in_array($this->adminId, [37, 988, 14346]) == false) {
  652. util::fail('没有数据哦1');
  653. }
  654. }
  655. //天天鲜花十堰店
  656. if ($this->mainId == 7184) {
  657. if (in_array($this->adminId, [8340, 8345, 9433]) == false) {
  658. util::fail('没有数据哦2');
  659. }
  660. }
  661. //小向花卉采购控制
  662. if ($this->mainId == 23390) {
  663. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4])) {
  664. util::fail('没有数据哦3');
  665. }
  666. }
  667. }
  668. $data = PurchaseOrderClass::getOrderList($where);
  669. if ($export == 1) {
  670. PurchaseOrderClass::exportOrderData($data, $this->mainId);
  671. }
  672. //状态统计,很慢,暂时隐藏
  673. //$statData = PurchaseOrderClass::statNum($this->shopId);
  674. $statData = [
  675. 'allNum' => 0,
  676. 'unPayNum' => 0,
  677. 'unSendNum' => 0,
  678. 'sendingNum' => 0,
  679. 'finishNum' => 0,
  680. ];
  681. $data = array_merge($data, $statData);
  682. util::success($data);
  683. }
  684. //订单详情
  685. public function actionDetail()
  686. {
  687. $get = Yii::$app->request->get();
  688. $orderSn = $get['orderSn'] ?? '';
  689. $salt = $get['salt'] ?? '';
  690. $adminId = $this->adminId ?? 0;
  691. $onBooking = 0;
  692. if (!empty($adminId) && empty($salt)) {
  693. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  694. $shop = $this->shop;
  695. $bookSn = $orderData['bookSn'] ?? 0;
  696. $shopBookSn = $shop->bookSn ?? 0;
  697. if (!empty($shopBookSn) && $shopBookSn == $bookSn) {
  698. $onBooking = 1;
  699. }
  700. $pfLevel = $shop->pfLevel ?? 0;
  701. } else {
  702. $info = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  703. if (empty($info)) {
  704. util::fail('没有找到采购单');
  705. }
  706. if ($info->salt != $salt) {
  707. util::fail('不是你的采购单');
  708. }
  709. $shopId = $info->shopId ?? 0;
  710. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $shopId);
  711. $shop = ShopClass::getById($shopId, true);
  712. $pfLevel = $shop->pfLevel ?? 0;
  713. }
  714. $mainId = $this->mainId;
  715. $staff = $this->shopAdmin;
  716. $addTime = $orderData['addTime'] ?? '';
  717. $currentTime = time();
  718. $hasOver = false;
  719. $overTime = $currentTime - strtotime($addTime);
  720. $overDay = ceil($overTime / 86400);
  721. if ($overDay > 3) {
  722. $hasOver = true;
  723. }
  724. if (getenv('YII_ENV') == 'production') {
  725. //花大苪没有财务权限的人,采购单只能看最近3天
  726. if ($mainId == 8164) {
  727. if (!isset($staff->finance) || $staff->finance == 0) {
  728. if ($hasOver) {
  729. util::fail('超过3天,无法查看');
  730. }
  731. }
  732. }
  733. } else {
  734. if ($mainId == 644) {
  735. if (!isset($staff->finance) || $staff->finance == 0) {
  736. if ($hasOver) {
  737. util::fail('超过3天,无法查看');
  738. }
  739. }
  740. }
  741. }
  742. $orderData['onBooking'] = $onBooking;
  743. $orderData['pfLevel'] = $pfLevel;
  744. util::success($orderData);
  745. }
  746. //采购页,定时检测货位有没更新 ssh 20240709
  747. public function actionCheckSeatUpdate()
  748. {
  749. $get = Yii::$app->request->get();
  750. $orderSn = $get['orderSn'] ?? '';
  751. $salt = $get['salt'] ?? '';
  752. if (empty($orderSn)) {
  753. util::success(['need' => 0, 'hint' => 'empty orderSn']);
  754. }
  755. $cg = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  756. if (empty($cg)) {
  757. util::success(['need' => 0, 'hint' => 'empty cg info']);
  758. }
  759. $adminId = $this->adminId ?? 0;
  760. $cgId = $cg->id ?? 0;
  761. $cgBookSn = $cg->bookSn ?? 0;
  762. if (!empty($adminId) && empty($salt)) {
  763. if ($cg->mainId != $this->mainId) {
  764. util::success(['need' => 0, 'hint' => 'cgMainId != thisMainId']);
  765. }
  766. $shop = $this->shop;
  767. $shopBookSn = $shop->bookSn ?? 0;
  768. if (empty($shopBookSn)) {
  769. util::success(['need' => 0, 'hint' => 'empty shopBookSn']);
  770. }
  771. if ($shopBookSn != $cgBookSn) {
  772. util::success(['need' => 0, 'hint' => 'shopBookSn!=cgBookSn']);
  773. }
  774. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $cgBookSn;
  775. $staff = $this->shopAdmin;
  776. $staffId = $staff->id ?? 0;
  777. $element = $cgId . '-' . $staffId;
  778. $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $element]);
  779. if (!empty($exists)) {
  780. Yii::$app->redis->executeCommand('SREM', [$cacheKey, $element]);
  781. util::success(['need' => 1]);
  782. }
  783. } else {
  784. if ($cg->salt != $salt) {
  785. util::success(['need' => 0, 'hint' => 'cg salt != post salt']);
  786. }
  787. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $cgBookSn;
  788. $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $cgId]);
  789. if (!empty($exists)) {
  790. Yii::$app->redis->executeCommand('SREM', [$cacheKey, $cgId]);
  791. util::success(['need' => 1]);
  792. }
  793. }
  794. util::success(['need' => 0, 'hint' => 'real no need']);
  795. }
  796. //修改备注
  797. public function actionUpdateRemark()
  798. {
  799. $remark = Yii::$app->request->post('remark', '');
  800. $id = Yii::$app->request->post('id', '');
  801. $cg = PurchaseOrderClass::getById($id, true);
  802. if (empty($cg)) {
  803. util::fail('没有找到订单');
  804. }
  805. if ($cg->shopId != $this->shopId) {
  806. util::fail('没有权限修改');
  807. }
  808. $cg->remark = $remark;
  809. $cg->save();
  810. util::complete('修改成功');
  811. }
  812. //应付款统计 ssh 20240528
  813. public function actionDueList()
  814. {
  815. $get = Yii::$app->request->get();
  816. $mainId = $this->mainId;
  817. $export = $get['export'] ?? 0;
  818. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : 0;
  819. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  820. $startTime = $get['startTime'] ?? '';
  821. $endTime = $get['endTime'] ?? '';
  822. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  823. $start = $period['startTime'];
  824. $end = $period['endTime'];
  825. $ghsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, 'id,name', 'id');
  826. $currentStartDate = date('Y-m-d', strtotime($start));
  827. $currentEndDate = date('Y-m-d', strtotime($end));
  828. $currentStartTime = $currentStartDate . ' 00:00:00';
  829. $currentEndTime = $currentEndDate . ' 23:59:59';
  830. $cgWhere = ['mainId' => $mainId, 'status' => 4];
  831. if ($debt > 0) {
  832. $cgWhere['debt'] = $debt;
  833. }
  834. $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
  835. $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
  836. $list = [];
  837. $totalAmount = 0;
  838. if (!empty($cgList)) {
  839. foreach ($cgList as $cgInfo) {
  840. $actPrice = $cgInfo['actPrice'] ?? 0;
  841. $ghsId = $cgInfo['ghsId'] ?? 0;
  842. if (isset($list[$ghsId])) {
  843. $list[$ghsId]['amount'] = bcadd($list[$ghsId]['amount'], $actPrice, 2);
  844. $list[$ghsId]['num'] = bcadd($list[$ghsId]['num'], 1);
  845. } else {
  846. $name = $ghsList[$ghsId] && $ghsList[$ghsId]['name'] ? $ghsList[$ghsId]['name'] : '未命名';
  847. $list[$ghsId] = ['id' => $ghsId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  848. }
  849. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  850. }
  851. $list = array_values($list);
  852. }
  853. if ($export == 1) {
  854. if (empty($list)) {
  855. util::fail('没有数据需要导出');
  856. }
  857. ini_set('memory_limit', '2045M');
  858. set_time_limit(0);
  859. PurchaseOrderClass::exportDueList($list, $mainId);
  860. util::stop();
  861. }
  862. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  863. }
  864. //修改入库时间 ssh 20240511
  865. public function actionModifyEntryTime()
  866. {
  867. $get = Yii::$app->request->get();
  868. $id = $get['id'] ?? 0;
  869. $date = $get['date'] ?? '';
  870. if (empty($date)) {
  871. util::fail('请选择日期');
  872. }
  873. $cg = PurchaseOrderClass::getById($id, true);
  874. if (empty($cg)) {
  875. util::fail('没有找到订单');
  876. }
  877. if ($cg->mainId != $this->mainId) {
  878. util::fail('不是你的订单');
  879. }
  880. $mainId = $this->mainId;
  881. //超管或者约定的人可以修改日期
  882. if (getenv('YII_ENV') == 'production') {
  883. if (in_array($mainId, [23390])) {
  884. if (!in_array($this->adminId, [24586, 23960])) {
  885. util::fail('你不能修改哦');
  886. }
  887. }
  888. } else {
  889. if (in_array($mainId, [644])) {
  890. if (!in_array($this->adminId, [919])) {
  891. }
  892. }
  893. }
  894. $entryTime = $cg->entryTime;
  895. $time = strtotime($entryTime);
  896. $after = date("H:i:s", $time);
  897. $new = $date . ' ' . $after;
  898. $cg->entryTime = $new;
  899. $cg->save();
  900. util::complete('修改成功');
  901. }
  902. //导入采购 ssh 20241126
  903. public function actionImportCreate()
  904. {
  905. $get = Yii::$app->request->get();
  906. $connection = Yii::$app->db;
  907. $transaction = $connection->beginTransaction();
  908. try {
  909. $ghsId = $get['id'] ?? '';
  910. $file = $_FILES['file'];
  911. if (!is_uploaded_file($file['tmp_name'])) {
  912. util::fail('please upload img');
  913. }
  914. $mainId = $this->sjId;
  915. $shopId = $this->shopId;
  916. $month = date("Ym");
  917. $date = date("d");
  918. $path = dirUtil::getImgUploadDir() . "/{$mainId}/cg/{$shopId}/{$month}/{$date}/";
  919. if (!file_exists($path)) {
  920. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  921. mkdir($path, 0700, true);
  922. }
  923. $preFileName = stringUtil::uniqueFileName();
  924. $newFile = $preFileName . ".xls";
  925. $fullPathFile = $path . $newFile;
  926. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  927. $arr = [];
  928. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  929. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  930. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  931. // 获取活动工作表
  932. $worksheet = $spreadsheet->getActiveSheet();
  933. // 遍历每一行
  934. foreach ($worksheet->getRowIterator() as $key => $row) {
  935. $cellIterator = $row->getCellIterator();
  936. // 这里设置为迭代所有单元格,包括空单元格
  937. $cellIterator->setIterateOnlyExistingCells(FALSE);
  938. // 遍历每列
  939. $rowData = [];
  940. foreach ($cellIterator as $cell) {
  941. $option = $cell->getValue();
  942. $rowData[] = trim($option);
  943. }
  944. $arr[] = $rowData;
  945. }
  946. array_shift($arr);
  947. $productIds = [];
  948. foreach ($arr as $k => $v) {
  949. $productId = $v[0] ?? 0;
  950. $productId = trim($productId);
  951. if (is_numeric($productId) && $productId > 0) {
  952. $productIds[] = $productId;
  953. }
  954. }
  955. if (empty($productIds)) {
  956. util::fail('没有识别出花材');
  957. }
  958. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  959. if (empty($productInfo)) {
  960. util::fail('没有找到有效花材');
  961. }
  962. $ghsItemInfo = [];
  963. foreach ($arr as $k => $v) {
  964. $productId = $v[0] ?? 0;
  965. $productId = trim($productId);
  966. $num = $v[2] ?? 0;
  967. $num = trim($num);
  968. $unitPrice = $v[3] ?? 0;
  969. $unitPrice = trim($unitPrice);
  970. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  971. $price = bcmul($unitPrice, $num, 2);
  972. $product = $productInfo[$productId] ?? [];
  973. $ptItemId = $product['itemId'] ?? 0;
  974. $ratio = $product['ratio'] ?? 20;
  975. $ratioType = $product['ratioType'] ?? 0;
  976. $ghsItemInfo[] = [
  977. 'productId' => $productId,
  978. 'bigNum' => $num,
  979. 'smallNum' => 0,
  980. 'itemId' => $ptItemId,
  981. 'itemPrice' => $unitPrice,
  982. 'totalPrice' => $price,
  983. 'assignSeat' => 0,
  984. 'ratio' => $ratio,
  985. 'ratioType' => $ratioType,
  986. 'aboutPrice' => 0,
  987. ];
  988. }
  989. }
  990. ini_set('memory_limit', '2045M');
  991. set_time_limit(0);
  992. $post = [];
  993. $post['sjId'] = $this->sjId;
  994. $post['shopId'] = $this->shopId;
  995. $post['adminId'] = $this->adminId;
  996. $post['mainId'] = $this->mainId;
  997. $staff = $this->shopAdmin;
  998. //以下二个都需要保留
  999. $post['staffId'] = $staff->id ?? 0;
  1000. $post['staffName'] = $staff->name ?? '';
  1001. $post['shopAdminId'] = $staff->id ?? 0;
  1002. $post['shopAdminName'] = $staff->name ?? '';
  1003. $shopAdmin = $this->shopAdmin;
  1004. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1005. util::fail('没有权限导入库存');
  1006. }
  1007. if (getenv('YII_ENV') == 'production') {
  1008. //小向花卉采购控制
  1009. if ($this->mainId == 23390) {
  1010. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4])) {
  1011. util::fail('你不能采购哦');
  1012. }
  1013. }
  1014. }
  1015. $shop = $this->shop;
  1016. $carSale = $shop->carSale ?? 0;
  1017. if ($carSale == 1) {
  1018. util::fail('车销不能采购');
  1019. }
  1020. //合并
  1021. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  1022. //判断花材格式,是否属于当前门店
  1023. ProductClass::valid($ghsItemInfo, $this->mainId);
  1024. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  1025. GhsClass::valid($ghsInfo, $this->shopId);
  1026. $post['ghsId'] = $ghsId;
  1027. $post['ghsInfo'] = json_encode($ghsInfo);
  1028. $post['ghsName'] = $ghsInfo['name'] ?? '';
  1029. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  1030. $shop = $this->shop;
  1031. $post['itemInfo'] = $ghsItemInfo;
  1032. //0稍后入库
  1033. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  1034. $post['inType'] = $inType;
  1035. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  1036. $post['debt'] = $debtStatus;
  1037. $order = PurchaseOrderClass::addOrder($post);
  1038. $transaction->commit();
  1039. util::success($order);
  1040. } else {
  1041. util::fail('导入失败了哦!');
  1042. }
  1043. } catch (\Exception $e) {
  1044. $transaction->rollBack();
  1045. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  1046. Yii::error("导入失败原因:" . $e->getMessage());
  1047. $msg = $e->getMessage();
  1048. util::fail('导入失败:' . $msg);
  1049. }
  1050. }
  1051. }