PurchaseOrderController.php 49 KB

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