NoticeRepositories.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_PAY_SUCCESS, [
  37. 'first' => '亲,您购买的商品已支付成功',
  38. 'keyword1' => $order['order_id'],
  39. 'keyword2' => $order['pay_price'],
  40. 'remark' => '点击查看订单详情'
  41. ], Route::buildUrl('order/detail/' . $order['order_id'])->suffix('')->domain(true)->build());
  42. //订单支付成功后给客服发送模版消息
  43. WechatTemplateService::sendAdminNoticeTemplate([
  44. 'first' => "亲,您有一个新订单 \n订单号:{$order['order_id']}",
  45. 'keyword1' => '新订单',
  46. 'keyword2' => '已支付',
  47. 'keyword3' => date('Y/m/d H:i', time()),
  48. 'remark' => '请及时处理'
  49. ]);
  50. //订单支付成功后给客服发送客服消息
  51. CustomerRepository::sendOrderPaySuccessCustomerService($order, 1);
  52. } else if ($routineOpenid && in_array($order['is_channel'], [1, 2])) {//小程序发送模板消息
  53. RoutineTemplate::sendOrderSuccess($order['uid'], $order['pay_price'], $order['order_id']);
  54. //订单支付成功后给客服发送客服消息
  55. CustomerRepository::sendOrderPaySuccessCustomerService($order, 0);
  56. }
  57. } catch (\Exception $e) {
  58. Log::error('购买后发送提醒失败,错误原因:' . $e->getMessage());
  59. }
  60. }
  61. if ($order['suit']) return;
  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'])->where('oid', $order['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()->selectStore($order['store_id'])->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. }