TikTokUserCharge.php 2.3 KB

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