OrderController.php 70 KB

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