OrderController.php 69 KB

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