123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- <?php
- /**
- * MemberModel.php UTF-8
- * 玩家Model
- *
- * @date : 2017/11/18 17:18
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\model\member;
- use huo\model\agent\AgentGameModel;
- use huo\model\common\CommonModel;
- use huo\model\user\UserModel;
- use huolib\constant\CacheConst;
- use huolib\constant\MemConst;
- use huolib\constant\OrderConst;
- use huomp\model\member\MemInvitedLogModel;
- class MemberModel extends CommonModel {
- protected $name = 'member';
- protected $pk = 'id';
- //设置只读字段
- protected $readonly = ['create_time'];
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- //类型转换
- protected $type
- = [
- 'mobile_prefix' => 'integer',
- 'app_id' => 'integer',
- 'agent_id' => 'integer',
- 'parent_mem_id' => 'integer'
- ];
- protected $cache_key_prefix = CacheConst::CACHE_MEM_PREFIX;
- public function getAvatarAttr($value) {
- if (!empty($value)) {
- return cmf_get_image_url($value);
- }
- return $value;
- }
- public function getStatusLabelAttr($value) {
- if (!empty($value)) {
- return MemConst::getStatus($value);
- }
- return $value;
- }
- /**
- * 通过玩家ID获取注册时间
- *
- * @param int $mem_id 玩家ID
- *
- * @return string
- */
- public function getCreateTimeById($mem_id) {
- $_mem_data = $this->getInfoById($mem_id);
- return get_val($_mem_data, 'create_time', null);
- }
- public function operator() {
- return $this->hasOne('huo\model\game\OperatorModel', 'id', 'op_id')
- ->field(['id', 'name']);
- }
- public function country() {
- return $this->hasOne('huo\model\district\CountryConfModel', 'mobile_prefix', 'mobile_prefix');
- }
- public function agent() {
- return $this->hasOne(UserModel::className(), 'id', 'agent_id')
- ->field('id,user_login,user_nicename,role_id');
- }
- public function game() {
- return $this->hasOne('huo\model\game\GameModel', 'id', 'app_id')
- ->field(['id', 'name']);
- }
- public function mem() {
- return $this->hasOne(self::className(), 'id', 'parent_mem_id')
- ->field('id,username,nickname');
- }
- public function submem() {
- return $this->hasMany('huo\model\member\MemberModel', 'member_model.id', 'parent_mem_id');
- }
- public function invited() {
- return $this->belongsTo(MemInvitedLogModel::className(), 'id', 'mem_id');
- }
- /**
- * 关联mem_ext表
- *
- * @return \think\model\relation\HasOne
- */
- public function ext() {
- return $this->hasOne('huo\model\member\MemberExtModel', 'mem_id', 'id', [], 'left')->setEagerlyType(0);
- }
- public function mg() {
- return $this->hasMany("huo\model\member\MemGameModel", 'mem_id', 'id');
- }
- /**
- * @param string $value
- *
- * @return string
- */
- public function setPayPwdAttr($value) {
- if (!empty($value)) {
- return cmf_password($value);
- }
- return $value;
- }
- /**
- * @param string $value
- *
- * @return string
- */
- public function setPasswordAttr($value = '') {
- if (!empty($value)) {
- return cmf_password($value);
- }
- return $value;
- }
- /**
- * @param array $data
- *
- * @return bool|mixed
- */
- public function addMem($data = []) {
- $_data['username'] = get_val($data, 'username', '');
- $_data['nickname'] = get_val($data, 'nickname', '');
- $_data['reg_mobile'] = get_val($data, 'reg_mobile', '');
- $_data['reg_email'] = get_val($data, 'reg_email', '');
- $_data['password'] = get_val($data, 'password', '');
- $_data['pay_pwd'] = get_val($data, 'pay_pwd', '');
- $_data['email'] = get_val($data, 'email', '');
- $_data['mobile'] = get_val($data, 'mobile', '');
- $_data['from_device'] = get_val($data, 'from_device', '');
- $_data['device_id'] = get_val($data, 'device_id', '');
- $_data['app_id'] = get_val($data, 'app_id', 0);
- $_data['agent_id'] = get_val($data, 'agent_id', 0);
- $_data['agent_game'] = get_val($data, 'agent_game', '');
- $_data['status'] = get_val($data, 'status', MemConst::STATUS_NORMAL);
- $_data['is_switch'] = get_val($data, 'is_switch', OrderConst::PAY_SWITCH_NO);
- $_data['reg_ip'] = get_val($data, 'reg_ip', '');
- $_data['avatar'] = get_val($data, 'avatar', '');
- $_data['vb_id'] = get_val($data, 'vb_id', 0);
- $_data['parent_mem_id'] = get_val($data, 'parent_mem_id', 0);
- $_data['create_time'] = get_val($data, 'create_time', time());
- if ($_obj = self::create($_data, true)) {
- /* 写入扩展 */
- $_ext_data['last_login_time'] = time();
- $_ext_data['last_login_ip'] = $_data['reg_ip'];
- $_obj->ext()->save($_ext_data);
- /* Modified by guxiannong BEGIN 2018/8/01 ISSUES:5314 LTV */
- // $_ltv_class = new \huolib\ads\Ltv();
- // $_ltv_class->reg($_data['app_id'], $_data['agent_id'], $_ext_data['last_login_time']);
- /* END 2018/8/1 ISSUES:5314 */
- return $_obj->id;
- } else {
- return false;
- }
- }
- /**
- * 计算付费玩家数
- *
- * @param $where
- *
- * @return int|string
- */
- public function paidCount($where) {
- $where['sum_money'] = ['>', 0];
- return $this->with('ext')->where($where)->count('id');
- }
- /**
- * 总计
- *
- * @param array $where
- *
- * @return int
- */
- public function total($where = []) {
- return $this->getRegisterCount(0, time(), $where);
- // return $this->where($where)->count('id');
- }
- /**
- * 昨天新增
- *
- * @param array $where
- *
- * @return int
- */
- public function yesterdayCount($where = []) {
- return $this->getRegisterCount(strtotime('yesterday'), strtotime('today') - 1, $where);
- }
- /**
- * 今天新增
- *
- * @param array $map
- *
- * @return int
- */
- public function todayCount($map = []) {
- return $this->getRegisterCount(strtotime('today'), time(), $map);
- }
- /**
- * 本周新增
- *
- * @param array $map
- *
- * @return int
- */
- public function thisWeekCount($map = []) {
- $_start_time = strtotime(date('Y-m-d 00:00:00', strtotime('this week')));
- return $this->getRegisterCount($_start_time, time(), $map);
- }
- /**
- * 本月新增
- *
- * @param array $map
- *
- * @return int
- */
- public function thisMonthCount($map = []) {
- $_start_time = strtotime(date('Y-m-01 00:00:00'));
- return $this->getRegisterCount($_start_time, time(), $map);
- }
- /**
- * 注册数
- *
- * @param int $start_time 开始时间,包括
- * @param int $end_time 结束时间,包括
- *
- * @param array $map
- *
- * @return int
- */
- public function getRegisterCount($start_time, $end_time, $map = []) {
- $_map = [
- 'create_time' => ['between', [$start_time, $end_time]],
- // 'status' => MemConst::STATUS_NORMAL,
- ];
- return $this->where($map)->where($_map)->count('id');
- }
- /**
- * 自然注册玩家数
- *
- * @param array $map
- *
- * @return int|string
- */
- public function nonAgentUserCount($map = []) {
- $_map = $map;
- return $this->where($_map)->count('id');
- }
- /**
- * 渠道注册玩家数
- *
- * @param array $map
- *
- * @return int|string
- */
- public function agentUserCount($map = []) {
- $_map = $map;
- $_map['agent_id'] = ['>', 0];
- return $this->where($_map)->count('id');
- }
- /**
- * 今日活跃
- *
- * @param array $map
- *
- * @return int
- */
- public function todayActive($map = []) {
- $_map = $map;
- $_map['last_login_time'] = ['gt', strtotime('today')];
- return $this->with('ext')->where($_map)->count('id');
- }
- /**
- * 总活跃数
- *
- * @param array $where
- *
- * @return int
- */
- public function totalActive($where = []) {
- $where['last_login_time'] = ['gt', 0];
- $result = $this->with('ext')->where($where)->count('id');
- return $result;
- }
- /**
- * 昨天活跃数
- *
- * @param array $where
- *
- * @return int
- */
- public function yesterdayActive($where = []) {
- return $this->getActiveCount(strtotime('yesterday'), strtotime('today') - 1, $where);
- }
- /**
- * 本周活跃数
- *
- * @param array $where
- *
- * @return int
- */
- public function thisWeekActive($where = []) {
- return $this->getActiveCount(strtotime(date('Y-m-d 00:00:00', strtotime('this week'))), time(), $where);
- }
- /**
- * 本月活跃数
- *
- * @param array $where
- *
- * @return int
- */
- public function thisMonthActive($where = []) {
- return $this->getActiveCount(strtotime(date('Y-m-01 00:00:00')), time(), $where);
- }
- /**
- * 获取活跃数
- *
- * @param int $start_time 开始时间
- * @param int $end_time 结束时间
- * @param array $where 其他条件
- *
- * @return int|string
- */
- public function getActiveCount($start_time, $end_time, $where = []) {
- return $this->with('ext')->where($where)->where('last_login_time', 'between', [$start_time, $end_time])
- ->count('DISTINCT id');
- }
- public function changeMemAgent($mem_id = 0, $agent_id = 0, $app_id = 0) {
- if (empty($mem_id)) {
- $mem_id = $this->id;
- }
- if (empty($agent_id)) {
- return false;
- }
- $_data = array();
- if ($app_id) {
- $_data['app_id'] = $app_id;
- $_agent_game_model = new AgentGameModel();
- $_agent_game = $_agent_game_model->where(array('agent_id' => $agent_id, 'app_id' => $app_id))->value(
- 'agent_game'
- );
- if ($_agent_game) {
- $_data['agent_game'] = $_agent_game;
- }
- }
- $_data['agent_id'] = $agent_id;
- $_re = self::update($_data, array('id' => $mem_id));
- if ($_re === false) {
- return false;
- }
- return true;
- }
- /***
- * 获取玩家ids
- *
- * @param array $map
- *
- * @return array
- */
- public function getMemIds($map = []) {
- return $this->where($map)->column('id');
- }
- public function getIdsByParentMemId($parent_mem_id, $where = []) {
- return $this->where('parent_mem_id', '=', $parent_mem_id)->where($where)->column('id');
- }
- public function getIdByUsername($username) {
- return $this->where('username', '=', $username)->value('id');
- }
- /**
- * 计算数量
- *
- * @param array $where
- *
- * @return int
- */
- public function getCnt($where = []) {
- $_map = $where;
- $_cnt = $this->useGlobalScope(false)->where($_map)->count();
- if (empty($_cnt)) {
- return 0;
- }
- return $_cnt;
- }
- /**
- * 查找玩家支付宝是否绑定玩家
- *
- * @param string $alipay_account
- *
- * @return int
- */
- public function getMemIdByAlipayAccount($alipay_account) {
- $_map = [
- 'alipay_account' => $alipay_account
- ];
- $_mem_id = $this->where($_map)->value('id');
- if (empty($_mem_id)) {
- return 0;
- }
- return $_mem_id;
- }
- public function getMemListByMobile($mobile) {
- if (empty($mobile)) {
- return [];
- }
- $_map = [
- 'mobile' => $mobile
- ];
- $_list = $this->where($_map)->select();
- if (empty($_list)) {
- return [];
- }
- return $_list;
- }
- public function getMemNumber($mobile) {
- if (empty($mobile)) {
- return [];
- }
- $_map = [
- 'mobile' => $mobile
- ];
- $_count = $this->where($_map)->count();
- if (empty($_count)) {
- return 0;
- }
- return $_count;
- }
- /**
- * 通过玩家ID获取手机号
- *
- * @param int $mem_id 玩家ID
- *
- * @return string
- */
- public function getMobileById($mem_id) {
- $_mem_data = $this->getInfoById($mem_id);
- return get_val($_mem_data, 'mobile', '');
- }
- /**
- * 查询玩家状态
- *
- * @param int $mem_id 玩家ID
- *
- * @return int
- */
- public function getStatus($mem_id) {
- $_data = $this->getInfoById($mem_id);
- return get_val($_data, 'status', 0);
- }
- }
|