OrderController.php 41 KB

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