StoreOrderRefundServices.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\services\pay\PayServices;
  13. use crmeb\services\AliPayService;
  14. use crmeb\utils\Str;
  15. use app\jobs\SmsAdminJob;
  16. use app\services\BaseServices;
  17. use app\dao\order\StoreOrderDao;
  18. use crmeb\services\WechatService;
  19. use app\jobs\RoutineTemplateJob;
  20. use app\services\user\UserServices;
  21. use crmeb\services\MiniProgramService;
  22. use think\exception\ValidateException;
  23. use app\services\user\UserBillServices;
  24. use crmeb\services\FormBuilder as Form;
  25. use app\services\wechat\WechatUserServices;
  26. use crmeb\services\workerman\ChannelService;
  27. use app\services\activity\StorePinkServices;
  28. use app\services\activity\StoreSeckillServices;
  29. use app\services\activity\StoreBargainServices;
  30. use app\services\coupon\StoreCouponUserServices;
  31. use app\jobs\WechatTemplateJob as TemplateJob;
  32. use app\services\activity\StoreCombinationServices;
  33. use app\services\message\service\StoreServiceServices;
  34. use app\services\product\product\StoreProductServices;
  35. /**
  36. * 订单退款
  37. * Class StoreOrderRefundServices
  38. * @package app\services\order
  39. */
  40. class StoreOrderRefundServices extends BaseServices
  41. {
  42. /**
  43. * 构造方法
  44. * StoreOrderRefundServices constructor.
  45. * @param StoreOrderDao $dao
  46. */
  47. public function __construct(StoreOrderDao $dao)
  48. {
  49. $this->dao = $dao;
  50. }
  51. /**
  52. * 订单退款表单
  53. * @param int $id
  54. * @return array
  55. * @throws \FormBuilder\Exception\FormBuilderException
  56. */
  57. public function refundOrderForm(int $id)
  58. {
  59. $order = $this->dao->get($id);
  60. if (!$order) {
  61. throw new ValidateException('未查到订单');
  62. }
  63. if (!$order['paid']) {
  64. throw new ValidateException('未支付无法退款');
  65. }
  66. if ($order['pay_price'] > 0 && in_array($order['refund_status'], [0, 1])) {
  67. if ($order['pay_price'] <= $order['refund_price']) {
  68. throw new ValidateException('订单已退款');
  69. }
  70. }
  71. $f[] = Form::input('order_id', '退款单号', $order->getData('order_id'))->disabled(true);
  72. $f[] = Form::number('refund_price', '退款金额', (float)bcsub((string)$order->getData('pay_price'), (string)$order->getData('refund_price'), 2))->precision(2)->required('请输入退款金额');
  73. // $f[] = Form::radio('type', '状态', 1)->options([['label' => '直接退款', 'value' => 1], ['label' => '退款(无需退货,并且返回原状态)', 'value' => 2]]);
  74. return create_form('退款处理', $f, $this->url('/order/refund/' . $id), 'PUT');
  75. }
  76. /**
  77. * 订单退款处理
  78. * @param int $type
  79. * @param $order
  80. * @param array $refundData
  81. * @return mixed
  82. */
  83. public function payOrderRefund(int $type, $order, array $refundData)
  84. {
  85. return $this->transaction(function () use ($type, $order, $refundData) {
  86. //回退积分和优惠卷
  87. if (!$this->integralAndCouponBack($order)) {
  88. throw new ValidateException('回退积分和优惠卷失败');
  89. }
  90. //退拼团
  91. if ($type == 1) {
  92. /** @var StorePinkServices $pinkServices */
  93. $pinkServices = app()->make(StorePinkServices::class);
  94. if (!$pinkServices->setRefundPink($order)) {
  95. throw new ValidateException('拼团修改失败!');
  96. }
  97. }
  98. //退佣金
  99. /** @var UserBillServices $userBillServices */
  100. $userBillServices = app()->make(UserBillServices::class);
  101. if (!$userBillServices->orderRefundBrokerageBack($order['id'], $order['order_id'])) {
  102. throw new ValidateException('回退佣金失败');
  103. }
  104. //回退库存
  105. if ($type == 1) {
  106. /** @var StoreOrderStatusServices $services */
  107. $services = app()->make(StoreOrderStatusServices::class);
  108. if (!$services->count(['oid' => $order['id'], 'change_type' => 'refund_price'])) {
  109. $this->regressionStock($order);
  110. }
  111. }
  112. //退金额
  113. if ($refundData['refund_price'] > 0) {
  114. switch ($order['pay_type']) {
  115. case PayServices::WEIXIN_PAY:
  116. $no = $order['order_id'];
  117. if ($order['trade_no']) {
  118. $no = $order['trade_no'];
  119. $refundData['type'] = 'trade_no';
  120. }
  121. if ($order['is_channel'] == 1) {
  122. //小程序退款
  123. MiniProgramService::payOrderRefund($no, $refundData);//小程序
  124. } else {
  125. //微信公众号退款
  126. WechatService::payOrderRefund($no, $refundData);//公众号
  127. }
  128. break;
  129. case PayServices::YUE_PAY:
  130. //余额退款
  131. if (!$this->yueRefund($order, $refundData)) {
  132. throw new ValidateException('余额退款失败');
  133. }
  134. break;
  135. case PayServices::ALIAPY_PAY:
  136. //支付宝退款
  137. AliPayService::instance()->refund(strpos($order['trade_no'], '_') !== false ? $order['trade_no'] : $order['order_id'], $refundData['pay_price']);
  138. break;
  139. }
  140. }
  141. /** @var UserServices $userServices */
  142. $userServices = app()->make(UserServices::class);
  143. $usermoney = $userServices->value(['uid' => $order['uid']], 'now_money');
  144. $userBillServices->income('pay_product_refund', $order['uid'], ['number' => $refundData['refund_price'], 'payType' => PayServices::PAY_TYPE[$order['pay_type']] ?? '未知'], bcadd((string)$usermoney, (string)$refundData['refund_price'], 2), $order['id']);
  145. //修改开票数据退款状态
  146. $orderInvoiceServices = app()->make(StoreOrderInvoiceServices::class);
  147. $orderInvoiceServices->update(['order_id' => $order['id']], ['is_refund' => 1]);
  148. });
  149. }
  150. /**
  151. * 余额退款
  152. * @param $order
  153. * @param array $refundData
  154. * @return bool
  155. */
  156. public function yueRefund($order, array $refundData)
  157. {
  158. /** @var UserServices $userServices */
  159. $userServices = app()->make(UserServices::class);
  160. // /** @var UserBillServices $userBillServices */
  161. // $userBillServices = app()->make(UserBillServices::class);
  162. //
  163. // $usermoney = $userServices->value(['uid' => $order['uid']], 'now_money');
  164. $res = $userServices->bcInc($order['uid'], 'now_money', $refundData['refund_price'], 'uid');
  165. return $res ? true : false;
  166. // return $res && $userBillServices->income('pay_product_refund', $order['uid'], $refundData['refund_price'], bcadd((string)$usermoney, (string)$refundData['refund_price'], 2), $order['id']);
  167. }
  168. /**
  169. * 回退积分和优惠卷
  170. * @param $order
  171. * @return bool
  172. */
  173. public function integralAndCouponBack($order)
  174. {
  175. if (!$order['use_integral'] && !$order['back_integral']) {
  176. return true;
  177. }
  178. if ($order['back_integral'] && !(int)$order['use_integral']) {
  179. return true;
  180. }
  181. if ($order['back_integral'] >= $order['use_integral']) {
  182. return true;
  183. }
  184. $data['back_integral'] = bcsub($order['use_integral'], $order['back_integral'], 0);
  185. if (!$data['back_integral']) {
  186. return true;
  187. }
  188. //回退积分
  189. $order = $this->regressionIntegral($order);
  190. $res = true;
  191. //回退优惠卷
  192. if ($order['coupon_id']) {
  193. /** @var StoreCouponUserServices $coumonUserServices */
  194. $coumonUserServices = app()->make(StoreCouponUserServices::class);
  195. $res = $res && $coumonUserServices->recoverCoupon((int)$order['coupon_id']);
  196. }
  197. /** @var StoreOrderStatusServices $statusService */
  198. $statusService = app()->make(StoreOrderStatusServices::class);
  199. $statusService->save([
  200. 'oid' => $order['id'],
  201. 'change_type' => 'integral_back',
  202. 'change_message' => '商品退积分:' . $data['back_integral'],
  203. 'change_time' => time()
  204. ]);
  205. $order['use_integral'] = 0;
  206. $order['deduction_price'] = 0;
  207. $order['coupon_id'] = 0;
  208. $order['coupon_price'] = 0;
  209. return $res && $order->save();
  210. }
  211. /**
  212. * 回退使用积分和赠送积分
  213. * @param $order
  214. * @return bool
  215. */
  216. public function regressionIntegral($order)
  217. {
  218. /** @var UserServices $userServices */
  219. $userServices = app()->make(UserServices::class);
  220. $userInfo = $userServices->get($order['uid'], ['integral']);
  221. if (!$userInfo) {
  222. $order->back_integral = $order->use_integral;
  223. return $order;
  224. }
  225. $integral = $userInfo['integral'];
  226. if ($order['status'] == -2 || $order['is_del']) {
  227. return $order;
  228. }
  229. if ((int)$order['refund_status'] != 2 && $order['back_integral'] >= $order['use_integral']) {
  230. return $order;
  231. }
  232. $res1 = $res2 = $res3 = $res4 = true;
  233. //订单赠送积分
  234. /** @var UserBillServices $userBillServices */
  235. $userBillServices = app()->make(UserBillServices::class);
  236. $give_integral = $userBillServices->sum([
  237. 'category' => 'integral',
  238. 'type' => 'sign',
  239. 'link_id' => $order['id']
  240. ], 'number');
  241. if ($give_integral) {
  242. //判断订单是否已经回退积分
  243. $count = $userBillServices->count(['category' => 'integral', 'type' => 'deduction', 'link_id' => $order['id']]);
  244. if (!$count) {
  245. $res1 = $userServices->bcDec($order['uid'], 'integral', $give_integral);
  246. //记录赠送积分收回
  247. $res2 = $userBillServices->income('integral_refund', $order['uid'], $give_integral, $integral, $order['id']);
  248. }
  249. }
  250. //返还下单使用积分
  251. $use_integral = $order['use_integral'];
  252. if ($use_integral > 0) {
  253. $res3 = $userServices->bcInc($order['uid'], 'integral', $use_integral);
  254. //记录下单使用积分还回
  255. $res4 = $userBillServices->income('pay_product_integral_back', $order['uid'], $use_integral, $integral, $order['id']);
  256. }
  257. if (!($res1 && $res2 && $res3 && $res4)) {
  258. throw new ValidateException('回退积分增加失败');
  259. }
  260. if ($use_integral > $give_integral) {
  261. $order->back_integral = bcsub($use_integral, $give_integral, 2);
  262. }
  263. return $order;
  264. }
  265. /**
  266. * 回退库存
  267. * @param $order
  268. * @return bool
  269. */
  270. public function regressionStock($order)
  271. {
  272. if ($order['status'] == -2 || $order['is_del']) return true;
  273. $combinationId = $order['combination_id'];
  274. $seckill_id = $order['seckill_id'];
  275. $bargain_id = $order['bargain_id'];
  276. $res5 = true;
  277. /** @var StoreOrderCartInfoServices $cartServices */
  278. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  279. /** @var StoreProductServices $services */
  280. $services = app()->make(StoreProductServices::class);
  281. /** @var StoreSeckillServices $seckillServices */
  282. $seckillServices = app()->make(StoreSeckillServices::class);
  283. /** @var StoreCombinationServices $pinkServices */
  284. $pinkServices = app()->make(StoreCombinationServices::class);
  285. /** @var StoreBargainServices $bargainServices */
  286. $bargainServices = app()->make(StoreBargainServices::class);
  287. $cartInfo = $cartServices->getCartInfoList(['cart_id' => $order['cart_id']], ['cart_info']);
  288. foreach ($cartInfo as $cart) {
  289. $cart['cart_info'] = is_array($cart['cart_info']) ? $cart['cart_info'] : json_decode($cart['cart_info'], true);
  290. //增库存减销量
  291. $unique = isset($cart['cart_info']['productInfo']['attrInfo']) ? $cart['cart_info']['productInfo']['attrInfo']['unique'] : '';
  292. if ($combinationId) $res5 = $res5 && $pinkServices->incCombinationStock((int)$cart['cart_info']['cart_num'], (int)$combinationId, $unique);
  293. else if ($seckill_id) $res5 = $res5 && $seckillServices->incSeckillStock((int)$cart['cart_info']['cart_num'], (int)$seckill_id, $unique);
  294. else if ($bargain_id) $res5 = $res5 && $bargainServices->incBargainStock((int)$cart['cart_info']['cart_num'], (int)$bargain_id, $unique);
  295. else $res5 = $res5 && $services->incProductStock((int)$cart['cart_info']['cart_num'], (int)$cart['cart_info']['productInfo']['id'], $unique);
  296. }
  297. return $res5;
  298. }
  299. /**
  300. * 发送退款模板消息
  301. * @param $data
  302. * @param $order
  303. */
  304. public function productOrderRefundYSendTemplate($data, $order)
  305. {
  306. /** @var WechatUserServices $wechatServices */
  307. $wechatServices = app()->make(WechatUserServices::class);
  308. if ($order['is_channel'] == 1) {
  309. /** @var StoreOrderCartInfoServices $orderInfoServices */
  310. $orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
  311. $storeName = $orderInfoServices->getCarIdByProductTitle($order['cart_id']);
  312. $storeTitle = Str::substrUTf8($storeName, 20, 'UTF-8', '');
  313. $openid = $wechatServices->uidToOpenid($order['uid'], 'routine');
  314. RoutineTemplateJob::dispatchDo('sendOrderRefundSuccess', [$openid, $order, $storeTitle]);
  315. } else {
  316. $openid = $wechatServices->uidToOpenid($order['uid'], 'wechat');
  317. TemplateJob::dispatchDo('sendOrderRefundSuccess', [$openid, $data, $order]);
  318. }
  319. }
  320. /**
  321. * 同意退款成功发送模板消息和记录订单状态
  322. * @param $data
  323. * @param $order
  324. * @param $refund_price
  325. * @param $id
  326. */
  327. public function storeProductOrderRefundY($data, $order, $refund_price)
  328. {
  329. $this->productOrderRefundYSendTemplate($data, $order);
  330. /** @var StoreOrderStatusServices $statusService */
  331. $statusService = app()->make(StoreOrderStatusServices::class);
  332. $statusService->save([
  333. 'oid' => $order['id'],
  334. 'change_type' => 'refund_price',
  335. 'change_message' => '退款给用户:' . $refund_price . '元',
  336. 'change_time' => time()
  337. ]);
  338. }
  339. /**
  340. * 同意退款退款失败写入订单记录
  341. * @param int $id
  342. * @param $refund_price
  343. */
  344. public function storeProductOrderRefundYFasle(int $id, $refund_price)
  345. {
  346. /** @var StoreOrderStatusServices $statusService */
  347. $statusService = app()->make(StoreOrderStatusServices::class);
  348. $statusService->save([
  349. 'oid' => $id,
  350. 'change_type' => 'refund_price',
  351. 'change_message' => '退款给用户:' . $refund_price . '元失败',
  352. 'change_time' => time()
  353. ]);
  354. }
  355. /**
  356. * 不退款记录订单变更状态
  357. * @param int $id
  358. * @param string $refundReason
  359. */
  360. public function storeProductOrderRefundNo(int $id, string $refundReason)
  361. {
  362. /** @var StoreOrderStatusServices $statusService */
  363. $statusService = app()->make(StoreOrderStatusServices::class);
  364. $statusService->save([
  365. 'oid' => $id,
  366. 'change_type' => 'refund_n',
  367. 'change_message' => '不退款原因:' . $refundReason,
  368. 'change_time' => time()
  369. ]);
  370. }
  371. /**
  372. * 不退款发送模板消息
  373. * @param $order
  374. * @param $data
  375. */
  376. public function OrderRefundNoSendTemplate($order)
  377. {
  378. /** @var WechatUserServices $wechatServices */
  379. $wechatServices = app()->make(WechatUserServices::class);
  380. if ($order->is_channel == 1) {
  381. /** @var StoreOrderCartInfoServices $orderInfoServices */
  382. $orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
  383. $storeName = $orderInfoServices->getCarIdByProductTitle($order['cart_id']);
  384. $storeTitle = Str::substrUTf8($storeName, 20, 'UTF-8', '');
  385. $openid = $wechatServices->uidToOpenid($order['uid'], 'routine');
  386. RoutineTemplateJob::dispatchDo('sendOrderRefundFail', [$openid, $order, $storeTitle]);
  387. } else {
  388. $openid = $wechatServices->uidToOpenid($order['uid'], 'wechat');
  389. TemplateJob::dispatchDo('sendOrderRefundNoStatus', [$openid, $order]);
  390. }
  391. }
  392. /**
  393. * 不退款表单
  394. * @param int $id
  395. * @return array
  396. * @throws \FormBuilder\Exception\FormBuilderException
  397. */
  398. public function noRefundForm(int $id)
  399. {
  400. $order = $this->dao->get($id);
  401. if (!$order) {
  402. throw new ValidateException('Data does not exist!');
  403. }
  404. $f[] = Form::input('order_id', '不退款单号', $order->getData('order_id'))->disabled(true);
  405. $f[] = Form::input('refund_reason', '不退款原因')->type('textarea')->required('请填写不退款原因');
  406. return create_form('不退款原因', $f, $this->url('order/no_refund/' . $id), 'PUT');
  407. }
  408. /**
  409. * 退积分表单创建
  410. * @param int $id
  411. * @return array
  412. * @throws \FormBuilder\Exception\FormBuilderException
  413. */
  414. public function refundIntegralForm(int $id)
  415. {
  416. if (!$orderInfo = $this->dao->get($id))
  417. throw new ValidateException('订单不存在');
  418. if ($orderInfo->use_integral < 0 || $orderInfo->use_integral == $orderInfo->back_integral)
  419. throw new ValidateException('积分已退或者积分为零无法再退');
  420. if (!$orderInfo->paid)
  421. throw new ValidateException('未支付无法退积分');
  422. $f[] = Form::input('order_id', '退款单号', $orderInfo->getData('order_id'))->disabled(1);
  423. $f[] = Form::number('use_integral', '使用的积分', (float)$orderInfo->getData('use_integral'))->min(0)->disabled(1);
  424. $f[] = Form::number('use_integrals', '已退积分', (float)$orderInfo->getData('back_integral'))->min(0)->disabled(1);
  425. $f[] = Form::number('back_integral', '可退积分', (float)bcsub($orderInfo->getData('use_integral'), $orderInfo->getData('back_integral')))->min(0)->precision(0)->required('请输入可退积分');
  426. return create_form('退积分', $f, $this->url('/order/refund_integral/' . $id), 'PUT');
  427. }
  428. /**
  429. * 单独退积分处理
  430. * @param $orderInfo
  431. * @param $back_integral
  432. */
  433. public function refundIntegral($orderInfo, $back_integral)
  434. {
  435. /** @var UserServices $userServices */
  436. $userServices = app()->make(UserServices::class);
  437. $integral = $userServices->value(['uid' => $orderInfo['uid']], 'integral');
  438. return $this->transaction(function () use ($userServices, $orderInfo, $back_integral, $integral) {
  439. $res1 = $userServices->bcInc($orderInfo['uid'], 'integral', $back_integral, 'uid');
  440. /** @var UserBillServices $userBillServices */
  441. $userBillServices = app()->make(UserBillServices::class);
  442. $res2 = $userBillServices->income('pay_product_integral_back', $orderInfo['uid'], $back_integral, $integral + $back_integral, $orderInfo['id']);
  443. /** @var StoreOrderStatusServices $statusService */
  444. $statusService = app()->make(StoreOrderStatusServices::class);
  445. $res3 = $statusService->save([
  446. 'oid' => $orderInfo['id'],
  447. 'change_type' => 'integral_back',
  448. 'change_message' => '商品退积分:' . $back_integral,
  449. 'change_time' => time()
  450. ]);
  451. $res4 = $orderInfo->save();
  452. $res = $res1 && $res2 && $res3 && $res4;
  453. if (!$res) {
  454. throw new ValidateException('订单退积分失败');
  455. }
  456. return true;
  457. });
  458. }
  459. /**
  460. * 订单申请退款
  461. * @param $uni
  462. * @param $uid
  463. * @param string $refundReasonWap
  464. * @param string $refundReasonWapExplain
  465. * @param array $refundReasonWapImg
  466. * @return bool|void
  467. */
  468. public function orderApplyRefund($order, string $refundReasonWap = '', string $refundReasonWapExplain = '', array $refundReasonWapImg = [])
  469. {
  470. if (!$order) {
  471. throw new ValidateException('支付订单不存在!');
  472. }
  473. if ($order['refund_status'] == 2) {
  474. throw new ValidateException('订单已退款!');
  475. }
  476. if ($order['refund_status'] == 1) {
  477. throw new ValidateException('正在申请退款中!');
  478. }
  479. // if ($order['status'] == 1) {
  480. // throw new ValidateException('订单当前无法退款!');
  481. // }
  482. $data = [
  483. 'refund_status' => 1,
  484. 'refund_reason_time' => time(),
  485. 'refund_reason_wap' => $refundReasonWap,
  486. 'refund_reason_wap_explain' => $refundReasonWapExplain,
  487. 'refund_reason_wap_img' => json_encode($refundReasonWapImg),
  488. ];
  489. // $order->refund_status = 1;
  490. // $order->refund_reason_time = time();
  491. // $order->refund_reason_wap = $refundReasonWap;
  492. // $order->refund_reason_wap_explain = $refundReasonWapExplain;
  493. // $order->refund_reason_wap_img = json_encode($refundReasonWapImg);
  494. $this->transaction(function () use ($order, $refundReasonWap, $data) {
  495. /** @var StoreOrderStatusServices $statusService */
  496. $statusService = app()->make(StoreOrderStatusServices::class);
  497. /** @var StoreOrderServices $orderService */
  498. $orderService = app()->make(StoreOrderServices::class);
  499. $res1 = false !== $statusService->save([
  500. 'oid' => $order['id'],
  501. 'change_type' => 'apply_refund',
  502. 'change_message' => '用户申请退款,原因:' . $refundReasonWap,
  503. 'change_time' => time()
  504. ]);
  505. // $res2 = false !== $order->save();
  506. $res2 = false !== $orderService->update(['id' => $order['id']], $data);
  507. $res = $res1 && $res2;
  508. if (!$res)
  509. throw new ValidateException('申请退款失败!');
  510. });
  511. try {
  512. ChannelService::instance()->send('NEW_REFUND_ORDER', ['order_id' => $order['order_id']]);
  513. } catch (\Exception $e) {
  514. }
  515. $this->sendAdminRefund($order);
  516. return true;
  517. }
  518. /**
  519. * 用户发起退款管理员短信提醒
  520. * 用户退款中模板消息
  521. * @param string $order_id
  522. */
  523. public function sendAdminRefund($order)
  524. {
  525. $switch = sys_config('admin_refund_switch') ? true : false;
  526. /** @var StoreServiceServices $services */
  527. $services = app()->make(StoreServiceServices::class);
  528. $adminList = $services->getStoreServiceOrderNotice();
  529. SmsAdminJob::dispatchDo('sendAdminRefund', [$switch, $adminList, $order]);
  530. /** @var WechatUserServices $wechatServices */
  531. $wechatServices = app()->make(WechatUserServices::class);
  532. if ($order['is_channel'] == 1) {
  533. //小程序
  534. $openid = $wechatServices->uidToOpenid($order['uid'], 'routine');
  535. return RoutineTemplateJob::dispatchDo('sendOrderRefundStatus', [$openid, $order]);
  536. } else {
  537. $openid = $wechatServices->uidToOpenid($order['uid'], 'wechat');
  538. return TemplateJob::dispatchDo('sendOrderApplyRefund', [$openid, $order]);
  539. }
  540. }
  541. }