zz 6 years ago
parent
commit
1a5dae5944

+ 21 - 1
app/Http/Controllers/Wap/Book/ChapterController.php

@@ -13,6 +13,7 @@ use App\Modules\Statistic\Services\DataAnalysisChapterService;
 use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
 use App\Modules\Statistic\Services\WapVisitStatService;
 use App\Modules\Subscribe\Services\OrderService;
+use App\Modules\User\Services\ForceSubscribeUserIService;
 use App\Modules\User\Services\ReadRecordStatsService;
 use App\Modules\YunQi\Services\BookUserService;
 use Illuminate\Http\Request;
@@ -70,6 +71,10 @@ class ChapterController extends BaseController
     //强关时间
     private $force_subscribe_time = null;
 
+    //关注的appid
+    private  $need_subscribe_appid;
+    private  $need_subscribe_name;
+
     /**
      * @apiVersion 1.0.0
      * @apiDescription 章节列表不分页
@@ -829,12 +834,17 @@ class ChapterController extends BaseController
 
     private function forceSubscribe()
     {
+        if($this->need_subscribe_appid){
+            $src = $this->getRcodeInfo(['appid' => $this->need_subscribe_appid], $this->book_info->bid);
+            if (empty($src)) return false;
+            $url = '/subscribe/qrcode?img=' . urlencode($src) . '&title=' . $this->need_subscribe_name . '&uid=' . $this->uid;
+            return ['error_type' => 'WAP_NOT_SUBSCRIBE', 'data' => ['src' => $url, 'head_img' => '']];
+        }
         //获取公众号信息
         $officialAccount = $this->getOfficialAccount();
         if (!$officialAccount || empty($officialAccount->appid)) {
             return false;
         }
-
         //如果是链接强关,则跳转
         $sub_type = $this->getSubscribeType($officialAccount->appid, $this->book_info->bid);
 
@@ -1079,6 +1089,16 @@ class ChapterController extends BaseController
      */
     protected function getSubscribe()
     {
+        if($this->send_order_id &&
+            in_array($this->distribution_channel_id,explode(',',env('INNER_CHANNEL_SUB','1'))) &&
+            ($send_order_info = SendOrderService::getById($this->send_order_id)) &&
+            $send_order_info->spromotion_type == 'EXTERNAL'
+        ){
+            $subscribe_info = ForceSubscribeUserIService::subscribes($this->uid,$this->distribution_channel_id,$this->send_order_id);
+            $this->need_subscribe_appid = $subscribe_info['appid'];
+            $this->need_subscribe_name = $subscribe_info['name'];
+            return $subscribe_info['is_subscribed'];
+        }
         $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
         if ($res) {
             $this->force_subscribe_time = isset($res->created_at)?$res->created_at:null;

+ 42 - 31
app/Modules/User/Services/ForceSubscribeUserIService.php

@@ -14,66 +14,77 @@ use Redis;
 
 class ForceSubscribeUserIService
 {
+    private static $official_name = [];
 
-    public static function subscribes($uid,$distribution_channel_id,$send_order_id){
+    public static function subscribes($uid, $distribution_channel_id, $send_order_id)
+    {
         $subscribe_info = self::getUserSubscribes($uid);
         //没关注
-        if($subscribe_info->isNotEmpty() &&
-            $subscribe_info->search(function ($item,$k)use ($send_order_id) {  return $item->send_order_id == $send_order_id;}) !== false ){
-            return ['is_subscribed'=>true,'appid'=>''];
+        if ($subscribe_info->isNotEmpty() &&
+            $subscribe_info->search(
+                function ($item, $k) use ($send_order_id) {
+                    return $item->send_order_id == $send_order_id;
+                }
+            ) !== false
+        ) {
+            return ['is_subscribed' => true, 'appid' => '','name'=>''];
         }
         $subscribe_appdis = $subscribe_info->pluck('appid')->all();
-        echo '$subscribe_appdis'.PHP_EOL;
-        print_r($subscribe_appdis);
+        //echo '$subscribe_appdis' . PHP_EOL;
+        //print_r($subscribe_appdis);
         $useable_appdis = self::getOfficialAccount($distribution_channel_id);
-        echo '$useable_appdis'.PHP_EOL;
-        print_r($useable_appdis);
+        //echo '$useable_appdis' . PHP_EOL;
+        //print_r($useable_appdis);
         //没有可用的公众号
-        if(empty($useable_appdis)) return ['is_subscribed'=>true,'appid'=>''];
-        echo '2222222222222222222222'.PHP_EOL;
+        if (empty($useable_appdis)) return ['is_subscribed' => true, 'appid' => '','name'=>''];
+        //echo '2222222222222222222222' . PHP_EOL;
         $appids = collect($useable_appdis)->diff($subscribe_appdis)->toArray();
-        if($appids){
-            echo '33333333333333333333'.PHP_EOL;
-            return ['is_subscribed'=>false,'appid'=>$appids[0]];
+        if ($appids) {
+            //echo '33333333333333333333' . PHP_EOL;
+            return ['is_subscribed' => false, 'appid' => $appids[0],'name'=>self::$official_name[$appids[0]]];
         }
-        return ['is_subscribed'=>true,'appid'=>''];
+        return ['is_subscribed' => true, 'appid' => '','name'=>''];
     }
 
     //用户强关公众号
-    public static function getUserSubscribes($uid){
-       return  ForceSubscribeUsers::where('uid',$uid)->where('is_subscribed',1)->select('appid','send_order_id')->get();
+    public static function getUserSubscribes($uid)
+    {
+        return ForceSubscribeUsers::where('uid', $uid)->where('is_subscribed', 1)->select('appid', 'send_order_id')->get();
     }
 
     //可用公众号
-    public static function getOfficialAccount($distribution_channel_id){
-        $result =  OfficialAccount::where('distribution_channel_id',$distribution_channel_id)
-            ->where('is_auth',1)
-            ->where('is_enabled',1)
-            ->where('subscribe_top_num','>',0)
-            ->where('subscribe_day_maximum','>',0)
+    public static function getOfficialAccount($distribution_channel_id)
+    {
+        $result = OfficialAccount::where('distribution_channel_id', $distribution_channel_id)
+            ->where('is_auth', 1)
+            ->where('is_enabled', 1)
+            ->where('subscribe_top_num', '>', 0)
+            ->where('subscribe_day_maximum', '>', 0)
             ->orderBy('sort_no', 'desc')
-            ->select('appid','subscribe_top_num','subscribe_day_maximum')
+            ->select('appid', 'subscribe_top_num', 'subscribe_day_maximum','nickname')
             ->get();
-        if($result->isEmpty()) return [];
+        if ($result->isEmpty()) return [];
         $data = [];
-        foreach ($result as $value){
+        foreach ($result as $value) {
+            self::$official_name[$value->appid] = $value->nickname;
             $fans_stats = self::getOfficialAccountFanStats($value->appid);
             {
                 $fans_stats['day_fans'] < $value->subscribe_day_maximum
-                && $fans_stats['all_fans'] < $value->subscribe_top_num && array_push($data,$value->appid);
+                && $fans_stats['all_fans'] < $value->subscribe_top_num && array_push($data, $value->appid);
             }
         }
         return $data;
     }
 
     //粉丝数
-    public static function getOfficialAccountFanStats($appid){
+    public static function getOfficialAccountFanStats($appid)
+    {
         $total_fans_cancel_nums = (int)Redis::hget('day_appid_fans_nums_appid:cancel:' . $appid, 'total');
 
-        $total_fan_info = Redis::hmget('day_appid_fans_nums_appid:add:' . $appid,['total',date('Y-m-d')]);
-        $total_fans_add_nums = $total_fan_info[0]?$total_fan_info[0]:0;
-        $day_fans = $total_fan_info[1]?$total_fan_info[1]:0;
+        $total_fan_info = Redis::hmget('day_appid_fans_nums_appid:add:' . $appid, ['total', date('Y-m-d')]);
+        $total_fans_add_nums = $total_fan_info[0] ? $total_fan_info[0] : 0;
+        $day_fans = $total_fan_info[1] ? $total_fan_info[1] : 0;
         $all_fans = $total_fans_add_nums - $total_fans_cancel_nums;
-        return compact('day_fans','all_fans');
+        return compact('day_fans', 'all_fans');
     }
 }