123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- <?php
- /**
- * MemberModel.php UTF-8
- * 玩家Model
- *
- * @date : 2017/11/18 17:18
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\member;
- use ban\BanConst;
- use ban\model\IpBanModel;
- use huo\model\common\CommonModel;
- use huo\model\member\MemberModel;
- use huo\model\member\MemoauthModel;
- use huo\model\user\UserModel;
- use huolib\constant\CommonConst;
- use huolib\constant\MemConst;
- use huolib\constant\OrderConst;
- use huolib\status\MemberStatus;
- use huolib\tool\StrUtils;
- use think\Exception;
- class MemberLogic extends CommonModel {
- /**
- * @param $username
- *
- * @return array|bool
- */
- public function getIdByName($username) {
- $_map['username'] = $username;
- $_mem_id = (new MemberModel())->where($_map)->value('id');
- if (false === $_mem_id) {
- return false;
- }
- if (empty($_mem_id)) {
- return 0;
- }
- return $_mem_id;
- }
- public function getNameById($id) {
- $_map['id'] = $id;
- $_username = (new MemberModel())->where($_map)->value('username');
- if (false === $_username) {
- return false;
- }
- if (empty($_username)) {
- return '';
- }
- return $_username;
- }
- /**
- * @param $mobile
- *
- * @return array|bool
- */
- public function getIdByMobile($mobile) {
- $_map['reg_mobile'] = $mobile;
- $_mem_id = (new MemberModel())->where($_map)->value('id');
- if (false === $_mem_id) {
- return false;
- }
- if (empty($_mem_id)) {
- return 0;
- }
- return $_mem_id;
- }
- /**
- * 根据玩家账号模糊查找玩家id
- *
- * @param $username
- *
- * @return mixed
- */
- public function getIdsByUsername($username) {
- $_map['username'] = ['like', ["%$username%"]];
- $_mem_ids = (new MemberModel())->where($_map)->column('id');
- return $_mem_ids;
- }
- public function getIdsByAgentId($agent_id, $where = []) {
- $_map['agent_id'] = $agent_id;
- $_map = array_merge($_map, $where);
- $_mem_ids = (new MemberModel())->where($_map)->column('id');
- return $_mem_ids;
- }
- /**
- * 通过玩家ID获取玩家信息
- *
- * @param string $mem_id
- *
- * @return array|bool
- */
- public function getInfoById($mem_id) {
- $_map['id'] = $mem_id;
- try {
- $_info = (new MemberModel())->where($_map)->find();
- if (false === $_info) {
- return false;
- }
- if (is_object($_info)) {
- return $_info->toArray();
- } else {
- return $_info;
- }
- } catch (Exception $_e) {
- return false;
- }
- }
- /**
- * 更新玩家信息
- *
- * @param string $mem_id
- * @param array $mem_data
- *
- * @return bool
- */
- public function updateMem($mem_id, $mem_data) {
- if (empty($mem_id) || empty($mem_data)) {
- return false;
- }
- $_map['id'] = $mem_id;
- if (isset($mem_data['password']) && cmf_pwd_is_encrypt($mem_data['password'])) {
- unset($mem_data['password']);
- }
- if (isset($mem_data['pay_pwd']) && cmf_pwd_is_encrypt($mem_data['pay_pwd'])) {
- unset($mem_data['pay_pwd']);
- }
- $_rs = MemberModel::update($mem_data, $_map, true);
- if (false === $_rs) {
- return false;
- }
- return true;
- }
- /**
- * 通过手机获取信息
- *
- * @param $mobile
- *
- * @return array|bool|false|\PDOStatement|string|\think\Model
- */
- public function getInfoByMobile($mobile) {
- $_map['mobile'] = $mobile;
- try {
- $_info = (new MemberModel())->where($_map)->find();
- if (false === $_info) {
- return false;
- }
- if (is_object($_info)) {
- return $_info->toArray();
- } else {
- return $_info;
- }
- } catch (Exception $_e) {
- return false;
- }
- }
- /**
- * 转换查询条件
- *
- * @param array $param
- *
- * @return array
- */
- public function getWhere($param = []) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['create_time']
- = [
- 'between',
- [
- strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
- ]
- ];
- } elseif (!empty($param['start_time'])) {
- $_map['create_time'] = ['egt', strtotime($param['start_time'])];
- } elseif (!empty($param['end_time'])) {
- $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($param['username'])) {
- $_map['username'] = ['like', $param['username'].'%'];
- }
- if (!empty($param['nickname'])) {
- $_map['nickname'] = ['like', $param['nickname'].'%'] ;
- }
- if (!empty($param['mem_name'])) {
- $_map['username'] = $param['mem_name'];
- }
- if (!empty($param['mem_id'])) {
- $_map['id'] = $param['mem_id'];
- }
- if (!empty($param['mobile'])) {
- $_map['mobile'] = $param['mobile'];
- }
- if (!empty($param['app_id'])) {
- $_map['app_id'] = $param['app_id'];
- }
- if (!empty($param['device_id'])) {
- $_map['device_id'] = $param['device_id'];
- }
- if (!empty($param['ip'])) {
- $_map['reg_ip'] = $param['ip'];
- }
- if (!empty($param['agent_id'])) {
- $_map['agent_id'] = $param['agent_id'];
- if ('-1' == $_map['agent_id']) {
- $_map['agent_id'] = 0;
- }
- // 数组类型官方渠道筛选
- if (is_array($param['agent_id']) && !empty($param['agent_id'][1]) &&
- is_array($param['agent_id'][1]) &&
- in_array('-1', $param['agent_id'][1])) {
- $_map['agent_id'] = 0;
- }
- }
- if (!empty($param['parent'])) {
- $_mem_id = (new MemberModel())->where(['username' => $param['parent']])->value('id');
- $_map['parent_mem_id'] = $_mem_id;
- }
- if (!empty($param['sub_agent_id'])) {
- $_map['agent_id'] = $param['sub_agent_id'];
- }
- if (!empty($param['game_id'])) {
- $_map['app_id'] = $param['game_id'];
- }
- if (!empty($param['status'])) {
- $_map['status'] = $param['status'];
- }
- if (!empty($param['ig_from_device'])) {
- $_map['from_device'] = $param['ig_from_device'];
- }
- if (!empty($param['parent_mem_id'])) {
- $_map['parent_mem_id'] = $param['parent_mem_id'];
- }
- if (!empty($param['is_real_name'])) {
- $_map['real_name'] = ['eq', ''];
- if (MemConst::REAL_NAME_Y == $param['is_real_name']) {
- $_map['real_name'] = ['neq', ''];
- }
- }
- if (!empty($param['is_bind_mobile'])) {
- $_map['mobile'] = ['eq', ''];
- if (MemConst::BIND_MOBILE_Y == $param['is_bind_mobile']) {
- $_map['mobile'] = ['neq', ''];
- }
- }
- if (!empty($param['mem_agent_id'])) {
- $_mem_id = (new UserModel())->getMemIdById($param['mem_agent_id']);
- if (!empty($_mem_id)) {
- $_map['id'] = $_mem_id;
- }
- }
- if (!empty($param['is_switch'])) {
- $_map['is_switch'] = $param['is_switch'];
- }
- if (!empty($param['switch_time'])) {
- if ($param['switch_time'] == OrderConst::PAY_SWITCH_NO) {
- $_map['switch_time'] = 0;
- } else {
- $_map['switch_time'] = ['gt', 0];
- }
- }
- if (!empty($param['switch_money'])) {
- if ($param['switch_money'] == OrderConst::PAY_SWITCH_NO) {
- $_map['switch_money'] = 0;
- } else {
- $_map['switch_money'] = ['gt', 0];
- }
- }
- return $_map;
- }
- /**
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @param array $field
- *
- * @param bool $_is_admin 是否后台获取,后台获取不限制 status
- *
- * @return int| array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getList($where = [], $page = '1,10', $order = '-create_time', $field = [], $_is_admin = false) {
- $_is_agent = get_val($where, 'is_agent', false);
- $_map = $this->getWhere($where);
- if (false === $_is_admin) {
- $_map['status'] = 2;
- }
- if (!empty($where['is_recharged'])) {
- if ($where['is_recharged'] == CommonConst::STATUS_YES) {
- $_map['ext.sum_money'] = ['>', 0];
- } else {
- $_map['ext.sum_money'] = ['=', 0];
- }
- }
- $_mem_model = new MemberModel();
- $_count = $_mem_model->with('ext,agent,game,mem')->where($_map)->count();
- if (empty($_count)) {
- return MemberStatus::CNT_IS_ZERO;
- }
- $_base_field = ['id', 'username', 'nickname', 'parent_mem_id', 'app_id', 'create_time', 'last_login_time',
- 'switch_time', 'switch_money', 'real_name', 'id_card', 'alipay_account','avatar'];
- $_field = array_merge($_base_field, $field);
- $_order = $this->orderFilter($order);
- $_members = $_mem_model->with('ext,agent,game,mem')
- ->field($_field)
- ->where($_map)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_members)) {
- $_members = $_members->toArray();
- }
- $_list = [];
- $_ipban_model = new IpBanModel();
- foreach ($_members as $_k => $_v) {
- $_data = [];
- $_data['id'] = $_v['id'];
- $_data['mem_id'] = $_v['id'];
- $_data['username'] = $_v['username'];
- $_data['nickname'] = $_v['nickname'];
- $_data['agent_id'] = !empty($_v['parent_mem_id']) ? 0 : $_v['agent_id'];
- $_data['agent_name'] = empty($_v['parent_mem_id']) && !empty($_v['agent']['user_nicename'])
- ? $_v['agent']['user_login'].'|'.$_v['agent']['user_nicename'] : '官方渠道';
- $_data['role_id'] = !empty($_v['agent']['role_id']) ? $_v['agent']['role_id'] : 0;
- $_data['app_id'] = $_v['app_id'];
- $_data['game_name'] = $_v['game']['name'];
- $_data['gamename'] = !empty($_v['game']['name']) ? $_v['game']['name'] : '';
- $_data['create_time'] = $_v['create_time'];
- $_data['last_login_time'] = $_v['last_login_time'];
- $_data['device_id'] = $_v['device_id'];
- $_data['status'] = $_v['status'];
- $_data['last_money'] = $_v['ext']['last_money'];
- $_data['sum_money'] = $_v['ext']['sum_money'];
- $_data['reg_ip'] = $_v['reg_ip'];
- $_data['from_device'] = MemConst::getFromDeviceMsg($_v['from_device']);
- $_data['mobile'] = $_v['mobile'];
- $_data['alipay_account'] = $_v['alipay_account'];
- if ($_is_agent) {
- $_data['mobile'] = StrUtils::encryptPhone($_v['mobile']);
- $_data['alipay_account'] = StrUtils::encryptName($_v['alipay_account']);
- }
- $_data['real_name'] = StrUtils::encryptName($_v['real_name']);
- $_data['id_card'] = StrUtils::encryptIdCard($_v['id_card']);
- $_data['parent_mem_id'] = $_v['parent_mem_id'];
- $_data['parent'] = !empty($_v['mem']['username']) ? $_v['mem']['username'] : '';
- $_data['parent_nickname'] = !empty($_v['mem']['nickname']) ? $_v['mem']['nickname'] : '';
- $_data['switch_time'] = $_v['switch_time'];
- $_data['switch_money'] = $_v['switch_money'];
- $_data['avatar'] = $_v['avatar'];
- /* 判断ip 是否被封*/
- if (!empty($_data['reg_ip'])) {
- $_ip_ban = $_ipban_model->isBan($_data['reg_ip']);
- $_data['ip_ban'] = $_ip_ban ? BanConst::IS_BAN : BanConst::NO_BAN;
- }
- $_list[] = $_data;
- }
- if (empty($_members)) {
- $_list = null;
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_list;
- return $_rdata;
- }
- /**
- * 获取玩家余额列表
- *
- * @param array $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getRemainList($param = [], $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($param);
- $_field = [];
- return $this->getExtList($_field, $_map, $page, $order);
- }
- /****
- * @throws
- */
- public function getExtList($field = [], $where, $page = '1,10', $order = '-create_time') {
- $_map = $where;
- $_model = new MemberModel();
- $_count = $_model->alias('member_model')->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- $_field = $field;
- if (empty($field)) {
- $_field = [];
- }
- $_order = $_model->orderFilter($order);
- $_datas = $_model
- ->alias('member_model')
- ->with('ext')
- ->with('agent')
- ->where($where)
- ->field($_field)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return [
- 'count' => $_count,
- 'list' => []
- ];
- }
- if (empty($_datas)) {
- return [
- 'count' => $_count,
- 'list' => []
- ];
- }
- return [
- 'count' => $_count,
- 'list' => $_datas
- ];
- }
- /**
- * 通过账号查询手机号邮箱
- *
- * @param $username
- *
- * @return array|bool
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getMobileEmailByName($username) {
- $_map['username'] = $username;
- $_data = (new MemberModel())->where($_map)->field('email,mobile')->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (empty($_data)) {
- $_data = [
- 'mobile' => '',
- 'email' => ''
- ];
- }
- return $_data;
- }
- /**
- * 获取玩家第三方账户信息
- *
- * @param $mem_id
- *
- * @return array|false|\PDOStatement|string|\think\Collection
- */
- public function getMemOauthList($mem_id) {
- if (empty($mem_id)) {
- return [];
- }
- $_map = ['mem_id' => $mem_id];
- $_field = ['id,`from`,conf_id,openid,unionid'];
- $_list = (new MemoauthModel())->where($_map)->field($_field)->select();
- if (empty($_list)) {
- return [];
- }
- if (is_object($_list)) {
- $_list = $_list->toArray();
- }
- return $_list;
- }
- }
|