OrderController.php 40 KB

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