PurchaseOrderController.php 59 KB

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