PurchaseOrderController.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. $connection = Yii::$app->db;
  898. $transaction = $connection->beginTransaction();
  899. try {
  900. $ghsId = $get['id'] ?? '';
  901. $file = $_FILES['file'];
  902. if (!is_uploaded_file($file['tmp_name'])) {
  903. util::fail('please upload img');
  904. }
  905. $mainId = $this->sjId;
  906. $shopId = $this->shopId;
  907. $month = date("Ym");
  908. $date = date("d");
  909. $path = dirUtil::getImgUploadDir() . "/{$mainId}/cg/{$shopId}/{$month}/{$date}/";
  910. if (!file_exists($path)) {
  911. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  912. mkdir($path, 0700, true);
  913. }
  914. $preFileName = stringUtil::uniqueFileName();
  915. $newFile = $preFileName . ".xls";
  916. $fullPathFile = $path . $newFile;
  917. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  918. $arr = [];
  919. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  920. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  921. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  922. // 获取活动工作表
  923. $worksheet = $spreadsheet->getActiveSheet();
  924. // 遍历每一行
  925. foreach ($worksheet->getRowIterator() as $key => $row) {
  926. $cellIterator = $row->getCellIterator();
  927. // 这里设置为迭代所有单元格,包括空单元格
  928. $cellIterator->setIterateOnlyExistingCells(FALSE);
  929. // 遍历每列
  930. $rowData = [];
  931. foreach ($cellIterator as $cell) {
  932. $option = $cell->getValue();
  933. $rowData[] = trim($option);
  934. }
  935. $arr[] = $rowData;
  936. }
  937. array_shift($arr);
  938. $productIds = [];
  939. foreach ($arr as $k => $v) {
  940. $productId = $v[0] ?? 0;
  941. $productId = trim($productId);
  942. if (is_numeric($productId) && $productId > 0) {
  943. $productIds[] = $productId;
  944. }
  945. }
  946. if (empty($productIds)) {
  947. util::fail('没有识别出花材');
  948. }
  949. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  950. if (empty($productInfo)) {
  951. util::fail('没有找到有效花材');
  952. }
  953. $ghsItemInfo = [];
  954. foreach ($arr as $k => $v) {
  955. $productId = $v[0] ?? 0;
  956. $productId = trim($productId);
  957. $num = $v[2] ?? 0;
  958. $num = trim($num);
  959. $unitPrice = $v[3] ?? 0;
  960. $unitPrice = trim($unitPrice);
  961. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  962. $price = bcmul($unitPrice,$num,2);
  963. $product = $productInfo[$productId] ?? [];
  964. $ptItemId = $product['itemId'] ?? 0;
  965. $ratio = $product['ratio']??20;
  966. $ratioType = $product['ratioType']??0;
  967. $ghsItemInfo[] = [
  968. 'productId'=>$productId,
  969. 'bigNum'=>$num,
  970. 'smallNum'=>0,
  971. 'itemId'=>$ptItemId,
  972. 'itemPrice'=>$unitPrice,
  973. 'totalPrice'=>$price,
  974. 'assignSeat'=>0,
  975. 'ratio'=>$ratio,
  976. 'ratioType'=>$ratioType,
  977. 'aboutPrice'=>0,
  978. ];
  979. }
  980. }
  981. ini_set('memory_limit', '2045M');
  982. set_time_limit(0);
  983. $post = [];
  984. $post['sjId'] = $this->sjId;
  985. $post['shopId'] = $this->shopId;
  986. $post['adminId'] = $this->adminId;
  987. $post['mainId'] = $this->mainId;
  988. $staff = $this->shopAdmin;
  989. //以下二个都需要保留
  990. $post['staffId'] = $staff->id ?? 0;
  991. $post['staffName'] = $staff->name ?? '';
  992. $post['shopAdminId'] = $staff->id ?? 0;
  993. $post['shopAdminName'] = $staff->name ?? '';
  994. $shopAdmin = $this->shopAdmin;
  995. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  996. util::fail('没有权限导入库存');
  997. }
  998. if (getenv('YII_ENV') == 'production') {
  999. //小向花卉采购控制
  1000. if ($this->mainId == 23390) {
  1001. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4])) {
  1002. util::fail('你不能采购哦');
  1003. }
  1004. }
  1005. }
  1006. $shop = $this->shop;
  1007. $carSale = $shop->carSale ?? 0;
  1008. if ($carSale == 1) {
  1009. util::fail('车销不能采购');
  1010. }
  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['ghsId'] = $ghsId;
  1018. $post['ghsInfo'] = json_encode($ghsInfo);
  1019. $post['ghsName'] = $ghsInfo['name'] ?? '';
  1020. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  1021. $shop = $this->shop;
  1022. $post['itemInfo'] = $ghsItemInfo;
  1023. //0稍后入库
  1024. $inType = PurchaseOrderClass::IN_TYPE_LATER;
  1025. $post['inType'] = $inType;
  1026. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  1027. $post['debt'] = $debtStatus;
  1028. $order = PurchaseOrderClass::addOrder($post);
  1029. $transaction->commit();
  1030. util::success($order);
  1031. } else {
  1032. util::fail('导入失败了哦!');
  1033. }
  1034. } catch (\Exception $e) {
  1035. $transaction->rollBack();
  1036. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  1037. Yii::error("导入失败原因:" . $e->getMessage());
  1038. $msg = $e->getMessage();
  1039. util::fail('导入失败:'.$msg);
  1040. }
  1041. }
  1042. }