GameModel.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. <?php
  2. /**
  3. * GameModel.php UTF-8
  4. * 游戏model
  5. *
  6. * @date : 2017/11/20 12:06
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\game;
  13. use huo\controller\game\GameCache;
  14. use huo\model\common\CommonModel;
  15. use huo\model\member\MemGameModel;
  16. use huo\model\rate\GameRateModel;
  17. use huo\model\slide\SlideModel;
  18. use huolib\constant\CacheConst;
  19. use huolib\constant\CommonConst;
  20. use huolib\constant\GameConst;
  21. use huolib\constant\MpConfConst;
  22. use huolib\constant\SlideConst;
  23. use huomp\model\game\GameMiniModel;
  24. use huomp\model\weixin\MpConfModel;
  25. use think\Cache;
  26. class GameModel extends CommonModel {
  27. protected $name = 'game';
  28. //设置只读字段
  29. // protected $readonly = ['app_key'];
  30. /* 自动写入 */
  31. protected $insert = ['app_key'];
  32. // 开启自动写入时间戳字段
  33. protected $autoWriteTimestamp = true;
  34. protected $type = ['image' => 'array'];
  35. protected $cache_tag = 'game_id_name';
  36. protected $list_tag = CacheConst::TAG_GAME_LIST;
  37. protected $agent_cache_tag = CacheConst::TAG_AGENT_GAME_LIST;
  38. /**
  39. * 基础查询
  40. *
  41. * @param $query
  42. */
  43. protected function base($query) {
  44. $query->where('delete_time', 0)
  45. ->where('is_delete', 2);
  46. }
  47. /**
  48. * @return \think\model\relation\HasMany
  49. */
  50. public function gift() {
  51. return $this->hasMany('huo\model\game\GiftModel', 'app_id');
  52. }
  53. /**
  54. * 关联游戏折扣表
  55. */
  56. public function rate() {
  57. return $this->hasOne(GameRateModel::className(), 'app_id', 'id', [], 'left')->setEagerlyType(0);
  58. }
  59. /**
  60. * 关联小游戏折扣表
  61. */
  62. public function mini() {
  63. return $this->hasOne(GameMiniModel::className(), 'app_id', 'id')->field('app_id,mini_app_id');
  64. }
  65. /**
  66. * @return \think\model\relation\HasMany
  67. */
  68. public function mg() {
  69. return $this->hasMany(MemGameModel::className(), 'app_id', 'id');
  70. }
  71. /**
  72. * @return \think\model\relation\HasMany
  73. */
  74. public function goods() {
  75. return $this->hasMany('huoAccountDeal\model\AccountGoodsModel', 'app_id', 'id');
  76. }
  77. //
  78. // /**
  79. // * 关联游戏类型表
  80. // */
  81. // public function classify() {
  82. // return $this->hasOne('huo\model\game\GameclassifyModel', 'id', 'classify', [], 'left')->setEagerlyType(0);
  83. // }
  84. /**
  85. * 关联game_ext表
  86. *
  87. * @return \think\model\relation\HasOne
  88. */
  89. public function ext() {
  90. return $this->hasOne('huo\model\game\GameextModel', 'app_id', 'id', [], 'left')->setEagerlyType(0);
  91. }
  92. /**
  93. * 关联oa_game表
  94. *
  95. * @return \think\model\relation\HasOne
  96. */
  97. public function oa() {
  98. if (\huolib\oa\oa::hasOa()) {
  99. return $this->hasOne('huo\model\oa\OaGameModel', 'app_id', 'id', [], 'left')->setEagerlyType(0);
  100. }
  101. }
  102. /**
  103. * @return \think\model\relation\HasMany
  104. */
  105. public function ag() {
  106. return $this->hasMany('huo\model\agent\AgentGameModel', 'app_id', 'id');
  107. }
  108. /**
  109. * 关联game_version表
  110. *
  111. * @return \think\model\relation\HasMany
  112. */
  113. public function gv() {
  114. return $this->hasMany('huo\model\game\GameversionModel', 'app_id');
  115. }
  116. public function cp() {
  117. return $this->hasOne('huo\model\game\CpModel', 'id', 'cp_id')
  118. ->field(['id', 'company_name']);
  119. }
  120. /**
  121. * @param string $value
  122. *
  123. * @param array $data
  124. *
  125. * @return string
  126. */
  127. public function setAppKeyAttr($value = '', $data) {
  128. if (empty($value)) {
  129. return md5($value.$data['name'].time().uniqid());
  130. }
  131. return $value;
  132. }
  133. /**
  134. * @param string $value
  135. *
  136. * @param array $data
  137. *
  138. * @return string
  139. */
  140. public function setEnAbbrAttr($value = '', $data) {
  141. return huo_initials($value.$data['en_name']).'_'.$data['id'];
  142. }
  143. /**
  144. * 游戏游戏图标获取器
  145. *
  146. * @param $value
  147. *
  148. * @return mixed
  149. */
  150. public function getIconAttr($value) {
  151. if (!empty($value)) {
  152. return cmf_get_image_url($value);
  153. }
  154. return $value;
  155. }
  156. /**
  157. * 游戏游戏图标获取器
  158. *
  159. * @param $value
  160. *
  161. * @return mixed
  162. */
  163. public function getExtInfoAttr($value) {
  164. if (!empty($value)) {
  165. return json_decode($value, true);
  166. }
  167. return $value;
  168. }
  169. public function setExtInfoAttr($value) {
  170. if (!empty($value)) {
  171. return json_encode($value);
  172. }
  173. return $value;
  174. }
  175. /**
  176. * 游戏类型获取器
  177. *
  178. * @param $value
  179. *
  180. *
  181. * @return mixed
  182. * */
  183. public function getClassifyLabelAttr($value) {
  184. if (empty($value)) {
  185. return '';
  186. } else {
  187. $_classify = substr($value, 0, 1);
  188. }
  189. if (GameConst::GAME_IOS == $_classify) {
  190. return '苹果';
  191. } elseif (GameConst::GAME_ANDROID == $_classify) {
  192. return '安卓';
  193. } elseif (GameConst::GAME_H5 == $_classify) {
  194. return 'H5';
  195. } elseif (GameConst::GAME_MP_BOX == $value) {
  196. return '金币盒子';
  197. } elseif (GameConst::GAME_MP_RPBOX == $value) {
  198. return '红包盒子';
  199. } elseif (GameConst::GAME_MP == $_classify) {
  200. return '小游戏';
  201. } else {
  202. return '';
  203. }
  204. }
  205. /**
  206. * 游戏状态获取器
  207. *
  208. * @param $value
  209. *
  210. *
  211. * @return mixed
  212. * */
  213. public function getStatusLabelAttr($value) {
  214. if (GameConst::GAME_STATUS_ACCESS == $value) {
  215. return '接入中';
  216. } elseif (GameConst::GAME_STATUS_ON == $value) {
  217. return '上线';
  218. } elseif (GameConst::GAME_STATUS_OFF == $value) {
  219. return '下线';
  220. } else {
  221. return '';
  222. }
  223. }
  224. /**
  225. * 推广状态获取器
  226. *
  227. * @param $value
  228. *
  229. *
  230. * @return mixed
  231. */
  232. public function getAgPsLabel($value) {
  233. if (empty($value)) {
  234. return '';
  235. }
  236. return GameConst::getPromotesMsg($value, false, true);
  237. }
  238. /**
  239. * 推广状态获取器
  240. *
  241. * @param $value
  242. *
  243. *
  244. * @return mixed
  245. */
  246. public function getPromoteSwitchLabelAttr($value) {
  247. if (empty($value)) {
  248. return '';
  249. }
  250. return GameConst::getPromotesMsg($value);
  251. }
  252. /**
  253. * 通过苹果Id查找游戏ID
  254. *
  255. * @param string $apple_id 苹果ID
  256. *
  257. * @return int|mixed
  258. */
  259. public function getAppIdByAppleId($apple_id = '') {
  260. if (empty($apple_id)) {
  261. return 0;
  262. }
  263. $_map['apple_id'] = $apple_id;
  264. $_app_id = $this->cache('apple_id'.$apple_id, CommonConst::CONST_DAY_SECONDS, $this->cache_tag)->where($_map)
  265. ->value('id');
  266. if (empty($_app_id)) {
  267. return 0;
  268. }
  269. return $_app_id;
  270. }
  271. /**
  272. * 添加游戏
  273. *
  274. * @param $data
  275. *
  276. * @return bool|mixed
  277. */
  278. public function addGames($data) {
  279. if (empty($data)) {
  280. return false;
  281. }
  282. $_has_oa = false;
  283. if ($_obj = self::create($data, true)) {
  284. Cache::clear($this->cache_tag);
  285. Cache::clear($this->agent_cache_tag);
  286. $data['id'] = $_obj->id;
  287. $data['en_abbr'] = $_obj->setEnAbbrAttr('', $data);
  288. $_obj->isUpdate(true)->save($data);
  289. /* 写入扩展 */
  290. $_ext_data['star_cnt'] = 5.0;
  291. $_obj->ext()->save($_ext_data);
  292. if (\huolib\oa\Oa::hasOa()) {
  293. $_oa_data = [];
  294. $_oa_data['app_id'] = $data['id'];
  295. $_obj->oa()->save($_oa_data);
  296. $_has_oa = true;
  297. }
  298. $_rate_data['app_id'] = $data['id'];
  299. $_obj->rate()->save($_rate_data);
  300. $_gv_model = new GameversionModel();
  301. $_gv_data['app_id'] = $data['id'];
  302. $_gv_model->addVersion($_gv_data);
  303. Cache::clear($this->cache_tag);
  304. if ($_has_oa) {
  305. $_oa_re = $this->addOaGame($_obj->id);
  306. if ($_oa_re) {
  307. \think\Log::write(
  308. $_oa_re, 'error'
  309. );
  310. }
  311. }
  312. /*小游戏 小程序*/
  313. $_mp_array = [GameConst::GAME_MP, GameConst::GAME_MP_BOX, GameConst::GAME_MP_RPBOX,
  314. GameConst::GAME_MP_PERSONAL];
  315. if (in_array($data['classify'], $_mp_array)) {
  316. $_data = ['app_id' => $_obj->id];
  317. $_data['mini_app_id'] = $data['mp_id'];
  318. if (empty($_data['mini_app_id'])) {
  319. $_data['mini_app_id'] = 'test'.$_data['app_id'];
  320. }
  321. $_gm_mini_model = new GameMiniModel();
  322. $_mini_data = $_gm_mini_model->getDataByMpAppId($_data['mini_app_id']);
  323. if (!empty($_mini_data)) {
  324. $_app_id = $_mini_data['app_id'];
  325. $_mini_data['app_id'] = $_obj->id;
  326. $_gm_mini_model->updateData($_mini_data, $_app_id);
  327. } else {
  328. $_gm_mini_model->addData($_data);
  329. $_mc_model = new MpConfModel();
  330. $_data = $_mc_model->getDataByMpId($_data['mini_app_id']);
  331. if (empty($_data)) {
  332. $_mp_data['app_id'] = $_obj->id;
  333. $_mp_data['type'] = MpConfConst::MP_CONF_TYPE_6;
  334. $_mp_data['mp_id'] = $data['mp_id'];
  335. $_mp_data['wx_name'] = $data['name'];
  336. (new MpConfModel())->addData($_mp_data);
  337. }
  338. //盒子添加启动图
  339. $_mpbox_array = [GameConst::GAME_MP_BOX, GameConst::GAME_MP_RPBOX];
  340. if (in_array($data['classify'], $_mpbox_array)) {
  341. /* 添加广告列表_str */
  342. $_slide = [
  343. 'status' => SlideConst::SLIDE_STATUS_SHOW,
  344. 'code' => SlideConst::SLIDE_MP_SPLASH_IMAGE.$_obj->id, //code 固定前缀加盒子id
  345. 'name' => '小游戏盒子【'.$data['name'].'】闪屏图',
  346. 'remark' => '小游戏盒子【'.$data['name'].'】闪屏图',
  347. 'type_id' => SlideConst::SLIDE_TYPE_ONE_IMG,
  348. ];
  349. (new SlideModel())->addData($_slide);
  350. /* 添加广告列表_end */
  351. }
  352. }
  353. }
  354. return $_obj->id;
  355. } else {
  356. return false;
  357. }
  358. }
  359. /**
  360. * @return array
  361. */
  362. public function oaSdkColumn() {
  363. $_oa_sdk_column_arr = array(
  364. 'app_id' => 'app_id',
  365. 'gamename' => 'name',
  366. 'classify' => 'classify',
  367. 'gameflag' => 'en_abbr',
  368. 'create_time' => 'create_time',
  369. 'status' => 'status',
  370. 'pinyin' => 'en_name',
  371. 'initial' => 'en_abbr',
  372. 'game_version' => 'version',
  373. 'update_time' => 'update_time',
  374. 'teststatus' => 'teststatus',
  375. 'icon' => 'icon',
  376. 'target_cnt' => 'standard_mem_cnt',
  377. 'target_level' => 'standard_level',
  378. 'run_time' => 'run_time',
  379. 'parent_id' => 'parent_id',
  380. );
  381. return $_oa_sdk_column_arr;
  382. }
  383. /**
  384. * 游戏同步到oa
  385. *
  386. * @param int $id
  387. *
  388. * @return bool
  389. */
  390. public function addOaGame($id = 0) {
  391. if (!$id) {
  392. return true;
  393. }
  394. $_map = array();/* 避免删除 */
  395. $_map['id'] = $id;
  396. $_game_base = \think\Db::name($this->name)->where($_map)->find();
  397. if (empty($_game_base)) {
  398. \think\Log::write(
  399. $_game_base, 'error'
  400. );
  401. \think\Log::write(
  402. '避免删除', 'error'
  403. );
  404. return true;
  405. }
  406. $_oa_map = array();
  407. $_oa_map['app_id'] = $id;
  408. $_oa_game_info = \think\Db::name('oa_game')->where($_oa_map)->find();
  409. if (!empty($_oa_game_info)) {
  410. $_game_base['standard_mem_cnt'] = $_oa_game_info['standard_mem_cnt']; /* 达标人数 */
  411. $_game_base['standard_level'] = $_oa_game_info['standard_level'];/* 达标等级 */
  412. }
  413. $_v_map = array();
  414. $_v_map['app_id'] = $id;
  415. $_v_map['is_default'] = 2;
  416. $_game_base['version'] = \think\Db::name('game_version')->where($_v_map)->value('version');
  417. if (!$_game_base['version']) {
  418. $_game_base['version'] = 1;
  419. }
  420. $_game_base['app_id'] = $id;
  421. $_send_data = array();
  422. $_oa_sdk = $this->oaSdkColumn();
  423. foreach ($_oa_sdk as $k => $v) {
  424. if (isset($_game_base[$v])) {
  425. $_send_data[$k] = $_game_base[$v];
  426. }
  427. }
  428. $_re = \huolib\oa\OaGame::addOaGame($_send_data);
  429. if ($_re) {
  430. return $_re;
  431. }
  432. }
  433. /**
  434. * 更新游戏同步到oa
  435. *
  436. * @param int $app_id
  437. * @param array $data
  438. *
  439. * @return array|bool
  440. */
  441. public function updateOaGame($app_id = 0, $data = array()) {
  442. $_send_data = array();
  443. $_send_data['app_id'] = $app_id;
  444. $_oa_sdk = $this->oaSdkColumn();
  445. foreach ($_oa_sdk as $k => $v) {
  446. if (isset($data[$v])) {
  447. $_send_data[$k] = $data[$v];
  448. }
  449. }
  450. $_re = \huolib\oa\OaGame::updateOaGame($_send_data);
  451. if ($_re) {
  452. \think\Log::write($data, 'debug');
  453. \think\Log::write($_re, 'debug');
  454. }
  455. return $_re;
  456. }
  457. /**
  458. * 删除游戏 同步到oa
  459. *
  460. * @param int $app_id
  461. *
  462. *
  463. */
  464. public function deleteOaGame($app_id = 0) {
  465. $delete_data = array('app_id' => $app_id);
  466. $_re = \huolib\oa\OaGame::deleteOaGame($delete_data);
  467. if ($_re) {
  468. }
  469. }
  470. /**
  471. * 还原游戏 同步到oa
  472. *
  473. * @param int $app_id
  474. *
  475. *
  476. */
  477. public function restoreOaGame($app_id = 0) {
  478. $delete_data = array('app_id' => $app_id);
  479. $_re = \huolib\oa\OaGame::restoreOaGame($delete_data);
  480. if ($_re) {
  481. }
  482. }
  483. /**
  484. * 获取游戏列表
  485. *
  486. * @param array $fields
  487. * @param array $where
  488. *
  489. * @return false|\PDOStatement|string|\think\Collection
  490. * @throws \think\db\exception\DataNotFoundException
  491. * @throws \think\db\exception\ModelNotFoundException
  492. * @throws \think\exception\DbException
  493. */
  494. public function getGames($fields = [], $where = []) {
  495. $_model = [];
  496. if (!empty($fields)) {
  497. $_model = $this->field($fields);
  498. }
  499. if (!empty($where)) {
  500. $_model = $this->where($where);
  501. }
  502. return $_model->select();
  503. }
  504. public function getNameById($app_id = 0) {
  505. if (empty($app_id)) {
  506. return '';
  507. }
  508. $_map['id'] = $app_id;
  509. return $this->where($_map)->value('name');
  510. }
  511. /**
  512. * 更新游戏
  513. *
  514. * @param array $game_data 父游戏信息
  515. * @param string $app_id 子游戏ID
  516. *
  517. * @return bool
  518. */
  519. public function updateGame($game_data, $app_id) {
  520. $_map['id'] = $app_id;
  521. $_data = $game_data;
  522. $_rs = self::update($_data, $_map, true);
  523. if (false == $_rs) {
  524. return false;
  525. } else {
  526. Cache::clear($this->cache_tag);
  527. Cache::clear($this->list_tag);
  528. Cache::clear($this->agent_cache_tag);
  529. if (\huolib\oa\Oa::hasOa()) {
  530. $this->updateOaGame($app_id, $_data);
  531. }
  532. return true;
  533. }
  534. }
  535. /**
  536. * 通过游戏ID获取AppleId
  537. *
  538. * @param int $app_id
  539. *
  540. * @return mixed|string
  541. */
  542. public function getAppleIdById($app_id = 0) {
  543. $_data = $this->getInfoById($app_id);
  544. return get_val($_data, 'apple_id', '');
  545. }
  546. /**
  547. * 游戏ID名称对应表
  548. *
  549. * @param int $status 是否上线
  550. * @param int $is_delete 是否删除 2 删除
  551. * @param int $is_sdk 是否是SDK
  552. * @param int $classify 游戏平台
  553. * @param bool $game_flag
  554. *
  555. * @param bool $add_plat
  556. *
  557. * @param array $where
  558. * @param string $page
  559. *
  560. * @return array
  561. * @internal param bool $option
  562. */
  563. public function getIdNames(
  564. $status = 0,
  565. $is_delete = 0,
  566. $is_sdk = 0,
  567. $classify = 0,
  568. $game_flag = false,
  569. $add_plat = false,
  570. $where = [],
  571. $page = ''
  572. ) {
  573. $_map = $where;
  574. if (!empty($status)) {
  575. $_map['status'] = $status;
  576. }
  577. if (!empty($is_delete)) {
  578. $_map['is_delete'] = $is_delete;
  579. }
  580. if (!empty($is_sdk)) {
  581. $_map['is_sdk'] = $is_sdk;
  582. }
  583. $_sub_classify = substr($classify, 0, 1);
  584. if (!empty($classify)) {
  585. if (3 == $_sub_classify) {
  586. $_map['classify'] = [
  587. ['eq', 3],
  588. ['between', [300, 399]],
  589. 'or'
  590. ];
  591. } elseif (4 == $_sub_classify && 401 != $classify) {
  592. $_map['classify'] = [
  593. ['eq', 4],
  594. ['between', [400, 499]],
  595. 'or'
  596. ];
  597. } elseif (in_array($classify, [601, 602])) {
  598. $_map['classify'] = ['in', [601, 602]];
  599. } elseif (in_array($classify, [603])) {
  600. $_map['classify'] = ['in', [603]];
  601. } elseif (6 == $_sub_classify) {
  602. $_map['classify'] = [
  603. ['eq', 6],
  604. ['between', [604, 699]],
  605. 'or'
  606. ];
  607. } else {
  608. $_map['classify'] = $classify;
  609. }
  610. }
  611. if (empty($_map['id'])) {
  612. $_map['id'] = ['not in', ['100']];
  613. }
  614. $_tag = $this->cache_tag;
  615. $_cache_key = md5($_tag.json_encode($_map));
  616. $_field = 'name';
  617. if (true == $add_plat) {
  618. $_cache_key = 'plat_'.$_cache_key;
  619. $_field
  620. = "CONCAT(name,'-',CASE classify WHEN 3 THEN '安卓' WHEN 4 THEN 'IOS' WHEN 402 THEN 'IOS马甲' WHEN 5 THEN 'H5' WHEN 6 THEN '小游戏' WHEN 601 THEN '金币盒子' WHEN 602 THEN '红包盒子' WHEN 603 THEN '个人小程序' ELSE 'APPSTORE' END,CASE is_sdk WHEN 1 THEN '-CPS游戏' ELSE '' END) as name";
  621. }
  622. if ($game_flag) {
  623. $_group = "parent_id";
  624. $_games = $this->useGlobalScope(false)
  625. ->where($_map)
  626. ->cache($_cache_key, CommonConst::CONST_DAY_SECONDS, $_tag)
  627. ->group($_group)
  628. ->page($page)
  629. ->column($_field, 'id');
  630. } else {
  631. $_games = $this->useGlobalScope(false)
  632. ->where($_map)
  633. ->cache($_cache_key, CommonConst::CONST_DAY_SECONDS, $_tag)
  634. ->column($_field, 'id');
  635. }
  636. return $_games;
  637. }
  638. /**
  639. * 总计
  640. *
  641. * @return int
  642. */
  643. public function total() {
  644. return $this->count('0');
  645. }
  646. /**
  647. * 今天新增
  648. *
  649. * @return int
  650. */
  651. public function todayCount() {
  652. return $this->getDayAddedCount(strtotime('today'));
  653. }
  654. /**
  655. * 昨天新增
  656. *
  657. * @return int
  658. */
  659. public function yesterdayCount() {
  660. return $this->getDayAddedCount(strtotime('yesterday'));
  661. }
  662. /**
  663. * 一天新增
  664. *
  665. * @param int $time 时间戳,0点
  666. *
  667. * @return int
  668. */
  669. public function getDayAddedCount($time) {
  670. return $this->where('create_time', 'between', [$time, $time + CommonConst::CONST_DAY_SECONDS - 1])->count('0');
  671. }
  672. /**
  673. * 接入游戏数量
  674. *
  675. * @param array $map
  676. *
  677. * @return int
  678. */
  679. public function onlineCount($map = []) {
  680. $_map = $map;
  681. $_map['status'] = GameConst::GAME_STATUS_ON;
  682. $_map['is_delete'] = CommonConst::CONST_NOT_DELETE;
  683. return $this->where($_map)->count('0');
  684. }
  685. /**
  686. * 获取游戏AppID
  687. *
  688. * @param $name
  689. *
  690. * @return bool|mixed
  691. */
  692. public function getAppIdByName($name) {
  693. if (empty($name)) {
  694. return false;
  695. }
  696. return $this->where(['name' => $name])->value('id');
  697. }
  698. /* 实名认证添加 */
  699. /**
  700. * 通过游戏ID获取游戏实名认证状态
  701. *
  702. * @param int $app_id
  703. *
  704. * @return string
  705. */
  706. public function getIsAuthById($app_id = 0) {
  707. if (empty($app_id)) {
  708. return GameConst::GAME_IDENTIFY_IS_YES;
  709. }
  710. $_data = GameCache::ins()->getInfoByAppId($app_id);
  711. return get_val($_data, 'is_auth', GameConst::GAME_IDENTIFY_IS_NO);
  712. }
  713. /**
  714. * 根据where获取id
  715. *
  716. * @param $where
  717. *
  718. * @return array
  719. */
  720. public function getIdByWhere($where) {
  721. $_map = $where;
  722. return $this->where($_map)->value('id');
  723. }
  724. /**
  725. * 根据where获取id
  726. *
  727. * @param $where
  728. *
  729. * @return array
  730. */
  731. public function getIdsByWhere($where) {
  732. $_map = $where;
  733. return $this->useGlobalScope(false)->where($_map)->column('id');
  734. }
  735. /**
  736. * 根据ID获取关联游戏ID
  737. *
  738. * @param int $id 游戏ID
  739. *
  740. * @return int 0 表示无关联游戏
  741. */
  742. public function getLinkAppId($id) {
  743. $_data = GameCache::ins()->getInfoByAppId($id);
  744. $_parent_id = get_val($_data, 'parent_id', CommonConst::CONST_ZERO);
  745. if (empty($_parent_id)) {
  746. return 0;
  747. }
  748. $_map = [
  749. 'parent_id' => $_parent_id,
  750. ];
  751. $_ids = $this->getIdsByWhere($_map);
  752. $_cnt = count($_ids);
  753. if (CommonConst::CONST_ONE >= $_cnt) {
  754. return 0;
  755. }
  756. foreach ($_ids as $_id) {
  757. if ($_id != $id) {
  758. return $_id;
  759. }
  760. }
  761. return 0;
  762. }
  763. /**
  764. * 获取游戏名称是否存在
  765. *
  766. * @param array $where 查询条件
  767. *
  768. * @return int|string
  769. */
  770. public function getNameExist($where) {
  771. $_map = $where;
  772. $_cnt = $this->where($_map)->count();
  773. return $_cnt;
  774. }
  775. /**
  776. * 获取类型下的游戏ids
  777. *
  778. * @param $classify
  779. *
  780. * @return array
  781. */
  782. public function getIdsByClassify($classify) {
  783. $_map = ['classify' => $classify];
  784. return $this->getIdsByWhere($_map);
  785. }
  786. /**
  787. * 获取马甲包关联游戏ID
  788. *
  789. * @return bool|mixed
  790. */
  791. public function getMpVestReGameId() {
  792. $_map = ['apple_id' => ['>', 0]];
  793. $_tag = $this->cache_tag;
  794. $_cache_key = md5($_tag.json_encode($_map));
  795. return $this->where($_map)->group('apple_id')->cache($_cache_key, CommonConst::CONST_5_MINUTE_SECONDS)->column(
  796. 'apple_id'
  797. );
  798. }
  799. public function linkgame() {
  800. return $this->belongsTo('huo\model\game\GameModel', 'apple_id');
  801. }
  802. /**
  803. * 通过app_id获取ids,父子孙级
  804. * @param int $app_id
  805. * @return array
  806. */
  807. public function getGameIds(int $app_id): array
  808. {
  809. $ids = [$app_id];
  810. $_data = $this->getInfoById($app_id);
  811. if ($_data['classify'] == 5) { // 判断是否父游戏
  812. $son_id = $this->getLinkAppId($_data['id']);
  813. if ($son_id) $ids = array_merge($ids, [$son_id]);
  814. $child_ids = $this->getAppIdsByAppleId($son_id);
  815. if ($child_ids) {
  816. $ids = array_merge($ids, $child_ids);
  817. }
  818. }
  819. return $ids;
  820. }
  821. /**
  822. * 提供apple_id获取IDS
  823. * @param $apple_id
  824. * @return array|int|string
  825. */
  826. public function getAppIdsByAppleId($apple_id) {
  827. if (empty($apple_id)) return 0;
  828. $_app_id = $this->cache('app_ids' . $apple_id, CommonConst::CONST_DAY_SECONDS, $this->cache_tag)
  829. ->where('apple_id', $apple_id)
  830. ->column('id');
  831. if (empty($_app_id)) return 0;
  832. return $_app_id;
  833. }
  834. }