OrderController.php 69 KB

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