|
@@ -484,6 +484,95 @@ class CoflController extends Controller
|
|
|
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){
|
|
|
$url_format = '%s://site%s.%s.com/';
|
|
|
return sprintf(
|
|
@@ -622,20 +711,44 @@ class CoflController extends Controller
|
|
|
$cookie_crm_img = Cookie::get('crm_person_img');
|
|
|
$cookie_crm_name = Cookie::get('crm_person_name','');
|
|
|
$get_info = UserBindHkWelfareService::isHasGet($uid);
|
|
|
+ $fee = $request->get('fee',200);
|
|
|
if($get_info) return back();
|
|
|
if($cookie_crm_img){
|
|
|
- return view('jump.guidePersonalAccountOurs',['img'=>$cookie_crm_img,'name'=>$cookie_crm_name]);
|
|
|
+ return view('jump.guidePersonalAccountOurs',['img'=>$cookie_crm_img,'name'=>$cookie_crm_name,'fee'=>$fee]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //$distribution_channel_id = decodeDistributionChannelId($channel_id);
|
|
|
+ $distribution_channel_id = $channel_id;
|
|
|
+ //if(in_array($distribution_channel_id,Redis::SISMEMBER('')));
|
|
|
+ //$out = false;
|
|
|
+ $group = 'ACTIVE';
|
|
|
+ if(Redis::SISMEMBER('crm:out_channel_sites',$distribution_channel_id)){
|
|
|
+ //$out = true;
|
|
|
+ $group = 'OUT_ACTIVE';
|
|
|
+ $env_config = redisEnvMulti('OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
|
|
|
+ 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV','OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
|
|
|
+ 'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
|
|
|
+ }else{
|
|
|
+ $env_config = redisEnvMulti('ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
|
|
|
+ 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV','ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
|
|
|
+ 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
|
|
|
}
|
|
|
-
|
|
|
- $env_config = redisEnvMulti('ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
|
|
|
- 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV','ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
|
|
|
- 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
|
|
|
- $img = empty($env_config[0])?'https://cdn-novel.iycdm.com/h5/personal_account/chenchen.jpg':$env_config[0];
|
|
|
+ if(empty($env_config[0])){
|
|
|
+ return back();
|
|
|
+ }
|
|
|
+ //$img = empty($env_config[0])?'https://cdn-novel.iycdm.com/h5/personal_account/chenchen.jpg':$env_config[0];
|
|
|
+ $img =$env_config[0];
|
|
|
$max = empty($env_config[1])?100:$env_config[1];
|
|
|
$max = (int)$max;
|
|
|
$one_loop_max = empty($env_config[3])?10:$env_config[3];
|
|
|
$now_id = (int)$env_config[2];
|
|
|
- $uv = Redis::scard('active_guide_personal_uv');
|
|
|
+
|
|
|
+ if($group == 'OUT_ACTIVE'){
|
|
|
+ $uv_key = 'out_active_guide_personal_uv';
|
|
|
+ }else{
|
|
|
+ $uv_key = 'active_guide_personal_uv';
|
|
|
+ }
|
|
|
+ $uv = Redis::scard($uv_key);
|
|
|
$personal_info = DB::table('personal_account_list')->where('id',$now_id)->select('count')->first();
|
|
|
if(!$personal_info){
|
|
|
return back();
|
|
@@ -659,12 +772,12 @@ class CoflController extends Controller
|
|
|
->where('is_enable',1)
|
|
|
->whereIn('status',[1,0])
|
|
|
->select('id','url')
|
|
|
- ->where('group','ACTIVE')
|
|
|
+ ->where('group',$group)
|
|
|
->where('count','<',$max)
|
|
|
->orderBy('count','asc')
|
|
|
->orderBy('id')
|
|
|
->first();
|
|
|
- Redis::del('active_guide_personal_uv');
|
|
|
+ Redis::del($uv_key);
|
|
|
if($account){
|
|
|
DB::table('personal_account_list')->where('id',$account->id)->update([
|
|
|
'status'=>1,
|
|
@@ -672,13 +785,13 @@ class CoflController extends Controller
|
|
|
]);
|
|
|
$img = $account->url;
|
|
|
$now_id = $account->id;
|
|
|
- Redis::Hmset('env','ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',$account->url,'ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',$account->id);
|
|
|
+ Redis::Hmset('env',$group.'_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',$account->url,$group.'_GUIDE_PERSONAL_ACCOUNT_ID',$account->id);
|
|
|
}else{
|
|
|
- Redis::Hmset('env','ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE','','ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID','');
|
|
|
+ Redis::Hmset('env',$group.'_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE','',$group.'_GUIDE_PERSONAL_ACCOUNT_ID','');
|
|
|
return back();
|
|
|
}
|
|
|
}
|
|
|
- Redis::sadd('active_guide_personal_uv',$uid);
|
|
|
+ Redis::sadd($uv_key,$uid);
|
|
|
|
|
|
if($uid){
|
|
|
DB::table('ad_pdd')->insert([
|
|
@@ -709,7 +822,7 @@ class CoflController extends Controller
|
|
|
Cookie::queue('crm_person_name', $name,$time);
|
|
|
//$page = 'jump.guidePersonalAccount';
|
|
|
//$img = collect($imgs)->random();
|
|
|
- return view($page,['img'=>$img,'name'=>$name]);
|
|
|
+ return view($page,['img'=>$img,'name'=>$name,'fee'=>$fee]);
|
|
|
}
|
|
|
|
|
|
public function r(Request $request,$number){
|
|
@@ -732,4 +845,76 @@ class CoflController extends Controller
|
|
|
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($distribution_channel_id).'?'.http_build_query($params));
|
|
|
+
|
|
|
+ $this->statsDetail($uid,'treward',0);
|
|
|
+
|
|
|
+ $get_free_currency = UserBindHkWelfareService::isHasGet($uid);
|
|
|
+ if($get_free_currency){
|
|
|
+ //已经领过
|
|
|
+ $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{
|
|
|
+ $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'=>$uid,'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;
|
|
|
+ }
|
|
|
}
|