OrderController.php 82 KB

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