|
@@ -10,6 +10,7 @@
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
use App\Modules\Subscribe\Services\OrderService;
|
|
|
+use GuzzleHttp\Client;
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
@@ -22,6 +23,8 @@ class AsyncOrderStats implements ShouldQueue
|
|
|
{
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
+ const SUCCESS = 'success';
|
|
|
+
|
|
|
private $orderId;
|
|
|
private $order_info = null;
|
|
|
|
|
@@ -40,13 +43,13 @@ class AsyncOrderStats implements ShouldQueue
|
|
|
public function handle()
|
|
|
{
|
|
|
$this->init();
|
|
|
- //qkm推送统计
|
|
|
- //$this->qkmPushOrderStats();
|
|
|
//activity 活动统计
|
|
|
$this->activityStats();
|
|
|
//$this->saveActivityOrder();
|
|
|
//图书充值统计
|
|
|
$this->bookChargeStats();
|
|
|
+ //订单上报给渠道
|
|
|
+ $this->reportToChannel();
|
|
|
}
|
|
|
|
|
|
private function init()
|
|
@@ -55,18 +58,6 @@ class AsyncOrderStats implements ShouldQueue
|
|
|
$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()
|
|
|
{
|
|
@@ -96,18 +87,6 @@ class AsyncOrderStats implements ShouldQueue
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- 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;
|
|
@@ -116,4 +95,42 @@ class AsyncOrderStats implements ShouldQueue
|
|
|
$price = $this->order_info->price * 100;
|
|
|
Redis::hincrby('book:charge:stats:'.$day, $bid, $price);
|
|
|
}
|
|
|
+
|
|
|
+ private function reportToChannel(){
|
|
|
+ $link = $this->getReportUrl($this->distribution_channel_id);
|
|
|
+ if(!$link) return ;
|
|
|
+ $uid = $this->uid;
|
|
|
+ $distribution_channel_id = $this->order_info->distribution_channel_id;
|
|
|
+ $price = $this->order_info->price;
|
|
|
+ $order_created_at = $this->order_info->created_at->format('Y-m-d H:i:s');
|
|
|
+ $client = new Client(['timeout'=>3.0]);
|
|
|
+ try{
|
|
|
+ $result = $client->request('post',$link,['form_params'=>[
|
|
|
+ 'uid'=>$uid,
|
|
|
+ 'distribution_channel_id'=>$distribution_channel_id,
|
|
|
+ 'price'=>$price,
|
|
|
+ 'order_created_at'=>$order_created_at,
|
|
|
+ ]])->getBody()->getContents();
|
|
|
+ if($result && str_contains(strtolower($result),self::SUCCESS)){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ $error = 'result error ,'.$result;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $error = 'exception,'.$e->getMessage();
|
|
|
+ }
|
|
|
+ DB::table('report_to_channel_orders')->insert([
|
|
|
+ 'uid'=>$uid,
|
|
|
+ 'distribution_channel_id'=>$distribution_channel_id,
|
|
|
+ 'price'=>$price,
|
|
|
+ 'order_created_at'=>$order_created_at,
|
|
|
+ 'report_status'=>0,
|
|
|
+ 'error_msg'=>$error,
|
|
|
+ 'created_at'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at'=>date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getReportUrl($distribution_channel_id){
|
|
|
+ return '';
|
|
|
+ }
|
|
|
}
|