TikTokUserCharge.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Jobs;
  3. use App\Consts\SysConsts;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Queue\SerializesModels;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Foundation\Bus\Dispatchable;
  10. use App\Modules\Trade\Models\Order;
  11. use App\Modules\User\Models\User;
  12. /**
  13. * 抖音用户推送数据
  14. */
  15. class TikTokUserCharge implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. private $uid;
  19. private $time;
  20. private $amount;
  21. /**
  22. * Create a new job instance.
  23. * @param int $uid
  24. * @param string $type 类型
  25. * @return void
  26. */
  27. public function __construct(int $uid, float $amount, string $time)
  28. {
  29. $this->uid = $uid;
  30. $this->amount = $amount;
  31. $this->time = $time;
  32. }
  33. /**
  34. * Execute the job.
  35. *
  36. * @return void
  37. */
  38. public function handle()
  39. {
  40. $client = new Client();
  41. $params = [
  42. 'uid' => $this->uid,
  43. 'amount' => $this->amount,
  44. 'time' => $this->time,
  45. 'source' => 'wdy'
  46. ];
  47. \Log::info('TikTokUserCharge:'.json_encode($params));
  48. // if( date('Y-m-d',strtotime( $this->time )) != date('Y-m-d')){
  49. // return ;
  50. // }
  51. $user = User::find($this->uid);
  52. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->orderBy('id', 'desc')->first();
  53. $current_day_register = date('Y-m-d', strtotime($order->created_at)) == date('Y-m-d', strtotime($user->created_at));
  54. if ($order && $current_day_register && $order->price >= 30) {
  55. $count = Order::where('uid', $this->uid)->where('status', 'PAID')->where('price', '>=', '30')->count();
  56. if ($count == 1) {
  57. } else {
  58. return;
  59. }
  60. } else {
  61. return;
  62. }
  63. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  64. $url = 'https://newtrackapi.zhuishuyun.com/api/user/tiktokUserChargePush';
  65. $response = $client->request('post', $url, ['form_params' => $params])->getBody()->getContents();
  66. myLog('tiktok_push_charge')->info($response);
  67. $result = json_decode($response);
  68. if ($result) {
  69. if ($result->code != 0) {
  70. myLog('tiktok_push_charge')->info($response);
  71. }
  72. }
  73. }
  74. }