|
@@ -484,6 +484,95 @@ class CoflController extends Controller
|
|
return [0,0];
|
|
return [0,0];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function getUsersV3($openid){
|
|
|
|
+ //5204
|
|
|
|
+ //\Log::info($inner_channels);
|
|
|
|
+ $users = User::where('openid',$openid)->select('id','distribution_channel_id')->get();
|
|
|
|
+
|
|
|
|
+ if($users->isEmpty()) return [0,0];
|
|
|
|
+
|
|
|
|
+ if(count($users) == 1){
|
|
|
|
+ return [$users->first()->id,$users->first()->distribution_channel_id];
|
|
|
|
+ }
|
|
|
|
+ $temp = null;
|
|
|
|
+
|
|
|
|
+ //筛选包年UID
|
|
|
|
+ $uid_list = [];
|
|
|
|
+ foreach ($users as $item) {
|
|
|
|
+ $uid_list[] =$item->id;
|
|
|
|
+ }
|
|
|
|
+ $year_order = YearOrder::whereIn('uid',$uid_list)->orderBy('end_time','desc')->first();
|
|
|
|
+ if($year_order) {
|
|
|
|
+ foreach ($users as $item) {
|
|
|
|
+ if($item->id == $year_order->uid) {
|
|
|
|
+ //筛选包年结束时间最后的UID
|
|
|
|
+ return [$item->id,$item->distribution_channel_id];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //按订阅章节数最多的筛选
|
|
|
|
+ $users_select = ['id'=>0,'count'=>0,'user'=>null,'create_time'=>0];
|
|
|
|
+ foreach ($users as $each){
|
|
|
|
+ $table_prefix = ($each->id)%512;
|
|
|
|
+ $chapter_count = DB::connection('chapter_order_mysql')
|
|
|
|
+ ->table('chapter_orders'.$table_prefix)
|
|
|
|
+ ->where('created_at','>=',date('Y-m-d H:i:s',strtotime('-3 day')))
|
|
|
|
+ ->where('uid',$each->id)
|
|
|
|
+ //->where('bid',$bid)
|
|
|
|
+ ->count('id');
|
|
|
|
+ $book_order = BookOrder::where('uid',$each->id)
|
|
|
|
+ //->where('bid',$bid)
|
|
|
|
+ ->where('created_at','>=',date('Y-m-d H:i:s',strtotime('-3 day')))
|
|
|
|
+ ->first();
|
|
|
|
+ if($book_order) {
|
|
|
|
+ $chapter_count += 30;
|
|
|
|
+ }
|
|
|
|
+ //$each->chapter_count = $chapter_count;
|
|
|
|
+ if($chapter_count>$users_select['count']) {
|
|
|
|
+ $users_select['id'] = $each->id;
|
|
|
|
+ $users_select['count'] = $chapter_count;
|
|
|
|
+ $users_select['user'] = $each;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if($users_select['id'] >0) {
|
|
|
|
+ $insert_data = ['uid'=>$users_select['user']->id,'openid'=>$openid ,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
|
|
|
|
+ return [$users_select['user']->id,$users_select['user']->distribution_channel_id];
|
|
|
|
+ }
|
|
|
|
+ //有订阅记录的
|
|
|
|
+ foreach ($users as $value) {
|
|
|
|
+ $table_prefix = ($value->id)%512;
|
|
|
|
+ $chapter_order = DB::connection('chapter_order_mysql')
|
|
|
|
+ ->table('chapter_orders'.$table_prefix)
|
|
|
|
+ ->where('uid',$value->id)
|
|
|
|
+ //->where('bid',$bid)
|
|
|
|
+ ->orderBy('created_at','desc')
|
|
|
|
+ ->first();
|
|
|
|
+ $book_order = BookOrder::where('uid',$value->id)
|
|
|
|
+ //->where('bid',$bid)
|
|
|
|
+ ->first();
|
|
|
|
+ if($chapter_order ){
|
|
|
|
+ if(strtotime($chapter_order->created_at) > $users_select['create_time']) {
|
|
|
|
+ $users_select['id'] = $value->id;
|
|
|
|
+ $users_select['create_time'] = strtotime($chapter_order->created_at);
|
|
|
|
+ $users_select['user'] = $value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if($book_order){
|
|
|
|
+ if(strtotime($book_order->created_at) > $users_select['create_time']){
|
|
|
|
+ $users_select['id']=$value->id;
|
|
|
|
+ $users_select['create_time']= strtotime($book_order->created_at);
|
|
|
|
+ $users_select['user']= $value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if($users_select['id'] >0) {
|
|
|
|
+ return [$users_select['user']->id,$users_select['user']->distribution_channel_id];
|
|
|
|
+ }
|
|
|
|
+ return [0,0];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private function getLink($distribution_channel_id=123){
|
|
private function getLink($distribution_channel_id=123){
|
|
$url_format = '%s://site%s.%s.com/';
|
|
$url_format = '%s://site%s.%s.com/';
|
|
return sprintf(
|
|
return sprintf(
|
|
@@ -732,4 +821,93 @@ class CoflController extends Controller
|
|
case 6:
|
|
case 6:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function freeCurrencyViewForTransfer(Request $request){
|
|
|
|
+ $openid = $request->get('openid');
|
|
|
|
+ //授权
|
|
|
|
+ $params = $request->except('_url');
|
|
|
|
+ if(empty($openid)){
|
|
|
|
+ //$url = str_replace('http://', env('PROTOCOL') . '://', url()->current() . '?' . http_build_query($params));
|
|
|
|
+ $url = url()->current() . '?' . http_build_query($params);
|
|
|
|
+ $params['redirect_url'] = urlencode($url);
|
|
|
|
+ $app = new Application($this->auth($params));
|
|
|
|
+ return $app->oauth->redirect();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $crm = $request->get('crm','treward');
|
|
|
|
+ $source = $request->get('wx','none');
|
|
|
|
+ $fee = 500;
|
|
|
|
+ $type = 'TCRM';
|
|
|
|
+ $this->stats('treward_500',$crm);
|
|
|
|
+
|
|
|
|
+ $crm_transfer_uid_bind = DB::table('crm_transfer')->where('openid',$openid)->first();
|
|
|
|
+ if($crm_transfer_uid_bind) {
|
|
|
|
+ $user = User::where('id',$crm_transfer_uid_bind->to_uid)->select('id','distribution_channel_id')->first();
|
|
|
|
+ $uid = $crm_transfer_uid_bind->to_uid;
|
|
|
|
+ $distribution_channel_id = 5204;
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ list($ouid,$distribution_channel_id) = $this->getUsersV3($openid);
|
|
|
|
+ $user = $this->createUser($openid,$openid,5204,0,'');
|
|
|
|
+ $uid = $user->id;
|
|
|
|
+ $distribution_channel_id = 5204;
|
|
|
|
+ UserService::transfer($ouid,$uid,5204);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!$user || !$user[0] || !$user[1]) return redirect()->to($this->getLink().'?'.http_build_query($params));
|
|
|
|
+
|
|
|
|
+ $this->statsDetail($user[0],'treward',0);
|
|
|
|
+
|
|
|
|
+ $get_free_currency = UserBindHkWelfareService::isHasGet($uid);
|
|
|
|
+ if($get_free_currency){
|
|
|
|
+ //已经领过
|
|
|
|
+ if($uid){
|
|
|
|
+ $bid = Hashids::encode($user[2]);
|
|
|
|
+ $cid = $user[3];
|
|
|
|
+ $params['bid'] = $bid;
|
|
|
|
+ $params['cid'] = $cid;
|
|
|
|
+ $link = $this->getLink($distribution_channel_id).'reader?'.http_build_query($params);
|
|
|
|
+ }else{
|
|
|
|
+ $link = $this->getLink($distribution_channel_id).'recent?'.http_build_query($params);
|
|
|
|
+ }
|
|
|
|
+ return view('jump.bindHkFreeCurrency',['fee'=>$fee,'url'=>$link,'is_get'=>1,'uid'=>$uid,'source'=>$source]);
|
|
|
|
+ }else{
|
|
|
|
+ if(($uid)){
|
|
|
|
+ $bid = Hashids::encode($user[2]);
|
|
|
|
+ $cid = $user[3];
|
|
|
|
+ $params['bid'] = $bid;
|
|
|
|
+ $params['cid'] = $cid;
|
|
|
|
+ $link = $this->getLink($distribution_channel_id).'reader?'.http_build_query($params);
|
|
|
|
+ }else{
|
|
|
|
+ $link = $this->getLink($distribution_channel_id).'recent?'.http_build_query($params);
|
|
|
|
+ }
|
|
|
|
+ $this->getReward($uid,$fee,$source,$type);
|
|
|
|
+ return view('jump.bindHkFreeCurrency',['fee'=>$fee,'url'=>$link,'is_get'=>0,'uid'=>$user[0],'source'=>$source]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function createUser($openid,$unionid,$distribution_channel_id,$send_order_id,$ip){
|
|
|
|
+ $user = null;
|
|
|
|
+ try{
|
|
|
|
+ $user = UserService::addUser(
|
|
|
|
+ ['openid' => $openid,
|
|
|
|
+ 'unionid' => $unionid,
|
|
|
|
+ 'distribution_channel_id' =>$distribution_channel_id,
|
|
|
|
+ 'send_order_id'=>$send_order_id,
|
|
|
|
+ 'is_new'=>1,
|
|
|
|
+ 'register_ip'=>$ip
|
|
|
|
+ ]);
|
|
|
|
+ }catch (\Exception $e){
|
|
|
|
+ myLog('user-error')->info($e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 注册动作
|
|
|
|
+ $action_type = 'Register';
|
|
|
|
+ $param = [
|
|
|
|
+ 'openid' => $openid,
|
|
|
|
+ 'uid' => isset($user->id)?$user->id:'0',
|
|
|
|
+ ];
|
|
|
|
+ UserService::PushUserActionToQueue($action_type,$distribution_channel_id,$param);
|
|
|
|
+ return $user;
|
|
|
|
+ }
|
|
}
|
|
}
|