| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- <?php
- namespace app\api\controller\v2;
- use app\api\controller\Api;
- use app\common\logic\SubPackage as SubChannel;
- use app\common\model\Game;
- use app\common\model\GameNotify as GameNotifyModel;
- use app\common\model\PromotionShortLink;
- use app\common\model\SdkGameList;
- use think\Db;
- /**
- * 公共&强更
- */
- class GameNotify extends Api
- {
- protected $noNeedLogin = ['index', 'getPackage'];
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * 强更&公告 - v1
- * 相关需求:
- * 1. 玩家当前版本不是最新版本时,以强更显示为主。
- * 2. 有强更时候显示强更,有公告时候显示公告,无则不显示。
- * 3. 客户端如果是强更,则每次打开游戏都要判断。
- *
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index(){
- $game_id = $this->input('gameid'); // 游戏ID
- $channel_id = $this->input('channel_id'); // 渠道ID
- $channel_version = $this->input('channel_version', ''); // 游戏的强更号
- if ( empty($game_id) ) {
- $this->jsonResult('', 0, '游戏ID不能为空');
- }
- elseif ( empty($channel_id) ) {
- $this->jsonResult('', 0, '渠道ID不能为空');
- }
- elseif ( empty($channel_version) ) {
- $this->jsonResult('', 0, '游戏的强更号不能为空');
- }
- // 返回内容
- $result = [
- 'notify' => [], // 公告详情
- 'status' => false, // // 状态:true=强更、false=弹框提醒
- 'url' => "", // 强更地址
- ];
- $sdkGameModel = new SdkGameList;
- $fbInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,channel_version,upload_status')->find();
- if(!$fbInfo){
- $this->jsonResult('', 0, '分包数据不存在!');
- }
- $gameModel = new Game;
- $gameInfo = $gameModel->where(['id' => $game_id])->field('id,type,pinyin,channel_version')->find();
- if(!$gameInfo){
- $this->jsonResult('', 0, '游戏不存在!');
- }
- $newVersion = false;
- // 客户端已是最新版本 则只 显示公告
- if($channel_version >= $gameInfo['channel_version']){
- $newVersion = true;
- }
- // 查询最新的公告&强更
- $ggInfo = Db::table('cy_game_notify')->field('id,title,content,notify_type')
- ->where(['status' => 1, 'game_id' => $game_id, 'notify_type' => 1])
- ->where('(end_time>0 AND end_time>'.NOW_TIMESTAMP.') or (end_time=0)')
- ->where('(deny_type=0 AND denied_channel not like :channelid1 and denied_channel not like :channelid2) or (deny_type=1 AND (denied_channel like :channelid3 or denied_channel like :channelid4))',['channelid1'=>$channel_id.',%', 'channelid2'=>'%,'.$channel_id.',%','channelid3'=>$channel_id.',%', 'channelid4'=>'%,'.$channel_id.',%'])
- ->order('create_time desc')
- ->find();
- $qgInfo = Db::table('cy_game_notify')->field('id,title,content,notify_type')
- ->where(['status' => 1, 'game_id' => $game_id, 'notify_type' => 3])
- ->where('(end_time>0 AND end_time>'.NOW_TIMESTAMP.') or (end_time=0)')
- ->where('(deny_type=0 AND denied_channel not like :channelid1 and denied_channel not like :channelid2) or (deny_type=1 AND (denied_channel like :channelid3 or denied_channel like :channelid4))',['channelid1'=>$channel_id.',%', 'channelid2'=>'%,'.$channel_id.',%','channelid3'=>$channel_id.',%', 'channelid4'=>'%,'.$channel_id.',%'])
- ->order('create_time desc')
- ->find();
- if(!$ggInfo && !$qgInfo){
- $this->jsonResult($result, 1, "无");
- }
- // 已是最新版本则只显示公告
- if($newVersion || !$qgInfo){
- // 没有公告则不显示
- if(!$ggInfo){
- $this->jsonResult($result, 1, "无");
- }
- $ggInfo['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $ggInfo['content'];
- $result['notify'] = [$ggInfo];
- // 加meta标签,使ios中的wkwebview字体正常
- $this->jsonResult($result, 1, "已是最新版本");
- }
- // 没有强更则无
- if($fbInfo['upload_status'] != 1 || !$qgInfo){
- $this->jsonResult($result, 1, "无");
- }
- // 获取强更包数据
- if($gameInfo['type'] == 2){ // 安卓
- if($fbInfo && isset($fbInfo['filename'])){
- $result['url'] = APK_DOWN_DOMAIN.'/sygame/'.$gameInfo['pinyin'].'/'.$fbInfo['filename'];
- }
- }elseif($gameInfo['type'] == 1){ // IOS
- $shortModel = new PromotionShortLink;
- $shortInfo = $shortModel->where(['channel_id' => $channel_id, 'game_id' => $game_id])->field('id,short_link')->find();
- if($shortInfo){
- $result['url'] = $shortInfo['short_link']?T_DOMAIN.'/'.$shortInfo['short_link']:'';
- }
- }
- if(!$result['url']){
- $this->jsonResult($result, 1, "无");
- }
- $result['status'] = true;
- $qgInfo['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $qgInfo['content'];
- $result['notify'] = [$qgInfo];
- $this->jsonResult($result, 1, '获取成功!');
- }
- private function getMergeDatas($gameid, $uid, $channel_id) {
- $now = time();
- $result = Db::table('cy_game_notify')->alias('cn')
- ->join('cy_game_notify_relation r', 'cn.id = r.notify_id', 'INNER')
- // 核心合并:通过 OR 逻辑,一次性关联渠道或用户的黑白名单记录
- ->join('cy_game_notify_deny d', "cn.id = d.notify_id AND d.deny_type = cn.deny_type AND (
- (cn.data_type = 1 AND d.target_type = 1 AND d.target_id = {$channel_id})
- OR
- (cn.data_type = 2 AND d.target_type = 2 AND d.target_id = {$uid})
- )", 'LEFT')
- ->where('cn.status', 1)
- ->where('r.game_id', $gameid)
- ->where('cn.data_type', 'in', [1, 2]) // 同时查渠道和用户公告
- // 1. 时间过滤 (保持不变)
- ->where(function ($query) use ($now) {
- $query->where('cn.notify_type', '<>', 4)
- ->whereOr(function ($q2) use ($now) {
- $q2->where('cn.notify_type', 4)
- ->where('cn.begin_time', '<=', $now)
- ->where('cn.end_time', '>=', $now);
- });
- })
- // 2. 黑白名单判定 (保持不变)
- ->where(function ($query) {
- $query->where(function ($q_black) {
- $q_black->where('cn.deny_type', 0)->where('d.id', 'NULL');
- })->whereOr(function ($q_white) {
- $q_white->where('cn.deny_type', 1)->where('d.id', 'NOT NULL');
- });
- })
- // 直接按 ID 倒序,取最新的一条即可
- ->order('cn.id desc')
- ->find();
- return $result ?: null;
- }
- /**
- * 获取合并后的强更&公告数据
- *
- * @param $gameid
- * @param $uid
- * @param $channel_id
- *
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- private function getMergeData($gameid, $uid, $channel_id) {
- $now = time();
- // --- 基础查询条件(复用) ---
- $baseQuery = Db::table('cy_game_notify')->alias('cn')
- ->join('cy_game_notify_relation r', 'cn.id = r.notify_id', 'INNER')
- ->join('cy_game_notify_deny d', "cn.id = d.notify_id AND d.deny_type = cn.deny_type AND (
- (cn.data_type = 1 AND d.target_type = 1 AND d.target_id = {$channel_id})
- OR
- (cn.data_type = 2 AND d.target_type = 2 AND d.target_id = {$uid})
- )", 'LEFT')
- ->where('cn.status', 1)
- ->where('r.game_id', $gameid)
- // 黑白名单逻辑
- ->where(function ($query) {
- $query->where(function ($q_black) {
- $q_black->where('cn.deny_type', 0)->where('d.id', 'NULL');
- })->whereOr(function ($q_white) {
- $q_white->where('cn.deny_type', 1)->where('d.id', 'NOT NULL');
- });
- });
- // --- 1. 获取最新的【强更公告】 (notify_type = 3) ---
- $forceUpdate = (clone $baseQuery)
- ->where('cn.notify_type', 3)
- ->order('cn.id desc')
- ->find();
- // --- 2. 获取最新的【普通公告】 (notify_type = 1 或 4) ---
- $normalNotify = (clone $baseQuery)
- ->field('cn.*')
- ->where('cn.notify_type', 'in', [1, 4])
- // 针对时效性公告(4)的额外时间判断
- ->where(function ($query) use ($now) {
- $query->where('cn.notify_type', 1) // 类型1直接过
- ->whereOr(function ($q2) use ($now) {
- $q2->where('cn.notify_type', 4) // 类型4查有效期
- ->where('cn.begin_time', '<=', $now)
- ->where('cn.end_time', '>=', $now);
- });
- })
- ->order('cn.id desc') // 在1和4中取最新的那一条
- ->find();
- // --- 3. 合并返回 ---
- $finalList = [];
- if ($forceUpdate) {
- $forceUpdate['priority_weight'] = 1; // 强更优先级最高
- $finalList['qg'] = $forceUpdate;
- }
- if ($normalNotify) {
- $normalNotify['priority_weight'] = 2; // 普通公告次之
- $finalList['gg'] = $normalNotify;
- }
- return $finalList;
- }
- /**
- * 强更&公共&分包更新 - v2
- *
- * 相关需求:
- * 1. 玩家当前版本不是最新版本时,以强更显示为主。
- * 2. 有强更时候显示强更,有公告时候显示公告,无则不显示。
- * 3. 客户端如果是强更,则每次打开游戏都要判断。
- * 4. 检测客户端是否最新版本,返回相关展示状态。
- *
- * 强更判断:
- * 1. 根据‘游戏版本’对比‘分包版本’确认是否强更;
- * 2. 根据客户端‘游戏版本’对比‘分包版本’,确认是否最新版本;
- *
- * 弹框优先级:强更》公告》时效公告;
- *
- * TODO: 想要强更,则游戏版本号大于当前客户端版本号
- *
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index_v2(){
-
- $game_id = $this->input('gameid'); // 游戏ID
- $channel_id = $this->input('channel_id'); // 渠道ID
- $channel_version = $this->input('channel_version', ''); // 游戏的强更号
- if ( empty($game_id) ) {
- $this->jsonResult('', -100, '游戏ID不能为空');
- }
- elseif ( empty($channel_id) ) {
- $this->jsonResult('', -100, '渠道ID不能为空');
- } elseif ($channel_version === '') {
- $this->jsonResult('', -100, '游戏的强更号不能为空');
- }
- $gameModel = new Game;
- $gameInfo = $gameModel->where(['id' => $game_id])->field('id,type,pinyin,channel_version')->find();
- if(!$gameInfo){
- $this->jsonResult('', -102, '游戏不存在!');
- }
- // 返回结构定义
- // 弹框优先级:强更》公告》时效公告;
- $result = [
- 'notify' => [], // 公告详情
- 'type' => 0, // 类型:0=无、1=公告、2=广告、3=强更、4=时效性公告;
- 'status' => 0, // 状态:0=无、1=已是最新版本(无用)、2=已是最新版本(可以强更)、3=获取最新分包(请求分包)、4=分包更新中(请求中)、5=分包失败(重新提交分包)
- 'url' => "", // 强更地址(强更时才返回)
- 'ext' => [
- 'game_version' => $gameInfo['channel_version'],
- 'channel_version' => "",
- 'client_version' => $channel_version,
- ]
- ];
- // TODO: 手动设置游戏版本,方便测试强更
- // if($this->input('imeil', '') == '00000000-2204-e204-ffff-ffffef05ac4a'){
- // $gameInfo['channel_version'] = 45;
- // }
- // 客户端已是最新版本 则只 显示公告
- if($channel_version >= $gameInfo['channel_version']){
- $result['status'] = 1;
- }
-
- // 查询最新的 公告&强更&部分玩家
- $userid = $this->input('userid', '');
- $getMergeList = $this->getMergeData($game_id, $userid, $channel_id);
- if (!$getMergeList) {
- $result['status'] = 0;
- $this->jsonResult($result, 1, "暂无公告!");
- }
- // dump($getMergeList);
- // 强更
- $getMergeData = $getMergeList['qg']??[];
- if($result['status'] == 1 && !empty($getMergeList['gg'])){
- // 公告
- $getMergeData = $getMergeList['gg'];
- $notidyData['id'] = $getMergeData['id'];
- if($getMergeData['notify_type'] == 4){
- $notidyData['id'] = time();
- }
- $result['type'] = $getMergeData['notify_type'];
- $notidyData['title'] = $getMergeData['title'];
- // 加meta标签,使ios中的wkwebview字体正常
- $notidyData['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $getMergeData['content'];
- $result['notify'] = [$notidyData];
- $this->jsonResult($result, 1, "有新公告!");
- }
- if(!$getMergeData || $result['status'] == 1){
- $result['status'] = 0;
- $this->jsonResult($result, 1, "暂无公告!");
- }
- // ## 强更逻辑处理开始 ##
- $sdkGameModel = new SdkGameList;
- $fbInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,channel_version,upload_status')->find();
- if(!$fbInfo){
- $this->jsonResult($result, 1, '分包数据不存在!');
- }
- $result['ext']['channel_version'] = $fbInfo['channel_version'];
- // 有强更则判断是否最新包,是否可以强更
- // status = 状态:0=无、1=已是最新版本(无用)、2=已是最新版本(可以强更)、3=获取最新分包(请求分包)、4=分包更新中(请求中)、5=分包失败(重新提交分包)
- if($fbInfo['upload_status'] == 1 && $fbInfo['channel_version'] == $gameInfo['channel_version']){
- // 可以强更
- $result['status'] = 2;
- } elseif ($fbInfo['upload_status'] == 4){
- // 分包中
- $result['status'] = 4;
- } elseif ($fbInfo['upload_status'] == 5){
- // 分包失败
- $result['status'] = 5;
- } else {
- $result['status'] = 3;
- }
- if($fbInfo['upload_status'] == 1 && $gameInfo['channel_version'] > $fbInfo['channel_version']){
- // 主动分包条件:分包>客户端、游戏>分包、游戏>客户端
- $result['status'] = 4;
- $subChannel = new SubChannel;
- // $platform = $gameInfo['type']==1?1:0; // 设备类型:1=ios、2=安卓、3=h5
- $subChannelRes = $subChannel->index($channel_id, $game_id, 'ydd_fb',$gameInfo['type'],0);
- if($subChannelRes['code'] === 0){
- $sdkGameModel->save(['upload_status' => 4, 'update_time' => time()], ['channel_id' => $channel_id, 'gameid' => $game_id]);
- }else{
- $result['status'] = 5;
- }
- }
- // 获取强更数据
- if($result['status'] == 2){
- // $result['game_type'] = $gameInfo['type'];
- if($gameInfo['type'] == 2){ // 安卓
- if($fbInfo && isset($fbInfo['filename'])){
- $result['url'] = APK_DOWN_DOMAIN_NEW.'/sygame/'.$gameInfo['pinyin'].'/'.$fbInfo['filename'];
- }
- }elseif($gameInfo['type'] == 1){ // IOS
- $shortModel = new PromotionShortLink;
- $shortInfo = $shortModel->where(['channel_id' => $channel_id, 'game_id' => $game_id])->field('id,short_link')->find();
- if($shortInfo){
- $result['url'] = $shortInfo['short_link']?T_DOMAIN.'/'.$shortInfo['short_link']:'';
- }
- }
- // TODO:H5分包地址(没有分包,不用处理)
- if(!$result['url']){
- $result['status'] = 3;
- }
- }
- $result['type'] = 3;
- $notidyData['id'] = $getMergeData['id'];
- $notidyData['title'] = $getMergeData['title'];
- $notidyData['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $getMergeData['content'];
- $result['notify'] = [$notidyData];
- // status = 状态:0=无、1=已是最新版本(无用)、2=已是最新版本(可以强更)、3=获取最新分包(请求分包)、4=分包更新中(请求中)、5=分包失败(重新提交分包)
- $msg = '可更新!';
- switch ($result['status']){
- case 1:
- $msg = '已是最新包';
- break;
- case 2:
- $msg = '下载最新包';
- break;
- case 3:
- $msg = '获取最新包';
- break;
- case 4:
- $msg = '分包处理中,请稍后...';
- break;
- case 5:
- $msg = isset($subChannelRes['msg'])?'分包失败:'.$subChannelRes['msg']:'分包失败';
- break;
- }
- $this->jsonResult($result, 1, $msg);
- }
- // 强更公告&公共&分包更新 - v3
- public function index_v3(){
- $game_id = $this->input('gameid'); // 游戏ID
- $channel_id = $this->input('channel_id'); // 渠道ID(客户端传入)
- // $channel_id = $this->input('member_channel_id'); // 渠道ID(当前账户所属渠道)
- $channel_version = $this->input('channel_version', ''); // 游戏的强更号
- $userId = $this->input('userid', ''); // 当前用户ID
- if ( empty($game_id) ) {
- $this->jsonResult('', -100, '游戏ID不能为空');
- }
- elseif ( empty($channel_id) ) {
- $this->jsonResult('', -100, '渠道ID不能为空');
- } elseif ($channel_version === '') {
- $this->jsonResult('', -100, '游戏的强更号不能为空');
- }
- $gameModel = new Game;
- $gameInfo = $gameModel->where(['id' => $game_id])->field('id,type,pinyin,channel_version')->find();
- if(!$gameInfo){
- $this->jsonResult('', -102, '游戏不存在!');
- }
- $channelId = $channel_id; // 当前渠道ID
- $now = time();
- // ## 返回结构定义
- // 弹框优先级:强更》公告》时效公告;
- $result = [
- // 'type' => 0, // 类型:0=无、1=公告、2=广告、3=强更、4=时效性公告;
- // 强更公告详情
- 'notify_qg' => [
- 'status' => 0, // 状态:0=无、1=已是最新版本(无用)、2=已是最新版本(可以强更)、3=获取最新分包(请求分包)、4=分包更新中(请求中)、5=分包失败(重新提交分包)
- 'url' => '', // 强更地址(强更时才返回)
- 'msg' => '', // 提示信息{当前状态的说明。例如:status = 状态:0=无、1=已是最新版本(正常)、2=已是最新版本(获取下载地址)、3=获取最新分包(客户端请求分包接口)、4=分包更新中(请求中)、5=分包失败(重新提交分包)}
- // 强更公告详情
- 'id' => '',
- 'title' => '',
- 'content' => '',
- ],
- // 单次公告详情
- 'notify_dc' => [
- 'status' => 0,
- 'url' => '',
- 'msg' => '',
- // 强更公告详情
- 'id' => '',
- 'title' => '',
- 'content' => '',
- ],
- // 时效公告详情
- 'notify_sx' => [
- 'status' => 0,
- 'url' => '',
- 'msg' => '',
- // 强更公告详情
- 'id' => '',
- 'title' => '',
- 'content' => '',
- ],
- // 扩展参数
- 'ext' => [
- 'game_version' => $gameInfo['channel_version'], // 游戏最新版本号
- 'channel_version' => "", // 分包版本号
- 'client_channel_version' => $channel_version, // 客户端传入的版本号
- ]
- ];
- // ================= 2. 第一步:获取所有符合资格的 ID 列表 =================
- // 这一步不做分组,只负责把“不能看的”全部剔除,剩下的按时间倒序
- $candidates = Db::table('cy_game_notify')->alias('cn')
- ->join('cy_game_notify_relation r', 'cn.id = r.notify_id', 'INNER')
- // 关键点:动态 JOIN 黑白名单表
- // 意思:如果公告是渠道类型(1),就匹配渠道ID;如果公告是用户类型(2),就匹配用户ID
- // 并且还要求 黑白名单记录的类型(deny_type) 必须和主表一致,防止脏数据
- ->join('cy_game_notify_deny d', "cn.id = d.notify_id
- AND d.deny_type = cn.deny_type
- AND (
- (cn.data_type = 1 AND d.target_type = 1 AND d.target_id = {$channelId})
- OR
- (cn.data_type = 2 AND d.target_type = 2 AND d.target_id = {$userId})
- )", 'LEFT')
- ->where('cn.status', 1) // 状态开启
- ->where('r.game_id', $game_id) // 必须是当前游戏
- // 1. 时间筛选逻辑 (保持不变)
- ->where(function ($query) use ($now) {
- $query->where('cn.notify_type', '<>', 4) // 非时效性
- ->whereOr(function ($q2) use ($now) {
- $q2->where('cn.notify_type', 4) // 时效性
- ->where('cn.begin_time', '<=', $now)
- ->where('cn.end_time', '>=', $now);
- });
- })
- // 2. 黑白名单筛选逻辑 (根据 JOIN 的结果判断)
- ->where(function ($query) {
- // 场景A:黑名单模式 (deny_type=0)。要求:关联表 d 必须没有记录 (IS NULL)
- $query->where(function ($q_black) {
- $q_black->where('cn.deny_type', 0)->where('d.id', 'NULL');
- })
- // 场景B:白名单模式 (deny_type=1)。要求:关联表 d 必须有记录 (IS NOT NULL)
- ->whereOr(function ($q_white) {
- $q_white->where('cn.deny_type', 1)->where('d.id', 'NOT NULL');
- });
- })
- // 只取 ID 和 类型,按创建时间倒序(最新的排前面)
- ->field('cn.id, cn.notify_type')
- ->order('cn.create_time desc')
- ->select();
- // ================= 3. PHP 内存分组 (替代 GROUP BY) =================
- // 因为上面已经按时间倒序了,所以每个类型拿到的第一个,绝对是“最新且有效”的
- $validIds = [];
- $seenTypes = [];
- foreach ($candidates as $item) {
- $type = $item['notify_type'];
- if (!in_array($type, $seenTypes)) {
- $validIds[] = $item['id']; // 只要第一个(最新的)
- $seenTypes[] = $type; // 标记该类型已存在
- }
- }
- if (empty($validIds)) {
- $this->jsonResult($result, 1, "获取成功!");
- }
- // ================= 4. 最后一步:查详情 =================
- $notifyResult = Db::table('cy_game_notify')->alias('cn')
- ->field('cn.*') // 查出所有字段
- // 自定义排序权重:强更(3)>单次(1)>时效(4)>广告(2)
- ->field("(CASE cn.notify_type WHEN 3 THEN 1 WHEN 1 THEN 2 WHEN 4 THEN 3 ELSE 4 END) AS sort_weight")
- ->whereIn('cn.id', $validIds)
- ->order('sort_weight ASC')
- ->select();
- $newList = array_column($notifyResult, null, 'notify_type');
- // ## 获取强更公告
- $notieQg = isset($newList[3]) ? $newList[3] : [];
- if($notieQg){
- // 状态:0=无、1=已是最新版本(无用)、2=已是最新版本(可以强更)、3=获取最新分包(请求分包)、4=分包更新中(请求中)、5=分包失败(重新提交分包)
- $fbStatus = 1;
- $sdkGameModel = new SdkGameList;
- $fbInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $gameInfo['id']])->field('id,filename,channel_version,upload_status,status')->find();
- if(!$fbInfo){
- $this->jsonResult($result, -120, '分包数据不存在!');
- }
- if($fbInfo['status'] === 0){
- $this->jsonResult($result, -121, '当前渠道已禁用,无法分包,请联系商务!');
- }
- $result['ext']['channel_version'] = $fbInfo['channel_version'];
- if($channel_version != $fbInfo['channel_version'] || $fbInfo['channel_version'] != $gameInfo['channel_version']){
- // 主动分包条件:分包和游戏包版本号不一致
- if($fbInfo['channel_version'] != $gameInfo['channel_version']){
- $fbStatus = 4;
- $subChannel = new SubChannel;
- $subChannelRes = $subChannel->index($channel_id, $game_id, 'ydd_fb',$gameInfo['type'],0);
- if($subChannelRes['code'] === 0){
- $sdkGameModel->save(['upload_status' => 4, 'update_time' => time()], ['channel_id' => $channel_id, 'gameid' => $game_id]);
- }else{
- $fbStatus = 5;
- }
- }else{
- // 获取分包数据条件:客户端包合分包版本号不一致
- if($channel_version != $fbInfo['channel_version']){
- $fbStatus = 2;
- if($gameInfo['type'] == 2){ // 安卓
- if($fbInfo && isset($fbInfo['filename'])){
- $result['notify_qg']['url'] = APK_DOWN_DOMAIN_NEW.'/sygame/'.$gameInfo['pinyin'].'/'.$fbInfo['filename'];
- }
- }elseif($gameInfo['type'] == 1){ // IOS
- $shortModel = new PromotionShortLink;
- $shortInfo = $shortModel->where(['channel_id' => $channel_id, 'game_id' => $game_id])->field('id,short_link')->find();
- if($shortInfo){
- $result['notify_qg']['url'] = $shortInfo['short_link']?T_DOMAIN.'/'.$shortInfo['short_link']:'';
- }
- }
- }
- }
- $msg = '可更新!';
- switch ($fbStatus){
- case 1:
- $msg = '已是最新包';
- break;
- case 2:
- $msg = '下载最新包';
- break;
- case 3:
- $msg = '获取最新包';
- break;
- case 4:
- $msg = '分包处理中,请稍后...';
- break;
- case 5:
- $msg = isset($subChannelRes['msg'])?'分包失败:'.$subChannelRes['msg']:'分包失败';
- break;
- }
- $result['notify_qg']['status'] = $fbStatus;
- $result['notify_qg']['msg'] = $msg;
- $result['notify_qg']['id'] = $notieQg['id']??'';
- $result['notify_qg']['title'] = $notieQg['title']??'';
- $result['notify_qg']['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $notieQg['content']??'';
- }
- }
- // ## 获取单次公告
- $notieDc = isset($newList[1]) ? $newList[1] : [];
- if($notieDc){
- $result['notify_dc']['id'] = $notieDc['id']??'';
- $result['notify_dc']['title'] = $notieDc['title']??'';
- $result['notify_dc']['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $notieDc['content']??'';
- }
- // ## 获取时效公告
- $notieSx = isset($newList[4]) ? $newList[4] : [];
- if($notieSx){
- $result['notify_sx']['id'] = $notieSx['id']??'';
- $result['notify_sx']['title'] = $notieSx['title']??'';
- $result['notify_sx']['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $notieSx['content']??'';
- }
- $this->jsonResult($result, 1, "获取成功!");
- }
- // 申请最新游戏包分包
- public function getPackage(){
- $game_id = $this->input('gameid'); // 游戏ID
- $channel_id = $this->input('channel_id'); // 渠道ID
- $channel_version = $this->input('channel_version', ''); // 游戏的强更号
- $sdkGameModel = new SdkGameList;
- $fbInfo = $sdkGameModel->where(['channel_id' => $channel_id, 'gameid' => $game_id])->field('id,filename,channel_version,upload_status')->find();
- if(!$fbInfo){
- $this->jsonResult('', 0, '分包数据不存在!');
- }
- if ($fbInfo['upload_status'] == 4){
- $this->jsonResult('', 1, '分包中...');
- }
- $gameModel = new Game;
- $gameInfo = $gameModel->where(['id' => $game_id])->field('id,type,pinyin,channel_version')->find();
- if(!$gameInfo){
- $this->jsonResult('', 0, '游戏不存在!');
- }
- // 客户端已是最新版本 则只 显示公告
- if($channel_version >= $gameInfo['channel_version']){
- $this->jsonResult('', 1, '已是最新版本!');
- }
- $subChannel = new SubChannel;
- // $platform = $gameInfo['type']==1?1:0; // 设备类型:1=ios、2=安卓、3=h5
- $subChannelRes = $subChannel->index($channel_id, $game_id, 'ydd_fb',$gameInfo['type'],0);
- if($subChannelRes['code'] === 0){
- $sdkGameModel->save(['upload_status' => 4, 'update_time' => time()], ['channel_id' => $channel_id, 'gameid' => $game_id]);
- $this->jsonResult('', 1, '提交成功!');
- }else{
- $this->jsonResult('', 0, '提交失败!');
- }
- }
- }
|