MemberLogic.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. /**
  3. * MemberModel.php UTF-8
  4. * 玩家Model
  5. *
  6. * @date : 2017/11/18 17:18
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\member;
  13. use ban\BanConst;
  14. use ban\model\IpBanModel;
  15. use huo\model\common\CommonModel;
  16. use huo\model\member\MemberModel;
  17. use huo\model\member\MemoauthModel;
  18. use huo\model\user\UserModel;
  19. use huolib\constant\CommonConst;
  20. use huolib\constant\MemConst;
  21. use huolib\constant\OrderConst;
  22. use huolib\status\MemberStatus;
  23. use huolib\tool\StrUtils;
  24. use think\Exception;
  25. class MemberLogic extends CommonModel {
  26. /**
  27. * @param $username
  28. *
  29. * @return array|bool
  30. */
  31. public function getIdByName($username) {
  32. $_map['username'] = $username;
  33. $_mem_id = (new MemberModel())->where($_map)->value('id');
  34. if (false === $_mem_id) {
  35. return false;
  36. }
  37. if (empty($_mem_id)) {
  38. return 0;
  39. }
  40. return $_mem_id;
  41. }
  42. public function getNameById($id) {
  43. $_map['id'] = $id;
  44. $_username = (new MemberModel())->where($_map)->value('username');
  45. if (false === $_username) {
  46. return false;
  47. }
  48. if (empty($_username)) {
  49. return '';
  50. }
  51. return $_username;
  52. }
  53. /**
  54. * @param $mobile
  55. *
  56. * @return array|bool
  57. */
  58. public function getIdByMobile($mobile) {
  59. $_map['reg_mobile'] = $mobile;
  60. $_mem_id = (new MemberModel())->where($_map)->value('id');
  61. if (false === $_mem_id) {
  62. return false;
  63. }
  64. if (empty($_mem_id)) {
  65. return 0;
  66. }
  67. return $_mem_id;
  68. }
  69. /**
  70. * 根据玩家账号模糊查找玩家id
  71. *
  72. * @param $username
  73. *
  74. * @return mixed
  75. */
  76. public function getIdsByUsername($username) {
  77. $_map['username'] = ['like', ["%$username%"]];
  78. $_mem_ids = (new MemberModel())->where($_map)->column('id');
  79. return $_mem_ids;
  80. }
  81. public function getIdsByAgentId($agent_id, $where = []) {
  82. $_map['agent_id'] = $agent_id;
  83. $_map = array_merge($_map, $where);
  84. $_mem_ids = (new MemberModel())->where($_map)->column('id');
  85. return $_mem_ids;
  86. }
  87. /**
  88. * 通过玩家ID获取玩家信息
  89. *
  90. * @param string $mem_id
  91. *
  92. * @return array|bool
  93. */
  94. public function getInfoById($mem_id) {
  95. $_map['id'] = $mem_id;
  96. try {
  97. $_info = (new MemberModel())->where($_map)->find();
  98. if (false === $_info) {
  99. return false;
  100. }
  101. if (is_object($_info)) {
  102. return $_info->toArray();
  103. } else {
  104. return $_info;
  105. }
  106. } catch (Exception $_e) {
  107. return false;
  108. }
  109. }
  110. /**
  111. * 更新玩家信息
  112. *
  113. * @param string $mem_id
  114. * @param array $mem_data
  115. *
  116. * @return bool
  117. */
  118. public function updateMem($mem_id, $mem_data) {
  119. if (empty($mem_id) || empty($mem_data)) {
  120. return false;
  121. }
  122. $_map['id'] = $mem_id;
  123. if (isset($mem_data['password']) && cmf_pwd_is_encrypt($mem_data['password'])) {
  124. unset($mem_data['password']);
  125. }
  126. if (isset($mem_data['pay_pwd']) && cmf_pwd_is_encrypt($mem_data['pay_pwd'])) {
  127. unset($mem_data['pay_pwd']);
  128. }
  129. $_rs = MemberModel::update($mem_data, $_map, true);
  130. if (false === $_rs) {
  131. return false;
  132. }
  133. return true;
  134. }
  135. /**
  136. * 通过手机获取信息
  137. *
  138. * @param $mobile
  139. *
  140. * @return array|bool|false|\PDOStatement|string|\think\Model
  141. */
  142. public function getInfoByMobile($mobile) {
  143. $_map['mobile'] = $mobile;
  144. try {
  145. $_info = (new MemberModel())->where($_map)->find();
  146. if (false === $_info) {
  147. return false;
  148. }
  149. if (is_object($_info)) {
  150. return $_info->toArray();
  151. } else {
  152. return $_info;
  153. }
  154. } catch (Exception $_e) {
  155. return false;
  156. }
  157. }
  158. /**
  159. * 转换查询条件
  160. *
  161. * @param array $param
  162. *
  163. * @return array
  164. */
  165. public function getWhere($param = []) {
  166. $_map = [];
  167. if (!empty($param['start_time']) && !empty($param['end_time'])) {
  168. $_map['create_time']
  169. = [
  170. 'between',
  171. [
  172. strtotime($param['start_time']),
  173. CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
  174. ]
  175. ];
  176. } elseif (!empty($param['start_time'])) {
  177. $_map['create_time'] = ['egt', strtotime($param['start_time'])];
  178. } elseif (!empty($param['end_time'])) {
  179. $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  180. }
  181. if (!empty($param['username'])) {
  182. $_map['username'] = ['like', $param['username'].'%'];
  183. }
  184. if (!empty($param['nickname'])) {
  185. $_map['nickname'] = ['like', $param['nickname'].'%'] ;
  186. }
  187. if (!empty($param['mem_name'])) {
  188. $_map['username'] = $param['mem_name'];
  189. }
  190. if (!empty($param['mem_id'])) {
  191. $_map['id'] = $param['mem_id'];
  192. }
  193. if (!empty($param['mobile'])) {
  194. $_map['mobile'] = $param['mobile'];
  195. }
  196. if (!empty($param['app_id'])) {
  197. $_map['app_id'] = $param['app_id'];
  198. }
  199. if (!empty($param['device_id'])) {
  200. $_map['device_id'] = $param['device_id'];
  201. }
  202. if (!empty($param['ip'])) {
  203. $_map['reg_ip'] = $param['ip'];
  204. }
  205. if (!empty($param['agent_id'])) {
  206. $_map['agent_id'] = $param['agent_id'];
  207. if ('-1' == $_map['agent_id']) {
  208. $_map['agent_id'] = 0;
  209. }
  210. // 数组类型官方渠道筛选
  211. if (is_array($param['agent_id']) && !empty($param['agent_id'][1]) &&
  212. is_array($param['agent_id'][1]) &&
  213. in_array('-1', $param['agent_id'][1])) {
  214. $_map['agent_id'] = 0;
  215. }
  216. }
  217. if (!empty($param['parent'])) {
  218. $_mem_id = (new MemberModel())->where(['username' => $param['parent']])->value('id');
  219. $_map['parent_mem_id'] = $_mem_id;
  220. }
  221. if (!empty($param['sub_agent_id'])) {
  222. $_map['agent_id'] = $param['sub_agent_id'];
  223. }
  224. if (!empty($param['game_id'])) {
  225. $_map['app_id'] = $param['game_id'];
  226. }
  227. if (!empty($param['status'])) {
  228. $_map['status'] = $param['status'];
  229. }
  230. if (!empty($param['ig_from_device'])) {
  231. $_map['from_device'] = $param['ig_from_device'];
  232. }
  233. if (!empty($param['parent_mem_id'])) {
  234. $_map['parent_mem_id'] = $param['parent_mem_id'];
  235. }
  236. if (!empty($param['is_real_name'])) {
  237. $_map['real_name'] = ['eq', ''];
  238. if (MemConst::REAL_NAME_Y == $param['is_real_name']) {
  239. $_map['real_name'] = ['neq', ''];
  240. }
  241. }
  242. if (!empty($param['is_bind_mobile'])) {
  243. $_map['mobile'] = ['eq', ''];
  244. if (MemConst::BIND_MOBILE_Y == $param['is_bind_mobile']) {
  245. $_map['mobile'] = ['neq', ''];
  246. }
  247. }
  248. if (!empty($param['mem_agent_id'])) {
  249. $_mem_id = (new UserModel())->getMemIdById($param['mem_agent_id']);
  250. if (!empty($_mem_id)) {
  251. $_map['id'] = $_mem_id;
  252. }
  253. }
  254. if (!empty($param['is_switch'])) {
  255. $_map['is_switch'] = $param['is_switch'];
  256. }
  257. if (!empty($param['switch_time'])) {
  258. if ($param['switch_time'] == OrderConst::PAY_SWITCH_NO) {
  259. $_map['switch_time'] = 0;
  260. } else {
  261. $_map['switch_time'] = ['gt', 0];
  262. }
  263. }
  264. if (!empty($param['switch_money'])) {
  265. if ($param['switch_money'] == OrderConst::PAY_SWITCH_NO) {
  266. $_map['switch_money'] = 0;
  267. } else {
  268. $_map['switch_money'] = ['gt', 0];
  269. }
  270. }
  271. return $_map;
  272. }
  273. /**
  274. * @param array $where
  275. * @param string $page
  276. * @param string $order
  277. *
  278. * @param array $field
  279. *
  280. * @param bool $_is_admin 是否后台获取,后台获取不限制 status
  281. *
  282. * @return int| array
  283. * @throws \think\db\exception\DataNotFoundException
  284. * @throws \think\db\exception\ModelNotFoundException
  285. * @throws \think\exception\DbException
  286. */
  287. public function getList($where = [], $page = '1,10', $order = '-create_time', $field = [], $_is_admin = false) {
  288. $_is_agent = get_val($where, 'is_agent', false);
  289. $_map = $this->getWhere($where);
  290. if (false === $_is_admin) {
  291. $_map['status'] = 2;
  292. }
  293. if (!empty($where['is_recharged'])) {
  294. if ($where['is_recharged'] == CommonConst::STATUS_YES) {
  295. $_map['ext.sum_money'] = ['>', 0];
  296. } else {
  297. $_map['ext.sum_money'] = ['=', 0];
  298. }
  299. }
  300. $_mem_model = new MemberModel();
  301. $_count = $_mem_model->with('ext,agent,game,mem')->where($_map)->count();
  302. if (empty($_count)) {
  303. return MemberStatus::CNT_IS_ZERO;
  304. }
  305. $_base_field = ['id', 'username', 'nickname', 'parent_mem_id', 'app_id', 'create_time', 'last_login_time',
  306. 'switch_time', 'switch_money', 'real_name', 'id_card', 'alipay_account','avatar'];
  307. $_field = array_merge($_base_field, $field);
  308. $_order = $this->orderFilter($order);
  309. $_members = $_mem_model->with('ext,agent,game,mem')
  310. ->field($_field)
  311. ->where($_map)
  312. ->order($_order)
  313. ->page($page)
  314. ->select();
  315. if (is_object($_members)) {
  316. $_members = $_members->toArray();
  317. }
  318. $_list = [];
  319. $_ipban_model = new IpBanModel();
  320. foreach ($_members as $_k => $_v) {
  321. $_data = [];
  322. $_data['id'] = $_v['id'];
  323. $_data['mem_id'] = $_v['id'];
  324. $_data['username'] = $_v['username'];
  325. $_data['nickname'] = $_v['nickname'];
  326. $_data['agent_id'] = !empty($_v['parent_mem_id']) ? 0 : $_v['agent_id'];
  327. $_data['agent_name'] = empty($_v['parent_mem_id']) && !empty($_v['agent']['user_nicename'])
  328. ? $_v['agent']['user_login'].'|'.$_v['agent']['user_nicename'] : '官方渠道';
  329. $_data['role_id'] = !empty($_v['agent']['role_id']) ? $_v['agent']['role_id'] : 0;
  330. $_data['app_id'] = $_v['app_id'];
  331. $_data['game_name'] = $_v['game']['name'];
  332. $_data['gamename'] = !empty($_v['game']['name']) ? $_v['game']['name'] : '';
  333. $_data['create_time'] = $_v['create_time'];
  334. $_data['last_login_time'] = $_v['last_login_time'];
  335. $_data['device_id'] = $_v['device_id'];
  336. $_data['status'] = $_v['status'];
  337. $_data['last_money'] = $_v['ext']['last_money'];
  338. $_data['sum_money'] = $_v['ext']['sum_money'];
  339. $_data['reg_ip'] = $_v['reg_ip'];
  340. $_data['from_device'] = MemConst::getFromDeviceMsg($_v['from_device']);
  341. $_data['mobile'] = $_v['mobile'];
  342. $_data['alipay_account'] = $_v['alipay_account'];
  343. if ($_is_agent) {
  344. $_data['mobile'] = StrUtils::encryptPhone($_v['mobile']);
  345. $_data['alipay_account'] = StrUtils::encryptName($_v['alipay_account']);
  346. }
  347. $_data['real_name'] = StrUtils::encryptName($_v['real_name']);
  348. $_data['id_card'] = StrUtils::encryptIdCard($_v['id_card']);
  349. $_data['parent_mem_id'] = $_v['parent_mem_id'];
  350. $_data['parent'] = !empty($_v['mem']['username']) ? $_v['mem']['username'] : '';
  351. $_data['parent_nickname'] = !empty($_v['mem']['nickname']) ? $_v['mem']['nickname'] : '';
  352. $_data['switch_time'] = $_v['switch_time'];
  353. $_data['switch_money'] = $_v['switch_money'];
  354. $_data['avatar'] = $_v['avatar'];
  355. /* 判断ip 是否被封*/
  356. if (!empty($_data['reg_ip'])) {
  357. $_ip_ban = $_ipban_model->isBan($_data['reg_ip']);
  358. $_data['ip_ban'] = $_ip_ban ? BanConst::IS_BAN : BanConst::NO_BAN;
  359. }
  360. $_list[] = $_data;
  361. }
  362. if (empty($_members)) {
  363. $_list = null;
  364. }
  365. $_rdata['count'] = $_count;
  366. $_rdata['list'] = $_list;
  367. return $_rdata;
  368. }
  369. /**
  370. * 获取玩家余额列表
  371. *
  372. * @param array $param
  373. * @param string $page
  374. * @param string $order
  375. *
  376. * @return array
  377. */
  378. public function getRemainList($param = [], $page = '1,10', $order = '-create_time') {
  379. $_map = $this->getWhere($param);
  380. $_field = [];
  381. return $this->getExtList($_field, $_map, $page, $order);
  382. }
  383. /****
  384. * @throws
  385. */
  386. public function getExtList($field = [], $where, $page = '1,10', $order = '-create_time') {
  387. $_map = $where;
  388. $_model = new MemberModel();
  389. $_count = $_model->alias('member_model')->where($_map)->count();
  390. if (empty($_count)) {
  391. return [
  392. 'count' => 0,
  393. 'list' => []
  394. ];
  395. }
  396. $_field = $field;
  397. if (empty($field)) {
  398. $_field = [];
  399. }
  400. $_order = $_model->orderFilter($order);
  401. $_datas = $_model
  402. ->alias('member_model')
  403. ->with('ext')
  404. ->with('agent')
  405. ->where($where)
  406. ->field($_field)
  407. ->order($_order)
  408. ->page($page)
  409. ->select();
  410. if (is_object($_datas)) {
  411. $_datas = $_datas->toArray();
  412. }
  413. if (empty($_datas)) {
  414. return [
  415. 'count' => $_count,
  416. 'list' => []
  417. ];
  418. }
  419. if (empty($_datas)) {
  420. return [
  421. 'count' => $_count,
  422. 'list' => []
  423. ];
  424. }
  425. return [
  426. 'count' => $_count,
  427. 'list' => $_datas
  428. ];
  429. }
  430. /**
  431. * 通过账号查询手机号邮箱
  432. *
  433. * @param $username
  434. *
  435. * @return array|bool
  436. * @throws Exception
  437. * @throws \think\db\exception\DataNotFoundException
  438. * @throws \think\db\exception\ModelNotFoundException
  439. * @throws \think\exception\DbException
  440. */
  441. public function getMobileEmailByName($username) {
  442. $_map['username'] = $username;
  443. $_data = (new MemberModel())->where($_map)->field('email,mobile')->find();
  444. if (is_object($_data)) {
  445. $_data = $_data->toArray();
  446. }
  447. if (empty($_data)) {
  448. $_data = [
  449. 'mobile' => '',
  450. 'email' => ''
  451. ];
  452. }
  453. return $_data;
  454. }
  455. /**
  456. * 获取玩家第三方账户信息
  457. *
  458. * @param $mem_id
  459. *
  460. * @return array|false|\PDOStatement|string|\think\Collection
  461. */
  462. public function getMemOauthList($mem_id) {
  463. if (empty($mem_id)) {
  464. return [];
  465. }
  466. $_map = ['mem_id' => $mem_id];
  467. $_field = ['id,`from`,conf_id,openid,unionid'];
  468. $_list = (new MemoauthModel())->where($_map)->field($_field)->select();
  469. if (empty($_list)) {
  470. return [];
  471. }
  472. if (is_object($_list)) {
  473. $_list = $_list->toArray();
  474. }
  475. return $_list;
  476. }
  477. }