OrderController.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  333. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  334. $post['debt'] = OrderClass::DEBT_YES;
  335. }
  336. $shopAdmin = $this->shopAdmin;
  337. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  338. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  339. util::fail('没有权限');
  340. }
  341. }
  342. $productJson = $post['product'] ?? '';
  343. if (empty($productJson)) {
  344. util::fail('请选择花材');
  345. }
  346. $productList = json_decode($productJson, true);
  347. if (empty($productList)) {
  348. util::fail('请选择花材');
  349. }
  350. $connection = Yii::$app->db;//事务处理
  351. $transaction = $connection->beginTransaction();
  352. try {
  353. //判断花材有效性
  354. ProductClass::valid($productList, $this->shopId);
  355. $post['product'] = $productList;
  356. //商家开单订单有效期更长(30)天
  357. $validTime = dict::getDict('kd_order_valid');
  358. $current = time() + $validTime;
  359. $post['deadline'] = date("Y-m-d H:i:s", $current);
  360. $return = OrderService::createOrder($post, $custom, $hasPay);
  361. $transaction->commit();
  362. util::success($return);
  363. } catch (\Exception $e) {
  364. $transaction->rollBack();
  365. Yii::error("下单失败原因:" . $e->getMessage());
  366. util::fail('下单失败');
  367. }
  368. }
  369. //修改订单 ssh 20210810
  370. public function actionUpdateOrder()
  371. {
  372. $post = Yii::$app->request->post();
  373. if (isset($post['newVersion']) == false) {
  374. util::fail('请升级小程序');
  375. }
  376. unset($post['newVersion']);
  377. //PC端开单
  378. if (isset($post['clearType'])) {
  379. $clearType = $post['clearType'];
  380. if ($clearType == OrderClass::CLEAR_DEBT) {
  381. $post['debt'] = OrderClass::DEBT_YES;
  382. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  383. } else {
  384. $post['debt'] = OrderClass::DEBT_NO;
  385. }
  386. }
  387. //员工不能开已收款订单
  388. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  389. if ($debt == OrderClass::DEBT_NO) {
  390. $shopAdmin = $this->shopAdmin;
  391. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  392. util::fail('不能开已收款订单');
  393. }
  394. }
  395. //PC端开单
  396. if (isset($post['getType'])) {
  397. util::fail('暂不支持PC端修改订单');
  398. $getType = $post['getType'];
  399. //自取
  400. if ($getType == 1) {
  401. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  402. } else {
  403. //选择配送时,在发货时让商家自己再确认一下用什么方式
  404. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  405. }
  406. }
  407. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  408. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  409. $post['debt'] = OrderClass::DEBT_NO;
  410. }
  411. $id = $post['id'] ?? 0;
  412. $order = OrderClass::getLockById($id);
  413. if (empty($order)) {
  414. util::fail('没有找到订单');
  415. }
  416. OrderClass::valid($order, $this->shopId);
  417. unset($post['id']);
  418. $shopAdmin = $this->shopAdmin;
  419. $post['shopAdminId'] = $this->shopAdminId;
  420. $post['shopAdminName'] = $shopAdmin->name ?? '';
  421. $post['fromType'] = 1;
  422. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  423. $productJson = $post['product'] ?? '';
  424. if (empty($productJson)) {
  425. util::fail('请选择花材');
  426. }
  427. $productList = json_decode($productJson, true);
  428. if (empty($productList)) {
  429. util::fail('请选择花材');
  430. }
  431. $connection = Yii::$app->db;//事务处理
  432. $transaction = $connection->beginTransaction();
  433. try {
  434. //判断花材有效性
  435. ProductClass::valid($productList, $this->shopId);
  436. $post['product'] = $productList;
  437. //商家开单订单有效期更长(30)天
  438. $validTime = dict::getDict('kd_order_valid');
  439. $current = time() + $validTime;
  440. $post['deadline'] = date("Y-m-d H:i:s", $current);
  441. $upData = [
  442. 'payWay' => $post['payWay'],
  443. 'sendType' => $post['sendType'],
  444. 'debt' => $post['debt'],
  445. 'needPrint' => $post['needPrint'],
  446. 'modifyPrice' => $post['modifyPrice'],
  447. 'shopAdminId' => $post['shopAdminId'],
  448. 'shopAdminName' => $post['shopAdminName'],
  449. 'fromType' => 1,
  450. 'sendCost' => $post['sendCost'],
  451. 'product' => $post['product'],
  452. 'deadline' => $post['deadline'],
  453. 'debt' => $post['debt'],
  454. ];
  455. $return = OrderService::updateOrder($order, $upData);
  456. $transaction->commit();
  457. util::success($return);
  458. } catch (\Exception $e) {
  459. $transaction->rollBack();
  460. Yii::error("下单失败原因:" . $e->getMessage());
  461. util::fail('下单失败');
  462. }
  463. }
  464. //延期支付 ssh 2021.1.19
  465. public function actionDebt()
  466. {
  467. $get = Yii::$app->request->get();
  468. $id = $get['id'] ?? 0;
  469. $info = OrderService::getOrderInfo($id);
  470. OrderClass::valid($info, $this->shopId);
  471. OrderClass::debt($info, $this->shop);
  472. util::complete();
  473. }
  474. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  475. public function actionWxPay()
  476. {
  477. ini_set('date.timezone', 'Asia/Shanghai');
  478. $post = Yii::$app->request->post();
  479. $couponId = $post['couponId'] ?? 0;
  480. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  481. $order = OrderClass::getByOrderSn($orderSn);
  482. if (empty($order)) {
  483. util::fail('订单号无效');
  484. }
  485. $id = $order['id'];
  486. //支付前验证订单有效性
  487. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  488. util::fail('没有权限操作');
  489. }
  490. $name = $order['orderName'] ?? '购买商品';
  491. $totalFee = $order['actPrice'];
  492. //强制使用小程序的miniOpenId
  493. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  494. if (empty($openId)) {
  495. util::fail('没有找到openId');
  496. }
  497. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  498. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  499. $wxPayType = 0;
  500. if (httpUtil::isMiniProgram()) {
  501. $wxPayType = 1;
  502. }
  503. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  504. //订单30分钟后过期
  505. $now = time();
  506. $expireTime = $now + 1800;
  507. $wx = Yii::getAlias("@vendor/weixin");
  508. require_once($wx . '/lib/WxPay.Api.php');
  509. require_once($wx . '/example/WxPay.JsApiPay.php');
  510. $input = new \WxPayUnifiedOrder();
  511. $input->SetBody($name);
  512. $input->SetOut_trade_no($orderSn);
  513. $input->SetTotal_fee($totalFee * 100);
  514. $input->SetTime_start(date("YmdHis", $now));
  515. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  516. $input->SetTime_expire(date("YmdHis", $expireTime));
  517. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  518. $input->SetTrade_type("JSAPI");
  519. //花卉宝代为申请的微信支付
  520. //$sjExtend = $this->sjExtend->attributes;
  521. $sjExtend = WxOpenClass::getGhsWxInfo();
  522. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  523. $input->SetSub_openid($openId);
  524. } else {
  525. $input->SetOpenid($openId);
  526. }
  527. //强制使用小程序的miniAppId
  528. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  529. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  530. $tools = new \JsApiPay();
  531. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  532. $newParams = json_decode($jsApiParameters, true);
  533. //微信不能修改价格
  534. $current = date("Y-m-d H:i:s");
  535. $updateData = ['deadline' => $current, 'modPrice' => 0];
  536. OrderClass::updateById($id, $updateData);
  537. util::success($newParams);
  538. }
  539. //获取订单详情 ssh 2021.1.21
  540. public function actionDetail()
  541. {
  542. $get = Yii::$app->request->get();
  543. $id = $get['id'] ?? 0;
  544. $info = OrderService::getOrderInfo($id, true, true, true, false);
  545. OrderClass::valid($info, $this->shopId);
  546. //是否有云打印判断
  547. $hasCloudPrint = 0;
  548. $shopExt = $this->shopExt;
  549. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  550. $hasCloudPrint = 1;
  551. }
  552. $info['hasCloudPrint'] = $hasCloudPrint;
  553. //店长信息
  554. $customShopId = $info['customShopId'] ?? 0;
  555. $superInfo = ShopAdminClass::getSuper($customShopId);
  556. $info['customSuper'] = $superInfo;
  557. $purchaseId = $info['purchaseId'] ?? 0;
  558. $cg = PurchaseClass::getById($purchaseId);
  559. $info['cgInfo'] = $cg;
  560. util::success($info);
  561. }
  562. //自取免发货流程处理 ssh 2021.1.22
  563. public function actionWithoutSend()
  564. {
  565. $get = Yii::$app->request->get();
  566. $id = $get['id'] ?? 0;
  567. $info = OrderService::getById($id, true);
  568. OrderClass::valid($info, $this->shopId);
  569. $purchaseId = $info->purchaseId;
  570. $purchase = PurchaseClass::getById($purchaseId, true);
  571. OrderService::withoutSend($info, $purchase);
  572. util::complete();
  573. }
  574. //本店送 ssh 2021.1.24
  575. public function actionSelfSend()
  576. {
  577. $get = Yii::$app->request->get();
  578. $id = isset($get['id']) ? $get['id'] : 0;
  579. $info = OrderClass::getById($id, true);
  580. OrderClass::valid($info->attributes, $this->shopId);
  581. $connection = Yii::$app->db;
  582. $transaction = $connection->beginTransaction();
  583. try {
  584. OrderClass::selfSend($info);
  585. $transaction->commit();
  586. } catch (\Exception $exception) {
  587. $transaction->rollBack();
  588. Yii::info("本店送操作报错:" . $exception->getMessage());
  589. util::fail('操作失败');
  590. }
  591. util::complete();
  592. }
  593. //运费计算 ssh 2021.1.24
  594. public function actionFreight()
  595. {
  596. //2021.3.28 接入达达
  597. $get = Yii::$app->request->get();
  598. $post = Yii::$app->request->post();
  599. if (empty($get)) {
  600. $get = $post;
  601. }
  602. $orderId = $get['id'] ?? 0; //订单ID
  603. $customId = $get['customId'] ?? 0;
  604. if (empty($orderId)) {
  605. //自定义运费
  606. //freight::getCost();
  607. if (empty($customId)) {
  608. util::fail("请选择客户");
  609. }
  610. $customInfo = CustomClass::getById($customId);
  611. if (empty($customInfo)) {
  612. util::fail('没有找到客户');
  613. }
  614. $shop = $this->shop;
  615. //花材信息
  616. $productJson = $get['product'] ?? '';
  617. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  618. if (empty($productJson)) {
  619. util::fail('请选择花材');
  620. }
  621. $productList = json_decode($productJson, true);
  622. if (empty($productList)) {
  623. util::fail('请选择花材');
  624. }
  625. $productList = ProductClass::mergeItemInfo($productList);
  626. $weight = 0;
  627. $price = 0;
  628. $productData = ProductClass::getProductMapData($productList);
  629. $bigNum = 0;
  630. foreach ($productList as $key => $val) {
  631. $productId = $val['productId'];
  632. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  633. $bigNum += $val['bigNum'];
  634. $weight = bcadd($w, $weight, 2);
  635. $ratio = $productData[$productId]['ratio'] ?? 0;
  636. //大小数量合并多少扎
  637. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  638. //售卖价格
  639. $itemPrice = $productData[$productId]['price'] ?? 0;
  640. //合计价格
  641. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  642. }
  643. //没有经纬度的客户运费直接返回空 shish 20210612
  644. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  645. util::success(['sedCost' => '']);
  646. }
  647. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  648. util::success(['sedCost' => $cost]);
  649. }
  650. $province = $get['province'] ?? '';
  651. $city = $get['city'] ?? '';
  652. $address = $get['address'] ?? '';
  653. $floor = $get['floor'] ?? '';
  654. $customName = $get['customName'] ?? '';
  655. $customMobile = $get['customMobile'] ?? '';
  656. $fullAddress = $province . $city . $address . $floor;
  657. $sendTime = $get['sendTime'] ?? '';
  658. $lat = $get['lat'] ?? '';
  659. $lng = $get['long'] ?? '';
  660. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  661. util::fail('请填写客户地址');
  662. }
  663. ini_set('date.timezone', 'Asia/Shanghai');
  664. if (!empty($sendTime)) {
  665. //配送时间不为空
  666. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  667. $sendTimeInt = strtotime($sendTime);
  668. $now = time();
  669. $diff = $sendTimeInt - $now;
  670. //因服务器写入时间,改为至少提前6分钟
  671. if ($diff <= 360) {
  672. util::fail('配送时间至少提前6分钟');
  673. }
  674. } else {
  675. //默认立即发送
  676. $sendTime = 0;
  677. }
  678. //更新订单表
  679. $info = OrderService::getOrderInfo($orderId);
  680. OrderClass::valid($info, $this->shopId);
  681. if ($sendTime) {
  682. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  683. } else {
  684. $sendTime = '0000-00-00 00:00:00';
  685. }
  686. $expressAddInfo = [
  687. 'customName' => $customName,
  688. 'customMobile' => $customMobile,
  689. 'province' => $province,
  690. 'city' => $city,
  691. 'address' => $address,
  692. 'floor' => $floor,
  693. 'lat' => $lat,
  694. 'long' => $lng,
  695. 'sendTime' => $sendTime,
  696. ];
  697. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  698. //计算运费
  699. $info['province'] = $province;
  700. $info['city'] = $city;
  701. $info['address'] = $address;
  702. $info['floor'] = $floor;
  703. $info['fullAddress'] = $fullAddress;
  704. $info['lat'] = $lat;
  705. $info['long'] = $lng;
  706. $info['sendTime'] = $expressAddInfo['sendTime'];
  707. $res = DadaExpressServices::queryDeliverFee($info);
  708. util::success(['sedCost' => $res['fee']]);
  709. }
  710. //发快递和第三方配送 ssh 2021.1.24
  711. public function actionThirdSend()
  712. {
  713. $get = Yii::$app->request->get();
  714. $id = isset($get['id']) ? $get['id'] : 0;
  715. $info = OrderService::getById($id, true);
  716. OrderClass::valid($info->attributes, $this->shopId);
  717. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  718. util::fail('请填写客户地址');
  719. }
  720. $connection = Yii::$app->db;
  721. $transaction = $connection->beginTransaction();
  722. try {
  723. $respond = OrderClass::thirdSend($info, $get);
  724. $transaction->commit();
  725. util::success($respond);
  726. } catch (\Exception $exception) {
  727. $transaction->rollBack();
  728. Yii::info("发快递操作报错:" . $exception->getMessage());
  729. util::fail('操作失败' . $exception->getMessage());
  730. }
  731. }
  732. //确认送达 ssh 2021.1.24
  733. public function actionReach()
  734. {
  735. $get = Yii::$app->request->get();
  736. $id = isset($get['id']) ? $get['id'] : 0;
  737. $info = OrderClass::getById($id, true);
  738. OrderClass::valid($info->attributes, $this->shopId);
  739. $connection = Yii::$app->db;
  740. $transaction = $connection->beginTransaction();
  741. try {
  742. OrderService::reach($info);
  743. $transaction->commit();
  744. } catch (\Exception $exception) {
  745. $transaction->rollBack();
  746. Yii::info("送达操作报错:" . $exception->getMessage());
  747. util::fail('操作失败');
  748. }
  749. util::complete();
  750. }
  751. //下单要用到的相关信息 ssh 2019.12.6
  752. public function actionOrderRelate()
  753. {
  754. $regionTree = RegionService::tree();
  755. $shop = $this->shop->attributes;
  756. $freight = ['first' => 5, 'add' => 2];
  757. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  758. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  759. util::success($out);
  760. }
  761. //客户欠款的订单 ssh 2021.2.4
  762. public function actionDebtList()
  763. {
  764. $id = Yii::$app->request->get('id', 0);
  765. $info = CustomClass::getCustom($id);
  766. CustomClass::valid($info, $this->shopId);
  767. $where = ['customId' => $id, 'debt' => 1];
  768. $respond = OrderService::getDebtOrderList($where);
  769. $respond['customInfo'] = $info;
  770. util::success($respond);
  771. }
  772. //更新打印次数
  773. public function actionAddPrintNum()
  774. {
  775. $id = Yii::$app->request->get('id', 0);
  776. $order = OrderClass::getById($id, true);
  777. OrderClass::valid($order, $this->shopId);
  778. $order->printNum += 1;
  779. $order->save();
  780. util::complete();
  781. }
  782. //打印订单 shish 20210714
  783. public function actionCloudPrintOrder()
  784. {
  785. $id = Yii::$app->request->get('id', 0);
  786. $order = OrderClass::getById($id, true);
  787. OrderClass::valid($order, $this->shopId);
  788. $ext = $this->shopExt;
  789. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  790. util::success(['hasNoPrint' => 1]);
  791. }
  792. OrderClass::onlinePrint($order);
  793. $order->printNum += 1;
  794. $order->save();
  795. util::complete();
  796. }
  797. //订单确认完成 shish 20210809
  798. public function actionConfirmFinish()
  799. {
  800. $payWay = Yii::$app->request->get('payWay', -1);
  801. $id = Yii::$app->request->get('id', 0);
  802. $clearType = Yii::$app->request->get('clearType', 0);
  803. $connection = Yii::$app->db;
  804. $transaction = $connection->beginTransaction();
  805. try {
  806. $order = OrderClass::getById($id, true);
  807. OrderClass::valid($order, $this->shopId);
  808. $purchaseId = $order->purchaseId ?? 0;
  809. $purchase = PurchaseClass::getById($purchaseId, true);
  810. if (empty($purchase)) {
  811. util::fail('没有采购信息');
  812. }
  813. if ($clearType == 1) {
  814. //欠款
  815. $payWay = dict::getDict('payWay', 'debtPay');
  816. } elseif ($clearType == 2) {
  817. //已收款
  818. if ($payWay == -1) {
  819. util::fail('请选择收款方式');
  820. }
  821. $shopAdmin = $this->shopAdmin;
  822. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  823. util::fail('超管才能发起已收款');
  824. }
  825. } else {
  826. util::fail('请选择结算方式');
  827. }
  828. //不需要打印
  829. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  830. $order->save();
  831. //支付
  832. PurchaseService::payAfter($purchase, $payWay);
  833. OrderService::payAfter($order, $payWay);
  834. //自己送
  835. $info = OrderClass::getById($id, true);
  836. OrderClass::selfSend($info);
  837. //确认送达,并且不需要微信通知
  838. Yii::$app->params['noNeedWxNotice'] = 1;
  839. $info = OrderClass::getById($id, true);
  840. OrderService::reach($info);
  841. $transaction->commit();
  842. util::complete('操作成功');
  843. } catch (\Exception $exception) {
  844. $transaction->rollBack();
  845. Yii::info("确认完成订单报错:" . $exception->getMessage());
  846. util::fail('操作失败');
  847. }
  848. }
  849. //取消订单 shish 20210810
  850. public function actionCancel()
  851. {
  852. $shopAdmin = $this->shopAdmin;
  853. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  854. util::fail('超管才能取消订单');
  855. }
  856. $id = Yii::$app->request->get('id', 0);
  857. $order = OrderClass::getLockById($id);
  858. OrderClass::valid($order, $this->shopId);
  859. OrderService::expire($order, true);
  860. util::complete();
  861. }
  862. //获取收款语音播报地址 shish 20211231
  863. public function actionGetPayVoice()
  864. {
  865. $id = Yii::$app->request->get('id');
  866. $order = OrderClass::getById($id, true);
  867. $payWay = $order->payWay ?? 0;
  868. $money = floatval($order->actPrice);
  869. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  870. $msg = $payment . '收款' . $money . '元';
  871. $audio = baiduAip::transfer($msg, 4, 0);
  872. //上传到oss
  873. $file = time() . rand(10000, 999999) . '.mp3';
  874. $filePath = 'tmp/arrival/money/' . $file;
  875. oss::uploadTmpAudio($filePath, $audio);
  876. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  877. util::success(['url' => $url]);
  878. }
  879. }