PurchaseOrderController.php 58 KB

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