NoticeRepositories.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xurongyao <763569752@qq.com>
  5. * Date: 2019/11/13 4:52 PM
  6. */
  7. namespace crmeb\repositories;
  8. use app\models\user\WechatUser;
  9. use crmeb\services\WechatService;
  10. use crmeb\services\WechatTemplateService;
  11. use crmeb\services\workerman\ChannelService;
  12. use app\models\routine\RoutineTemplate;
  13. use app\models\store\StoreOrderCartInfo;
  14. use app\models\user\User;
  15. use crmeb\services\YLYService;
  16. use think\facade\Log;
  17. use think\facade\Route;
  18. /** 消息通知静态类
  19. * Class NoticeRepositories
  20. * @package crmeb\repositories
  21. */
  22. class NoticeRepositories
  23. {
  24. /** 支付成功通知
  25. * @param $order
  26. * @param $formId
  27. */
  28. public static function noticeOrderPaySuccess($order)
  29. {
  30. $wechatUser = WechatUser::where('uid', $order['uid'])->field(['openid', 'routine_openid'])->find();
  31. if ($wechatUser) {
  32. $openid = $wechatUser['openid'];
  33. $routineOpenid = $wechatUser['routine_openid'];
  34. try {
  35. if ($openid && in_array($order['is_channel'], [0, 2])) {//公众号发送模板消息
  36. $urlWeChat = config('wx.wx_notify_jump_url') . $order['order_id'];
  37. WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_PAY_SUCCESS, [
  38. 'first' => '亲,您购买的商品已支付成功',
  39. 'keyword1' => $order['order_id'],
  40. 'keyword2' => $order['pay_price'],
  41. 'remark' => '点击查看订单详情'
  42. ], $urlWeChat);
  43. //订单支付成功后给客服发送模版消息
  44. WechatTemplateService::sendAdminNoticeTemplate([
  45. 'first' => "亲,您有一个新订单 \n订单号:{$order['order_id']}",
  46. 'keyword1' => '新订单',
  47. 'keyword2' => '已支付',
  48. 'keyword3' => date('Y/m/d H:i', time()),
  49. 'remark' => '请及时处理'
  50. ]);
  51. //订单支付成功后给客服发送客服消息
  52. CustomerRepository::sendOrderPaySuccessCustomerService($order, 1);
  53. } else if ($routineOpenid && in_array($order['is_channel'], [1, 2])) {//小程序发送模板消息
  54. RoutineTemplate::sendOrderSuccess($order['uid'], $order['pay_price'], $order['order_id']);
  55. //订单支付成功后给客服发送客服消息
  56. CustomerRepository::sendOrderPaySuccessCustomerService($order, 0);
  57. }
  58. } catch (\Exception $e) {
  59. Log::error('购买后发送提醒失败,错误原因:' . $e->getMessage());
  60. }
  61. }
  62. //打印小票
  63. $switch = sys_config('pay_success_printing_switch') ? true : false;
  64. if ($switch) {
  65. try {
  66. $order['cart_id'] = is_string($order['cart_id']) ? json_decode($order['cart_id'], true) : $order['cart_id'];
  67. $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $order['cart_id'])->field('cart_info')->select();
  68. $cartInfo = count($cartInfo) ? $cartInfo->toArray() : [];
  69. $product = [];
  70. foreach ($cartInfo as $item) {
  71. $value = is_string($item['cart_info']) ? json_decode($item['cart_info'], true) : $item['cart_info'];
  72. $value['productInfo']['store_name'] = $value['productInfo']['store_name'] ?? "";
  73. $value['productInfo']['store_name'] = StoreOrderCartInfo::getSubstrUTf8($value['productInfo']['store_name'], 10, 'UTF-8', '');
  74. $product[] = $value;
  75. }
  76. YLYService::instance()->setContent(sys_config('site_name'), is_object($order) ? $order->toArray() : $order, $product)->orderPrinting();
  77. } catch (\Exception $e) {
  78. Log::error('小票打印出现错误,错误原因:' . $e->getMessage());
  79. }
  80. }
  81. //短信通知 下发用户支付成功 下发管理员支付通知
  82. event('ShortMssageSend', [$order['order_id'], ['PaySuccess', 'AdminPaySuccess']]);
  83. }
  84. }