GameLogic.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. /**
  3. * GameLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2018/1/23 14:54
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : linjiebin <ljb@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace web\pc\logic;
  13. use huo\model\common\CommonModel;
  14. use huo\model\game\GameModel as huoGameModel;
  15. use huo\model\game\CategoryModel;
  16. use huo\model\game\GiftModel;
  17. use huo\model\game\GameclassifyModel;
  18. use huo\model\game\GamecategoryModel;
  19. use huolib\constant\CommonConst;
  20. use huolib\constant\GameConst;
  21. class GameLogic extends CommonModel {
  22. /**
  23. * @param array $where
  24. * @param string $page
  25. * @param string $order
  26. *
  27. * @return mixed
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. * @throws \think\exception\DbException
  31. */
  32. public function getList($where = [], $page = '10', $order = '') {
  33. $map['status'] = GameConst::GAME_STATUS_ON;
  34. $map['is_delete'] = CommonConst::CONST_NOT_DELETE;
  35. $map['classify'] = ['neq', GameConst::GAME_H5];
  36. if (isset($where['id']) && !empty($where['id'])) {
  37. $map['id'] = $where['id'];
  38. }
  39. if (isset($where['type']) && !empty($where['type'])) {
  40. $_ids = $this->strToArr($where['type']);
  41. foreach ($_ids as $_k => $_v) {
  42. $_ids[$_k] = intval($_v);
  43. }
  44. $_find_category = CategoryModel::whereIn('id', $_ids)->column('id');
  45. if (empty($_find_category)) {
  46. return [
  47. 'count' => 0,
  48. 'list' => []
  49. ];
  50. }
  51. $_app_ids = GamecategoryModel::whereIn('cate_id', $_find_category)->column('app_id');
  52. $map['id'] = ['in', $_app_ids];
  53. }
  54. if (isset($where['classify']) && !empty($where['classify'])) {
  55. $map['classify'] = $where['classify'];
  56. }
  57. if (isset($where['name']) && !empty($where['name'])) {
  58. $map['name'] = ['like', "%{$where['name']}%"];
  59. }
  60. if (isset($where['fine']) && !empty($where['fine'])) {
  61. $map['fine_order'] = ['neq', 0];
  62. }
  63. if (isset($where['hot']) && !empty($where['hot'])) {
  64. $map['hot_order'] = ['neq', 0];
  65. }
  66. $_count = huoGameModel::where($map)->count();
  67. if (empty($_count)) {
  68. return [
  69. 'count' => 0,
  70. 'list' => []
  71. ];
  72. }
  73. $_order = $this->orderFilter($order);
  74. // $_games = huoGameModel::with('ext')->with('gv')->where($map)->order($_order)->paginate($page);
  75. $_games = huoGameModel::with('ext')->with('gv')->where($map)->order($_order)->page($page)
  76. ->select();//->toArray()
  77. // $_page = $_games->render();
  78. $_list = [];
  79. $_cate_model = new CategoryModel();
  80. foreach ($_games as $_game) {
  81. $_data = null;
  82. $_data['gameid'] = $_game['id'];
  83. $_data['icon'] = $_game['icon'];
  84. $_data['gamename'] = $_game['name'];
  85. $_data['type'] = $_cate_model->getNameByIds($_game['category']);
  86. $_data['size'] = empty($_game['gv'][0]['size']) ? 0 : $_game['gv'][0]['size'];
  87. $_data['down_cnt'] = empty($_game['ext']['down_cnt']) ? 0 : $_game['ext']['down_cnt'];
  88. $_data['star_cnt'] = empty($_game['ext']['star_cnt']) ? 0 : $_game['ext']['star_cnt'];
  89. $_data['hot'] = empty($_game['hot_order']) ? 1 : 2; /* 2热门1普通 */
  90. $_data['down_url'] = isset($_game['gv'][0]['package_url']) ? $_game['gv'][0]['package_url'] : '';
  91. $_data['gift_cnt'] = $this->getGiftCnt($_game['id']);
  92. $_data['package_name'] = $_game['package_name'];
  93. $_data['classify'] = $_game['classify'];
  94. $_data['classify_name'] = $this->getClassifyName($_game['classify']);
  95. $_data['publicity'] = $_game['publicity'];
  96. $_data['hot_image'] = '';
  97. // $_data['hot_image'] = $this->getImage($_game['hot_image']);
  98. // $_data['fine_image'] = $this->getImage($_game['fine_image']);
  99. $_list[] = $_data;
  100. }
  101. $_rdata['count'] = $_count;
  102. $_rdata['list'] = $_list;
  103. return $_rdata;
  104. }
  105. /**
  106. * 获取分类列表
  107. * @param $_cates
  108. * @param $page
  109. * @param $_order
  110. *
  111. * @return array|mixed
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. * @throws \think\exception\DbException
  115. */
  116. public function getCateList($_cates, $page, $_order) {
  117. if (empty($_cates)) {
  118. return [
  119. 'count' => 0,
  120. 'list' => []
  121. ];
  122. }
  123. // 设置id,ids
  124. if (!empty($_cates)) {
  125. $_ids = $this->strToArr($_cates);
  126. foreach ($_ids as $_k => $_v) {
  127. $_ids[$_k] = intval($_v);
  128. }
  129. }
  130. $_find_category = CategoryModel::whereIn('id', $_ids)->column('id');
  131. if (empty($_find_category)) {
  132. return [
  133. 'count' => 0,
  134. 'list' => []
  135. ];
  136. }
  137. $_app_ids = GamecategoryModel::whereIn('cate_id', $_find_category)->column('app_id');
  138. $_map['id'] = ['in', $_app_ids];
  139. $_param['page'] = $page;
  140. $_param['order'] = $_order;
  141. return $this->getList($_map, $page, $_order);
  142. }
  143. /**
  144. * 根据游戏获取礼包数量
  145. *
  146. * @param int $app_id
  147. *
  148. * @return int|string
  149. */
  150. public function getGiftCnt($app_id = 0) {
  151. $_map['remain_cnt'] = ['gt', 0];
  152. $_map['end_time'] = ['gt', time()];
  153. $_map['app_id'] = $app_id;
  154. $_cnt = GiftModel::where($_map)->count();
  155. if (empty($_cnt)) {
  156. return 0;
  157. }
  158. return $_cnt;
  159. }
  160. /**
  161. * 获取游戏详情
  162. * @param $where
  163. * @param string $field
  164. *
  165. * @return mixed
  166. * @throws \think\db\exception\DataNotFoundException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. * @throws \think\exception\DbException
  169. */
  170. public function getDetail($where, $field = '') {
  171. $_game = huoGameModel::with('ext')->with('gv')->field($field)->where($where)->find();
  172. $_cate_model = new CategoryModel();
  173. $_gift_class = new GiftLogic();
  174. $_data['gameid'] = $_game['id'];
  175. $_data['icon'] = $_game['icon'];
  176. $_data['gamename'] = $_game['name'];
  177. $_data['type'] = $_cate_model->getNameByIds($_game['category']);
  178. $_data['category'] = $_game['category'];
  179. $_data['size'] = isset($_game['gv'][0]['size']) ? $_game['gv'][0]['size'] : '';
  180. $_data['down_cnt'] = empty($_game['ext']['down_cnt']) ? 0 : $_game['ext']['down_cnt'];
  181. $_data['star_cnt'] = empty($_game['ext']['star_cnt']) ? 0 : $_game['ext']['star_cnt'];
  182. $_data['hot'] = empty($_game['hot_order']) ? 1 : 2; /* 2热门1普通 */
  183. $_data['down_url'] = isset($_game['gv'][0]['package_url']) ? $_game['gv'][0]['package_url'] : '';
  184. // $_data['down_url'] = url('v8/game/down',['gameid'=>$_game['id']]);
  185. $_data['gift_cnt'] = $this->getGiftCnt($_game['id']);
  186. $_data['gift_list'] = $_gift_class->getGifts(0, ['app_id' => $_game['id']], '1,4');
  187. $_data['package_name'] = $_game['package_name'];
  188. $_data['desc'] = $_game['description'];
  189. $_data['run_time'] = $_game['run_time'];
  190. $_data['language'] = $_game['language'];
  191. $_data['publicity'] = $_game['publicity'];
  192. $_data['classify'] = $_game['classify'];
  193. $_data['classify_name'] = $this->getClassifyName($_game['classify']);
  194. $_data['image'] = $this->getImages($_game['image']);
  195. return $_data;
  196. }
  197. public function getImages($value) {
  198. $_images = $value;
  199. if (!empty($_images)) {
  200. foreach ($_images as $_key => $_image) {
  201. $_images[$_key] = cmf_get_image_url($_image['url']);
  202. }
  203. }
  204. return $_images;
  205. }
  206. public function getImage($value) {
  207. $_images = $value;
  208. if (!empty($_images)) {
  209. $_images = cmf_get_image_url($_images);
  210. }
  211. return $_images;
  212. }
  213. /**
  214. * 获取类型
  215. * @param array $where
  216. * @param string $page
  217. * @param string $order
  218. *
  219. * @return mixed
  220. * @throws \think\db\exception\DataNotFoundException
  221. * @throws \think\db\exception\ModelNotFoundException
  222. * @throws \think\exception\DbException
  223. */
  224. public function getCategory($where = [], $page = '1,10', $order = '') {
  225. $_cate_model = new CategoryModel();
  226. if (!empty($where['parent_id'])) {
  227. $_datas = $_cate_model->getList($where['parent_id'], $order);
  228. } else {
  229. $_datas = $_cate_model->getList(0, $order);
  230. }
  231. $_count = count($_datas);
  232. if (empty($_count)) {
  233. $_rdata['count'] = 0;
  234. $_rdata['list'] = [];
  235. } else {
  236. $_rdata['count'] = $_count;
  237. $_rdata['list'] = $_datas;
  238. }
  239. return $_rdata;
  240. }
  241. public function getClassifyName($classify) {
  242. $_map['id'] = $classify;
  243. $_name = GameclassifyModel::where($_map)->value('name');
  244. return $_name;
  245. }
  246. public function gamePlatfromClass() {
  247. $_rdata = [
  248. GameConst::GAME_ANDROID => 'Android',
  249. GameConst::GAME_IOS => 'IOS',
  250. ];
  251. // $_map['status'] = 2;
  252. // $_rdata = GameclassifyModel::where($_map)->column('name', 'id');
  253. return $_rdata;
  254. }
  255. public function getSimilarList($app_id = 0, $_cates, $page, $_order) {
  256. if ($app_id == 0) {
  257. $this->getCateList($_cates, $page, $_order);
  258. }
  259. if (empty($_cates)) {
  260. return [
  261. 'count' => 0,
  262. 'list' => []
  263. ];
  264. }
  265. // 设置id,ids
  266. if (!empty($_cates)) {
  267. $_ids = $this->strToArr($_cates);
  268. foreach ($_ids as $_k => $_v) {
  269. $_ids[$_k] = intval($_v);
  270. }
  271. }
  272. $_find_category = CategoryModel::whereIn('id', $_ids)->column('id');
  273. if (empty($_find_category)) {
  274. return [
  275. 'count' => 0,
  276. 'list' => []
  277. ];
  278. }
  279. $_app_ids = GamecategoryModel::whereIn('cate_id', $_find_category)->group('app_id')->column('app_id');
  280. foreach ($_app_ids as $_k => $_v) {
  281. if ($_v == $app_id) {
  282. unset($_app_ids[$_k]);
  283. }
  284. }
  285. if (empty($_app_ids)) {
  286. return [
  287. 'count' => 0,
  288. 'list' => []
  289. ];
  290. }
  291. $_map['id'] = ['in', $_app_ids];
  292. $_param['page'] = $page;
  293. $_param['order'] = $_order;
  294. return $this->getList($_map, $page, $_order);
  295. }
  296. }