OrderController.php 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizHd\purchase\classes\PurchaseClass;
  6. use bizHd\purchase\services\PurchaseService;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use bizGhs\order\classes\OrderClass;
  10. use bizGhs\order\services\OrderService;
  11. use bizHd\saas\services\RegionService;
  12. use bizGhs\product\classes\ProductClass;
  13. use common\components\baiduAip;
  14. use common\components\dict;
  15. use common\components\dateUtil;
  16. use common\components\freight;
  17. use common\components\httpUtil;
  18. use common\components\noticeUtil;
  19. use common\components\oss;
  20. use common\components\payUtil;
  21. use common\components\qrCodeUtil;
  22. use Yii;
  23. use common\components\util;
  24. use biz\shop\classes\ShopAdminClass;
  25. use biz\notice\classes\NoticeClass;
  26. use biz\wx\classes\WxMessageClass;
  27. use biz\shop\classes\ShopClass;
  28. use common\components\lakala\Lakala;
  29. class OrderController extends BaseController
  30. {
  31. public $guestAccess = ['create-order', 'order-relate', 'fast-pay', 'info'];
  32. //确认送达
  33. public function actionConfirmReach()
  34. {
  35. $get = Yii::$app->request->get();
  36. $id = $get['id'] ?? '';
  37. $order = OrderClass::getById($id, true);
  38. if (empty($order)) {
  39. util::fail('没有找到订单');
  40. }
  41. if ($order->mainId != $this->mainId) {
  42. util::fail('不是你的订单');
  43. }
  44. if ($order->status == 1) {
  45. util::fail('订单待付款');
  46. }
  47. if ($order->status == 4) {
  48. util::fail('订单已完成');
  49. }
  50. if ($order->status == 5) {
  51. util::fail('订单已取消');
  52. }
  53. OrderClass::confirmReach($order);
  54. util::complete('操作成功');
  55. }
  56. public function actionAllFh()
  57. {
  58. $post = Yii::$app->request->post();
  59. $ids = $post['ids'] ?? '';
  60. if (empty($ids)) {
  61. util::fail('请选择要合并发货的订单');
  62. }
  63. $arr = explode(',', $ids);
  64. if (empty($arr)) {
  65. util::fail('请选择要合并发货的订单哦');
  66. }
  67. $fhWl = $post['fhWl'] ?? '';
  68. $fhWlNo = $post['fhWlNo'] ?? '';
  69. $fhType = 0;
  70. $params = [
  71. 'fhType' => $fhType,
  72. 'fhWl' => $fhWl,
  73. 'fhWlNo' => $fhWlNo,
  74. ];
  75. $connection = Yii::$app->db;
  76. $transaction = $connection->beginTransaction();
  77. try {
  78. $all = OrderClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true);
  79. foreach ($all as $order) {
  80. if ($order->book == 1) {
  81. util::fail('有预订单,不能一起发货');
  82. }
  83. if ($order->mainId != $this->mainId) {
  84. util::fail('不是你的订单哦');
  85. }
  86. OrderClass::orderSend($order, $params, true);
  87. }
  88. $transaction->commit();
  89. util::complete();
  90. } catch (\Exception $e) {
  91. $transaction->rollBack();
  92. Yii::error("操作失败原因:" . $e->getMessage());
  93. util::fail('操作失败');
  94. }
  95. }
  96. //发货 ssh 20230613
  97. public function actionFh()
  98. {
  99. $post = Yii::$app->request->post();
  100. $id = $post['id'] ?? '';
  101. $order = OrderClass::getById($id, true);
  102. OrderClass::valid($order, $this->shopId);
  103. $fhWl = $post['fhWl'] ?? '';
  104. $fhWlNo = $post['fhWlNo'] ?? '';
  105. $fhType = $post['fhType'] ?? '';
  106. $params = [
  107. 'fhType' => $fhType,
  108. 'fhWl' => $fhWl,
  109. 'fhWlNo' => $fhWlNo,
  110. ];
  111. if ($order->book == 1) {
  112. util::fail('预订单不支持这个发货方式');
  113. }
  114. $connection = Yii::$app->db;
  115. $transaction = $connection->beginTransaction();
  116. try {
  117. OrderClass::orderSend($order, $params);
  118. $transaction->commit();
  119. util::complete();
  120. } catch (\Exception $e) {
  121. $transaction->rollBack();
  122. Yii::error("操作失败原因:" . $e->getMessage());
  123. util::fail('操作失败');
  124. }
  125. }
  126. //合并打印 ssh 20230929
  127. public function actionMergePrint()
  128. {
  129. $post = Yii::$app->request->post();
  130. $ids = $post['ids'] ?? '';
  131. if (empty($ids)) {
  132. util::fail('请选择要合并打印的订单');
  133. }
  134. $arr = explode(',', $ids);
  135. if (empty($arr)) {
  136. util::fail('请选择要合并打印的订单哦');
  137. }
  138. if (getenv('YII_ENV') == 'production') {
  139. if ($this->mainId != 10536 && $this->mainId != 50) {
  140. //util::fail('功能开发中');
  141. }
  142. } else {
  143. if ($this->mainId != 11) {
  144. //util::fail('功能开发中');
  145. }
  146. }
  147. OrderClass::mergePrintOrder($arr, $this->mainId);
  148. util::complete('打印成功');
  149. }
  150. //修改分工 ssh 20221129
  151. public function actionChangeWorker()
  152. {
  153. $post = Yii::$app->request->post();
  154. $id = $post['id'] ?? 0;
  155. $shopAdminId = $post['shopAdminId'] ?? 0;
  156. $shopAdminName = $post['shopAdminName'] ?? '';
  157. $order = OrderClass::getById($id, true);
  158. OrderClass::valid($order, $this->shopId);
  159. $preShopAdminId = $order->shopAdminId ?? 0;
  160. if (!empty($preShopAdminId)) {
  161. $shopAdmin = $this->shopAdmin;
  162. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  163. util::fail('管理员才能操作');
  164. }
  165. }
  166. $order->shopAdminId = $shopAdminId;
  167. $order->shopAdminName = $shopAdminName;
  168. $order->save();
  169. util::complete();
  170. }
  171. //预订单到货 ssh 20220321
  172. public function actionArrival()
  173. {
  174. $post = Yii::$app->request->post();
  175. $id = $post['id'] ?? 0;
  176. $connection = Yii::$app->db;
  177. $transaction = $connection->beginTransaction();
  178. try {
  179. $order = OrderClass::getById($id, true);
  180. OrderClass::valid($order, $this->shopId);
  181. $post['shopAdminId'] = $this->shopAdminId;
  182. $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
  183. OrderService::arrival($order, $post);
  184. $transaction->commit();
  185. util::complete();
  186. } catch (\Exception $e) {
  187. $transaction->rollBack();
  188. Yii::error("操作失败原因:" . $e->getMessage());
  189. util::fail('操作失败');
  190. }
  191. }
  192. //到货获取订单详情 ssh 20220323
  193. public function actionArrivalDetail()
  194. {
  195. $get = Yii::$app->request->get();
  196. $id = $get['id'] ?? 0;
  197. $info = OrderClass::getById($id);
  198. OrderClass::valid($info, $this->shopId);
  199. $showItemData = OrderClass::getOriginalShowItem(true, $info);
  200. $itemList = $showItemData['list'] ?? [];
  201. $info['product'] = $itemList;
  202. $kiloFee = $this->shop->kiloFee ?? 0;
  203. $miniKilo = $this->shop->miniKilo ?? 0;
  204. $info['kiloFee'] = $kiloFee;
  205. $info['miniKilo'] = $miniKilo;
  206. util::success($info);
  207. }
  208. //支付宝扫码支付 ssh 20210103
  209. public function actionScanPayCheck()
  210. {
  211. $get = Yii::$app->request->get();
  212. $id = isset($get['id']) ? $get['id'] : 0;
  213. $order = OrderClass::getById($id, true);
  214. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
  215. util::success(['returnStatus' => 'SUCCESS']);
  216. }
  217. $deadline = $order->deadline ?? '';
  218. $deadTime = strtotime($deadline);
  219. $current = time();
  220. $diff = bcsub($deadTime, $current);
  221. if ($diff <= 60) {
  222. util::success(['returnStatus' => 'EXPIRE']);
  223. }
  224. util::success(['returnStatus' => 'FAILURE']);
  225. }
  226. //微信和支付宝扫码支付 ssh 20210103
  227. public function actionScanPay()
  228. {
  229. ini_set('date.timezone', 'Asia/Shanghai');
  230. header("Content-type: text/html; charset=utf-8");
  231. $get = Yii::$app->request->get();
  232. $id = isset($get['id']) ? $get['id'] : 0;
  233. $order = OrderClass::getById($id, true);
  234. if (isset($order->status) == false || $order->status != 1) {
  235. util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
  236. }
  237. OrderClass::valid($order, $this->shopId);
  238. $cgId = $order->purchaseId ?? 0;
  239. $cg = PurchaseClass::getById($cgId, true);
  240. $orderSn = $cg->orderSn ?? '';
  241. if (empty($orderSn)) {
  242. util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
  243. }
  244. $deadline = $cg->deadline;
  245. $current = date("Y-m-d H:i:s");
  246. if ((strtotime($deadline) + 20) < strtotime($current)) {
  247. util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
  248. }
  249. $totalFee = $cg->actPrice ?? 0;
  250. $subject = '购买鲜花';
  251. $totalAmount = $totalFee;
  252. $body = "到店订单";
  253. //标记为扫码支付 和 自取订单
  254. $order->codePay = 2;
  255. $order->sendType = OrderClass::SEND_TYPE_NO;
  256. $order->save();
  257. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  258. $cg->codePay = 2;
  259. $cg->save();
  260. $shop = $this->shop;
  261. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  262. $wxPayWay = dict::getDict('payWay', 'wxPay');
  263. $aliPayWay = dict::getDict('payWay', 'alipay');
  264. $payWay = Yii::$app->request->get('payWay', $wxPayWay);
  265. if ($payWay == $wxPayWay) {
  266. if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
  267. $url = $order->wxPayUrl;
  268. } else {
  269. util::fail('暂不支持');
  270. $merchantExtend = WxOpenClass::getWxInfo();
  271. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  272. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  273. $params = [
  274. 'appid' => 'OP00002119',
  275. 'serial_no' => '018b08cfddbd',
  276. 'merchant_no' => $shop->lklSjNo,
  277. 'term_no' => $shop->lklScanTermNo,
  278. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  279. 'lklCertificatePath' => $lklCertificatePath,
  280. ];
  281. $laResource = new Lakala($params);
  282. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  283. $wxParams = [
  284. 'orderSn' => $orderSn,
  285. 'amount' => $totalFee,
  286. 'capitalType' => $currentCapitalType,
  287. 'notifyUrl' => $notifyUrl,
  288. 'subject' => $subject,
  289. 'couponId' => 0,
  290. 'wxAppId' => $merchantExtend['miniAppId'],
  291. ];
  292. $response = $laResource->driveNativeWxPay($wxParams);
  293. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  294. $msg = $response['msg'] ?? '';
  295. noticeUtil::push($msg, '15280215347');
  296. util::fail('二维码生成失败');
  297. }
  298. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  299. if (empty($url)) {
  300. util::fail('二维码生成失败..');
  301. }
  302. $order->wxPayUrl = $url;
  303. $order->save();
  304. }
  305. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  306. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  307. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  308. }
  309. if ($payWay == $aliPayWay) {
  310. if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
  311. $url = $order->aliPayUrl;
  312. } else {
  313. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  314. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  315. $params = [
  316. 'appid' => 'OP00002119',
  317. 'serial_no' => '018b08cfddbd',
  318. 'merchant_no' => $shop->lklSjNo,
  319. 'term_no' => $shop->lklScanTermNo,
  320. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  321. 'lklCertificatePath' => $lklCertificatePath,
  322. ];
  323. $laResource = new Lakala($params);
  324. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  325. $aliParams = [
  326. 'orderSn' => $orderSn,
  327. 'amount' => $totalFee,
  328. 'capitalType' => $currentCapitalType,
  329. 'notifyUrl' => $notifyUrl,
  330. 'subject' => $subject,
  331. ];
  332. $response = $laResource->driveAliPay($aliParams);
  333. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  334. util::fail('二维码生成失败');
  335. }
  336. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  337. if (empty($url)) {
  338. util::fail('二维码生成失败..');
  339. }
  340. $order->aliPayUrl = $url;
  341. $order->save();
  342. }
  343. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  344. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  345. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  346. }
  347. util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
  348. }
  349. //微信和支付宝付款码支付复查 ssh 20211231
  350. public function actionCodePayCheck()
  351. {
  352. ini_set('date.timezone', 'Asia/Shanghai');
  353. header("Content-type: text/html; charset=utf-8");
  354. $get = Yii::$app->request->get();
  355. $id = isset($get['id']) ? $get['id'] : 0;
  356. $order = OrderClass::getById($id, true);
  357. if (empty($order)) {
  358. util::success(['returnStatus' => 'SUCCESS']);
  359. }
  360. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  361. util::complete('订单已付款');
  362. }
  363. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  364. util::complete('订单不是待付款状态');
  365. }
  366. OrderClass::valid($order, $this->shopId);
  367. $cgId = $order->purchaseId ?? 0;
  368. $cg = PurchaseClass::getById($cgId, true);
  369. $orderSn = $cg->orderSn ?? '';
  370. $totalFee = $cg->actPrice ?? 0;
  371. if (empty($orderSn)) {
  372. util::complete('没有找到采购单');
  373. }
  374. $connection = Yii::$app->db;
  375. $transaction = $connection->beginTransaction();
  376. try {
  377. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  378. $shop = $this->shop;
  379. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  380. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  381. $params = [
  382. 'appid' => 'OP00002119',
  383. 'serial_no' => '018b08cfddbd',
  384. 'merchant_no' => $shop->lklSjNo,
  385. 'term_no' => $shop->lklScanTermNo,
  386. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  387. 'lklCertificatePath' => $lklCertificatePath,
  388. ];
  389. $laResource = new Lakala($params);
  390. $scanParams = ['orderSn' => $orderSn,];
  391. $response = $laResource->query($scanParams);
  392. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  393. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  394. //支付成功
  395. $transactionId = $response['resp_data']['trade_no'] ?? '';
  396. $openId = '';
  397. $aliUserId = '';
  398. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  399. $cg->codePay = 1;
  400. $cg->payOpenId = $openId;
  401. $cg->aliUserId = $aliUserId;
  402. //自取订单
  403. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  404. $cg->save();
  405. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  406. $order->codePay = 1;
  407. //自取订单
  408. $order->sendType = OrderClass::SEND_TYPE_NO;
  409. $order->save();
  410. $payWayType = dict::getDict('payWay', 'wxPay');
  411. $account_type = $response['resp_data']['account_type'] ?? '';
  412. if ($account_type == 'WECHAT') {
  413. $payWayType = dict::getDict('payWay', 'wxPay');
  414. }
  415. if ($account_type == 'ALIPAY') {
  416. $payWayType = dict::getDict('payWay', 'alipay');
  417. }
  418. $order->payWay = $payWayType;
  419. $order->save();
  420. $cg->payWay = $payWayType;
  421. $cg->save();
  422. $attach = '';
  423. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  424. $transaction->commit();
  425. $saleId = $order->id ?? 0;
  426. $order = OrderClass::getById($saleId, true);
  427. if (!empty($order)) {
  428. //订单生成时唤起在线打印
  429. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  430. if ($order->status != 1 && $order->status != 5) {
  431. OrderClass::onlinePrint($order);
  432. $order->printNum += 1;
  433. $order->save();
  434. }
  435. }
  436. ShopExtClass::ghsGatheringReport($order);
  437. }
  438. util::success(['returnStatus' => 'SUCCESS']);
  439. } else {
  440. util::complete('未知状态..');
  441. }
  442. } else {
  443. util::complete('未知状态....');
  444. }
  445. } catch (\Exception $e) {
  446. $transaction->rollBack();
  447. noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
  448. util::fail('支付失败');
  449. }
  450. }
  451. //微信和支付宝付款码支付 ssh 2021.4.11
  452. public function actionCodePay()
  453. {
  454. ini_set('date.timezone', 'Asia/Shanghai');
  455. header("Content-type: text/html; charset=utf-8");
  456. $get = Yii::$app->request->get();
  457. $id = isset($get['id']) ? $get['id'] : 0;
  458. $order = OrderClass::getById($id, true);
  459. if (isset($order->status) == false || $order->status != 1) {
  460. util::fail('不是待付款订单');
  461. }
  462. OrderClass::valid($order, $this->shopId);
  463. $cgId = $order->purchaseId ?? 0;
  464. $cg = PurchaseClass::getById($cgId, true);
  465. $orderSn = $cg->orderSn ?? '';
  466. if (empty($orderSn)) {
  467. util::fail('没有找到采购单');
  468. }
  469. //付款码
  470. $authCode = (string)$get['authCode'] ?? '';
  471. if (empty($authCode)) {
  472. util::fail('支付失败');
  473. }
  474. $deadline = $cg->deadline;
  475. $current = date("Y-m-d H:i:s");
  476. if ((strtotime($deadline) + 20) < strtotime($current)) {
  477. util::fail('订单已经失效');
  478. }
  479. $totalFee = $cg->actPrice ?? 0;
  480. $connection = Yii::$app->db;
  481. $transaction = $connection->beginTransaction();
  482. try {
  483. $subject = '购买花材';
  484. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  485. $shop = $this->shop;
  486. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  487. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  488. $params = [
  489. 'appid' => 'OP00002119',
  490. 'serial_no' => '018b08cfddbd',
  491. 'merchant_no' => $shop->lklSjNo,
  492. 'term_no' => $shop->lklScanTermNo,
  493. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  494. 'lklCertificatePath' => $lklCertificatePath,
  495. ];
  496. $laResource = new Lakala($params);
  497. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  498. $scanParams = [
  499. 'orderSn' => $orderSn,
  500. 'amount' => $totalFee,
  501. 'capitalType' => $capitalType,
  502. 'notifyUrl' => $notifyUrl,
  503. 'subject' => $subject,
  504. 'authCode' => $authCode,
  505. ];
  506. $response = $laResource->scanPay($scanParams);
  507. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  508. $account_type = $response['resp_data']['account_type'] ?? '';
  509. $payWayType = dict::getDict('payWay', 'wxPay');
  510. if ($account_type == 'WECHAT') {
  511. $payWayType = dict::getDict('payWay', 'wxPay');
  512. }
  513. if ($account_type == 'ALIPAY') {
  514. $payWayType = dict::getDict('payWay', 'alipay');
  515. }
  516. $order->payWay = $payWayType;
  517. $order->save();
  518. $cg->payWay = $payWayType;
  519. $cg->save();
  520. $transactionId = $response['resp_data']['trade_no'] ?? '';
  521. $openId = '';
  522. $aliUserId = '';
  523. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  524. $cg->codePay = 1;
  525. $cg->payOpenId = $openId;
  526. $cg->aliUserId = $aliUserId;
  527. //自取订单
  528. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  529. $cg->save();
  530. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  531. $order->codePay = 1;
  532. //自取订单
  533. $order->sendType = OrderClass::SEND_TYPE_NO;
  534. $order->save();
  535. $attach = '';
  536. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  537. $transaction->commit();
  538. $saleId = $order->id ?? 0;
  539. $order = OrderClass::getById($saleId, true);
  540. if (!empty($order)) {
  541. //订单生成时唤起在线打印
  542. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  543. if ($order->status != 1 && $order->status != 5) {
  544. OrderClass::onlinePrint($order);
  545. $order->printNum += 1;
  546. $order->save();
  547. }
  548. }
  549. ShopExtClass::ghsGatheringReport($order);
  550. }
  551. util::success(['returnStatus' => 'SUCCESS']);
  552. } else {
  553. $msg = $response['msg'] ?? '';
  554. util::success(['returnStatus' => 'FAILURE'], $msg);
  555. }
  556. } catch (\Exception $e) {
  557. $transaction->rollBack();
  558. Yii::error("支付失败原因:" . $e->getMessage());
  559. util::fail('支付失败');
  560. }
  561. }
  562. //订单列表 ssh 2021.1.20
  563. public function actionList()
  564. {
  565. $get = Yii::$app->request->get();
  566. $where['mainId'] = $this->mainId;
  567. $status = $get['status'] ?? 0;
  568. if (!empty($status)) {
  569. $where['status'] = $status;
  570. }
  571. $book = $get['book'] ?? -1;
  572. if ($book > -1) {
  573. $where['book'] = $book;
  574. }
  575. $searchTime = $get['searchTime'] ?? '';
  576. if (!empty($searchTime)) {
  577. $startTime = $get['startTime'] ?? '';
  578. $endTime = $get['endTime'] ?? '';
  579. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  580. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  581. }
  582. $name = $get['name'] ?? '';
  583. if (!empty($name)) {
  584. $searchType = $get['searchType'] ?? 0;
  585. if (empty($searchType)) {
  586. //订单编号
  587. if (strpos($name, 'XSD') === 0) {
  588. $where['orderSn'] = $name;
  589. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  590. $where['customNamePy'] = ['like', $name];
  591. } else {
  592. $where['customName'] = ['like', $name];
  593. }
  594. } elseif ($searchType == 1) {
  595. $where['sendNum'] = $name;
  596. } else {
  597. }
  598. }
  599. if (isset($get['customId']) && !empty($get['customId'])) {
  600. $where['customId'] = $get['customId'];
  601. }
  602. if (isset($get['ids']) && !empty($get['ids'])) {
  603. $stringIds = $get['ids'];
  604. $newIds = explode(',', $stringIds);
  605. $where['id'] = ['in', $newIds];
  606. }
  607. $respond = OrderClass::getOrderList($where);
  608. $respond['shop'] = $this->shop;
  609. $respond['shopExt'] = $this->shopExt;
  610. util::success($respond);
  611. }
  612. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  613. public function actionNewOrderList()
  614. {
  615. $get = Yii::$app->request->get();
  616. $where['shopId'] = $this->shopId;
  617. /*$status = $get['status'] ?? 0;
  618. if (!empty($status)) {
  619. $where['status'] = $status;
  620. }*/
  621. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  622. if (isset($get['type'])) {
  623. $type = $get['type'];
  624. if ($type == 1) { // 今日实收
  625. $get['searchTime'] = 'today';
  626. $where['debt'] = 0;
  627. $where['debtPrice'] = '0.00';
  628. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  629. } elseif ($type == 2) { // 今日欠款
  630. $get['searchTime'] = 'today';
  631. $where['debt'] = 1;
  632. } elseif ($type == 3) { // 总欠款
  633. $where['debt'] = 1;
  634. } else {
  635. util::fail('查询的订单类别不存在');
  636. }
  637. }
  638. $searchTime = $get['searchTime'] ?? '';
  639. if (!empty($searchTime)) {
  640. $startTime = '';
  641. $endTime = '';
  642. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  643. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  644. }
  645. $name = $get['name'] ?? '';
  646. if (!empty($name)) {
  647. $searchType = $get['searchType'] ?? 0;
  648. if (empty($searchType)) {
  649. //订单编号
  650. if (strpos($name, 'XSD') === 0) {
  651. $where['orderSn'] = $name;
  652. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  653. $where['customNamePy'] = ['like', $name];
  654. } else {
  655. $where['customName'] = ['like', $name];
  656. }
  657. } elseif ($searchType == 1) {
  658. $where['sendNum'] = $name;
  659. } else {
  660. util::fail('搜索的订单类别不存在');
  661. }
  662. }
  663. $respond = OrderClass::getOrderList($where);
  664. $respond['shop'] = $this->shop;
  665. $respond['shopExt'] = $this->shopExt;
  666. $respond['type'] = $type; //把查询类别返回
  667. util::success($respond);
  668. }
  669. //商城下单操作 ssh 2021.1.14
  670. public function actionCreateOrder()
  671. {
  672. $post = Yii::$app->request->post();
  673. $shopId = $this->shopId;
  674. $customId = $post['customId'] ?? 0;
  675. $post['customId'] = $customId;
  676. //开单必须选客户
  677. if (empty($customId)) {
  678. util::fail('请选择客户');
  679. }
  680. $custom = CustomClass::getCustom($customId);
  681. if (empty($custom)) {
  682. util::fail('请选客户哦');
  683. }
  684. CustomClass::valid($custom, $this->shopId);
  685. if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  686. util::fail('不能给自己的零售店开单');
  687. }
  688. $post['ghsId'] = $custom['ghsId'] ?? 0;
  689. $post['customMobile'] = $custom['mobile'] ?? '';
  690. $customName = $custom['name'] ?? '';
  691. $post['customName'] = $customName;
  692. $post['customNamePy'] = $custom['py'] ?? '';
  693. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  694. $post['province'] = $custom['province'] ?? '';
  695. $post['city'] = $custom['city'] ?? '';
  696. $post['dist'] = $custom['dist'] ?? '';
  697. $post['address'] = $custom['address'] ?? '';
  698. $post['floor'] = $custom['floor'] ?? '';
  699. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  700. $post['showAddress'] = $custom['showAddress'] ?? '';
  701. $post['long'] = $custom['long'] ?? '';
  702. $post['lat'] = $custom['lat'] ?? '';
  703. $shopAdmin = $this->shopAdmin;
  704. $shopAdminId = $this->shopAdminId;
  705. $shopAdminName = $shopAdmin->name ?? '';
  706. if (isset($post['getStaffId']) == true && !empty($post['getStaffId'])) {
  707. $getStaffName = $post['getStaffName'] ?? '';
  708. $shopAdminId = $post['getStaffId'];
  709. $shopAdminName = $getStaffName;
  710. }
  711. //开单人和收款人必定是同个人
  712. $post['shopAdminId'] = $shopAdminId;
  713. $post['shopAdminName'] = $shopAdminName;
  714. $post['getStaffId'] = $shopAdminId;
  715. $post['getStaffName'] = $shopAdminName;
  716. $post['sjId'] = $this->sjId;
  717. $post['shopId'] = $shopId;
  718. $post['mainId'] = $this->mainId;
  719. $post['fromType'] = 1;
  720. $post['expressId'] = $post['expressId'] ?? 0;
  721. $book = $post['book'] ?? 0;
  722. $post['book'] = $book;
  723. $sendType = $post['sendType'] ?? 0;
  724. $transType = $post['transType'] ?? 0;
  725. $shop = $this->shop;
  726. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  727. //昆明发往全国
  728. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  729. $post['sendCost'] = $sendCost;
  730. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  731. $post['packCost'] = $packCost;
  732. $post['transType'] = $transType;
  733. $post['localOrder'] = 1;
  734. } else {
  735. //同步配送
  736. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  737. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  738. util::fail('填了运费,请选择代叫跑腿');
  739. }
  740. $post['sendCost'] = $sendCost;
  741. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  742. }
  743. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  744. $post['debt'] = OrderClass::DEBT_NO;
  745. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  746. $post['debt'] = OrderClass::DEBT_YES;
  747. }
  748. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  749. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  750. //util::fail('没有权限');
  751. }
  752. }
  753. //多颜色数据整理
  754. $colorItem = $post['xj'] ?? [];
  755. $newXj = [];
  756. if (!empty($colorItem)) {
  757. $colorData = json_decode($colorItem, true);
  758. if (!empty($colorData) && is_array($colorData)) {
  759. foreach ($colorData as $colorInfo) {
  760. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  761. $colorList = $colorInfo['list'] ?? [];
  762. if (!empty($colorList)) {
  763. foreach ($colorList as $colorItemKey => $colorItem) {
  764. $newXj[$ptItemId][] = $colorItem;
  765. }
  766. }
  767. }
  768. }
  769. }
  770. $post['xj'] = $newXj;
  771. $productJson = $post['product'] ?? '';
  772. if (empty($productJson)) {
  773. util::fail('请选择花材');
  774. }
  775. $productList = json_decode($productJson, true);
  776. if (empty($productList)) {
  777. util::fail('请选择花材');
  778. }
  779. $dealPrice = $post['dealPrice'] ?? 0;
  780. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  781. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  782. if (empty($itemInfo)) {
  783. util::fail('请选择花材哦');
  784. }
  785. //判断花材有效性
  786. foreach ($itemInfo as $itemData) {
  787. if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
  788. util::fail('只能选择同一家的商品哈');
  789. }
  790. }
  791. //开单提交订单时,别人修改价格,暂成提交价格不是真实卖价问题解决!!
  792. if ($dealPrice == 0) {
  793. $diff = [];
  794. $priceMap = CustomClass::$levelPriceKeyMap;
  795. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  796. $level = $custom['level'] ?? 1;
  797. foreach ($productList as $currentKey => $currentProduct) {
  798. $currentPrice = $currentProduct['price'] ?? 0;
  799. $currentId = $currentProduct['productId'] ?? 0;
  800. $systemInfo = $itemInfo[$currentId] ?? [];
  801. $name = $systemInfo['name'] ?? '';
  802. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  803. if (floatval($currentPrice) != floatval($systemPrice)) {
  804. $diff[] = [
  805. 'name' => $name,
  806. 'price' => $systemPrice,
  807. 'kdPrice' => $currentPrice,
  808. ];
  809. }
  810. }
  811. if (!empty($diff)) {
  812. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  813. }
  814. }
  815. if ($book == 1) {
  816. foreach ($productList as $currentKey => $currentProduct) {
  817. //帮开预订单没有价格
  818. $productList[$currentKey]['price'] = 0.06;
  819. }
  820. $post['hasPay'] = 2;
  821. $post['payWay'] = 0;
  822. } else {
  823. foreach ($productList as $currentKey => $currentProduct) {
  824. //预订单用了0.06这个价格
  825. $nowPrice = $currentProduct['price'];
  826. if ($nowPrice == 0.06) {
  827. util::fail('花材不允许使用0.06元,请改其它价');
  828. }
  829. }
  830. }
  831. //4秒内不允许重复开单
  832. $staffId = $this->shopAdminId ?? 0;
  833. $cacheKey = 'ghs_create_order_' . $staffId . '_' . $customId;
  834. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  835. if (!empty($has)) {
  836. util::fail('请稍等');
  837. }
  838. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  839. $connection = Yii::$app->db;//事务处理
  840. $transaction = $connection->beginTransaction();
  841. try {
  842. $post['product'] = $productList;
  843. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  844. $time = time();
  845. $hasTime = dict::getDict('order_pay_has_time');
  846. $totalTime = bcadd($time, $hasTime);
  847. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  848. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  849. $transaction->commit();
  850. $saleId = $return->id ?? 0;
  851. $order = OrderClass::getById($saleId, true);
  852. if (!empty($order)) {
  853. $shopId = $order->shopId ?? 0;
  854. $shop = ShopClass::getById($shopId, true);
  855. if (isset($order->payStatus) && $order->payStatus == 1) {
  856. if (!empty($shop)) {
  857. //通知员工
  858. $noticeText = json_encode(['orderId' => $saleId]);
  859. $noticeKey = "hdCgNoticeGhs";
  860. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  861. //通知花店
  862. // $noticeText = json_encode(['id' => $order->purchaseId]);
  863. // $noticeKey = "ghsKdNoticeHd";
  864. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  865. }
  866. }
  867. //订单生成时唤起在线打印
  868. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  869. if ($order->status != 1 && $order->status != 5) {
  870. OrderClass::onlinePrint($order);
  871. $order->printNum += 1;
  872. $order->save();
  873. }
  874. }
  875. //前台提醒出示付款码
  876. if (isset($order->status) && $order->status == 1) {
  877. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  878. ShopExtClass::ghsPleasePayReport($order);
  879. }
  880. }
  881. }
  882. util::success($return);
  883. } catch (\Exception $e) {
  884. $transaction->rollBack();
  885. Yii::error("下单失败原因:" . $e->getMessage());
  886. noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
  887. util::fail('下单失败');
  888. }
  889. }
  890. //修改订单 ssh 20210810
  891. public function actionUpdateOrder()
  892. {
  893. $post = Yii::$app->request->post();
  894. util::fail('订单不可修改');
  895. //PC端开单
  896. if (isset($post['clearType'])) {
  897. $clearType = $post['clearType'];
  898. if ($clearType == OrderClass::CLEAR_DEBT) {
  899. $post['debt'] = OrderClass::DEBT_YES;
  900. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  901. } else {
  902. $post['debt'] = OrderClass::DEBT_NO;
  903. }
  904. }
  905. //员工不能开已收款订单
  906. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  907. if ($debt == OrderClass::DEBT_NO) {
  908. $shopAdmin = $this->shopAdmin;
  909. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  910. util::fail('不能开已收款订单');
  911. }
  912. }
  913. //PC端开单
  914. if (isset($post['getType'])) {
  915. util::fail('暂不支持PC端修改订单');
  916. $getType = $post['getType'];
  917. //自取
  918. if ($getType == 1) {
  919. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  920. } else {
  921. //选择配送时,在发货时让商家自己再确认一下用什么方式
  922. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  923. }
  924. }
  925. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  926. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  927. $post['debt'] = OrderClass::DEBT_NO;
  928. }
  929. $id = $post['id'] ?? 0;
  930. $order = OrderClass::getLockById($id);
  931. if (empty($order)) {
  932. util::fail('没有找到订单');
  933. }
  934. OrderClass::valid($order, $this->shopId);
  935. unset($post['id']);
  936. $shopAdmin = $this->shopAdmin;
  937. $post['shopAdminId'] = $this->shopAdminId;
  938. $post['shopAdminName'] = $shopAdmin->name ?? '';
  939. $post['fromType'] = 1;
  940. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  941. $productJson = $post['product'] ?? '';
  942. if (empty($productJson)) {
  943. util::fail('请选择花材');
  944. }
  945. $productList = json_decode($productJson, true);
  946. if (empty($productList)) {
  947. util::fail('请选择花材');
  948. }
  949. $connection = Yii::$app->db;//事务处理
  950. $transaction = $connection->beginTransaction();
  951. try {
  952. //判断花材有效性
  953. ProductClass::valid($productList, $this->mainId);
  954. $post['product'] = $productList;
  955. //商家开单订单有效期,到期记欠款
  956. $validTime = dict::getDict('order_pay_has_time');
  957. $current = time() + $validTime;
  958. $post['deadline'] = date("Y-m-d H:i:s", $current);
  959. $upData = [
  960. 'payWay' => $post['payWay'],
  961. 'sendType' => $post['sendType'],
  962. 'debt' => $post['debt'],
  963. 'needPrint' => $post['needPrint'],
  964. 'modifyPrice' => $post['modifyPrice'],
  965. 'shopAdminId' => $post['shopAdminId'],
  966. 'shopAdminName' => $post['shopAdminName'],
  967. 'fromType' => 1,
  968. 'sendCost' => $post['sendCost'],
  969. 'product' => $post['product'],
  970. 'deadline' => $post['deadline'],
  971. 'debt' => $post['debt'],
  972. ];
  973. $return = OrderService::updateOrder($order, $upData);
  974. $transaction->commit();
  975. util::success($return);
  976. } catch (\Exception $e) {
  977. $transaction->rollBack();
  978. Yii::error("下单失败原因:" . $e->getMessage());
  979. util::fail('下单失败');
  980. }
  981. }
  982. //取消订单 shizhongqi 20220619
  983. public function actionCancelOrder()
  984. {
  985. $post = Yii::$app->request->post();
  986. $id = $post['orderId'] ?? 0;
  987. if (empty($id)) {
  988. util::fail('请选择订单');
  989. }
  990. $order = OrderClass::getById($id, true);
  991. if (empty($order)) {
  992. util::fail('请选择订单...');
  993. }
  994. OrderClass::valid($order, $this->shopId);
  995. if (isset($order->status) == false || $order->status != 1) {
  996. util::fail('不是待付款状态,无法取消');
  997. }
  998. $purchaseId = $order->purchaseId ?? 0;
  999. $purchase = PurchaseClass::getById($purchaseId);
  1000. if (empty($purchase)) {
  1001. util::fail('没有找到采购单');
  1002. }
  1003. $deadLineTime = strtotime($purchase['deadline']);
  1004. $diff = $deadLineTime - time();
  1005. if ($diff <= 60) {
  1006. util::fail('1分钟后订单将自动取消');
  1007. }
  1008. $connection = Yii::$app->db;//事务处理
  1009. $transaction = $connection->beginTransaction();
  1010. $orderSn = $purchase['orderSn'];
  1011. try {
  1012. $current = PurchaseClass::getById($purchaseId, true);
  1013. PurchaseService::expire($current);
  1014. $transaction->commit();
  1015. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1016. } catch (\Exception $e) {
  1017. $transaction->rollBack();
  1018. $msg = $e->getMessage();
  1019. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1020. }
  1021. util::complete();
  1022. }
  1023. //延期支付 ssh 2021.1.19
  1024. public function actionDebt()
  1025. {
  1026. $id = Yii::$app->request->get('id');
  1027. $order = OrderClass::getById($id, true);
  1028. OrderClass::valid($order, $this->shopId);
  1029. $payWay = dict::getDict('payWay', 'debtPay');
  1030. $cgId = $order->purchaseId ?? 0;
  1031. $cg = PurchaseClass::getById($cgId, true);
  1032. if (empty($cg)) {
  1033. util::fail('没有找到采购单');
  1034. }
  1035. if ($order->book == 1) {
  1036. util::fail('预订单不能记欠款');
  1037. }
  1038. PurchaseService::payAfter($cg, $payWay);
  1039. OrderService::payAfter($order, $payWay);
  1040. $order = OrderClass::getById($id, true);
  1041. if (!empty($order)) {
  1042. $shopId = $order->shopId ?? 0;
  1043. $shop = ShopClass::getById($shopId, true);
  1044. if (!empty($shop)) {
  1045. //花店采购供货商端微信收到通知
  1046. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1047. $noticeText = json_encode(['orderId' => $id]);
  1048. $noticeKey = "hdCgNoticeGhs";
  1049. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1050. }
  1051. //订单生成时唤起在线打印
  1052. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1053. if ($order->status != 1 && $order->status != 5) {
  1054. OrderClass::onlinePrint($order);
  1055. $order->printNum += 1;
  1056. $order->save();
  1057. }
  1058. }
  1059. if ($order->status != 1 && $order->status != 5) {
  1060. //花店采购供货商端APP收到通知
  1061. //NoticeClass::ghsNewOrderNotice($order);
  1062. }
  1063. }
  1064. util::complete();
  1065. }
  1066. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1067. public function actionWxPay()
  1068. {
  1069. ini_set('date.timezone', 'Asia/Shanghai');
  1070. $post = Yii::$app->request->post();
  1071. $couponId = $post['couponId'] ?? 0;
  1072. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1073. $order = OrderClass::getByOrderSn($orderSn);
  1074. if (empty($order)) {
  1075. util::fail('订单号无效');
  1076. }
  1077. $id = $order['id'];
  1078. //支付前验证订单有效性
  1079. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1080. util::fail('无法操作');
  1081. }
  1082. $name = $order['orderName'] ?? '购买商品';
  1083. $totalFee = $order['actPrice'];
  1084. //强制使用小程序的miniOpenId
  1085. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1086. if (empty($openId)) {
  1087. util::fail('没有找到openId');
  1088. }
  1089. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1090. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1091. $wxPayType = 0;
  1092. if (httpUtil::isMiniProgram()) {
  1093. $wxPayType = 1;
  1094. }
  1095. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1096. //订单30分钟后过期
  1097. $now = time();
  1098. $expireTime = $now + 1800;
  1099. $wx = Yii::getAlias("@vendor/weixin");
  1100. require_once($wx . '/lib/WxPay.Api.php');
  1101. require_once($wx . '/example/WxPay.JsApiPay.php');
  1102. $input = new \WxPayUnifiedOrder();
  1103. $input->SetBody($name);
  1104. $input->SetOut_trade_no($orderSn);
  1105. $input->SetTotal_fee($totalFee * 100);
  1106. $input->SetTime_start(date("YmdHis", $now));
  1107. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1108. $input->SetTime_expire(date("YmdHis", $expireTime));
  1109. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1110. $input->SetTrade_type("JSAPI");
  1111. //花卉宝代为申请的微信支付
  1112. //$sjExtend = $this->sjExtend->attributes;
  1113. $sjExtend = WxOpenClass::getGhsWxInfo();
  1114. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1115. $input->SetSub_openid($openId);
  1116. } else {
  1117. $input->SetOpenid($openId);
  1118. }
  1119. //强制使用小程序的miniAppId
  1120. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1121. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1122. $tools = new \JsApiPay();
  1123. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1124. $newParams = json_decode($jsApiParameters, true);
  1125. //微信不能修改价格
  1126. $current = date("Y-m-d H:i:s");
  1127. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1128. OrderClass::updateById($id, $updateData);
  1129. util::success($newParams);
  1130. }
  1131. //获取订单详情 ssh 2021.1.21
  1132. public function actionDetail()
  1133. {
  1134. $get = Yii::$app->request->get();
  1135. $id = $get['id'] ?? 0;
  1136. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1137. OrderClass::valid($info, $this->shopId);
  1138. //A4打印需要用到的数据
  1139. $customId = $info['customId'] ?? 0;
  1140. $custom = CustomClass::getById($customId, true);
  1141. if (empty($custom)) {
  1142. util::fail('没有找到客户');
  1143. }
  1144. $customName = $custom->name ?? '';
  1145. $seatSn = $custom->seatSn ?? '';
  1146. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1147. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1148. $table = [];
  1149. if (isset($info['product']) && !empty($info['product'])) {
  1150. foreach ($info['product'] as $key => $val) {
  1151. $currentName = $val['name'] ?? '';
  1152. $num = $val['xhNum'] ?? 0;
  1153. $table[] = [
  1154. 'name' => $currentName,
  1155. 'num' => $num,
  1156. 'confirmNum' => '',
  1157. 'remark' => '',
  1158. ];
  1159. }
  1160. }
  1161. $a4Print = [
  1162. 'customName' => $customName,
  1163. 'seatSn' => $seatSn,
  1164. 'shortSendTimeWant' => $shortSendTimeWant,
  1165. 'table' => $table,
  1166. ];
  1167. $info['printData'] = $a4Print;
  1168. //是否有云打印判断
  1169. $hasCloudPrint = 0;
  1170. $shopExt = $this->shopExt;
  1171. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1172. $hasCloudPrint = 1;
  1173. }
  1174. $info['hasCloudPrint'] = $hasCloudPrint;
  1175. $purchaseId = $info['purchaseId'] ?? 0;
  1176. $cg = PurchaseClass::getById($purchaseId);
  1177. $info['cgInfo'] = $cg;
  1178. //店长信息
  1179. $mainId = $cg['mainId'] ?? 0;
  1180. $superInfo = ShopAdminClass::getManager($mainId);
  1181. $info['customSuper'] = $superInfo;
  1182. util::success($info);
  1183. }
  1184. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1185. public function actionInfo()
  1186. {
  1187. $get = Yii::$app->request->get();
  1188. $id = $get['id'] ?? 0;
  1189. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1190. if (empty($info)) {
  1191. util::fail('没有找到订单');
  1192. }
  1193. //是否有云打印判断
  1194. $hasCloudPrint = 0;
  1195. $shopExt = $this->shopExt;
  1196. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1197. $hasCloudPrint = 1;
  1198. }
  1199. $info['hasCloudPrint'] = $hasCloudPrint;
  1200. $purchaseId = $info['purchaseId'] ?? 0;
  1201. $cg = PurchaseClass::getById($purchaseId);
  1202. $info['cgInfo'] = $cg;
  1203. //店长信息
  1204. $mainId = $cg['mainId'] ?? 0;
  1205. $superInfo = ShopAdminClass::getManager($mainId);
  1206. $info['customSuper'] = $superInfo;
  1207. util::success($info);
  1208. }
  1209. //自取免发货流程处理 ssh 2021.1.22
  1210. public function actionWithoutSend()
  1211. {
  1212. util::complete();
  1213. }
  1214. //本店送 ssh 2021.1.24
  1215. public function actionSelfSend()
  1216. {
  1217. $get = Yii::$app->request->get();
  1218. $id = isset($get['id']) ? $get['id'] : 0;
  1219. $info = OrderClass::getById($id, true);
  1220. OrderClass::valid($info->attributes, $this->shopId);
  1221. $connection = Yii::$app->db;
  1222. $transaction = $connection->beginTransaction();
  1223. try {
  1224. OrderClass::selfSend($info);
  1225. $transaction->commit();
  1226. } catch (\Exception $exception) {
  1227. $transaction->rollBack();
  1228. Yii::info("本店送操作报错:" . $exception->getMessage());
  1229. util::fail('操作失败');
  1230. }
  1231. util::complete();
  1232. }
  1233. //运费计算 ssh 2021.1.24
  1234. public function actionFreight()
  1235. {
  1236. //2021.3.28 接入达达
  1237. $get = Yii::$app->request->get();
  1238. $post = Yii::$app->request->post();
  1239. if (empty($get)) {
  1240. $get = $post;
  1241. }
  1242. $orderId = $get['id'] ?? 0; //订单ID
  1243. $customId = $get['customId'] ?? 0;
  1244. if (empty($orderId)) {
  1245. //自定义运费
  1246. //freight::getCost();
  1247. if (empty($customId)) {
  1248. util::fail("请选择客户");
  1249. }
  1250. $customInfo = CustomClass::getById($customId);
  1251. if (empty($customInfo)) {
  1252. util::fail('没有找到客户');
  1253. }
  1254. $shop = $this->shop;
  1255. //花材信息
  1256. $productJson = $get['product'] ?? '';
  1257. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1258. if (empty($productJson)) {
  1259. util::fail('请选择花材');
  1260. }
  1261. $productList = json_decode($productJson, true);
  1262. if (empty($productList)) {
  1263. util::fail('请选择花材');
  1264. }
  1265. $productList = ProductClass::mergeItemInfo($productList);
  1266. $weight = 0;
  1267. $price = 0;
  1268. $productData = ProductClass::getProductMapData($productList);
  1269. $bigNum = 0;
  1270. foreach ($productList as $key => $val) {
  1271. $productId = $val['productId'];
  1272. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1273. $bigNum += $val['bigNum'];
  1274. $weight = bcadd($w, $weight, 2);
  1275. $ratio = $productData[$productId]['ratio'] ?? 0;
  1276. //大小数量合并多少扎
  1277. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1278. //售卖价格
  1279. $itemPrice = $productData[$productId]['price'] ?? 0;
  1280. //合计价格
  1281. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1282. }
  1283. //没有经纬度的客户运费直接返回空 ssh 20210612
  1284. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1285. util::success(['sedCost' => '']);
  1286. }
  1287. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1288. util::success(['sedCost' => $cost]);
  1289. }
  1290. $province = $get['province'] ?? '';
  1291. $city = $get['city'] ?? '';
  1292. $address = $get['address'] ?? '';
  1293. $floor = $get['floor'] ?? '';
  1294. $customName = $get['customName'] ?? '';
  1295. $customMobile = $get['customMobile'] ?? '';
  1296. $fullAddress = $province . $city . $address . $floor;
  1297. $sendTime = $get['sendTime'] ?? '';
  1298. $lat = $get['lat'] ?? '';
  1299. $lng = $get['long'] ?? '';
  1300. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1301. util::fail('请填写客户地址');
  1302. }
  1303. ini_set('date.timezone', 'Asia/Shanghai');
  1304. if (!empty($sendTime)) {
  1305. //配送时间不为空
  1306. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1307. $sendTimeInt = strtotime($sendTime);
  1308. $now = time();
  1309. $diff = $sendTimeInt - $now;
  1310. //因服务器写入时间,改为至少提前6分钟
  1311. if ($diff <= 360) {
  1312. util::fail('配送时间至少提前6分钟');
  1313. }
  1314. } else {
  1315. //默认立即发送
  1316. $sendTime = 0;
  1317. }
  1318. //更新订单表
  1319. $info = OrderService::getOrderInfo($orderId);
  1320. OrderClass::valid($info, $this->shopId);
  1321. if ($sendTime) {
  1322. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1323. } else {
  1324. $sendTime = '0000-00-00 00:00:00';
  1325. }
  1326. $expressAddInfo = [
  1327. 'customName' => $customName,
  1328. 'customMobile' => $customMobile,
  1329. 'province' => $province,
  1330. 'city' => $city,
  1331. 'address' => $address,
  1332. 'floor' => $floor,
  1333. 'lat' => $lat,
  1334. 'long' => $lng,
  1335. 'sendTime' => $sendTime,
  1336. ];
  1337. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  1338. //计算运费
  1339. $info['province'] = $province;
  1340. $info['city'] = $city;
  1341. $info['address'] = $address;
  1342. $info['floor'] = $floor;
  1343. $info['fullAddress'] = $fullAddress;
  1344. $info['lat'] = $lat;
  1345. $info['long'] = $lng;
  1346. $info['sendTime'] = $expressAddInfo['sendTime'];
  1347. $res = DadaExpressServices::queryDeliverFee($info);
  1348. util::success(['sedCost' => $res['fee']]);
  1349. }
  1350. //发快递和第三方配送 ssh 2021.1.24
  1351. public function actionThirdSend()
  1352. {
  1353. $get = Yii::$app->request->get();
  1354. $id = isset($get['id']) ? $get['id'] : 0;
  1355. $info = OrderService::getById($id, true);
  1356. OrderClass::valid($info->attributes, $this->shopId);
  1357. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  1358. util::fail('请填写客户地址');
  1359. }
  1360. $connection = Yii::$app->db;
  1361. $transaction = $connection->beginTransaction();
  1362. try {
  1363. $respond = OrderClass::thirdSend($info, $get);
  1364. $transaction->commit();
  1365. util::success($respond);
  1366. } catch (\Exception $exception) {
  1367. $transaction->rollBack();
  1368. Yii::info("发快递操作报错:" . $exception->getMessage());
  1369. util::fail('操作失败' . $exception->getMessage());
  1370. }
  1371. }
  1372. //确认送达 ssh 2021.1.24
  1373. public function actionReach()
  1374. {
  1375. $get = Yii::$app->request->get();
  1376. $id = isset($get['id']) ? $get['id'] : 0;
  1377. $info = OrderClass::getById($id, true);
  1378. OrderClass::valid($info->attributes, $this->shopId);
  1379. $connection = Yii::$app->db;
  1380. $transaction = $connection->beginTransaction();
  1381. try {
  1382. OrderService::reach($info);
  1383. $transaction->commit();
  1384. } catch (\Exception $exception) {
  1385. $transaction->rollBack();
  1386. Yii::info("送达操作报错:" . $exception->getMessage());
  1387. util::fail('操作失败');
  1388. }
  1389. util::complete();
  1390. }
  1391. //下单要用到的相关信息 ssh 2019.12.6
  1392. public function actionOrderRelate()
  1393. {
  1394. $regionTree = RegionService::tree();
  1395. $shop = $this->shop->attributes;
  1396. $freight = ['first' => 5, 'add' => 2];
  1397. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1398. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1399. util::success($out);
  1400. }
  1401. //客户欠款的订单 ssh 2021.2.4
  1402. public function actionDebtList()
  1403. {
  1404. $get = Yii::$app->request->get();
  1405. $id = $get['id'] ?? 0;
  1406. $info = CustomClass::getCustom($id);
  1407. CustomClass::valid($info, $this->shopId);
  1408. $where = ['customId' => $id, 'debt' => 1];
  1409. $searchTime = $get['searchTime'] ?? '';
  1410. if (!empty($searchTime)) {
  1411. $startTime = $get['startTime'] ?? '';
  1412. $endTime = $get['endTime'] ?? '';
  1413. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1414. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1415. }
  1416. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
  1417. $result = ['customInfo' => $info, 'list' => $list];
  1418. util::success($result);
  1419. }
  1420. //更新打印次数
  1421. public function actionAddPrintNum()
  1422. {
  1423. $id = Yii::$app->request->get('id', 0);
  1424. $order = OrderClass::getById($id, true);
  1425. OrderClass::valid($order, $this->shopId);
  1426. $order->printNum += 1;
  1427. $order->save();
  1428. util::complete();
  1429. }
  1430. //打印订单 ssh 20210714
  1431. public function actionCloudPrintOrder()
  1432. {
  1433. $get = Yii::$app->request->get();
  1434. $id = $get['id'] ?? 0;
  1435. $showPrice = $get['showPrice'] ?? 1;
  1436. $order = OrderClass::getById($id, true);
  1437. OrderClass::valid($order, $this->shopId);
  1438. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  1439. util::fail('订单还没有付款');
  1440. }
  1441. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  1442. util::fail('订单已取消');
  1443. }
  1444. $ext = $this->shopExt;
  1445. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  1446. util::success(['hasNoPrint' => 1]);
  1447. }
  1448. OrderClass::onlinePrint($order, $showPrice);
  1449. $order->printNum += 1;
  1450. $order->save();
  1451. util::complete();
  1452. }
  1453. //订单确认完成 ssh 20210809
  1454. public function actionConfirmFinish()
  1455. {
  1456. $payWay = Yii::$app->request->get('payWay', -1);
  1457. $id = Yii::$app->request->get('id', 0);
  1458. $clearType = Yii::$app->request->get('clearType', 0);
  1459. $connection = Yii::$app->db;
  1460. $transaction = $connection->beginTransaction();
  1461. try {
  1462. $order = OrderClass::getById($id, true);
  1463. OrderClass::valid($order, $this->shopId);
  1464. $purchaseId = $order->purchaseId ?? 0;
  1465. $purchase = PurchaseClass::getById($purchaseId, true);
  1466. if (empty($purchase)) {
  1467. util::fail('没有采购信息');
  1468. }
  1469. if ($clearType == 1) {
  1470. //欠款
  1471. $payWay = dict::getDict('payWay', 'debtPay');
  1472. } elseif ($clearType == 2) {
  1473. //已收款
  1474. if ($payWay == -1) {
  1475. util::fail('请选择收款方式');
  1476. }
  1477. $shopAdmin = $this->shopAdmin;
  1478. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1479. util::fail('超管才能发起已收款');
  1480. }
  1481. } else {
  1482. util::fail('请选择结算方式');
  1483. }
  1484. //不需要打印
  1485. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  1486. $order->save();
  1487. //支付
  1488. PurchaseService::payAfter($purchase, $payWay);
  1489. OrderService::payAfter($order, $payWay);
  1490. //自己送
  1491. $info = OrderClass::getById($id, true);
  1492. OrderClass::selfSend($info);
  1493. //确认送达,并且不需要微信通知
  1494. Yii::$app->params['noNeedWxNotice'] = 1;
  1495. $info = OrderClass::getById($id, true);
  1496. OrderService::reach($info);
  1497. $transaction->commit();
  1498. util::complete('操作成功');
  1499. } catch (\Exception $exception) {
  1500. $transaction->rollBack();
  1501. Yii::info("确认完成订单报错:" . $exception->getMessage());
  1502. util::fail('操作失败');
  1503. }
  1504. }
  1505. //取消订单 ssh 20220110
  1506. public function actionCancel()
  1507. {
  1508. $shopAdmin = $this->shopAdmin;
  1509. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1510. util::fail('超管才能取消订单');
  1511. }
  1512. $id = Yii::$app->request->get('id');
  1513. $order = OrderClass::getById($id, true);
  1514. if ($order->orderType == 2) {
  1515. util::fail('客户下单,不能主动取消');
  1516. }
  1517. OrderClass::valid($order, $this->shopId);
  1518. OrderService::expire($order, true);
  1519. util::complete('已取消');
  1520. }
  1521. //获取收款语音播报地址 ssh 20211231
  1522. public function actionGetPayVoice()
  1523. {
  1524. $id = Yii::$app->request->get('id');
  1525. $order = OrderClass::getById($id, true);
  1526. $payWay = $order->payWay ?? 0;
  1527. $money = floatval($order->actPrice);
  1528. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  1529. $msg = $payment . '收款' . $money . '元';
  1530. $audio = baiduAip::transfer($msg, 4, 0);
  1531. //上传到oss
  1532. $file = time() . rand(10000, 999999) . '.mp3';
  1533. $filePath = 'tmp/arrival/money/' . $file;
  1534. oss::uploadTmpAudio($filePath, $audio);
  1535. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  1536. util::success(['url' => $url]);
  1537. }
  1538. //修改备注
  1539. public function actionModifyRemark()
  1540. {
  1541. $post = Yii::$app->request->post();
  1542. $id = $post['id'] ?? 0;
  1543. $remark = $post['remark'] ?? '';
  1544. $order = OrderClass::getById($id, true);
  1545. if (empty($order)) {
  1546. util::fail('没有找到订单');
  1547. }
  1548. if ($order->mainId != $this->mainId) {
  1549. util::fail('不是你的订单');
  1550. }
  1551. $cgId = $order->purchaseId ?? 0;
  1552. $cg = PurchaseClass::getById($cgId, true);
  1553. if (empty($cg)) {
  1554. util::fail('采购单没有找到');
  1555. }
  1556. $order->remark = $remark;
  1557. $order->save();
  1558. $cg->remark = $remark;
  1559. $cg->save();
  1560. util::complete('修改成功');
  1561. }
  1562. }