123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- namespace App\Jobs;
- use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
- use App\Modules\OfficialAccount\Models\OfficialAccount;
- use App\Modules\Statistic\Models\SendOrderBreadevenStat;
- use App\Modules\User\Services\UserDivisionCpcPropertyService;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- class SendStatisticsList extends Job implements ShouldQueue
- {
- use InteractsWithQueue, SerializesModels;
- private $data;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($data)
- {
- $data['send_time']=date("Y-m-d H:i:s");
- $this->data = $data;
- }
-
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- if($this->data['type'] == 'order_info'){
- $this->orderInfo($this->data['data']);
- }elseif($this->data['type'] == 'visit'){
- $this->visit($this->data['data']['openid']);
- }elseif($this->data['type'] == 'subscribe'){
- // \Log::info('SendStatisticsList data is');
- // \Log::info($this->data);
- $this->subscribe($this->data['data']['uid']);
- }
- else{
- $this->subscribe_info($this->data['data']);
- }
- }
- private function orderInfo($order_info){
- $uid = $order_info['uid'];
- \Log::info('orderInfo_start:'.$uid);
- $sub_info = ForceSubscribeUsers::where('uid',$uid)->select('official_account_id','appid','created_at','distribution_channel_id')->first();
- if(is_null($sub_info)){
- \Log::info('sub_info_is_null:'.$uid);
- return ;
- }
- $official = OfficialAccount::where('appid',$sub_info->appid)->select('id','nickname')->first();
- $date = date('Y-m-d',strtotime($sub_info->created_at));
- $old = $this->getDateRes($date,$sub_info->distribution_channel_id,$official->id);
- $pay_end = $order_info['pay_end_at'];
- $sub_timestamp = strtotime($sub_info->created_at);
- if($pay_end){
- $pay_end_timestamp = strtotime($pay_end);
- }else{
- $pay_end_timestamp = time();
- }
- $del = $pay_end_timestamp-$sub_timestamp;
- if($old){
- if($del <= 86400){
- $old->recharge_amount_in_one_day = $old->recharge_amount_in_one_day+$order_info['price'];
- $old->recharge_amount_in_three_days = $old->recharge_amount_in_three_days+$order_info['price'];
- $old->recharge_amount_in_one_month = $old->recharge_amount_in_one_month+$order_info['price'];
- $old->recharge_amount_in_two_months = $old->recharge_amount_in_two_months+$order_info['price'];
- $old->recharge_amount_in_three_months = $old->recharge_amount_in_three_months+$order_info['price'];
- }
- if($del > 86400 && $del<= 86400*3){
- $old->recharge_amount_in_three_days = $old->recharge_amount_in_three_days+$order_info['price'];
- $old->recharge_amount_in_one_month = $old->recharge_amount_in_one_month+$order_info['price'];
- $old->recharge_amount_in_two_months = $old->recharge_amount_in_two_months+$order_info['price'];
- $old->recharge_amount_in_three_months = $old->recharge_amount_in_three_months+$order_info['price'];
- }
- if($del > 86400*3 && $del <= 30*86400){
- $old->recharge_amount_in_one_month = $old->recharge_amount_in_one_month+$order_info['price'];
- $old->recharge_amount_in_two_months = $old->recharge_amount_in_two_months+$order_info['price'];
- $old->recharge_amount_in_three_months = $old->recharge_amount_in_three_months+$order_info['price'];
- }
- if($del > 30*86400 && $del <= 60*86400){
- $old->recharge_amount_in_two_months = $old->recharge_amount_in_two_months+$order_info['price'];
- $old->recharge_amount_in_three_months = $old->recharge_amount_in_three_months+$order_info['price'];
- }
- if($del> 60*86400 && $del <= 90*86400){
- $old->recharge_amount_in_three_months = $old->recharge_amount_in_three_months+$order_info['price'];
- }
- $old->save();
- }else{
- $nickname = '未知';
- $official_account_id = 0;
- if($official && isset($official->nickname)){
- $nickname = $official->nickname;
- }
- if($official && isset($official->id)){
- $official_account_id = $official->id;
- }
- $data = [];
- $data['recharge_amount_in_one_day'] = 0;
- $data['recharge_amount_in_three_days'] = 0;
- $data['recharge_amount_in_one_month'] = 0;
- $data['recharge_amount_in_two_months'] = 0;
- $data['recharge_amount_in_three_months'] = 0;
- $data['distribution_channel_id'] = $sub_info->distribution_channel_id;
- $data['official_account_id'] = $official_account_id;
- $data['official_account_name'] = $nickname;
- $data['date'] = $date;
- $data['force_user_num'] = 0;
- $data['total_force_user_num'] = 0;
- $data['unsubscribe_in_one_day_user_num'] =0;
- if($del <= 86400){
- $data['recharge_amount_in_one_day'] = $order_info['price'];
- $data['recharge_amount_in_three_days'] = $order_info['price'];
- $data['recharge_amount_in_one_month'] = $order_info['price'];
- $data['recharge_amount_in_two_months'] = $order_info['price'];
- $data['recharge_amount_in_three_months'] = $order_info['price'];
- }
- if($del > 86400 && $del<= 86400*3){
- $data['recharge_amount_in_three_days'] = $order_info['price'];
- $data['recharge_amount_in_one_month'] = $order_info['price'];
- $data['recharge_amount_in_two_months'] = $order_info['price'];
- $data['recharge_amount_in_three_months'] = $order_info['price'];
- }
- if($del > 86400*3 && $del <= 30*86400){
- $data['recharge_amount_in_one_month'] = $order_info['price'];
- $data['recharge_amount_in_two_months'] = $order_info['price'];
- $data['recharge_amount_in_three_months'] = $order_info['price'];
- }
- if($del > 30*86400 && $del <= 60*86400){
- $data['recharge_amount_in_two_months'] = $order_info['price'];
- $data['recharge_amount_in_three_months'] = $order_info['price'];
- }
- if($del> 60*86400 && $del <= 90*86400){
- $data['recharge_amount_in_three_months'] = $order_info['price'];
- }
- SendOrderBreadevenStat::create($data);
- }
- }
- private function subscribe_info($subscribe_info){
- $subscribe_info = (array) $subscribe_info;
- $date = date('Y-m-d',strtotime($subscribe_info['created_at']));
- $official = OfficialAccount::where('appid',$subscribe_info['appid'])->select('id','nickname')->first();
- $old = $this->getDateRes($date,$subscribe_info['distribution_channel_id'],$official->id);
- if($old){
- if( (strtotime($subscribe_info['unsubscribe_time']) - strtotime($subscribe_info['created_at']) ) < 86400){
- $old->unsubscribe_in_one_day_user_num +=1;
- $old->save();
- }
- }else{
- $data = [];
- $nickname = '未知';
- $official_account_id = 0;
- if($official && isset($official->nickname)){
- $nickname = $official->nickname;
- }
- if($official && isset($official->id)){
- $official_account_id = $official->id;
- }
- $data['recharge_amount_in_one_day'] = 0;
- $data['recharge_amount_in_three_days'] = 0;
- $data['recharge_amount_in_one_month'] = 0;
- $data['recharge_amount_in_two_months'] = 0;
- $data['recharge_amount_in_three_months'] = 0;
- $data['distribution_channel_id'] = $subscribe_info['distribution_channel_id'];
- $data['official_account_id'] = $official_account_id;
- $data['official_account_name'] = $nickname;
- $data['date'] = $date;
- $data['force_user_num'] = 0;
- $data['total_force_user_num'] = 0;
- if( (strtotime($subscribe_info['unsubscribe_time']) - strtotime($subscribe_info['created_at']) ) < 86400){
- $data['unsubscribe_in_one_day_user_num'] =1;
- }
- SendOrderBreadevenStat::create($data);
- }
- }
- private function subscribe($uid){
- if(!is_numeric($uid)) return ;
- //UserDivisionCpcPropertyService::afterForceSubscribe($uid);
- }
- private function visit($openid){
- $user = UserDivisionCpcPropertyService::userLevel($openid);
- if(!$user){
- return ;
- }
- if($user->type != 'NEW'){
- return ;
- }
- $level = UserDivisionCpcPropertyService::getUserSubscribeAndChargeInfoByOpenid($openid);
- if(!$level) return ;
- if($level['type'] == $user->type) return ;
- UserDivisionCpcPropertyService::update($openid,$level['property'],$level['type']);
- }
- private function getDateRes($date,$distribution_channel_id,$official_account_id){
- return SendOrderBreadevenStat::where('date',$date)
- ->where('distribution_channel_id',$distribution_channel_id)
- ->where('official_account_id',$official_account_id)
- ->first();
- }
- }
|