123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764 |
- <?php
- /**
- * MemberOut.php UTF-8
- * 玩家管理类
- *
- * @date : 2017/11/24 22:30
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huomp\controller\member;
- use huo\controller\agent\AgentCache;
- use huo\controller\common\Base;
- use huo\controller\common\CommonFunc;
- use huo\controller\game\GameCache;
- use huo\controller\integral\IaCache;
- use huo\controller\integral\MemIa;
- use huo\controller\integral\MemIaCache;
- use huo\controller\member\MemCache;
- use huo\controller\member\Oauth;
- use huo\controller\queue\OpenGameQueue;
- use huo\controller\rate\Rate;
- use huo\controller\sign\Sign;
- use huo\controller\wallet\GmCache;
- use huo\controller\wap\Option;
- use huo\model\finance\SettleModel;
- use huo\model\game\GamecategoryModel;
- use huo\model\game\GameModel;
- use huo\model\member\MemberModel;
- use huo\model\member\MemGameMapModel;
- use huo\model\member\MemGameModel;
- use huo\model\member\MemoauthModel;
- use huo\model\member\MgRoleModel;
- use huo\model\user\UserModel;
- use huolib\constant\CacheConst;
- use huolib\constant\CategoryConst;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\constant\IaConst;
- use huolib\constant\MemConst;
- use huolib\constant\MpConfConst;
- use huolib\constant\OauthConst;
- use huolib\constant\OptionConst;
- use huolib\status\CommonStatus;
- use huolib\tool\SimpleSec;
- use huolib\tool\StrUtils;
- use huolib\tool\Time;
- use huomp\controller\share\ShareOut;
- use think\Cache;
- use think\Log;
- class MemberOut extends Base {
- /**
- * 更新玩家信息
- *
- * @param $mem_id
- * @param $open_id
- * @param $data
- * @param string $type
- * @param string $device_type
- * @param int $app_id
- *
- * @return array|mixed
- */
- public function upMemInfo($mem_id, $open_id, $data, $type = OauthConst::OAUTH_MP, $device_type = '', $app_id = 0) {
- $_ma_model = new MemoauthModel();
- $_oauth_data = $_ma_model->getInfoByOpenId($type, $open_id);
- $_status = $_oauth_data['status'];
- $_union_id = get_val($data, 'unionId', '');
- $_is_auth = 0;
- if (MemConst::STATUS_TRY == $_status || (!empty($_union_id) && $_union_id != $_oauth_data['unionid'])) {
- /* 未授权 走登陆授权流程 */
- $_oauth_data['gender'] = get_val($data, 'gender', MemConst::GENDER_N);
- $_oauth_data['city'] = get_val($data, 'city', '');
- $_oauth_data['province'] = get_val($data, 'province', '');
- $_oauth_data['country'] = get_val($data, 'country', '');
- $_oauth_data['avatar'] = get_val($data, 'avatarUrl', '');
- $_oauth_data['nickname'] = get_val($data, 'nickName', '');
- $_oauth_data['status'] = MemConst::STATUS_NORMAL;
- if (!empty($_union_id) && $_union_id != $_oauth_data['unionid']) {
- $_oauth_data['unionid'] = $_union_id;
- $_mem_id = (new Oauth())->getMemIdByUnionId($type, $_union_id);
- if (!empty($_mem_id)) {
- $_oauth_data['mem_id'] = $_mem_id;
- $mem_id = $_mem_id;
- }
- }
- $_language = get_val($data, 'language', '');
- $_more = !empty($_oauth_data['more']) ? json_decode($_oauth_data['more'], true) : [];
- $_more['language'] = $_language;
- $_more['watermark'] = get_val($data, 'watermark', []);
- $_oauth_data['more'] = json_encode($_more);
- $_rs = $_ma_model->updateOauth($type, $open_id, $_oauth_data);
- if (false == $_rs) {
- $_code = CommonStatus::DB_EXCEPTION;
- return $this->retErrMsg($_code);
- }
- $_mc_class = MemCache::ins();
- $_mem_data = $_mc_class->getInfoById($mem_id);
- $_mem_data['nickname'] = $_oauth_data['nickname'];
- $_mem_data['avatar'] = $_oauth_data['avatar'];
- if (MemConst::STATUS_TRY == $_mem_data['status']) {
- /* 设置上级邀请记录 */
- $_parent_mem_id = $_mem_data['parent_mem_id'];
- if (!empty($_parent_mem_id)) {
- (new MemberOut())->setShareCnt($_parent_mem_id);
- }
- $_aec_class = AgentCache::ins();
- $_ae_data = $_aec_class->getAgentExtByAgentId($_mem_data['agent_id']);
- if (!empty($_ae_data) && isset($_ae_data['reg_cnt'])) {
- $_ae_data['reg_cnt']++;
- $_aec_class->updateAgentExt($_mem_data['agent_id'], $_ae_data);
- }
- $_mem_data['status'] = MemConst::STATUS_NORMAL;
- }
- $_rs = $_mc_class->updateMem($mem_id, $_mem_data);
- if (false == $_rs) {
- $_code = CommonStatus::DB_EXCEPTION;
- return $this->retErrMsg($_code);
- }
- $_agent_id = (new UserModel())->getIdByMemId($mem_id);
- if (!empty($_agent_id)) {
- $_agent_data['user_nicename'] = $_mem_data['nickname'];
- $_agent_data['avatar'] = $_mem_data['avatar'];
- $_agent_data['user_status'] = MemConst::STATUS_NORMAL;
- AgentCache::ins()->updateAgent($_agent_id, $_agent_data);
- }
- /* 登陆授权队列 */
- $_device_rq = new \huo\controller\request\Device();
- $_game_rq = new \huo\controller\request\Game();
- $_channel_rq = new \huo\controller\request\Channel();
- $_mem_rq = new \huo\controller\request\Mem();
- $_device_rq->setIp(get_client_ip(0, true));
- $_channel_rq->setCh($_mem_data['agent_id']);
- $_mem_rq->setMemId($mem_id);
- $_mem_rq->setRegTime($_oauth_data['create_time']);
- $_mem_rq->setLoginTime(time());
- $_mem_rq->setStatus($_oauth_data['status']);
- (new \huo\controller\queue\Mem($app_id))->create(
- $_device_rq, $_game_rq, $_channel_rq, $_mem_rq
- );
- $_is_auth = 1;
- }
- $_token = (new \huo\controller\member\Member())->updateToken($mem_id, $device_type);
- return $this->getMemInfo($mem_id, $open_id, $type, $_token, $app_id, $_is_auth);
- }
- /**
- * 获取玩家信息
- *
- * @param int $mem_id
- * @param string $open_id
- * @param string $type
- * @param string $token
- * @param int $app_id
- * @param int $is_auth
- *
- * @return array
- */
- public function getMemInfo($mem_id, $open_id, $type = OauthConst::OAUTH_MP, $token = '', $app_id = 0, $is_auth = 0
- ) {
- $_mc_class = MemCache::ins();
- $_mem_data = $_mc_class->getInfoById($mem_id);
- $_me_data = $_mc_class->getMeInfoById($mem_id);
- $_gm_data = null;
- if (!empty($app_id)) {
- $_gm_class = GmCache::ins();
- $_gm_data = $_gm_class->getInfoByMemGame($mem_id, $app_id);
- }
- $_rdata['mem_id'] = isset($_mem_data['id']) ? $_mem_data['id'] : 0;
- $_rdata['avatar'] = isset($_mem_data['avatar']) ? $_mem_data['avatar'] : '';
- $_rdata['nickname'] = empty($_mem_data['nickname']) ? $_mem_data['username'] : $_mem_data['nickname'];
- $_rdata['my_integral'] = isset($_me_data['my_integral']) ? $_me_data['my_integral'] : 0;
- $_rdata['gift_cnt'] = isset($_me_data['gift_cnt']) ? $_me_data['gift_cnt'] : 0;
- $_rdata['game_cnt'] = isset($_me_data['game_cnt']) ? $_me_data['game_cnt'] : 0;
- $_rdata['ptb_cnt'] = isset($_me_data['ptb_cnt']) ? StrUtils::formatNumber($_me_data['ptb_cnt']) : 0;
- $_rdata['gm_cnt'] = isset($_gm_data['remain']) ? StrUtils::formatNumber($_gm_data['remain']) : 0;
- $_rdata['has_msg'] = isset($_me_data['has_msg']) ? $_me_data['has_msg'] : 0;
- $_rdata['last_sign_time'] = isset($_me_data['last_sign_time']) ? $_me_data['last_sign_time'] : 0;
- $_rdata['sign_days'] = isset($_me_data['sign_days']) ? $_me_data['sign_days'] : 0;
- $_rdata['has_identify'] = empty($_mem_data['id_card']) ? 1 : 2;
- $_rdata['has_bind_mobile'] = empty($_mem_data['mobile']) ? 1 : 2;
- list($_rdata['sign_days'], $_rdata['last_sign_time']) = Sign::getSignDaysAndTime(
- $_rdata['sign_days'], $_rdata['last_sign_time']
- );
- $_rdata['has_sign'] = Sign::isSignToday($_rdata['last_sign_time']) ? 2 : 1;
- $_rdata['mobile'] = !empty($_mem_data['mobile']) ? $_mem_data['mobile'] : '';
- $_rdata['email'] = !empty($_mem_data['email']) ? $_mem_data['email'] : '';
- $_rdata['user_token'] = $token;
- $_rdata['cp_user_token'] = SimpleSec::encode($_rdata['user_token'], config('CPAUTHCODE'));
- $_rdata['agentgame'] = '';// TODO: wuyonghong 2018/8/9
- $_oauth_data = (new MemoauthModel())->getInfoByOpenId($type, $open_id);
- $_rdata['gender'] = !empty($_oauth_data['gender']) ? $_oauth_data['gender'] : MemConst::GENDER_N;
- $_rdata['city'] = !empty($_oauth_data['city']) ? $_oauth_data['city'] : '';
- $_rdata['province'] = !empty($_oauth_data['province']) ? $_oauth_data['province'] : '';
- $_rdata['country'] = !empty($_oauth_data['country']) ? $_oauth_data['country'] : '';
- $_rdata['openid'] = $open_id;
- $_rdata['report_status'] = empty($_mem_data['is_switch']) ? CommonConst::STATUS_NO : $_mem_data['is_switch'];
- $_code = CommonStatus::NO_ERROR;
- if (empty($is_auth)) {
- /* 登陆队列 */
- $_device_rq = new \huo\controller\request\Device();
- $_game_rq = new \huo\controller\request\Game();
- $_channel_rq = new \huo\controller\request\Channel();
- $_mem_rq = new \huo\controller\request\Mem();
- $_device_rq->setIp(get_client_ip(0, true));
- $_channel_rq->setCh($_mem_data['agent_id']);
- $_mg_mem_id = (new MemGameModel())->getMgMemId($app_id, $mem_id);
- $_mem_rq->setMgMemId($_mg_mem_id);
- $_mem_rq->setMemId($mem_id);
- $_mem_rq->setRegTime($_oauth_data['create_time']);
- $_status = !empty($_mem_data['status']) ? $_mem_data['status'] : MemConst::STATUS_TRY;
- $_mem_rq->setStatus($_status);
- $_mem_rq->setLoginTime(time());
- (new \huo\controller\queue\Mem($app_id))->online(
- $_device_rq, $_game_rq, $_channel_rq, $_mem_rq
- );
- }
- /* 西游仙缘特殊处理 切换open_id */
- if ($app_id == '81234724') {
- $_mem_game_map = (new MemGameMapModel())->getInfoByMemIdAppId($mem_id, $app_id);
- if (!empty($_mem_game_map['old_mem_id'])) {
- $_rdata['openid'] = (new MemoauthModel())->getOpenidByMemId($type, $_mem_game_map['old_mem_id']);
- }
- }
- return $this->retSucMsg($_code, $_rdata);
- }
- public function getMgMemId($app_id, $mem_id) {
- $_mem_info = (new MemberModel())->getInfoById($mem_id);
- if ($_mem_info['create_time'] > strtotime(date("2021-01-26 18:20"))) {
- $_game_model = new GameModel();
- $_mg_role_model = new MgRoleModel();
- $_mem_game_model = new MemGameModel();
- $_master_app_id = $_game_model->getAppleIdById($app_id);
- // 查找关联同类型游戏的玩家游戏角色id
- if (!empty($_master_app_id)) {
- // 子包
- $_same_series_app_ids = $_game_model->getIdsByWhere(['apple_id' => $_master_app_id]);
- // 加入当前游戏id,主包游戏id
- $_same_series_app_ids[] = $app_id;
- $_same_series_app_ids[] = $_master_app_id;
- $_link_app_id = (new GameModel())->getLinkAppId($_master_app_id);
- if (!empty($_link_app_id)) {
- // 加入主包关联的H5游戏
- $_same_series_app_ids[] = $_link_app_id;
- }
- $_same_series_mem_game_ids = $_mem_game_model->getMemGameIds($_same_series_app_ids, $mem_id);
- $_first_mg_role_data = $_mg_role_model->getFirstMgRoleData($_same_series_mem_game_ids);
- if (!empty($_first_mg_role_data)) {
- $_mg_mem_id = $_first_mg_role_data['mg_mem_id'];
- }
- } else {
- // 主包
- $_same_series_app_ids = $_game_model->getIdsByWhere(['apple_id' => $app_id]);
- // 加入当前游戏id
- $_same_series_app_ids[] = $app_id;
- $_link_app_id = (new GameModel())->getLinkAppId($app_id);
- if (!empty($_link_app_id)) {
- // 加入主包关联的H5游戏
- $_same_series_app_ids[] = $_link_app_id;
- }
- $_same_series_mem_game_ids = $_mem_game_model->getMemGameIds($_same_series_app_ids, $mem_id);
- $_first_mg_role_data = $_mg_role_model->getFirstMgRoleData($_same_series_mem_game_ids);
- if (!empty($_first_mg_role_data)) {
- $_mg_mem_id = $_first_mg_role_data['mg_mem_id'];
- }
- }
- if (empty($_mg_mem_id)) {
- $_mg_mem_id = (new MemGameModel())->getMgMemId($app_id, $mem_id);
- }
- // if ($mem_id == 79742) {
- if (empty($_mg_mem_id)) {
- // 关联游戏互通
- $_link_app_id = (new GameModel())->getLinkAppId($app_id);
- if (!empty($_link_app_id)) {
- $_mg_mem_id = (new MemGameModel())->getMgMemId($_link_app_id, $mem_id);
- }
- }
- // }
- if ($mem_id == 124009) {
- $_mg_mem_id = $this->specificGame6006($_mg_mem_id, $app_id, $mem_id);
- }
- return $_mg_mem_id;
- } else {
- /* 关联游戏相同角色处理 */
- $_master_app_id = (new GameModel())->getAppleIdById($app_id);
- if (!empty($_master_app_id) && $_master_app_id != $app_id) {
- // 使用父游戏角色
- $_mg_mem_id = (new MemGameModel())->getMgMemId($_master_app_id, $mem_id);
- }
- if (empty($_mg_mem_id)) {
- // 关联游戏互通
- $_link_app_id = (new GameModel())->getLinkAppId($app_id);
- if (!empty($_link_app_id)) {
- $_mg_mem_id = (new MemGameModel())->getMgMemId($_link_app_id, $mem_id);
- }
- }
- if (empty($_mg_mem_id)) {
- // 查找当前游戏
- $_mg_mem_id = (new MemGameModel())->getMgMemId($app_id, $mem_id);
- }
- $_mg_mem_id = $this->specificGame7($_mg_mem_id, $_master_app_id, $mem_id);
- return $_mg_mem_id;
- }
- }
- /**
- * 盛世遮天游戏,特定玩家角色转换处理
- *
- * @param $mg_mem_id
- * @param $app_id
- * @param $mem_id
- *
- * @return int
- */
- private function specificGame7($mg_mem_id, $app_id, $mem_id) {
- if ($app_id == 7) {
- // 盛世遮天游戏,特定玩家角色转换处理
- if ($mem_id == 14760) {
- $mg_mem_id = 14613;
- }
- if ($mem_id == 24431) {
- $mg_mem_id = 24181;
- }
- }
- return $mg_mem_id;
- }
- private function specificGame6006($mg_mem_id, $app_id, $mem_id) {
- if ($app_id == 6006 || $app_id == 7) {
- // 盛世遮天霸业、盛世遮天游戏,特定玩家角色转换处理
- if ($mem_id == 124009) {
- $mg_mem_id = 124784;
- }
- }
- return $mg_mem_id;
- }
- /**
- * 获取盒子玩家信息
- *
- * @param $mem_id
- * @param int $app_id 应用ID
- * @param array $extra
- *
- * @return array
- */
- public function getBoxMemInfo($mem_id, $app_id = 0, $extra = []) {
- $_mc_class = MemCache::ins();
- $_mem_data = $_mc_class->getInfoById($mem_id);
- $_agent_data = (new UserModel())->getInfoByMemId($mem_id);
- $_me_data = $_mc_class->getMeInfoById($mem_id);
- $_my_integral = !empty($_me_data) ? $_me_data['my_integral'] : 0;
- $_total_integral = !empty($_me_data) ? $_me_data['integral_total'] : 0;
- $_balance = 0;
- $_total_amount = 0;
- $_withdraw_amount = 0;
- if (!empty($_agent_data)) {
- $_agent_ext_data = (new AgentCache())->getAgentExtByAgentId($_agent_data['id']);
- $_balance = !empty($_agent_ext_data) ? $_agent_ext_data['share_remain'] : 0;
- $_total_amount = !empty($_agent_ext_data) ? $_agent_ext_data['share_total'] : 0;
- $_withdraw_amount = (new SettleModel())->getTotalAmount($_agent_data['id']);
- }
- $_share_data = (new ShareOut())->getAllShareInfo($mem_id, $app_id);
- if (CommonStatus::NO_ERROR == $_share_data['code']) {
- $extra = array_merge($extra, $_share_data['data']);
- }
- $_app_data = GameCache::ins()->getInfoByAppId($app_id);
- $_is_rp = false;
- if (!empty($_app_data) && GameConst::GAME_MP_RPBOX == $_app_data['classify']) { //红包盒子
- $_is_rp = true;
- }
- $extra['sign'] = $this->getSignData($mem_id, $_is_rp);
- $extra['share'] = $this->getShareData($mem_id, $_is_rp);
- $extra['playtry'] = $this->getPlayTryData($mem_id, $_is_rp);
- $_novice_award = (new Rate($app_id))->getMemReward();
- $_invite_award = (new Rate($app_id))->getMemAgentReward();
- $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
- $_oauth_data = (new MemoauthModel())->getInfoByAppMemId($app_id, $mem_id);
- if (!empty($_oauth_data)) {
- $_mem_data['nickname'] = $_oauth_data['nickname'];
- $_mem_data['avatar'] = $_oauth_data['avatar'];
- }
- $_rdata = array_merge(
- [
- 'mem_id' => $mem_id,
- 'avatar' => $_mem_data['avatar'],
- 'nickname' => $_mem_data['nickname'],
- 'balance' => StrUtils::formatNumber($_balance),
- 'total_amount' => StrUtils::formatNumber($_total_amount),
- 'my_integral' => StrUtils::formatNumber($_my_integral),
- 'total_integral' => StrUtils::formatNumber($_total_integral),
- 'withdraw_amount' => StrUtils::formatNumber($_withdraw_amount),
- 'novice_award' => StrUtils::formatNumber($_novice_award),
- 'novice_award_integral' => intval($_novice_award * $_gold_rmb_rate),
- /* Modified by liuhongliang BEGIN 2018/10/21 后台返回控制玩家分享奖励数值 */
- 'invite_award' => StrUtils::formatNumber($_invite_award),
- 'invite_award_integral' => intval($_invite_award * $_gold_rmb_rate)
- /* END 2018/10/21 ISSUES:123 */
- ],
- $extra
- );
- //$_rdata['auth'] = (new HomepageLogic())->getAuthSet();
- $_code = CommonStatus::NO_ERROR;
- return $this->retSucMsg($_code, $_rdata);
- }
- /**
- * 获取玩家余额
- *
- * @param int $mem_id
- *
- * @return array|bool
- */
- public function getBalance($mem_id) {
- $_agent_data = (new UserModel())->getInfoByMemId($mem_id);
- if (!empty($_agent_data)) {
- $_agent_ext_data = (new AgentCache())->getAgentExtByAgentId($_agent_data['id']);
- $_total_amount = !empty($_agent_ext_data) ? $_agent_ext_data['share_remain'] : 0;
- } else {
- $_total_amount = 0;
- }
- return StrUtils::formatNumber($_total_amount);
- }
- /**
- * 获取分享信息
- *
- * @param $mem_id
- * @param bool $is_rp 是否红包盒子
- *
- * @return array
- */
- public function getShareData($mem_id, $is_rp) {
- $_rdata = $this->getIaData(IaConst::IA_INVITE_3, $is_rp);
- if (empty($_rdata)) {
- return $_rdata;
- }
- $_share_data = $this->getShareCnt($mem_id);
- $_rdata['status'] = $_share_data['status'];
- if (IaConst::IA_STATUS_REWARD != $_rdata['status']) {
- $_rdata['name'] = $_rdata['name'].' ('.$_share_data['cnt'].'/10)';
- }
- return $_rdata;
- }
- /**
- * 获取签到信息
- *
- * @param $mem_id
- * @param bool $is_rp 是否红包盒子
- *
- * @return array
- */
- public function getSignData($mem_id, $is_rp) {
- $_rdata = $this->getIaData(IaConst::IA_SIGN, $is_rp);
- if (empty($_rdata)) {
- return $_rdata;
- }
- $_me_data = MemCache::ins()->getMeInfoById($mem_id);
- list($_rdata['sign_days'], $_rdata['last_sign_time']) = Sign::getSignDaysAndTime(
- $_me_data['sign_days'], $_me_data['last_sign_time']
- );
- $_rdata['status'] = Sign::isSignToday($_rdata['last_sign_time']) ? 2 : 1;
- return $_rdata;
- }
- /**
- * 获取试玩信息
- *
- * @param $mem_id
- * @param bool $is_rp 是否红包盒子
- *
- * @return array
- */
- public function getPlayTryData($mem_id, $is_rp) {
- $_rdata = $this->getIaData(IaConst::IA_PLAY_3, $is_rp);
- if (empty($_rdata)) {
- return $_rdata;
- }
- $_play_data = $this->getPlayCnt($mem_id);
- $_rdata['status'] = $_play_data['status'];
- if (IaConst::IA_STATUS_REWARD != $_rdata['status']) {
- $_rdata['name'] = $_rdata['name'].' ('.$_play_data['cnt'].'/3)';
- }
- return $_rdata;
- }
- public function getIaData($ia_id, $is_rp = false) {
- $_ia_data = (IaCache::ins())->getIa($ia_id);
- if (empty($_ia_data)) {
- return [];
- }
- if (!empty($_ia_data['ia_desc'])) {
- $_ia_data['ia_desc'] = json_decode($_ia_data['ia_desc'], true);
- }
- if ($is_rp) {
- $_ia_data['ia_desc'] = empty($_ia_data['ia_desc'][1]) ? '' : $_ia_data['ia_desc'][1];
- } else {
- $_ia_data['ia_desc'] = empty($_ia_data['ia_desc'][0]) ? '' : $_ia_data['ia_desc'][0];
- }
- $_rdata = [
- 'status' => IaConst::IA_STATUS_NOT,
- 'name' => $_ia_data['ia_name'],
- 'icon' => $_ia_data['icon'],
- 'intro' => $_ia_data['ia_desc'],
- ];
- return $_rdata;
- }
- /**
- * 获取分享次数
- *
- * @param $mem_id
- *
- * @return array|mixed
- */
- public function getShareCnt($mem_id) {
- $_cache_key = CacheConst::CACHE_IA_SHARE_PREFIX.$mem_id;
- $_rdata = Cache::get($_cache_key);
- if (empty($_rdata)) {
- return [
- 'cnt' => 0,
- 'status' => IaConst::IA_STATUS_NOT,
- ];
- }
- return $_rdata;
- }
- /**
- * 设置分享信息
- *
- * @param $mem_id
- * @param int $plus
- * @param int $status
- */
- public function setShareCnt($mem_id, $plus = 1, $status = IaConst::IA_STATUS_NOT) {
- $_rdata = $this->getShareCnt($mem_id);
- if (IaConst::IA_STATUS_REWARD == $_rdata['status']) {
- return;
- }
- $_rdata = [
- 'cnt' => $_rdata['cnt'] + $plus,
- 'status' => $status,
- ];
- if (IaConst::IA_STATUS_REWARD != $status) {
- if ($_rdata['cnt'] >= 10) {
- $_rdata['cnt'] = 10;
- /* Modified by liuhongliang BEGIN 2018/10/21 不再给玩家额外发放试玩奖励,试玩任务直接完成 */
- // $_rdata['status'] = IaConst::IA_STATUS_SUC;
- $_rdata['status'] = IaConst::IA_STATUS_REWARD;
- /* END 2018/10/21 ISSUES:123 */
- }
- }
- $_cache_key = CacheConst::CACHE_IA_SHARE_PREFIX.$mem_id;
- list($_start_time, $_end_time) = Time::today();
- $_diff_time = $_end_time - time();
- Cache::set($_cache_key, $_rdata, $_diff_time);
- }
- /**
- * 获取试玩次数
- *
- * @param $mem_id
- *
- * @return array|mixed
- */
- public function getPlayCnt($mem_id) {
- $_cache_key = CacheConst::CACHE_IA_PLAY_PREFIX.$mem_id;
- $_rdata = Cache::get($_cache_key);
- if (empty($_rdata)) {
- return [
- 'cnt' => 0,
- 'status' => IaConst::IA_STATUS_NOT,
- ];
- }
- return $_rdata;
- }
- /**
- * 设置试玩信息
- *
- * @param $mem_id
- * @param int $plus
- * @param int $status
- * @param array $ext //扩展参数 2018/10/06 chenbingling
- */
- public function setPlayCnt($mem_id, $plus = 1, $status = IaConst::IA_STATUS_NOT, $ext = []) {
- $_ia_id = IaConst::IA_PLAY_3;
- $_rdata = $this->getPlayCnt($mem_id);
- if (IaConst::IA_STATUS_REWARD == $_rdata['status']) {
- return;
- }
- if (0 >= $_rdata['cnt']) { //首次重置玩家积分任务次数
- MemIaCache::ins()->updateMemTodayCnt($_ia_id, $mem_id, 0);
- }
- $_rdata = [
- 'cnt' => $_rdata['cnt'] + $plus,
- 'status' => $status,
- ];
- if (IaConst::IA_STATUS_REWARD != $status) {
- if ($_rdata['cnt'] >= 3) {
- $_rdata['cnt'] = 3;
- $_rdata['status'] = IaConst::IA_STATUS_REWARD;
- }
- if (3 >= $_rdata['cnt']) {
- $_ext = [
- 'app_id' => get_val($ext, 'app_id', 0),
- 'game_id' => get_val($ext, 'game_id', 0)
- ];
- (new MemIa($mem_id))->doItgAct($_ia_id, $_ext);
- }
- }
- $_cache_key = CacheConst::CACHE_IA_PLAY_PREFIX.$mem_id;
- list($_start_time, $_end_time) = Time::today();
- $_diff_time = $_end_time - time();
- Cache::set($_cache_key, $_rdata, $_diff_time);
- }
- /**
- * 判断游戏是否试玩任务游戏并设置游戏试玩信息
- *
- * @param int $mem_id
- * @param int $game_id
- *
- * @return bool
- */
- public function setRpGamePlayCnt($mem_id, $game_id) {
- if (empty($mem_id) || empty($game_id)) {
- return false;
- }
- /* 判断是否为红包任务列表游戏 */
- $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $game_id);
- if ($_rs == false) {
- return false;
- }
- $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($mem_id, $game_id)));
- $_cache = Cache::get($_cache_key);
- if (empty($_cache) || empty($_cache['status']) || MemConst::OPEN_GAME_STATUS_2 == $_cache['status']) {
- return false;
- }
- $_time = time();
- $_og_set = $this->getOpenGameSet();
- if (!empty($_og_set['duration'])) { //不为空的 需要判断
- $_cha = $_time - $_cache['start_time'];
- if (StrUtils::compareNumber($_cha, $_og_set['duration']) >= 0) {
- Cache::set($_cache_key, MemConst::OPEN_GAME_STATUS_2);
- }
- }
- return true;
- }
- /**
- * 获取后台显示红包类型
- */
- public function getHomeRp() {
- $_setting_name = OptionConst::SETTING_HOME_RP_TYPE;
- $_option_value = [
- 'show_type' => MpConfConst::MP_RP_TYPE_1
- ];
- $_m = new Option();
- $_item = $_m->getOptionData($_setting_name, 1, true, json_encode($_option_value));
- if (!empty($_item['option_value'])) {
- $_item['option_value'] = json_decode($_item['option_value'], true);
- }
- $_option_value = array_merge($_option_value, $_item['option_value']);
- return $_option_value['show_type'];
- }
- /**
- * 写任务
- *
- * @param $mem_id
- * @param $app_id
- * @param $game_id
- *
- * @return bool|int|mixed
- */
- public function doOpenGame($mem_id, $app_id, $game_id) {
- $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($mem_id, $game_id)));
- $_status = Cache::get($_cache_key);
- list($today_start, $today_end) = Time::today();
- $_time = time();
- $_expire = $today_end - $_time;
- if (empty($_status)) {
- $_status = [];
- $_status['status'] = MemConst::OPEN_GAME_STATUS_1;
- $_status['start_time'] = $_time;
- /* 打开游戏标记 */
- Cache::set($_cache_key, json_encode($_status), $_expire);
- $_open_game_set = $this->getOpenGameSet();
- $_duration = $_open_game_set['duration'];
- $_delay = empty($_duration) ? CommonConst::SECONDS_30 : $_duration * 2;
- $_data = [
- 'date' => date('Y-m-d', $_time),
- 'mem_id' => $mem_id,
- 'app_id' => $app_id,
- 'game_id' => $game_id,
- 'status' => $_status['status'],
- 'default_duration' => $_duration,
- 'start_time' => $_time,
- 'end_time' => 0,
- 'duration' => 0,
- 'create_time' => $_time,
- 'update_time' => $_time,
- 'delay' => $_delay
- ];
- $_rs = (new OpenGameQueue($_data))->pushQueue();
- if (CommonStatus::NO_ERROR != $_rs['code']) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&code=".$_rs['code'].'&msg=打开游戏获取奖励:'.$_rs['msg']."&data="
- .json_encode($_data),
- LOG::ERROR
- );
- return false;
- }
- return $_status['status'];
- }
- return $_status['status'];
- }
- /**
- * 获取打开游戏领奖设置
- */
- public function getOpenGameSet() {
- $_setting_name = OptionConst::SETTING_OPEN_GAME;
- $_option_value = [
- 'duration' => 0, //默认时长 s
- 'msg' => '' //提示文字
- ];
- $_m = new Option();
- $_item = $_m->getOptionData($_setting_name, 1, true, json_encode($_option_value));
- if (!empty($_item['option_value'])) {
- $_option_value = json_decode($_item['option_value'], true);
- }
- return $_option_value;
- }
- }
|