Quellcode durchsuchen

轮播图根据 男女频渠道判断

zhoulj vor 6 Jahren
Ursprung
Commit
78faa074f3

+ 17 - 5
app/Modules/Book/Models/BookConfig.php

@@ -5,10 +5,12 @@ namespace App\Modules\Book\Models;
 use App\Modules\Book\Services\BookTagsService;
 use App\Modules\User\Services\ReadRecordService;
 use App\Modules\Book\Services\BookConfigService;
+use App\Modules\Channel\Services\ChannelService;
 use App\Modules\OfficialAccount\Services\ForceSubscribeService;
 use DB;
 use Hashids;
 use Illuminate\Database\Eloquent\Model;
+use App\Modules\User\Models\User;
 use Log;
 use Redis;
 
@@ -658,11 +660,6 @@ class BookConfig extends Model
      */
     public static function  getH5RecommendBooks($uid, $pos, $num=4){
 
-    	$sex = ForceSubscribeService::getSimpleSexByUid($uid);
-    	$channel_name = $sex==1?'男频':'女频';
-    	\Log::info('getH5RecommendBooks:pos:'.$pos.' uid:'.$uid.' num:'.$num.' channel_name:'.$channel_name);
-    	$bids = [];
-    	
     	// 先从缓存取,1天有效期
     	$h5_book_cache = Redis::get('userH5RecommendBids:' . $uid.':'.$pos);
     	if(!empty($h5_book_cache)){
@@ -670,6 +667,21 @@ class BookConfig extends Model
     		return json_decode($h5_book_cache);
     	}
     	
+    	// 判断渠道男女频
+    	$user = User::getById($uid);
+    	$distribution_channel_id = isset($user->distribution_channel_id)?$user->distribution_channel_id:'';
+    	// 男频强制推广男频书
+    	$channel_sex = ChannelService::getChannelCompanySex($distribution_channel_id);
+    	$channel_name = '';
+    	if($channel_sex == 1){
+    		$channel_name = '男频';
+    	}else{
+	    	$sex = ForceSubscribeService::getSimpleSexByUid($uid);
+	    	$channel_name = $sex==1?'男频':'女频';
+    	}
+
+    	\Log::info('getH5RecommendBooks:pos:'.$pos.' uid:'.$uid.' num:'.$num.' channel_name:'.$channel_name.' channel_sex:'.$channel_sex.' distribution_channel_id:'.$distribution_channel_id);
+    	
     	$bids = [];
     	$random_recommend = true;
     	if($random_recommend){

+ 12 - 0
app/Modules/Channel/Services/ChannelService.php

@@ -429,4 +429,16 @@ class ChannelService
             ->where('distribution_channels.id',$distribution_channel_id)
             ->first();
     }
+    
+    public static function getChannelCompanySex($distribution_channel_id){
+    	$company =  Channel::select(DB::raw("companies.*"))
+    	->leftjoin('channel_users','channel_users.id','=','distribution_channels.channel_user_id')
+    	->leftjoin('companies','companies.id','=','channel_users.company_id')
+    	->where('distribution_channels.id',$distribution_channel_id)
+    	->first();
+    	// 1男 2女 3混合
+    	$sex = isset($company->fans_gender)?$company->fans_gender:'3';
+    	return $sex;
+    }
+    
 }