OrderController.php 67 KB

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