TikTokUserCharge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. if(empty($this->time)){
  42. \Log::info('origin_params:'.$this->time);
  43. $this->time = date('Y-m-d H:i:s');
  44. }
  45. $params = [
  46. 'uid' => $this->uid,
  47. 'amount' => $this->amount,
  48. 'time' => $this->time,
  49. 'source' => 'wdy'
  50. ];
  51. \Log::info('TikTokUserCharge:'.json_encode($params));
  52. // if( date('Y-m-d',strtotime( $this->time )) != date('Y-m-d')){
  53. // return ;
  54. // }
  55. $user = User::find($this->uid);
  56. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->orderBy('id', 'desc')->first();
  57. $current_day_register = date('Y-m-d', strtotime($order->created_at)) == date('Y-m-d', strtotime($user->created_at));
  58. if ($order && $current_day_register && $order->price >= 30) {
  59. $count = Order::where('uid', $this->uid)->where('status', 'PAID')->where('price', '>=', '30')->count();
  60. if ($count == 1) {
  61. } else {
  62. return;
  63. }
  64. } else {
  65. return;
  66. }
  67. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  68. $url = 'https://newtrackapi.zhuishuyun.com/api/user/tiktokUserChargePush';
  69. $response = $client->request('post', $url, ['form_params' => $params])->getBody()->getContents();
  70. myLog('tiktok_push_charge')->info($response);
  71. $result = json_decode($response);
  72. if ($result) {
  73. if ($result->code != 0) {
  74. myLog('tiktok_push_charge')->info($response);
  75. }
  76. }
  77. }
  78. }