PaySuccessJob.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace crmeb\jobs;
  3. use app\models\store\StoreOrderCartInfo;
  4. use app\models\wechat\StoreService;
  5. use app\models\user\BindUser;
  6. use crmeb\services\WechatService;
  7. use crmeb\services\MiniProgramService;
  8. use crmeb\basic\BaseJob;
  9. use think\facade\Log;
  10. /**
  11. * 订单消息队列
  12. */
  13. class PaySuccessJob extends BaseJob
  14. {
  15. //新订单提醒
  16. const REMIND = 'Pr-Lg7zgHJKnXEsicuLCwihJLA2BpfkyUp1FU1FMtEs';
  17. public static function sendTemplate($order)
  18. {
  19. $info = StoreOrderCartInfo::where('oid', $order['id'])->field('cart_info')->select();
  20. $info = count($info) ? $info->toArray() : [];
  21. $goodsName = [];
  22. foreach ($info as $k => $v) {
  23. $cart_info = is_string($v['cart_info']) ? json_decode($v['cart_info'], true) : $v['cart_info'];
  24. $suk = '';
  25. if (isset($cart_info['productInfo']['attrInfo'])) {
  26. if (isset($cart_info['productInfo']['attrInfo']['suk'])) {
  27. $suk = '(' . $cart_info['productInfo']['attrInfo']['suk'] . ')';
  28. }
  29. }
  30. $goodsName[] = implode(
  31. [$cart_info['productInfo']['store_name'],
  32. $suk,
  33. "[{$cart_info['cart_num']} * {$cart_info['truePrice']}]"
  34. ], ' ');
  35. }
  36. $user = StoreService::alias('s')->where(['mer_id' => $order['mer_id'], 'status' => 1])->join('wechat_user u', 'u.uid=s.uid')->column('routine_openid');
  37. $bindUser = BindUser::where(['mer_id' => $order['mer_id'], 'status' => 1, 'is_del' => 0])->column('openid');
  38. foreach($bindUser as $value){
  39. $firstWeChat = '你有一个新的订单';
  40. $keyword1WeChat = $order['order_id'];
  41. $keyword2WeChat = date("Y-m-d H:i:s", $order['add_time']);
  42. $keyword3WeChat = $goodsName ? implode("\n", $goodsName) : '';
  43. $keyword4WeChat = $order['user_address'];
  44. $remarkWeChat = '请登录后台管理系统进行查看';
  45. WechatService::sendTemplate($value, self::REMIND, [
  46. 'first' => $firstWeChat,
  47. 'keyword1' => $keyword1WeChat,
  48. 'keyword2' => $keyword2WeChat,
  49. 'keyword3' => $keyword3WeChat,
  50. 'keyword4' => $keyword4WeChat,
  51. 'remark' => $remarkWeChat
  52. ]);
  53. }
  54. }
  55. public static function profitSharingFinish($order)
  56. {
  57. @file_put_contents('paySuccess.txt', 11111111 . PHP_EOL, FILE_APPEND);
  58. @file_put_contents('paySuccess.txt', $order->toArray() . PHP_EOL, FILE_APPEND);
  59. $res = MiniProgramService::profit_sharing_finish($order['transaction_id'], $order['order_id'], $order['mer_id']);
  60. dump($res);
  61. @file_put_contents('paySuccess.txt', 22222222 . PHP_EOL, FILE_APPEND);
  62. @file_put_contents('paySuccess.txt', $res->toArray() . PHP_EOL, FILE_APPEND);
  63. }
  64. }