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