OrderController.php 69 KB

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