OrderController.php 67 KB

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