PurchaseOrderController.php 65 KB

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