PurchaseOrderController.php 60 KB

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