|
@@ -4,6 +4,10 @@ namespace App\Http\Controllers\Wap\User;
|
|
|
|
|
|
use App\Modules\Activity\Services\ActivityService;
|
|
use App\Modules\Activity\Services\ActivityService;
|
|
use App\Modules\Book\Services\BookConfigService;
|
|
use App\Modules\Book\Services\BookConfigService;
|
|
|
|
+use App\Modules\Channel\Models\Channel;
|
|
|
|
+use App\Modules\Subscribe\Models\BookOrder;
|
|
|
|
+use App\Modules\Subscribe\Models\YearOrder;
|
|
|
|
+use App\Modules\Subscribe\Services\YearOrderService;
|
|
use App\Modules\User\Models\User;
|
|
use App\Modules\User\Models\User;
|
|
use App\Modules\User\Services\ReadRecordService;
|
|
use App\Modules\User\Services\ReadRecordService;
|
|
use App\Modules\User\Services\UserBindHkWelfareService;
|
|
use App\Modules\User\Services\UserBindHkWelfareService;
|
|
@@ -47,7 +51,9 @@ class CoflController extends Controller
|
|
}
|
|
}
|
|
$crm = $request->get('crm');
|
|
$crm = $request->get('crm');
|
|
//获取用户
|
|
//获取用户
|
|
- $user = $this->getUsers($openid);
|
|
|
|
|
|
+ //$user = $this->getUsers($openid);
|
|
|
|
+ $user = $this->getUsersV2($openid,$bid);
|
|
|
|
+
|
|
if(!$user[0]){
|
|
if(!$user[0]){
|
|
$user[1] = 123;
|
|
$user[1] = 123;
|
|
}
|
|
}
|
|
@@ -223,6 +229,118 @@ class CoflController extends Controller
|
|
return [$uid,$distribution_channel_id];
|
|
return [$uid,$distribution_channel_id];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param $openid
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ private function getUsersV2($openid,$bid){
|
|
|
|
+ $friend_link_uid_bind = DB::table('friend_link_uid_bind')->where('openid',$openid)->where('bid',$bid)->first();
|
|
|
|
+ if($friend_link_uid_bind) {
|
|
|
|
+ $user = User::where('id',$friend_link_uid_bind->uid)->select('id','distribution_channel_id')->get();
|
|
|
|
+ if($user) {
|
|
|
|
+ return [$user->id,$user->distribution_channel_id];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $inner_channels = Channel::join('channel_users','channel_users.id','=','distribution_channels.channel_user_id')
|
|
|
|
+ ->select('distribution_channls.id')
|
|
|
|
+ ->whereIn('channel_users.id',explode(',',redisEnv('PROMOTION_GROUP_CHANNEL_USER_ID')))
|
|
|
|
+ ->get()
|
|
|
|
+ ->pluck('id');
|
|
|
|
+ $users = User::where('openid',$openid)->select('id','distribution_channel_id')->get();
|
|
|
|
+ if($users->isEmpty()) return [0,0];
|
|
|
|
+ $temp = null;
|
|
|
|
+ $distribution_channel_id = 0;
|
|
|
|
+ $uid = 0;
|
|
|
|
+ $inner_channel_uid_list = [];
|
|
|
|
+ //先筛网站运营部UID
|
|
|
|
+ foreach ($users as $user){
|
|
|
|
+ if(in_array($user->distribution_channel_id,$inner_channels)) {
|
|
|
|
+ $inner_channel_uid_list[] = $user;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(count($inner_channel_uid_list) == 1) {
|
|
|
|
+ return [$inner_channel_uid_list[0]->id,$inner_channel_uid_list[0]->distribution_channel_id];
|
|
|
|
+ }
|
|
|
|
+ if(count($inner_channel_uid_list)>1) {
|
|
|
|
+ //有多个网站运营部UID,针对网站运营部UID进入到下一步筛选
|
|
|
|
+ $users = $inner_channel_uid_list;
|
|
|
|
+ }
|
|
|
|
+ //筛选包年UID
|
|
|
|
+ $uid_list = [];
|
|
|
|
+ foreach ($users as $item) {
|
|
|
|
+ $uid_list[] =$item->id;
|
|
|
|
+ }
|
|
|
|
+ $year_order = YearOrder::whereIn('uid',$uid_list)->where('bid')->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];
|
|
|
|
+ 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) {
|
|
|
|
+ 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(
|