OrderController.php 40 KB

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