MemberOut.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <?php
  2. /**
  3. * MemberOut.php UTF-8
  4. * 玩家管理类
  5. *
  6. * @date : 2017/11/24 22:30
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huomp\controller\member;
  13. use huo\controller\agent\AgentCache;
  14. use huo\controller\common\Base;
  15. use huo\controller\common\CommonFunc;
  16. use huo\controller\game\GameCache;
  17. use huo\controller\integral\IaCache;
  18. use huo\controller\integral\MemIa;
  19. use huo\controller\integral\MemIaCache;
  20. use huo\controller\member\MemCache;
  21. use huo\controller\member\Oauth;
  22. use huo\controller\queue\OpenGameQueue;
  23. use huo\controller\rate\Rate;
  24. use huo\controller\sign\Sign;
  25. use huo\controller\wallet\GmCache;
  26. use huo\controller\wap\Option;
  27. use huo\model\finance\SettleModel;
  28. use huo\model\game\GamecategoryModel;
  29. use huo\model\game\GameModel;
  30. use huo\model\member\MemberModel;
  31. use huo\model\member\MemGameMapModel;
  32. use huo\model\member\MemGameModel;
  33. use huo\model\member\MemoauthModel;
  34. use huo\model\member\MgRoleModel;
  35. use huo\model\user\UserModel;
  36. use huolib\constant\CacheConst;
  37. use huolib\constant\CategoryConst;
  38. use huolib\constant\CommonConst;
  39. use huolib\constant\GameConst;
  40. use huolib\constant\IaConst;
  41. use huolib\constant\MemConst;
  42. use huolib\constant\MpConfConst;
  43. use huolib\constant\OauthConst;
  44. use huolib\constant\OptionConst;
  45. use huolib\status\CommonStatus;
  46. use huolib\tool\SimpleSec;
  47. use huolib\tool\StrUtils;
  48. use huolib\tool\Time;
  49. use huomp\controller\share\ShareOut;
  50. use think\Cache;
  51. use think\Log;
  52. class MemberOut extends Base {
  53. /**
  54. * 更新玩家信息
  55. *
  56. * @param $mem_id
  57. * @param $open_id
  58. * @param $data
  59. * @param string $type
  60. * @param string $device_type
  61. * @param int $app_id
  62. *
  63. * @return array|mixed
  64. */
  65. public function upMemInfo($mem_id, $open_id, $data, $type = OauthConst::OAUTH_MP, $device_type = '', $app_id = 0) {
  66. $_ma_model = new MemoauthModel();
  67. $_oauth_data = $_ma_model->getInfoByOpenId($type, $open_id);
  68. $_status = $_oauth_data['status'];
  69. $_union_id = get_val($data, 'unionId', '');
  70. $_is_auth = 0;
  71. if (MemConst::STATUS_TRY == $_status || (!empty($_union_id) && $_union_id != $_oauth_data['unionid'])) {
  72. /* 未授权 走登陆授权流程 */
  73. $_oauth_data['gender'] = get_val($data, 'gender', MemConst::GENDER_N);
  74. $_oauth_data['city'] = get_val($data, 'city', '');
  75. $_oauth_data['province'] = get_val($data, 'province', '');
  76. $_oauth_data['country'] = get_val($data, 'country', '');
  77. $_oauth_data['avatar'] = get_val($data, 'avatarUrl', '');
  78. $_oauth_data['nickname'] = get_val($data, 'nickName', '');
  79. $_oauth_data['status'] = MemConst::STATUS_NORMAL;
  80. if (!empty($_union_id) && $_union_id != $_oauth_data['unionid']) {
  81. $_oauth_data['unionid'] = $_union_id;
  82. $_mem_id = (new Oauth())->getMemIdByUnionId($type, $_union_id);
  83. if (!empty($_mem_id)) {
  84. $_oauth_data['mem_id'] = $_mem_id;
  85. $mem_id = $_mem_id;
  86. }
  87. }
  88. $_language = get_val($data, 'language', '');
  89. $_more = !empty($_oauth_data['more']) ? json_decode($_oauth_data['more'], true) : [];
  90. $_more['language'] = $_language;
  91. $_more['watermark'] = get_val($data, 'watermark', []);
  92. $_oauth_data['more'] = json_encode($_more);
  93. $_rs = $_ma_model->updateOauth($type, $open_id, $_oauth_data);
  94. if (false == $_rs) {
  95. $_code = CommonStatus::DB_EXCEPTION;
  96. return $this->retErrMsg($_code);
  97. }
  98. $_mc_class = MemCache::ins();
  99. $_mem_data = $_mc_class->getInfoById($mem_id);
  100. $_mem_data['nickname'] = $_oauth_data['nickname'];
  101. $_mem_data['avatar'] = $_oauth_data['avatar'];
  102. if (MemConst::STATUS_TRY == $_mem_data['status']) {
  103. /* 设置上级邀请记录 */
  104. $_parent_mem_id = $_mem_data['parent_mem_id'];
  105. if (!empty($_parent_mem_id)) {
  106. (new MemberOut())->setShareCnt($_parent_mem_id);
  107. }
  108. $_aec_class = AgentCache::ins();
  109. $_ae_data = $_aec_class->getAgentExtByAgentId($_mem_data['agent_id']);
  110. if (!empty($_ae_data) && isset($_ae_data['reg_cnt'])) {
  111. $_ae_data['reg_cnt']++;
  112. $_aec_class->updateAgentExt($_mem_data['agent_id'], $_ae_data);
  113. }
  114. $_mem_data['status'] = MemConst::STATUS_NORMAL;
  115. }
  116. $_rs = $_mc_class->updateMem($mem_id, $_mem_data);
  117. if (false == $_rs) {
  118. $_code = CommonStatus::DB_EXCEPTION;
  119. return $this->retErrMsg($_code);
  120. }
  121. $_agent_id = (new UserModel())->getIdByMemId($mem_id);
  122. if (!empty($_agent_id)) {
  123. $_agent_data['user_nicename'] = $_mem_data['nickname'];
  124. $_agent_data['avatar'] = $_mem_data['avatar'];
  125. $_agent_data['user_status'] = MemConst::STATUS_NORMAL;
  126. AgentCache::ins()->updateAgent($_agent_id, $_agent_data);
  127. }
  128. /* 登陆授权队列 */
  129. $_device_rq = new \huo\controller\request\Device();
  130. $_game_rq = new \huo\controller\request\Game();
  131. $_channel_rq = new \huo\controller\request\Channel();
  132. $_mem_rq = new \huo\controller\request\Mem();
  133. $_device_rq->setIp(get_client_ip(0, true));
  134. $_channel_rq->setCh($_mem_data['agent_id']);
  135. $_mem_rq->setMemId($mem_id);
  136. $_mem_rq->setRegTime($_oauth_data['create_time']);
  137. $_mem_rq->setLoginTime(time());
  138. $_mem_rq->setStatus($_oauth_data['status']);
  139. (new \huo\controller\queue\Mem($app_id))->create(
  140. $_device_rq, $_game_rq, $_channel_rq, $_mem_rq
  141. );
  142. $_is_auth = 1;
  143. }
  144. $_token = (new \huo\controller\member\Member())->updateToken($mem_id, $device_type);
  145. return $this->getMemInfo($mem_id, $open_id, $type, $_token, $app_id, $_is_auth);
  146. }
  147. /**
  148. * 获取玩家信息
  149. *
  150. * @param int $mem_id
  151. * @param string $open_id
  152. * @param string $type
  153. * @param string $token
  154. * @param int $app_id
  155. * @param int $is_auth
  156. *
  157. * @return array
  158. */
  159. public function getMemInfo($mem_id, $open_id, $type = OauthConst::OAUTH_MP, $token = '', $app_id = 0, $is_auth = 0
  160. ) {
  161. $_mc_class = MemCache::ins();
  162. $_mem_data = $_mc_class->getInfoById($mem_id);
  163. $_me_data = $_mc_class->getMeInfoById($mem_id);
  164. $_gm_data = null;
  165. if (!empty($app_id)) {
  166. $_gm_class = GmCache::ins();
  167. $_gm_data = $_gm_class->getInfoByMemGame($mem_id, $app_id);
  168. }
  169. $_rdata['mem_id'] = isset($_mem_data['id']) ? $_mem_data['id'] : 0;
  170. $_rdata['avatar'] = isset($_mem_data['avatar']) ? $_mem_data['avatar'] : '';
  171. $_rdata['nickname'] = empty($_mem_data['nickname']) ? $_mem_data['username'] : $_mem_data['nickname'];
  172. $_rdata['my_integral'] = isset($_me_data['my_integral']) ? $_me_data['my_integral'] : 0;
  173. $_rdata['gift_cnt'] = isset($_me_data['gift_cnt']) ? $_me_data['gift_cnt'] : 0;
  174. $_rdata['game_cnt'] = isset($_me_data['game_cnt']) ? $_me_data['game_cnt'] : 0;
  175. $_rdata['ptb_cnt'] = isset($_me_data['ptb_cnt']) ? StrUtils::formatNumber($_me_data['ptb_cnt']) : 0;
  176. $_rdata['gm_cnt'] = isset($_gm_data['remain']) ? StrUtils::formatNumber($_gm_data['remain']) : 0;
  177. $_rdata['has_msg'] = isset($_me_data['has_msg']) ? $_me_data['has_msg'] : 0;
  178. $_rdata['last_sign_time'] = isset($_me_data['last_sign_time']) ? $_me_data['last_sign_time'] : 0;
  179. $_rdata['sign_days'] = isset($_me_data['sign_days']) ? $_me_data['sign_days'] : 0;
  180. $_rdata['has_identify'] = empty($_mem_data['id_card']) ? 1 : 2;
  181. $_rdata['has_bind_mobile'] = empty($_mem_data['mobile']) ? 1 : 2;
  182. list($_rdata['sign_days'], $_rdata['last_sign_time']) = Sign::getSignDaysAndTime(
  183. $_rdata['sign_days'], $_rdata['last_sign_time']
  184. );
  185. $_rdata['has_sign'] = Sign::isSignToday($_rdata['last_sign_time']) ? 2 : 1;
  186. $_rdata['mobile'] = !empty($_mem_data['mobile']) ? $_mem_data['mobile'] : '';
  187. $_rdata['email'] = !empty($_mem_data['email']) ? $_mem_data['email'] : '';
  188. $_rdata['user_token'] = $token;
  189. $_rdata['cp_user_token'] = SimpleSec::encode($_rdata['user_token'], config('CPAUTHCODE'));
  190. $_rdata['agentgame'] = '';// TODO: wuyonghong 2018/8/9
  191. $_oauth_data = (new MemoauthModel())->getInfoByOpenId($type, $open_id);
  192. $_rdata['gender'] = !empty($_oauth_data['gender']) ? $_oauth_data['gender'] : MemConst::GENDER_N;
  193. $_rdata['city'] = !empty($_oauth_data['city']) ? $_oauth_data['city'] : '';
  194. $_rdata['province'] = !empty($_oauth_data['province']) ? $_oauth_data['province'] : '';
  195. $_rdata['country'] = !empty($_oauth_data['country']) ? $_oauth_data['country'] : '';
  196. $_rdata['openid'] = $open_id;
  197. $_rdata['report_status'] = empty($_mem_data['is_switch']) ? CommonConst::STATUS_NO : $_mem_data['is_switch'];
  198. $_code = CommonStatus::NO_ERROR;
  199. if (empty($is_auth)) {
  200. /* 登陆队列 */
  201. $_device_rq = new \huo\controller\request\Device();
  202. $_game_rq = new \huo\controller\request\Game();
  203. $_channel_rq = new \huo\controller\request\Channel();
  204. $_mem_rq = new \huo\controller\request\Mem();
  205. $_device_rq->setIp(get_client_ip(0, true));
  206. $_channel_rq->setCh($_mem_data['agent_id']);
  207. $_mg_mem_id = (new MemGameModel())->getMgMemId($app_id, $mem_id);
  208. $_mem_rq->setMgMemId($_mg_mem_id);
  209. $_mem_rq->setMemId($mem_id);
  210. $_mem_rq->setRegTime($_oauth_data['create_time']);
  211. $_status = !empty($_mem_data['status']) ? $_mem_data['status'] : MemConst::STATUS_TRY;
  212. $_mem_rq->setStatus($_status);
  213. $_mem_rq->setLoginTime(time());
  214. (new \huo\controller\queue\Mem($app_id))->online(
  215. $_device_rq, $_game_rq, $_channel_rq, $_mem_rq
  216. );
  217. }
  218. /* 西游仙缘特殊处理 切换open_id */
  219. if ($app_id == '81234724') {
  220. $_mem_game_map = (new MemGameMapModel())->getInfoByMemIdAppId($mem_id, $app_id);
  221. if (!empty($_mem_game_map['old_mem_id'])) {
  222. $_rdata['openid'] = (new MemoauthModel())->getOpenidByMemId($type, $_mem_game_map['old_mem_id']);
  223. }
  224. }
  225. return $this->retSucMsg($_code, $_rdata);
  226. }
  227. public function getMgMemId($app_id, $mem_id) {
  228. $_mem_info = (new MemberModel())->getInfoById($mem_id);
  229. if ($_mem_info['create_time'] > strtotime(date("2021-01-26 18:20"))) {
  230. $_game_model = new GameModel();
  231. $_mg_role_model = new MgRoleModel();
  232. $_mem_game_model = new MemGameModel();
  233. $_master_app_id = $_game_model->getAppleIdById($app_id);
  234. // 查找关联同类型游戏的玩家游戏角色id
  235. if (!empty($_master_app_id)) {
  236. // 子包
  237. $_same_series_app_ids = $_game_model->getIdsByWhere(['apple_id' => $_master_app_id]);
  238. // 加入当前游戏id,主包游戏id
  239. $_same_series_app_ids[] = $app_id;
  240. $_same_series_app_ids[] = $_master_app_id;
  241. $_link_app_id = (new GameModel())->getLinkAppId($_master_app_id);
  242. if (!empty($_link_app_id)) {
  243. // 加入主包关联的H5游戏
  244. $_same_series_app_ids[] = $_link_app_id;
  245. }
  246. $_same_series_mem_game_ids = $_mem_game_model->getMemGameIds($_same_series_app_ids, $mem_id);
  247. $_first_mg_role_data = $_mg_role_model->getFirstMgRoleData($_same_series_mem_game_ids);
  248. if (!empty($_first_mg_role_data)) {
  249. $_mg_mem_id = $_first_mg_role_data['mg_mem_id'];
  250. }
  251. } else {
  252. // 主包
  253. $_same_series_app_ids = $_game_model->getIdsByWhere(['apple_id' => $app_id]);
  254. // 加入当前游戏id
  255. $_same_series_app_ids[] = $app_id;
  256. $_link_app_id = (new GameModel())->getLinkAppId($app_id);
  257. if (!empty($_link_app_id)) {
  258. // 加入主包关联的H5游戏
  259. $_same_series_app_ids[] = $_link_app_id;
  260. }
  261. $_same_series_mem_game_ids = $_mem_game_model->getMemGameIds($_same_series_app_ids, $mem_id);
  262. $_first_mg_role_data = $_mg_role_model->getFirstMgRoleData($_same_series_mem_game_ids);
  263. if (!empty($_first_mg_role_data)) {
  264. $_mg_mem_id = $_first_mg_role_data['mg_mem_id'];
  265. }
  266. }
  267. if (empty($_mg_mem_id)) {
  268. $_mg_mem_id = (new MemGameModel())->getMgMemId($app_id, $mem_id);
  269. }
  270. // if ($mem_id == 79742) {
  271. if (empty($_mg_mem_id)) {
  272. // 关联游戏互通
  273. $_link_app_id = (new GameModel())->getLinkAppId($app_id);
  274. if (!empty($_link_app_id)) {
  275. $_mg_mem_id = (new MemGameModel())->getMgMemId($_link_app_id, $mem_id);
  276. }
  277. }
  278. // }
  279. if ($mem_id == 124009) {
  280. $_mg_mem_id = $this->specificGame6006($_mg_mem_id, $app_id, $mem_id);
  281. }
  282. return $_mg_mem_id;
  283. } else {
  284. /* 关联游戏相同角色处理 */
  285. $_master_app_id = (new GameModel())->getAppleIdById($app_id);
  286. if (!empty($_master_app_id) && $_master_app_id != $app_id) {
  287. // 使用父游戏角色
  288. $_mg_mem_id = (new MemGameModel())->getMgMemId($_master_app_id, $mem_id);
  289. }
  290. if (empty($_mg_mem_id)) {
  291. // 关联游戏互通
  292. $_link_app_id = (new GameModel())->getLinkAppId($app_id);
  293. if (!empty($_link_app_id)) {
  294. $_mg_mem_id = (new MemGameModel())->getMgMemId($_link_app_id, $mem_id);
  295. }
  296. }
  297. if (empty($_mg_mem_id)) {
  298. // 查找当前游戏
  299. $_mg_mem_id = (new MemGameModel())->getMgMemId($app_id, $mem_id);
  300. }
  301. $_mg_mem_id = $this->specificGame7($_mg_mem_id, $_master_app_id, $mem_id);
  302. return $_mg_mem_id;
  303. }
  304. }
  305. /**
  306. * 盛世遮天游戏,特定玩家角色转换处理
  307. *
  308. * @param $mg_mem_id
  309. * @param $app_id
  310. * @param $mem_id
  311. *
  312. * @return int
  313. */
  314. private function specificGame7($mg_mem_id, $app_id, $mem_id) {
  315. if ($app_id == 7) {
  316. // 盛世遮天游戏,特定玩家角色转换处理
  317. if ($mem_id == 14760) {
  318. $mg_mem_id = 14613;
  319. }
  320. if ($mem_id == 24431) {
  321. $mg_mem_id = 24181;
  322. }
  323. }
  324. return $mg_mem_id;
  325. }
  326. private function specificGame6006($mg_mem_id, $app_id, $mem_id) {
  327. if ($app_id == 6006 || $app_id == 7) {
  328. // 盛世遮天霸业、盛世遮天游戏,特定玩家角色转换处理
  329. if ($mem_id == 124009) {
  330. $mg_mem_id = 124784;
  331. }
  332. }
  333. return $mg_mem_id;
  334. }
  335. /**
  336. * 获取盒子玩家信息
  337. *
  338. * @param $mem_id
  339. * @param int $app_id 应用ID
  340. * @param array $extra
  341. *
  342. * @return array
  343. */
  344. public function getBoxMemInfo($mem_id, $app_id = 0, $extra = []) {
  345. $_mc_class = MemCache::ins();
  346. $_mem_data = $_mc_class->getInfoById($mem_id);
  347. $_agent_data = (new UserModel())->getInfoByMemId($mem_id);
  348. $_me_data = $_mc_class->getMeInfoById($mem_id);
  349. $_my_integral = !empty($_me_data) ? $_me_data['my_integral'] : 0;
  350. $_total_integral = !empty($_me_data) ? $_me_data['integral_total'] : 0;
  351. $_balance = 0;
  352. $_total_amount = 0;
  353. $_withdraw_amount = 0;
  354. if (!empty($_agent_data)) {
  355. $_agent_ext_data = (new AgentCache())->getAgentExtByAgentId($_agent_data['id']);
  356. $_balance = !empty($_agent_ext_data) ? $_agent_ext_data['share_remain'] : 0;
  357. $_total_amount = !empty($_agent_ext_data) ? $_agent_ext_data['share_total'] : 0;
  358. $_withdraw_amount = (new SettleModel())->getTotalAmount($_agent_data['id']);
  359. }
  360. $_share_data = (new ShareOut())->getAllShareInfo($mem_id, $app_id);
  361. if (CommonStatus::NO_ERROR == $_share_data['code']) {
  362. $extra = array_merge($extra, $_share_data['data']);
  363. }
  364. $_app_data = GameCache::ins()->getInfoByAppId($app_id);
  365. $_is_rp = false;
  366. if (!empty($_app_data) && GameConst::GAME_MP_RPBOX == $_app_data['classify']) { //红包盒子
  367. $_is_rp = true;
  368. }
  369. $extra['sign'] = $this->getSignData($mem_id, $_is_rp);
  370. $extra['share'] = $this->getShareData($mem_id, $_is_rp);
  371. $extra['playtry'] = $this->getPlayTryData($mem_id, $_is_rp);
  372. $_novice_award = (new Rate($app_id))->getMemReward();
  373. $_invite_award = (new Rate($app_id))->getMemAgentReward();
  374. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  375. $_oauth_data = (new MemoauthModel())->getInfoByAppMemId($app_id, $mem_id);
  376. if (!empty($_oauth_data)) {
  377. $_mem_data['nickname'] = $_oauth_data['nickname'];
  378. $_mem_data['avatar'] = $_oauth_data['avatar'];
  379. }
  380. $_rdata = array_merge(
  381. [
  382. 'mem_id' => $mem_id,
  383. 'avatar' => $_mem_data['avatar'],
  384. 'nickname' => $_mem_data['nickname'],
  385. 'balance' => StrUtils::formatNumber($_balance),
  386. 'total_amount' => StrUtils::formatNumber($_total_amount),
  387. 'my_integral' => StrUtils::formatNumber($_my_integral),
  388. 'total_integral' => StrUtils::formatNumber($_total_integral),
  389. 'withdraw_amount' => StrUtils::formatNumber($_withdraw_amount),
  390. 'novice_award' => StrUtils::formatNumber($_novice_award),
  391. 'novice_award_integral' => intval($_novice_award * $_gold_rmb_rate),
  392. /* Modified by liuhongliang BEGIN 2018/10/21 后台返回控制玩家分享奖励数值 */
  393. 'invite_award' => StrUtils::formatNumber($_invite_award),
  394. 'invite_award_integral' => intval($_invite_award * $_gold_rmb_rate)
  395. /* END 2018/10/21 ISSUES:123 */
  396. ],
  397. $extra
  398. );
  399. //$_rdata['auth'] = (new HomepageLogic())->getAuthSet();
  400. $_code = CommonStatus::NO_ERROR;
  401. return $this->retSucMsg($_code, $_rdata);
  402. }
  403. /**
  404. * 获取玩家余额
  405. *
  406. * @param int $mem_id
  407. *
  408. * @return array|bool
  409. */
  410. public function getBalance($mem_id) {
  411. $_agent_data = (new UserModel())->getInfoByMemId($mem_id);
  412. if (!empty($_agent_data)) {
  413. $_agent_ext_data = (new AgentCache())->getAgentExtByAgentId($_agent_data['id']);
  414. $_total_amount = !empty($_agent_ext_data) ? $_agent_ext_data['share_remain'] : 0;
  415. } else {
  416. $_total_amount = 0;
  417. }
  418. return StrUtils::formatNumber($_total_amount);
  419. }
  420. /**
  421. * 获取分享信息
  422. *
  423. * @param $mem_id
  424. * @param bool $is_rp 是否红包盒子
  425. *
  426. * @return array
  427. */
  428. public function getShareData($mem_id, $is_rp) {
  429. $_rdata = $this->getIaData(IaConst::IA_INVITE_3, $is_rp);
  430. if (empty($_rdata)) {
  431. return $_rdata;
  432. }
  433. $_share_data = $this->getShareCnt($mem_id);
  434. $_rdata['status'] = $_share_data['status'];
  435. if (IaConst::IA_STATUS_REWARD != $_rdata['status']) {
  436. $_rdata['name'] = $_rdata['name'].' ('.$_share_data['cnt'].'/10)';
  437. }
  438. return $_rdata;
  439. }
  440. /**
  441. * 获取签到信息
  442. *
  443. * @param $mem_id
  444. * @param bool $is_rp 是否红包盒子
  445. *
  446. * @return array
  447. */
  448. public function getSignData($mem_id, $is_rp) {
  449. $_rdata = $this->getIaData(IaConst::IA_SIGN, $is_rp);
  450. if (empty($_rdata)) {
  451. return $_rdata;
  452. }
  453. $_me_data = MemCache::ins()->getMeInfoById($mem_id);
  454. list($_rdata['sign_days'], $_rdata['last_sign_time']) = Sign::getSignDaysAndTime(
  455. $_me_data['sign_days'], $_me_data['last_sign_time']
  456. );
  457. $_rdata['status'] = Sign::isSignToday($_rdata['last_sign_time']) ? 2 : 1;
  458. return $_rdata;
  459. }
  460. /**
  461. * 获取试玩信息
  462. *
  463. * @param $mem_id
  464. * @param bool $is_rp 是否红包盒子
  465. *
  466. * @return array
  467. */
  468. public function getPlayTryData($mem_id, $is_rp) {
  469. $_rdata = $this->getIaData(IaConst::IA_PLAY_3, $is_rp);
  470. if (empty($_rdata)) {
  471. return $_rdata;
  472. }
  473. $_play_data = $this->getPlayCnt($mem_id);
  474. $_rdata['status'] = $_play_data['status'];
  475. if (IaConst::IA_STATUS_REWARD != $_rdata['status']) {
  476. $_rdata['name'] = $_rdata['name'].' ('.$_play_data['cnt'].'/3)';
  477. }
  478. return $_rdata;
  479. }
  480. public function getIaData($ia_id, $is_rp = false) {
  481. $_ia_data = (IaCache::ins())->getIa($ia_id);
  482. if (empty($_ia_data)) {
  483. return [];
  484. }
  485. if (!empty($_ia_data['ia_desc'])) {
  486. $_ia_data['ia_desc'] = json_decode($_ia_data['ia_desc'], true);
  487. }
  488. if ($is_rp) {
  489. $_ia_data['ia_desc'] = empty($_ia_data['ia_desc'][1]) ? '' : $_ia_data['ia_desc'][1];
  490. } else {
  491. $_ia_data['ia_desc'] = empty($_ia_data['ia_desc'][0]) ? '' : $_ia_data['ia_desc'][0];
  492. }
  493. $_rdata = [
  494. 'status' => IaConst::IA_STATUS_NOT,
  495. 'name' => $_ia_data['ia_name'],
  496. 'icon' => $_ia_data['icon'],
  497. 'intro' => $_ia_data['ia_desc'],
  498. ];
  499. return $_rdata;
  500. }
  501. /**
  502. * 获取分享次数
  503. *
  504. * @param $mem_id
  505. *
  506. * @return array|mixed
  507. */
  508. public function getShareCnt($mem_id) {
  509. $_cache_key = CacheConst::CACHE_IA_SHARE_PREFIX.$mem_id;
  510. $_rdata = Cache::get($_cache_key);
  511. if (empty($_rdata)) {
  512. return [
  513. 'cnt' => 0,
  514. 'status' => IaConst::IA_STATUS_NOT,
  515. ];
  516. }
  517. return $_rdata;
  518. }
  519. /**
  520. * 设置分享信息
  521. *
  522. * @param $mem_id
  523. * @param int $plus
  524. * @param int $status
  525. */
  526. public function setShareCnt($mem_id, $plus = 1, $status = IaConst::IA_STATUS_NOT) {
  527. $_rdata = $this->getShareCnt($mem_id);
  528. if (IaConst::IA_STATUS_REWARD == $_rdata['status']) {
  529. return;
  530. }
  531. $_rdata = [
  532. 'cnt' => $_rdata['cnt'] + $plus,
  533. 'status' => $status,
  534. ];
  535. if (IaConst::IA_STATUS_REWARD != $status) {
  536. if ($_rdata['cnt'] >= 10) {
  537. $_rdata['cnt'] = 10;
  538. /* Modified by liuhongliang BEGIN 2018/10/21 不再给玩家额外发放试玩奖励,试玩任务直接完成 */
  539. // $_rdata['status'] = IaConst::IA_STATUS_SUC;
  540. $_rdata['status'] = IaConst::IA_STATUS_REWARD;
  541. /* END 2018/10/21 ISSUES:123 */
  542. }
  543. }
  544. $_cache_key = CacheConst::CACHE_IA_SHARE_PREFIX.$mem_id;
  545. list($_start_time, $_end_time) = Time::today();
  546. $_diff_time = $_end_time - time();
  547. Cache::set($_cache_key, $_rdata, $_diff_time);
  548. }
  549. /**
  550. * 获取试玩次数
  551. *
  552. * @param $mem_id
  553. *
  554. * @return array|mixed
  555. */
  556. public function getPlayCnt($mem_id) {
  557. $_cache_key = CacheConst::CACHE_IA_PLAY_PREFIX.$mem_id;
  558. $_rdata = Cache::get($_cache_key);
  559. if (empty($_rdata)) {
  560. return [
  561. 'cnt' => 0,
  562. 'status' => IaConst::IA_STATUS_NOT,
  563. ];
  564. }
  565. return $_rdata;
  566. }
  567. /**
  568. * 设置试玩信息
  569. *
  570. * @param $mem_id
  571. * @param int $plus
  572. * @param int $status
  573. * @param array $ext //扩展参数 2018/10/06 chenbingling
  574. */
  575. public function setPlayCnt($mem_id, $plus = 1, $status = IaConst::IA_STATUS_NOT, $ext = []) {
  576. $_ia_id = IaConst::IA_PLAY_3;
  577. $_rdata = $this->getPlayCnt($mem_id);
  578. if (IaConst::IA_STATUS_REWARD == $_rdata['status']) {
  579. return;
  580. }
  581. if (0 >= $_rdata['cnt']) { //首次重置玩家积分任务次数
  582. MemIaCache::ins()->updateMemTodayCnt($_ia_id, $mem_id, 0);
  583. }
  584. $_rdata = [
  585. 'cnt' => $_rdata['cnt'] + $plus,
  586. 'status' => $status,
  587. ];
  588. if (IaConst::IA_STATUS_REWARD != $status) {
  589. if ($_rdata['cnt'] >= 3) {
  590. $_rdata['cnt'] = 3;
  591. $_rdata['status'] = IaConst::IA_STATUS_REWARD;
  592. }
  593. if (3 >= $_rdata['cnt']) {
  594. $_ext = [
  595. 'app_id' => get_val($ext, 'app_id', 0),
  596. 'game_id' => get_val($ext, 'game_id', 0)
  597. ];
  598. (new MemIa($mem_id))->doItgAct($_ia_id, $_ext);
  599. }
  600. }
  601. $_cache_key = CacheConst::CACHE_IA_PLAY_PREFIX.$mem_id;
  602. list($_start_time, $_end_time) = Time::today();
  603. $_diff_time = $_end_time - time();
  604. Cache::set($_cache_key, $_rdata, $_diff_time);
  605. }
  606. /**
  607. * 判断游戏是否试玩任务游戏并设置游戏试玩信息
  608. *
  609. * @param int $mem_id
  610. * @param int $game_id
  611. *
  612. * @return bool
  613. */
  614. public function setRpGamePlayCnt($mem_id, $game_id) {
  615. if (empty($mem_id) || empty($game_id)) {
  616. return false;
  617. }
  618. /* 判断是否为红包任务列表游戏 */
  619. $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $game_id);
  620. if ($_rs == false) {
  621. return false;
  622. }
  623. $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($mem_id, $game_id)));
  624. $_cache = Cache::get($_cache_key);
  625. if (empty($_cache) || empty($_cache['status']) || MemConst::OPEN_GAME_STATUS_2 == $_cache['status']) {
  626. return false;
  627. }
  628. $_time = time();
  629. $_og_set = $this->getOpenGameSet();
  630. if (!empty($_og_set['duration'])) { //不为空的 需要判断
  631. $_cha = $_time - $_cache['start_time'];
  632. if (StrUtils::compareNumber($_cha, $_og_set['duration']) >= 0) {
  633. Cache::set($_cache_key, MemConst::OPEN_GAME_STATUS_2);
  634. }
  635. }
  636. return true;
  637. }
  638. /**
  639. * 获取后台显示红包类型
  640. */
  641. public function getHomeRp() {
  642. $_setting_name = OptionConst::SETTING_HOME_RP_TYPE;
  643. $_option_value = [
  644. 'show_type' => MpConfConst::MP_RP_TYPE_1
  645. ];
  646. $_m = new Option();
  647. $_item = $_m->getOptionData($_setting_name, 1, true, json_encode($_option_value));
  648. if (!empty($_item['option_value'])) {
  649. $_item['option_value'] = json_decode($_item['option_value'], true);
  650. }
  651. $_option_value = array_merge($_option_value, $_item['option_value']);
  652. return $_option_value['show_type'];
  653. }
  654. /**
  655. * 写任务
  656. *
  657. * @param $mem_id
  658. * @param $app_id
  659. * @param $game_id
  660. *
  661. * @return bool|int|mixed
  662. */
  663. public function doOpenGame($mem_id, $app_id, $game_id) {
  664. $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($mem_id, $game_id)));
  665. $_status = Cache::get($_cache_key);
  666. list($today_start, $today_end) = Time::today();
  667. $_time = time();
  668. $_expire = $today_end - $_time;
  669. if (empty($_status)) {
  670. $_status = [];
  671. $_status['status'] = MemConst::OPEN_GAME_STATUS_1;
  672. $_status['start_time'] = $_time;
  673. /* 打开游戏标记 */
  674. Cache::set($_cache_key, json_encode($_status), $_expire);
  675. $_open_game_set = $this->getOpenGameSet();
  676. $_duration = $_open_game_set['duration'];
  677. $_delay = empty($_duration) ? CommonConst::SECONDS_30 : $_duration * 2;
  678. $_data = [
  679. 'date' => date('Y-m-d', $_time),
  680. 'mem_id' => $mem_id,
  681. 'app_id' => $app_id,
  682. 'game_id' => $game_id,
  683. 'status' => $_status['status'],
  684. 'default_duration' => $_duration,
  685. 'start_time' => $_time,
  686. 'end_time' => 0,
  687. 'duration' => 0,
  688. 'create_time' => $_time,
  689. 'update_time' => $_time,
  690. 'delay' => $_delay
  691. ];
  692. $_rs = (new OpenGameQueue($_data))->pushQueue();
  693. if (CommonStatus::NO_ERROR != $_rs['code']) {
  694. Log::write(
  695. "func=".__FUNCTION__."&class=".__CLASS__."&code=".$_rs['code'].'&msg=打开游戏获取奖励:'.$_rs['msg']."&data="
  696. .json_encode($_data),
  697. LOG::ERROR
  698. );
  699. return false;
  700. }
  701. return $_status['status'];
  702. }
  703. return $_status['status'];
  704. }
  705. /**
  706. * 获取打开游戏领奖设置
  707. */
  708. public function getOpenGameSet() {
  709. $_setting_name = OptionConst::SETTING_OPEN_GAME;
  710. $_option_value = [
  711. 'duration' => 0, //默认时长 s
  712. 'msg' => '' //提示文字
  713. ];
  714. $_m = new Option();
  715. $_item = $_m->getOptionData($_setting_name, 1, true, json_encode($_option_value));
  716. if (!empty($_item['option_value'])) {
  717. $_option_value = json_decode($_item['option_value'], true);
  718. }
  719. return $_option_value;
  720. }
  721. }