OrderController.php 40 KB

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