PurchaseOrderController.php 41 KB

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