OrderController.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\express\services\DadaExpressServices;
  4. use bizHd\purchase\classes\PurchaseClass;
  5. use bizHd\purchase\services\PurchaseService;
  6. use bizHd\wx\classes\WxOpenClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\order\classes\OrderClass;
  9. use bizGhs\order\services\OrderService;
  10. use bizHd\saas\services\RegionService;
  11. use bizGhs\product\classes\ProductClass;
  12. use common\components\baiduAip;
  13. use common\components\dict;
  14. use common\components\dateUtil;
  15. use common\components\freight;
  16. use common\components\httpUtil;
  17. use common\components\oss;
  18. use common\components\payUtil;
  19. use common\components\qrCodeUtil;
  20. use Yii;
  21. use common\components\util;
  22. use biz\shop\classes\ShopAdminClass;
  23. class OrderController extends BaseController
  24. {
  25. public $guestAccess = ['create-order', 'order-relate', 'fast-pay'];
  26. //预订单到货 ssh 20220321
  27. public function actionArrival()
  28. {
  29. $post = Yii::$app->request->post();
  30. $id = $post['id'] ?? 0;
  31. $connection = Yii::$app->db;
  32. $transaction = $connection->beginTransaction();
  33. try {
  34. $order = OrderClass::getById($id, true);
  35. OrderClass::valid($order, $this->shopId);
  36. $post['shopAdminId'] = $this->shopAdminId;
  37. $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
  38. OrderService::arrival($order, $post);
  39. $transaction->commit();
  40. util::complete();
  41. } catch (\Exception $e) {
  42. $transaction->rollBack();
  43. Yii::error("操作失败原因:" . $e->getMessage());
  44. util::fail('操作失败');
  45. }
  46. }
  47. //到货获取订单详情 ssh 20220323
  48. public function actionArrivalDetail()
  49. {
  50. $get = Yii::$app->request->get();
  51. $id = $get['id'] ?? 0;
  52. $info = OrderClass::getById($id);
  53. OrderClass::valid($info, $this->shopId);
  54. $showItemData = OrderClass::getOriginalShowItem(true, $info);
  55. $itemList = $showItemData['list'] ?? [];
  56. $info['product'] = $itemList;
  57. $kiloFee = $this->shop->kiloFee ?? 0;
  58. $miniKilo = $this->shop->miniKilo ?? 0;
  59. $info['kiloFee'] = $kiloFee;
  60. $info['miniKilo'] = $miniKilo;
  61. util::success($info);
  62. }
  63. //支付宝扫码支付 ssh 20210103
  64. public function actionScanPayCheck()
  65. {
  66. $get = Yii::$app->request->get();
  67. $id = isset($get['id']) ? $get['id'] : 0;
  68. $order = OrderClass::getById($id, true);
  69. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
  70. util::success(['returnStatus' => 'SUCCESS']);
  71. }
  72. util::success(['returnStatus' => 'FAILURE']);
  73. }
  74. //微信和支付宝扫码支付 ssh 20210103
  75. public function actionScanPay()
  76. {
  77. ini_set('date.timezone', 'Asia/Shanghai');
  78. header("Content-type: text/html; charset=utf-8");
  79. $get = Yii::$app->request->get();
  80. $id = isset($get['id']) ? $get['id'] : 0;
  81. $order = OrderClass::getById($id, true);
  82. if (isset($order->status) == false || $order->status != 1) {
  83. util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
  84. }
  85. OrderClass::valid($order, $this->shopId);
  86. $cgId = $order->purchaseId ?? 0;
  87. $cg = PurchaseClass::getById($cgId, true);
  88. $orderSn = $cg->orderSn ?? '';
  89. if (empty($orderSn)) {
  90. util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
  91. }
  92. $deadline = $cg->deadline;
  93. $current = date("Y-m-d H:i:s");
  94. if ((strtotime($deadline) + 20) < strtotime($current)) {
  95. util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
  96. }
  97. $totalFee = $cg->actPrice ?? 0;
  98. $outTradeNo = $orderSn;
  99. $subject = '购买商品';
  100. $totalAmount = $totalFee;
  101. $body = "到店订单";
  102. //标记为扫码支付 和 自取订单
  103. $order->codePay = 2;
  104. $order->sendType = OrderClass::SEND_TYPE_NO;
  105. $order->save();
  106. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  107. $cg->codePay = 2;
  108. $cg->save();
  109. $wxPayWay = dict::getDict('payWay', 'wxPay');
  110. $aliPayWay = dict::getDict('payWay', 'alipay');
  111. $payWay = Yii::$app->request->get('payWay', $wxPayWay);
  112. if ($payWay == $wxPayWay) {
  113. if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
  114. $url = $order->wxPayUrl;
  115. } else {
  116. $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
  117. require_once($wx . '/lib/WxPay.Api.php');
  118. require_once($wx . '/example/WxPay.NativePay.php');
  119. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  120. $wxPayType = 0;
  121. if (httpUtil::isMiniProgram()) {
  122. $wxPayType = 1;
  123. }
  124. $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
  125. $attach = "couponId=0&capitalType=" . $purchaseCapital . '&wxPayType=' . $wxPayType;
  126. $input = new \WxPayUnifiedOrder();
  127. $input->SetBody($subject);
  128. $input->SetOut_trade_no($orderSn);
  129. $input->SetTotal_fee($totalFee * 100);
  130. $input->SetAttach($attach);
  131. $input->SetTime_start(date("YmdHis"));
  132. $input->SetTime_expire(date("YmdHis", time() + 600));
  133. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  134. $input->SetTrade_type("NATIVE");
  135. //native支付必传
  136. $input->SetProduct_id("hdCG_" . $cgId);
  137. //获取微信商户号等信息
  138. $sjExtend = WxOpenClass::getWxInfo();
  139. $notify = new \NativePay();
  140. $result = $notify->GetPayUrl($input, $sjExtend);
  141. $url = $result["code_url"] ?? '';
  142. if (empty($url)) {
  143. util::success(['returnStatus' => 'FAILURE'], '二维码生成失败');
  144. }
  145. $order->wxPayUrl = $url;
  146. $order->save();
  147. }
  148. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  149. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  150. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  151. }
  152. if ($payWay == $aliPayWay) {
  153. if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
  154. $url = $order->aliPayUrl;
  155. } else {
  156. $aliF2F = Yii::getAlias("@vendor/alipayF2F");
  157. require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
  158. require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
  159. $aliPId = '2017041906821571';
  160. $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOii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ublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB';
  162. $config = array(
  163. //签名方式,默认为RSA2(RSA2048)
  164. 'sign_type' => "RSA2",
  165. //支付宝公钥
  166. 'alipay_public_key' => $aliPublicKey,
  167. //商户私钥
  168. 'merchant_private_key' => $aliKey,
  169. //编码格式
  170. 'charset' => "UTF-8",
  171. //支付宝网关
  172. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  173. //应用ID
  174. 'app_id' => $aliPId,
  175. //异步通知地址,只有扫码支付预下单可用
  176. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/cg-ali-callback",
  177. //最大查询重试次数
  178. 'MaxQueryRetry' => "10",
  179. //查询间隔
  180. 'QueryDuration' => "3"
  181. );
  182. // 支付超时,线下扫码交易定义为5分钟
  183. $timeExpress = "5m";
  184. // 创建请求builder,设置请求参数
  185. $qrPayRequestBuilder = new \AlipayTradePayContentBuilder();
  186. $qrPayRequestBuilder->setOutTradeNo($outTradeNo);
  187. $qrPayRequestBuilder->setTotalAmount($totalAmount);
  188. $qrPayRequestBuilder->setTimeExpress($timeExpress);
  189. $qrPayRequestBuilder->setSubject($subject);
  190. $qrPayRequestBuilder->setBody($body);
  191. // 调用barPay方法获取当面付应答
  192. $qrPay = new \AlipayTradeService($config);
  193. $qrPayResult = $qrPay->qrPay($qrPayRequestBuilder);
  194. if ($qrPayResult->getTradeStatus() != 'SUCCESS') {
  195. util::success(['returnStatus' => 'FAILURE'], '二维码生成失败..');
  196. }
  197. $respond = $qrPayResult->getResponse();
  198. $url = $respond->qr_code ?? '';
  199. if (empty($url)) {
  200. util::success(['returnStatus' => 'FAILURE'], '二维码生成失败');
  201. }
  202. $order->aliPayUrl = $url;
  203. $order->save();
  204. }
  205. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  206. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  207. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  208. }
  209. util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
  210. }
  211. //微信和支付宝付款码支付复查 ssh 20211231
  212. public function actionCodePayCheck()
  213. {
  214. ini_set('date.timezone', 'Asia/Shanghai');
  215. header("Content-type: text/html; charset=utf-8");
  216. $get = Yii::$app->request->get();
  217. $id = isset($get['id']) ? $get['id'] : 0;
  218. $order = OrderClass::getById($id, true);
  219. if (empty($order)) {
  220. util::success(['returnStatus' => 'SUCCESS']);
  221. }
  222. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  223. util::complete('订单已付款');
  224. }
  225. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  226. util::complete('订单不是待付款状态');
  227. }
  228. OrderClass::valid($order, $this->shopId);
  229. $cgId = $order->purchaseId ?? 0;
  230. $cg = PurchaseClass::getById($cgId, true);
  231. $orderSn = $cg->orderSn ?? '';
  232. $totalFee = $cg->actPrice ?? 0;
  233. if (empty($orderSn)) {
  234. util::complete('没有找到采购单');
  235. }
  236. $payWay = $cg->payWay ?? dict::getDict('payWay', 'wxPay');
  237. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  238. if ($payWay == dict::getDict('payWay', 'wxPay')) {
  239. //微信付款
  240. $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
  241. require_once($wx . '/lib/WxPay.Api.php');
  242. require_once($wx . '/example/WxPay.MicroPay.php');
  243. //获取微信商户号等信息
  244. $sjExtend = WxOpenClass::getGhsWxInfo();
  245. $microPay = new \MicroPay();
  246. $payReturn = $microPay->query($orderSn, $sjExtend);
  247. if ($payReturn["return_code"] == "SUCCESS" && $payReturn["result_code"] == "SUCCESS") {
  248. if ($payReturn["trade_state"] == "SUCCESS") {
  249. //支付成功
  250. $transactionId = $payReturn['transaction_id'] ?? '';
  251. $openId = $payReturn['openid'] ?? '';
  252. $aliUserId = '';
  253. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  254. $cg->codePay = 1;
  255. $cg->payOpenId = $openId;
  256. $cg->aliUserId = $aliUserId;
  257. //自取订单
  258. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  259. $cg->save();
  260. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  261. $order->codePay = 1;
  262. //自取订单
  263. $order->sendType = OrderClass::SEND_TYPE_NO;
  264. $order->save();
  265. $attach = '';
  266. payUtil::thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  267. util::success(['returnStatus' => 'SUCCESS']);
  268. } else if ($payReturn["trade_state"] == "USERPAYING") {
  269. //用户支付中
  270. util::complete('正在付款,请稍候..');
  271. }
  272. }
  273. if ($payReturn["err_code"] == "ORDERNOTEXIST") {
  274. //交易订单号不存在
  275. util::complete('订单没有付款');
  276. } else {
  277. util::complete('系统错误,请稍候再试');
  278. }
  279. } elseif ($payWay == dict::getDict('payWay', 'alipay')) {
  280. //支付宝付款
  281. $aliF2F = Yii::getAlias("@vendor/alipayF2F");
  282. require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
  283. require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
  284. $aliPId = '2017041906821571';
  285. $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc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VZhu6XqKO3VUX+IWFQdaNGh2F13iLozIDLQOtKw3WfcjOq0xpZ5pwXq0RI8iSw+IUhyD8EHNZW2qU8CiRBhyt6hsywqQECgYBa8+06FAachI/XqWfF/UvcDdJ5AkS9/L8SvmmdsSkItjSIkfLHAqdxkbwl6Vu6kUOX/PJIFZjuAWTZFl4xBFNgFYj01uZHnnT6cnIp6HteD2CAqTSFAMqgfFWoL6zoaYAmJBnxO4oZPTYI+ilnQcts5VLFaChx0GCvS2BZgy2W0QKBgQDjP2VtRq4aVSLUq2z1KIDI7GJBbOM5KSW1OEj4sfEdViozPh3Ar/FQWiij1oCZF+iJdKkonHoDbDd+Q0ykcpQ+5Gv07iiT8wJYFR/0j8g2kfql7bVQhGSBeBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==';
  286. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB';
  287. $config = array(
  288. //签名方式,默认为RSA2(RSA2048)
  289. 'sign_type' => "RSA2",
  290. //支付宝公钥
  291. 'alipay_public_key' => $aliPublicKey,
  292. //商户私钥
  293. 'merchant_private_key' => $aliKey,
  294. //编码格式
  295. 'charset' => "UTF-8",
  296. //支付宝网关
  297. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  298. //应用ID
  299. 'app_id' => $aliPId,
  300. //异步通知地址,只有扫码支付预下单可用
  301. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  302. //最大查询重试次数
  303. 'MaxQueryRetry' => "10",
  304. //查询间隔
  305. 'QueryDuration' => "3"
  306. );
  307. //构造查询业务请求参数对象
  308. $queryContentBuilder = new \AlipayTradeQueryContentBuilder();
  309. $queryContentBuilder->setOutTradeNo($orderSn);
  310. //初始化类对象,调用queryTradeResult方法获取查询应答
  311. $queryResponse = new \AlipayTradeService($config);
  312. $queryResult = $queryResponse->queryTradeResult($queryContentBuilder);
  313. if ($queryResult->getTradeStatus() == 'SUCCESS') {
  314. $respond = $queryResult->getResponse();
  315. $openId = '';
  316. $aliUserId = $respond->buyer_user_id ?? '';
  317. $transactionId = $respond->trade_no ?? '';
  318. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  319. $cg->codePay = 1;
  320. $cg->payOpenId = $openId;
  321. $cg->aliUserId = $aliUserId;
  322. //自取订单
  323. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  324. $cg->save();
  325. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  326. $order->codePay = 1;
  327. //自取订单
  328. $order->sendType = OrderClass::SEND_TYPE_NO;
  329. $order->save();
  330. $attach = '';
  331. payUtil::thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  332. util::success(['returnStatus' => 'SUCCESS']);
  333. }
  334. } else {
  335. util::fail('还没有付款哦');
  336. }
  337. }
  338. //微信和支付宝付款码支付 ssh 2021.4.11
  339. public function actionCodePay()
  340. {
  341. ini_set('date.timezone', 'Asia/Shanghai');
  342. header("Content-type: text/html; charset=utf-8");
  343. $get = Yii::$app->request->get();
  344. $id = isset($get['id']) ? $get['id'] : 0;
  345. $order = OrderClass::getById($id, true);
  346. if (isset($order->status) == false || $order->status != 1) {
  347. util::fail('不是待付款订单');
  348. }
  349. OrderClass::valid($order, $this->shopId);
  350. $cgId = $order->purchaseId ?? 0;
  351. $cg = PurchaseClass::getById($cgId, true);
  352. $orderSn = $cg->orderSn ?? '';
  353. if (empty($orderSn)) {
  354. util::fail('没有找到采购单');
  355. }
  356. //付款码
  357. $authCode = (string)$get['authCode'] ?? '';
  358. if (empty($authCode)) {
  359. util::fail('支付失败');
  360. }
  361. $wxPrefix = ['10', '11', '12', '13', '14', '15'];
  362. $isWx = false;
  363. foreach ($wxPrefix as $wxId) {
  364. if (strpos($authCode, $wxId) === 0) {
  365. $isWx = true;
  366. }
  367. }
  368. $deadline = $cg->deadline;
  369. $current = date("Y-m-d H:i:s");
  370. if ((strtotime($deadline) + 20) < strtotime($current)) {
  371. util::fail('订单已经失效');
  372. }
  373. $totalFee = $cg->actPrice ?? 0;
  374. $outTradeNo = $orderSn;
  375. $subject = '购买商品';
  376. $totalAmount = $totalFee;
  377. $body = "门店";
  378. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  379. if ($isWx) {
  380. $wxPayWay = dict::getDict('payWay', 'wxPay');
  381. $order->payWay = $wxPayWay;
  382. $order->save();
  383. $cg->payWay = $wxPayWay;
  384. $cg->save();
  385. $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
  386. require_once($wx . '/lib/WxPay.Api.php');
  387. require_once($wx . '/example/WxPay.MicroPay.php');
  388. $input = new \WxPayMicroPay();
  389. $input->SetAuth_code($authCode);
  390. $input->SetBody($subject);
  391. $input->SetTotal_fee($totalFee * 100);
  392. $input->SetOut_trade_no($orderSn);
  393. //获取微信商户号等信息
  394. $sjExtend = WxOpenClass::getGhsWxInfo();
  395. $microPay = new \MicroPay();
  396. $res = $microPay->pay($input, $sjExtend);
  397. if (isset($res["return_code"]) && $res["return_code"] == "SUCCESS" && isset($res["result_code"]) && $res["result_code"] == 'SUCCESS') {
  398. $transactionId = $res['transaction_id'] ?? '';
  399. $openId = $res['openid'] ?? '';
  400. $aliUserId = '';
  401. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  402. $cg->codePay = 1;
  403. $cg->payOpenId = $openId;
  404. $cg->aliUserId = $aliUserId;
  405. //自取订单
  406. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  407. $cg->save();
  408. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  409. $order->codePay = 1;
  410. //自取订单
  411. $order->sendType = OrderClass::SEND_TYPE_NO;
  412. $order->save();
  413. $attach = '';
  414. payUtil::thirdPay($wxPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  415. util::success(['returnStatus' => 'SUCCESS']);
  416. } else {
  417. Yii::info(json_encode($res));
  418. $errCode = $res['err_code'] ?? '';
  419. $msg = '';
  420. if ($errCode == 'NOTENOUGH') {
  421. $msg = '余额不足';
  422. }
  423. if ($errCode == 'USERPAYING') {
  424. $msg = '等待客户输入支付密码';
  425. }
  426. util::success(['returnStatus' => 'FAILURE'], $msg);
  427. }
  428. } else {
  429. $aliPayWay = dict::getDict('payWay', 'alipay');
  430. $order->payWay = $aliPayWay;
  431. $order->save();
  432. $cg->payWay = $aliPayWay;
  433. $cg->save();
  434. $aliF2F = Yii::getAlias("@vendor/alipayF2F");
  435. require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
  436. require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
  437. // $aliPId = '2017041906821571';
  438. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAo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q4f2FOoV8gHTTMpWHAKlivwCRzuHHPWXVOvv70jaG5XSdzQa1A=';
  442. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmENuDs4DBEe22a5OYGo8mgx7FENnyBuxw9At63IlRP7jHJ2tBk5sVb2WRTxALwO2K9iqQsd//ePsTc3NLztVM9a9GasW5o9LEZFAn1QwInCwUklkJdlfqkU0EIcvnty2Hf6KXlWspttUNgQOdq9vpq2zIwoFziewG1zewdYqCqiq+a8PKsGokpVq6O5E5C9Po0utMPULQcMH6LBO1yQ6MKUfWhz5SDHf/w4Uj1TemUQny470JfyS5RF9aBv+jUcA7jRgPNbhEu1O1OsZvoPgMjCyYmJoAHwfVvOmaIyGBDrFeaGIp8jbRC+Q9Qp0o5AkeeVWHokt1IiAld9wjrU/6wIDAQAB';
  443. $config = array(
  444. //签名方式,默认为RSA2(RSA2048)
  445. 'sign_type' => "RSA2",
  446. //支付宝公钥
  447. 'alipay_public_key' => $aliPublicKey,
  448. //商户私钥
  449. 'merchant_private_key' => $aliKey,
  450. //编码格式
  451. 'charset' => "UTF-8",
  452. //支付宝网关
  453. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  454. //应用ID
  455. 'app_id' => $aliPId,
  456. //异步通知地址,只有扫码支付预下单可用
  457. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  458. //最大查询重试次数
  459. 'MaxQueryRetry' => "10",
  460. //查询间隔
  461. 'QueryDuration' => "3"
  462. );
  463. // 支付超时,线下扫码交易定义为5分钟
  464. $timeExpress = "5m";
  465. // 创建请求builder,设置请求参数
  466. $barPayRequestBuilder = new \AlipayTradePayContentBuilder();
  467. $barPayRequestBuilder->setOutTradeNo($outTradeNo);
  468. $barPayRequestBuilder->setTotalAmount($totalAmount);
  469. $barPayRequestBuilder->setAuthCode($authCode);
  470. $barPayRequestBuilder->setTimeExpress($timeExpress);
  471. $barPayRequestBuilder->setSubject($subject);
  472. $barPayRequestBuilder->setBody($body);
  473. // 调用barPay方法获取当面付应答
  474. $barPay = new \AlipayTradeService($config);
  475. $barPayResult = $barPay->barPay($barPayRequestBuilder);
  476. if ($barPayResult->getTradeStatus() == 'SUCCESS') {
  477. $respond = $barPayResult->getResponse();
  478. $openId = '';
  479. $aliUserId = $respond->buyer_user_id ?? '';
  480. $transactionId = $respond->trade_no ?? '';
  481. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  482. $cg->codePay = 1;
  483. $cg->payOpenId = $openId;
  484. $cg->aliUserId = $aliUserId;
  485. //自取订单
  486. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  487. $cg->save();
  488. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  489. $order->codePay = 1;
  490. //自取订单
  491. $order->sendType = OrderClass::SEND_TYPE_NO;
  492. $order->save();
  493. $attach = '';
  494. payUtil::thirdPay($aliPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  495. util::success(['returnStatus' => 'SUCCESS']);
  496. }
  497. util::success(['returnStatus' => 'FAILURE']);
  498. }
  499. }
  500. //订单列表 ssh 2021.1.20
  501. public function actionList()
  502. {
  503. $get = Yii::$app->request->get();
  504. $status = $get['status'] ?? 0;
  505. if (!empty($status)) {
  506. $where['status'] = $status;
  507. }
  508. $where['sjId'] = $this->sjId;
  509. if (isset($get['shopId'])) {
  510. $shopId = $get['shopId'] ?? 0;
  511. if (!empty($shopId)) {
  512. $where['shopId'] = $this->shopId;
  513. }
  514. } else {
  515. $where['shopId'] = $this->shopId;
  516. }
  517. $searchTime = $get['searchTime'] ?? '';
  518. if (!empty($searchTime)) {
  519. $startTime = $get['startTime'] ?? '';
  520. $endTime = $get['endTime'] ?? '';
  521. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  522. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  523. }
  524. $name = $get['name'] ?? '';
  525. if (!empty($name)) {
  526. $searchType = $get['searchType'] ?? 0;
  527. if (empty($searchType)) {
  528. //订单编号
  529. if (strpos($name, 'XSD') === 0) {
  530. $where['orderSn'] = $name;
  531. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  532. $where['customNamePy'] = ['like', $name];
  533. } else {
  534. $where['customName'] = ['like', $name];
  535. }
  536. } elseif ($searchType == 1) {
  537. $where['sendNum'] = $name;
  538. } else {
  539. }
  540. }
  541. $respond = OrderClass::getOrderList($where);
  542. $respond['shop'] = $this->shop;
  543. $respond['shopExt'] = $this->shopExt;
  544. util::success($respond);
  545. }
  546. //商城下单操作 ssh 2021.1.14
  547. public function actionCreateOrder()
  548. {
  549. $post = Yii::$app->request->post();
  550. $shopId = $this->shopId;
  551. $customId = $post['customId'] ?? 0;
  552. $post['customId'] = $customId;
  553. //开单必须选客户
  554. if (empty($customId)) {
  555. util::fail('请选择客户');
  556. }
  557. $custom = CustomClass::getCustom($customId);
  558. if (empty($custom)) {
  559. util::fail('请选客户哦');
  560. }
  561. CustomClass::valid($custom, $this->shopId);
  562. if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  563. util::fail('不能给自己的零售店开单');
  564. }
  565. $post['ghsId'] = $custom['ghsId'] ?? 0;
  566. $post['customMobile'] = $custom['mobile'] ?? '';
  567. $customName = $custom['name'] ?? '';
  568. $post['customName'] = $customName;
  569. $post['customNamePy'] = $custom['py'] ?? '';
  570. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  571. $post['province'] = $custom['province'] ?? '';
  572. $post['city'] = $custom['city'] ?? '';
  573. $post['dist'] = $custom['dist'] ?? '';
  574. $post['address'] = $custom['address'] ?? '';
  575. $post['floor'] = $custom['floor'] ?? '';
  576. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  577. $post['showAddress'] = $custom['showAddress'] ?? '';
  578. $post['long'] = $custom['long'] ?? '';
  579. $post['lat'] = $custom['lat'] ?? '';
  580. $shopAdmin = $this->shopAdmin->attributes;
  581. $post['shopAdminId'] = isset($post['shopAdminId']) && !empty($post['shopAdminId']) ? $post['shopAdminId'] : $this->shopAdminId;
  582. $post['shopAdminName'] = isset($post['shopAdminName']) && !empty($post['shopAdminName']) ? $post['shopAdminName'] : $shopAdmin['name'];
  583. $post['sjId'] = $this->sjId;
  584. $post['shopId'] = $shopId;
  585. $post['mainId'] = $this->mainId;
  586. $post['fromType'] = 1;
  587. $post['expressId'] = $post['expressId'] ?? 0;
  588. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  589. $post['book'] = $post['book'] ?? 0;
  590. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  591. $post['debt'] = OrderClass::DEBT_NO;
  592. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  593. $post['debt'] = OrderClass::DEBT_YES;
  594. }
  595. $shopAdmin = $this->shopAdmin;
  596. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  597. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  598. util::fail('没有权限');
  599. }
  600. }
  601. $productJson = $post['product'] ?? '';
  602. if (empty($productJson)) {
  603. util::fail('请选择花材');
  604. }
  605. $productList = json_decode($productJson, true);
  606. if (empty($productList)) {
  607. util::fail('请选择花材');
  608. }
  609. $connection = Yii::$app->db;//事务处理
  610. $transaction = $connection->beginTransaction();
  611. try {
  612. //判断花材有效性
  613. ProductClass::valid($productList, $this->mainId);
  614. $post['product'] = $productList;
  615. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  616. $time = time();
  617. $hasTime = dict::getDict('order_pay_has_time');
  618. $totalTime = bcadd($time, $hasTime);
  619. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  620. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  621. $transaction->commit();
  622. util::success($return);
  623. } catch (\Exception $e) {
  624. $transaction->rollBack();
  625. Yii::error("下单失败原因:" . $e->getMessage());
  626. util::fail('下单失败');
  627. }
  628. }
  629. //修改订单 ssh 20210810
  630. public function actionUpdateOrder()
  631. {
  632. $post = Yii::$app->request->post();
  633. //PC端开单
  634. if (isset($post['clearType'])) {
  635. $clearType = $post['clearType'];
  636. if ($clearType == OrderClass::CLEAR_DEBT) {
  637. $post['debt'] = OrderClass::DEBT_YES;
  638. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  639. } else {
  640. $post['debt'] = OrderClass::DEBT_NO;
  641. }
  642. }
  643. //员工不能开已收款订单
  644. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  645. if ($debt == OrderClass::DEBT_NO) {
  646. $shopAdmin = $this->shopAdmin;
  647. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  648. util::fail('不能开已收款订单');
  649. }
  650. }
  651. //PC端开单
  652. if (isset($post['getType'])) {
  653. util::fail('暂不支持PC端修改订单');
  654. $getType = $post['getType'];
  655. //自取
  656. if ($getType == 1) {
  657. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  658. } else {
  659. //选择配送时,在发货时让商家自己再确认一下用什么方式
  660. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  661. }
  662. }
  663. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  664. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  665. $post['debt'] = OrderClass::DEBT_NO;
  666. }
  667. $id = $post['id'] ?? 0;
  668. $order = OrderClass::getLockById($id);
  669. if (empty($order)) {
  670. util::fail('没有找到订单');
  671. }
  672. OrderClass::valid($order, $this->shopId);
  673. unset($post['id']);
  674. $shopAdmin = $this->shopAdmin;
  675. $post['shopAdminId'] = $this->shopAdminId;
  676. $post['shopAdminName'] = $shopAdmin->name ?? '';
  677. $post['fromType'] = 1;
  678. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  679. $productJson = $post['product'] ?? '';
  680. if (empty($productJson)) {
  681. util::fail('请选择花材');
  682. }
  683. $productList = json_decode($productJson, true);
  684. if (empty($productList)) {
  685. util::fail('请选择花材');
  686. }
  687. $connection = Yii::$app->db;//事务处理
  688. $transaction = $connection->beginTransaction();
  689. try {
  690. //判断花材有效性
  691. ProductClass::valid($productList, $this->mainId);
  692. $post['product'] = $productList;
  693. //商家开单订单有效期,到期记欠款
  694. $validTime = dict::getDict('order_pay_has_time');
  695. $current = time() + $validTime;
  696. $post['deadline'] = date("Y-m-d H:i:s", $current);
  697. $upData = [
  698. 'payWay' => $post['payWay'],
  699. 'sendType' => $post['sendType'],
  700. 'debt' => $post['debt'],
  701. 'needPrint' => $post['needPrint'],
  702. 'modifyPrice' => $post['modifyPrice'],
  703. 'shopAdminId' => $post['shopAdminId'],
  704. 'shopAdminName' => $post['shopAdminName'],
  705. 'fromType' => 1,
  706. 'sendCost' => $post['sendCost'],
  707. 'product' => $post['product'],
  708. 'deadline' => $post['deadline'],
  709. 'debt' => $post['debt'],
  710. ];
  711. $return = OrderService::updateOrder($order, $upData);
  712. $transaction->commit();
  713. util::success($return);
  714. } catch (\Exception $e) {
  715. $transaction->rollBack();
  716. Yii::error("下单失败原因:" . $e->getMessage());
  717. util::fail('下单失败');
  718. }
  719. }
  720. //延期支付 ssh 2021.1.19
  721. public function actionDebt()
  722. {
  723. $id = Yii::$app->request->get('id');
  724. $order = OrderClass::getById($id, true);
  725. OrderClass::valid($order, $this->shopId);
  726. $payWay = dict::getDict('payWay', 'debtPay');
  727. $cgId = $order->purchaseId ?? 0;
  728. $cg = PurchaseClass::getById($cgId, true);
  729. if (empty($cg)) {
  730. util::fail('没有找到采购单');
  731. }
  732. PurchaseService::payAfter($cg, $payWay);
  733. OrderService::payAfter($order, $payWay);
  734. util::complete();
  735. }
  736. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  737. public function actionWxPay()
  738. {
  739. ini_set('date.timezone', 'Asia/Shanghai');
  740. $post = Yii::$app->request->post();
  741. $couponId = $post['couponId'] ?? 0;
  742. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  743. $order = OrderClass::getByOrderSn($orderSn);
  744. if (empty($order)) {
  745. util::fail('订单号无效');
  746. }
  747. $id = $order['id'];
  748. //支付前验证订单有效性
  749. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  750. util::fail('没有权限操作');
  751. }
  752. $name = $order['orderName'] ?? '购买商品';
  753. $totalFee = $order['actPrice'];
  754. //强制使用小程序的miniOpenId
  755. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  756. if (empty($openId)) {
  757. util::fail('没有找到openId');
  758. }
  759. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  760. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  761. $wxPayType = 0;
  762. if (httpUtil::isMiniProgram()) {
  763. $wxPayType = 1;
  764. }
  765. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  766. //订单30分钟后过期
  767. $now = time();
  768. $expireTime = $now + 1800;
  769. $wx = Yii::getAlias("@vendor/weixin");
  770. require_once($wx . '/lib/WxPay.Api.php');
  771. require_once($wx . '/example/WxPay.JsApiPay.php');
  772. $input = new \WxPayUnifiedOrder();
  773. $input->SetBody($name);
  774. $input->SetOut_trade_no($orderSn);
  775. $input->SetTotal_fee($totalFee * 100);
  776. $input->SetTime_start(date("YmdHis", $now));
  777. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  778. $input->SetTime_expire(date("YmdHis", $expireTime));
  779. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  780. $input->SetTrade_type("JSAPI");
  781. //花卉宝代为申请的微信支付
  782. //$sjExtend = $this->sjExtend->attributes;
  783. $sjExtend = WxOpenClass::getGhsWxInfo();
  784. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  785. $input->SetSub_openid($openId);
  786. } else {
  787. $input->SetOpenid($openId);
  788. }
  789. //强制使用小程序的miniAppId
  790. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  791. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  792. $tools = new \JsApiPay();
  793. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  794. $newParams = json_decode($jsApiParameters, true);
  795. //微信不能修改价格
  796. $current = date("Y-m-d H:i:s");
  797. $updateData = ['deadline' => $current, 'modPrice' => 0];
  798. OrderClass::updateById($id, $updateData);
  799. util::success($newParams);
  800. }
  801. //获取订单详情 ssh 2021.1.21
  802. public function actionDetail()
  803. {
  804. $get = Yii::$app->request->get();
  805. $id = $get['id'] ?? 0;
  806. $info = OrderService::getOrderInfo($id, true, true, true, false);
  807. OrderClass::valid($info, $this->shopId);
  808. //是否有云打印判断
  809. $hasCloudPrint = 0;
  810. $shopExt = $this->shopExt;
  811. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  812. $hasCloudPrint = 1;
  813. }
  814. $info['hasCloudPrint'] = $hasCloudPrint;
  815. $purchaseId = $info['purchaseId'] ?? 0;
  816. $cg = PurchaseClass::getById($purchaseId);
  817. $info['cgInfo'] = $cg;
  818. //店长信息
  819. $mainId = $cg['mainId'] ?? 0;
  820. $superInfo = ShopAdminClass::getManager($mainId);
  821. $info['customSuper'] = $superInfo;
  822. util::success($info);
  823. }
  824. //自取免发货流程处理 ssh 2021.1.22
  825. public function actionWithoutSend()
  826. {
  827. util::complete();
  828. }
  829. //本店送 ssh 2021.1.24
  830. public function actionSelfSend()
  831. {
  832. $get = Yii::$app->request->get();
  833. $id = isset($get['id']) ? $get['id'] : 0;
  834. $info = OrderClass::getById($id, true);
  835. OrderClass::valid($info->attributes, $this->shopId);
  836. $connection = Yii::$app->db;
  837. $transaction = $connection->beginTransaction();
  838. try {
  839. OrderClass::selfSend($info);
  840. $transaction->commit();
  841. } catch (\Exception $exception) {
  842. $transaction->rollBack();
  843. Yii::info("本店送操作报错:" . $exception->getMessage());
  844. util::fail('操作失败');
  845. }
  846. util::complete();
  847. }
  848. //运费计算 ssh 2021.1.24
  849. public function actionFreight()
  850. {
  851. //2021.3.28 接入达达
  852. $get = Yii::$app->request->get();
  853. $post = Yii::$app->request->post();
  854. if (empty($get)) {
  855. $get = $post;
  856. }
  857. $orderId = $get['id'] ?? 0; //订单ID
  858. $customId = $get['customId'] ?? 0;
  859. if (empty($orderId)) {
  860. //自定义运费
  861. //freight::getCost();
  862. if (empty($customId)) {
  863. util::fail("请选择客户");
  864. }
  865. $customInfo = CustomClass::getById($customId);
  866. if (empty($customInfo)) {
  867. util::fail('没有找到客户');
  868. }
  869. $shop = $this->shop;
  870. //花材信息
  871. $productJson = $get['product'] ?? '';
  872. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  873. if (empty($productJson)) {
  874. util::fail('请选择花材');
  875. }
  876. $productList = json_decode($productJson, true);
  877. if (empty($productList)) {
  878. util::fail('请选择花材');
  879. }
  880. $productList = ProductClass::mergeItemInfo($productList);
  881. $weight = 0;
  882. $price = 0;
  883. $productData = ProductClass::getProductMapData($productList);
  884. $bigNum = 0;
  885. foreach ($productList as $key => $val) {
  886. $productId = $val['productId'];
  887. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  888. $bigNum += $val['bigNum'];
  889. $weight = bcadd($w, $weight, 2);
  890. $ratio = $productData[$productId]['ratio'] ?? 0;
  891. //大小数量合并多少扎
  892. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  893. //售卖价格
  894. $itemPrice = $productData[$productId]['price'] ?? 0;
  895. //合计价格
  896. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  897. }
  898. //没有经纬度的客户运费直接返回空 ssh 20210612
  899. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  900. util::success(['sedCost' => '']);
  901. }
  902. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  903. util::success(['sedCost' => $cost]);
  904. }
  905. $province = $get['province'] ?? '';
  906. $city = $get['city'] ?? '';
  907. $address = $get['address'] ?? '';
  908. $floor = $get['floor'] ?? '';
  909. $customName = $get['customName'] ?? '';
  910. $customMobile = $get['customMobile'] ?? '';
  911. $fullAddress = $province . $city . $address . $floor;
  912. $sendTime = $get['sendTime'] ?? '';
  913. $lat = $get['lat'] ?? '';
  914. $lng = $get['long'] ?? '';
  915. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  916. util::fail('请填写客户地址');
  917. }
  918. ini_set('date.timezone', 'Asia/Shanghai');
  919. if (!empty($sendTime)) {
  920. //配送时间不为空
  921. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  922. $sendTimeInt = strtotime($sendTime);
  923. $now = time();
  924. $diff = $sendTimeInt - $now;
  925. //因服务器写入时间,改为至少提前6分钟
  926. if ($diff <= 360) {
  927. util::fail('配送时间至少提前6分钟');
  928. }
  929. } else {
  930. //默认立即发送
  931. $sendTime = 0;
  932. }
  933. //更新订单表
  934. $info = OrderService::getOrderInfo($orderId);
  935. OrderClass::valid($info, $this->shopId);
  936. if ($sendTime) {
  937. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  938. } else {
  939. $sendTime = '0000-00-00 00:00:00';
  940. }
  941. $expressAddInfo = [
  942. 'customName' => $customName,
  943. 'customMobile' => $customMobile,
  944. 'province' => $province,
  945. 'city' => $city,
  946. 'address' => $address,
  947. 'floor' => $floor,
  948. 'lat' => $lat,
  949. 'long' => $lng,
  950. 'sendTime' => $sendTime,
  951. ];
  952. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  953. //计算运费
  954. $info['province'] = $province;
  955. $info['city'] = $city;
  956. $info['address'] = $address;
  957. $info['floor'] = $floor;
  958. $info['fullAddress'] = $fullAddress;
  959. $info['lat'] = $lat;
  960. $info['long'] = $lng;
  961. $info['sendTime'] = $expressAddInfo['sendTime'];
  962. $res = DadaExpressServices::queryDeliverFee($info);
  963. util::success(['sedCost' => $res['fee']]);
  964. }
  965. //发快递和第三方配送 ssh 2021.1.24
  966. public function actionThirdSend()
  967. {
  968. $get = Yii::$app->request->get();
  969. $id = isset($get['id']) ? $get['id'] : 0;
  970. $info = OrderService::getById($id, true);
  971. OrderClass::valid($info->attributes, $this->shopId);
  972. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  973. util::fail('请填写客户地址');
  974. }
  975. $connection = Yii::$app->db;
  976. $transaction = $connection->beginTransaction();
  977. try {
  978. $respond = OrderClass::thirdSend($info, $get);
  979. $transaction->commit();
  980. util::success($respond);
  981. } catch (\Exception $exception) {
  982. $transaction->rollBack();
  983. Yii::info("发快递操作报错:" . $exception->getMessage());
  984. util::fail('操作失败' . $exception->getMessage());
  985. }
  986. }
  987. //确认送达 ssh 2021.1.24
  988. public function actionReach()
  989. {
  990. $get = Yii::$app->request->get();
  991. $id = isset($get['id']) ? $get['id'] : 0;
  992. $info = OrderClass::getById($id, true);
  993. OrderClass::valid($info->attributes, $this->shopId);
  994. $connection = Yii::$app->db;
  995. $transaction = $connection->beginTransaction();
  996. try {
  997. OrderService::reach($info);
  998. $transaction->commit();
  999. } catch (\Exception $exception) {
  1000. $transaction->rollBack();
  1001. Yii::info("送达操作报错:" . $exception->getMessage());
  1002. util::fail('操作失败');
  1003. }
  1004. util::complete();
  1005. }
  1006. //下单要用到的相关信息 ssh 2019.12.6
  1007. public function actionOrderRelate()
  1008. {
  1009. $regionTree = RegionService::tree();
  1010. $shop = $this->shop->attributes;
  1011. $freight = ['first' => 5, 'add' => 2];
  1012. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1013. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1014. util::success($out);
  1015. }
  1016. //客户欠款的订单 ssh 2021.2.4
  1017. public function actionDebtList()
  1018. {
  1019. $get = Yii::$app->request->get();
  1020. $id = $get['id'] ?? 0;
  1021. $info = CustomClass::getCustom($id);
  1022. CustomClass::valid($info, $this->shopId);
  1023. $where = ['customId' => $id, 'debt' => 1];
  1024. $searchTime = $get['searchTime'] ?? '';
  1025. if (!empty($searchTime)) {
  1026. $startTime = $get['startTime'] ?? '';
  1027. $endTime = $get['endTime'] ?? '';
  1028. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1029. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1030. }
  1031. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
  1032. $result = ['customInfo' => $info, 'list' => $list];
  1033. util::success($result);
  1034. }
  1035. //更新打印次数
  1036. public function actionAddPrintNum()
  1037. {
  1038. $id = Yii::$app->request->get('id', 0);
  1039. $order = OrderClass::getById($id, true);
  1040. OrderClass::valid($order, $this->shopId);
  1041. $order->printNum += 1;
  1042. $order->save();
  1043. util::complete();
  1044. }
  1045. //打印订单 ssh 20210714
  1046. public function actionCloudPrintOrder()
  1047. {
  1048. $id = Yii::$app->request->get('id', 0);
  1049. $order = OrderClass::getById($id, true);
  1050. OrderClass::valid($order, $this->shopId);
  1051. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  1052. util::fail('订单还没有付款');
  1053. }
  1054. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  1055. util::fail('订单已取消');
  1056. }
  1057. $ext = $this->shopExt;
  1058. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  1059. util::success(['hasNoPrint' => 1]);
  1060. }
  1061. OrderClass::onlinePrint($order);
  1062. $order->printNum += 1;
  1063. $order->save();
  1064. util::complete();
  1065. }
  1066. //订单确认完成 ssh 20210809
  1067. public function actionConfirmFinish()
  1068. {
  1069. $payWay = Yii::$app->request->get('payWay', -1);
  1070. $id = Yii::$app->request->get('id', 0);
  1071. $clearType = Yii::$app->request->get('clearType', 0);
  1072. $connection = Yii::$app->db;
  1073. $transaction = $connection->beginTransaction();
  1074. try {
  1075. $order = OrderClass::getById($id, true);
  1076. OrderClass::valid($order, $this->shopId);
  1077. $purchaseId = $order->purchaseId ?? 0;
  1078. $purchase = PurchaseClass::getById($purchaseId, true);
  1079. if (empty($purchase)) {
  1080. util::fail('没有采购信息');
  1081. }
  1082. if ($clearType == 1) {
  1083. //欠款
  1084. $payWay = dict::getDict('payWay', 'debtPay');
  1085. } elseif ($clearType == 2) {
  1086. //已收款
  1087. if ($payWay == -1) {
  1088. util::fail('请选择收款方式');
  1089. }
  1090. $shopAdmin = $this->shopAdmin;
  1091. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1092. util::fail('超管才能发起已收款');
  1093. }
  1094. } else {
  1095. util::fail('请选择结算方式');
  1096. }
  1097. //不需要打印
  1098. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  1099. $order->save();
  1100. //支付
  1101. PurchaseService::payAfter($purchase, $payWay);
  1102. OrderService::payAfter($order, $payWay);
  1103. //自己送
  1104. $info = OrderClass::getById($id, true);
  1105. OrderClass::selfSend($info);
  1106. //确认送达,并且不需要微信通知
  1107. Yii::$app->params['noNeedWxNotice'] = 1;
  1108. $info = OrderClass::getById($id, true);
  1109. OrderService::reach($info);
  1110. $transaction->commit();
  1111. util::complete('操作成功');
  1112. } catch (\Exception $exception) {
  1113. $transaction->rollBack();
  1114. Yii::info("确认完成订单报错:" . $exception->getMessage());
  1115. util::fail('操作失败');
  1116. }
  1117. }
  1118. //取消订单 ssh 20220110
  1119. public function actionCancel()
  1120. {
  1121. $shopAdmin = $this->shopAdmin;
  1122. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1123. util::fail('超管才能取消订单');
  1124. }
  1125. $id = Yii::$app->request->get('id');
  1126. $order = OrderClass::getById($id, true);
  1127. if ($order->orderType == 2) {
  1128. util::fail('客户下单,不能主动取消');
  1129. }
  1130. OrderClass::valid($order, $this->shopId);
  1131. OrderService::expire($order, true);
  1132. util::complete('已取消');
  1133. }
  1134. //获取收款语音播报地址 ssh 20211231
  1135. public function actionGetPayVoice()
  1136. {
  1137. $id = Yii::$app->request->get('id');
  1138. $order = OrderClass::getById($id, true);
  1139. $payWay = $order->payWay ?? 0;
  1140. $money = floatval($order->actPrice);
  1141. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  1142. $msg = $payment . '收款' . $money . '元';
  1143. $audio = baiduAip::transfer($msg, 4, 0);
  1144. //上传到oss
  1145. $file = time() . rand(10000, 999999) . '.mp3';
  1146. $filePath = 'tmp/arrival/money/' . $file;
  1147. oss::uploadTmpAudio($filePath, $audio);
  1148. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  1149. util::success(['url' => $url]);
  1150. }
  1151. }