zz hace 4 años
padre
commit
f35494a821

+ 119 - 0
app/Jobs/AsyncOrderStats.php

@@ -0,0 +1,119 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2020/5/5
+ * Time: 11:29
+ */
+
+namespace App\Jobs;
+
+use App\Modules\Subscribe\Services\OrderService;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Redis;
+use DB;
+
+class AsyncOrderStats implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $orderId;
+    private $order_info = null;
+
+    private $uid = 0;
+
+    public function __construct(int $order_id)
+    {
+        $this->orderId = $order_id;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $this->init();
+        //qkm推送统计
+        //$this->qkmPushOrderStats();
+        //activity 活动统计
+        $this->activityStats();
+        //$this->saveActivityOrder();
+        //图书充值统计
+        $this->bookChargeStats();
+    }
+
+    private function init()
+    {
+        $this->order_info = OrderService::getById($this->orderId);
+        $this->uid = $this->order_info->uid;
+    }
+
+    private function qkmPushOrderStats()
+    {
+        $push_id = Redis::hget('book_read:' . $this->uid, 'qkm_push');
+        if (!$push_id) return;
+        $push_time = Redis::hget('qkm_push:time', $push_id);
+        if (empty($push_time) || !is_numeric($push_time)) return;
+        $time = ceil((time() - $push_time) / 86400);
+        if ($time > 0 && $time <= 31) {
+            $price = $this->order_info->price * 100;
+            Redis::hincrby('qkm_push:amount', $push_id, $price);
+        }
+    }
+
+    private function activityStats()
+    {
+        $item = $this->order_info;
+        if ($item->status != 'PAID') return;
+        if (!$item->activity_id) return;
+        $day = date('Y-m-d', strtotime($item->created_at));
+        $exist = DB::table('activity_statistic_all')
+            ->where('activity_id', $item->activity_id)
+            ->where('day', $day)
+            ->select('id', 'amount')
+            ->where('distribution_channel_id', $item->distribution_channel_id)->first();
+        if ($exist) {
+            DB::table('activity_statistic_all')->where('id', $exist->id)->update(
+                [
+                    'amount' => $exist->amount + $item->price * 100,
+                    'updated_at' => date('Y-m-d H:i:s')
+                ]
+            );
+            return;
+        }
+        $pv = 0;
+        $uv = 0;
+        DB::table('activity_statistic_all')->insert([
+            'activity_id' => $item->activity_id, 'day' => $day, 'distribution_channel_id' => $item->distribution_channel_id,
+            'amount' => $item->price * 100, 'pv' => $pv, 'uv' => $uv, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')
+        ]);
+    }
+
+    private function saveActivityOrder()
+    {
+        if ($this->order_info->status != 'PAID') return;
+        if (!$this->order_info->activity_id) return;
+        DB::table('activity_order')->insert([
+            'order_id' => $this->orderId,
+            'activity_id' => $this->order_info->activity_id,
+            'distribution_channel_id' => $this->order_info->distribution_channel_id,
+            'created_at' => $this->order_info->created_at,
+            'updated_at' => date('Y-m-d H:i:s')
+        ]);
+    }
+
+    private function bookChargeStats(){
+        $bid = $this->order_info->from_bid;
+        if(!$bid) return ;
+        $day = date('Y-m-d', strtotime($this->order_info->created_at));
+        $price = $this->order_info->price * 100;
+        Redis::hincrby('book:charge:stats:'.$day, $bid, $price);
+    }
+}

+ 67 - 0
app/Jobs/NewTikTokUser.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Consts\SysConsts;
+use GuzzleHttp\Client;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+
+/**
+ * 抖音用户注册
+ */
+class NewTikTokUser implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $ip;
+    private $ua;
+    private $channel_id;
+    private $uid;
+    private $register_time;
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(string $ip, string $ua, int $channel_id, int $uid, string $register_time)
+    {
+        $this->ip = $ip;
+        $this->ua = $ua;
+        $this->channel_id = $channel_id;
+        $this->uid = $uid;
+        $this->register_time = $register_time;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'ip' => $this->ip,
+            'ua' => $this->ua,
+            'channel_id' => $this->channel_id,
+            'uid' => $this->uid,
+            'register_time' => $this->register_time,
+            'source' => 'wdy'
+        ];
+        $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
+        $url = 'https://newtrackapi.zhuishuyun.com/api/user/register';
+        $response =  $client->request('post', $url, ['form_params' => $params])->getBody()->getContents();
+        myLog('new_user_register')->info("uid:{$this->uid}{$response}");
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('new_user_register')->info($response);
+            }
+        }
+    }
+}

+ 85 - 0
app/Jobs/NewTikTokUserCharge.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Consts\SysConsts;
+use GuzzleHttp\Client;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+
+/**
+ * 抖音用户充值
+ */
+class NewTikTokUserCharge implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $uid;
+    private $amount;
+    private $pay_time;
+    private $type;
+    /**
+     * 分子
+     */
+    private $molecule;
+    /**
+     * 分母
+     */
+    private $denominator;
+
+    protected $url = 'https://newtrackapi.zhuishuyun.com/api/user/charge';
+
+    /**
+     * 一般情况都上传
+     */
+    const COMMON = 'common';
+    /**
+     * 只有当天注册当天充值用户才上传
+     */
+    const CURRENT_DAY_REGISTER = 'current_day_register';
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(int $uid, float $amount, string $pay_time, string $type = null, int $molecule = 1, int $denominator = 1)
+    {
+        $this->uid = $uid;
+        $this->amount = $amount;
+        $this->pay_time = $pay_time;
+        $this->type = $type ? $type : self::CURRENT_DAY_REGISTER;
+        $this->molecule = $molecule;
+        $this->denominator = $denominator;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'uid' => $this->uid,
+            'amount' => $this->amount,
+            'pay_time' => $this->pay_time,
+            'type' => $this->type,
+            'molecule' => $this->molecule,
+            'denominator' => $this->denominator,
+            'source' => 'wdy'
+        ];
+        $params['sign'] = _sign($params,  SysConsts::TIKTOK_KEY);
+        $response =  $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
+        myLog('new_user_charge')->info($response);
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('new_user_charge')->info($response);
+            }
+        }
+    }
+}

+ 73 - 0
app/Jobs/NewTikTokUserChargeV2.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Consts\SysConsts;
+use GuzzleHttp\Client;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+
+/**
+ * 抖音用户充值
+ */
+class NewTikTokUserChargeV2 implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $uid;
+    private $amount;
+    private $pay_time;
+    private $order_no;
+
+    protected $url = 'https://newtrackapi.zhuishuyun.com/api/user/new_charge';
+
+    /**
+     * 一般情况都上传
+     */
+    const COMMON = 'common';
+    /**
+     * 只有当天注册当天充值用户才上传
+     */
+    const CURRENT_DAY_REGISTER = 'current_day_register';
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(int $uid, float $amount, string $pay_time, string $order_no)
+    {
+        $this->uid = $uid;
+        $this->amount = $amount;
+        $this->pay_time = $pay_time;
+        $this->order_no = $order_no;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'uid' => $this->uid,
+            'amount' => $this->amount,
+            'pay_time' => $this->pay_time,
+            'order_no' => $this->order_no,
+            'source' => 'wdy'
+        ];
+        $params['sign'] = _sign($params,  SysConsts::TIKTOK_KEY);
+        $response =  $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
+        myLog('new_user_charge')->info($response);
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('new_user_charge')->info($response);
+            }
+        }
+    }
+}

+ 37 - 0
app/Jobs/OrderQueryJob.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2020/11/16
+ * Time: 15:49
+ */
+
+namespace App\Jobs;
+
+use App\Modules\Trade\Services\OrderQuery;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+
+class OrderQueryJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $trade_no;
+
+    public function __construct(string $trade_no)
+    {
+        $this->trade_no = $trade_no;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle(){
+        OrderQuery::query($this->trade_no);
+    }
+}

+ 106 - 0
app/Jobs/TikTokUser.php

@@ -0,0 +1,106 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Consts\SysConsts;
+use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
+use App\Modules\OfficialAccount\Models\OfficialAccount;
+use App\Modules\Trade\Models\Order;
+use App\Modules\User\Models\User;
+use App\Modules\User\Models\UserEnv;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\ConnectException;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Support\Facades\Log;
+
+/**
+ * 抖音用户推送数据
+ */
+class TikTokUser implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    /**
+     * 类型:充值
+     */
+    const charge = 'charge';
+    /**
+     * 类型:注册
+     */
+    const register = 'register';
+
+    private $uid;
+    private $type;
+
+    /**
+     * Create a new job instance.
+     * @param int $uid
+     * @param string $type 类型
+     * @return void
+     */
+    public function __construct(int $uid, string $type)
+    {
+        $this->uid = $uid;
+        $this->type = $type;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $user = User::find($this->uid);
+        $user_env = UserEnv::where('uid', $this->uid)->first();
+        if ($user && $user_env) {
+            if ($this->type == self::charge) {
+                $order = Order::where('uid', $this->uid)->where('status', 'PAID')->orderBy('id', 'desc')->first();
+                $current_day_register = date('Y-m-d', strtotime($order->created_at)) ==  date('Y-m-d', strtotime($user->created_at));
+                if ($order && $current_day_register && $order->price >= 30) {
+                    $time = (string) $order->created_at;
+                    $ip = $order->create_ip;
+                    $count = Order::where('uid', $this->uid)->where('status', 'PAID')->where('price', '>=', '30')->count();
+                    if ($count == 1) {
+                        $amount = $order->price;
+                    } else {
+                        return;
+                    }
+                } else {
+                    return;
+                }
+            } else {
+                $time = (string) $user->created_at;
+                $ip = $user->register_ip;
+            }
+            $wechat = OfficialAccount::where('distribution_channel_id', $user->distribution_channel_id)->orderBy('id', 'desc')->first();
+            if ($wechat) {
+                $params = [
+                    'ip' => trim($ip),
+                    'ua' => trim($user_env->ua),
+                    'open_id' => trim($user->openid),
+                    'account_id' => trim($wechat->alias),
+                    'app_id' => trim($wechat->appid),
+                    'source' => 'wdy',
+                    'amount' =>  isset($amount) ? $amount : '',
+                    'type' => $this->type,
+                    'time' => $time,
+                ];
+                $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
+                $client = new Client(['timeout' => 4]);
+                $url = 'https://newtrackapi.zhuishuyun.com/api/tiktokPushInfo';
+                try {
+                    $response = $client->post($url, ['form_params' => $params]);
+                    $code = $response->getStatusCode();
+                    $res = $code == 200 ? 'success' : 'fail';
+                    Log::info('TikTokUser .' . $this->type . '. result : ' . $res . ' request params :' . json_encode($params) . ' http code: ' . $response->getStatusCode() . ' return content:' . $response->getBody()->getContents());
+                } catch (ConnectException $e) {
+                    Log::error($e->getMessage());
+                }
+            }
+        }
+    }
+}

+ 62 - 0
app/Jobs/TikTokUserCharge.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Consts\SysConsts;
+use GuzzleHttp\Client;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+
+/**
+ * 抖音用户推送数据
+ */
+class TikTokUserCharge implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $uid;
+    private $time;
+    private $amount;
+
+    /**
+     * Create a new job instance.
+     * @param int $uid
+     * @param string $type 类型
+     * @return void
+     */
+    public function __construct(int $uid, float $amount, string $time)
+    {
+        $this->uid = $uid;
+        $this->amount = $amount;
+        $this->time = $time;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'uid' => $this->uid,
+            'amount' => $this->amount,
+            'time' => $this->time,
+            'source' => 'wdy'
+        ];
+        $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
+        $url = 'https://newtrackapi.zhuishuyun.com/api/user/tiktokUserChargePush';
+        $response =  $client->request('post', $url, ['form_params' => $params])->getBody()->getContents();
+        myLog('tiktok_push_charge')->info($response);
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('tiktok_push_charge')->info($response);
+            }
+        }
+    }
+}

+ 74 - 0
app/Jobs/TikTokUserRegister.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Consts\SysConsts;
+use GuzzleHttp\Client;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+
+/**
+ * 抖音用户推送数据
+ */
+class TikTokUserRegister implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $uid;
+    private $ip;
+    private $ua;
+    private $app_id;
+    private $open_id;
+    private $account_id;
+    private $time;
+
+    /**
+     * Create a new job instance.
+     * @param int $uid
+     * @param string $type 类型
+     * @return void
+     */
+    public function __construct(string $ip, string $ua, string $app_id, string $open_id, string $account_id, int $uid, string $time)
+    {
+        $this->uid = $uid;
+        $this->ip = $ip;
+        $this->ua = $ua;
+        $this->app_id = $app_id;
+        $this->open_id = $open_id;
+        $this->account_id = $account_id;
+        $this->time = $time;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'uid' => $this->uid,
+            'ip' => $this->ip,
+            'ua' => $this->ua,
+            'app_id' => $this->app_id,
+            'open_id' => $this->open_id,
+            'account_id' => $this->account_id,
+            'time' => $this->time,
+            'source' => 'wdy'
+        ];
+        $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
+        $url = 'https://newtrackapi.zhuishuyun.com/api/user/tiktokUserPush';
+        $response =  $client->request('post', $url, ['form_params' => $params])->getBody()->getContents();
+        myLog('tiktok_push_register')->info($response);
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('tiktok_push_register')->info($response);
+            }
+        }
+    }
+}

+ 1 - 1
app/Jobs/UserAddDeskJob.php

@@ -44,7 +44,7 @@ class UserAddDeskJob implements ShouldQueue
         $client = new Client();
         $params = [
             'uid' => $this->uid,
-            'source' => 'zsy'
+            'source' => 'wdy'
         ];
         $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
         $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/addDesk';

+ 1 - 1
app/Jobs/UserRententionJob.php

@@ -49,7 +49,7 @@ class UserRententionJob implements ShouldQueue
         $client = new Client();
         $params = [
             'uid' => $this->uid,
-            'source' => 'zsy'
+            'source' => 'wdy'
         ];
         $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
         $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/rentention';