PurchaseOrderController.php 43 KB

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