PurchaseOrderController.php 58 KB

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