* @version : HUOSDK 8.0 */ namespace huo\model\user; use huo\model\common\CommonModel; use huolib\constant\AgentConst; class AgentExtModel extends CommonModel { protected $name = 'agent_ext'; public function agent() { return $this->belongsTo('huo\model\user\UserModel', 'agent_id'); } public function mem() { return $this->belongsTo('huo\model\member\MemberModel', 'mem_id')->field('id,username,nickname'); } public function mpagent() { return $this->belongsTo('huo\model\user\UserModel', 'agent_id', 'id')->setEagerlyType(0); } /** * 获取渠道扩展信息 * * @param $agent_id * * @return array|false */ public function getAgentExtByAgentId($agent_id) { $_map['agent_id'] = $agent_id; $_info = $this->where($_map)->find(); if (false === $_info) { return false; } if (is_object($_info)) { return $_info->toArray(); } else { return $_info; } } /** * 更新数据 * * @param array $data * * @param int $id * * @return bool|mixed */ public function updateData($data = [], $id) { $_map['agent_id'] = $id; $_data = $data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } /** * 渠道流水排行 * * @param int $size * * @return false|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getMoneyRank($size = 6) { return $this->alias('ag') ->field('ag.agent_id,u.user_nicename,ag.sum_money') ->join('user u', 'ag.agent_id=u.id', 'left') ->order('sum_money desc') ->limit($size) ->select(); } /** * 获取渠道推广金额 * * @param int $size * * @return false|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getAgShareTotalRank($size = 6) { $_map = []; $_map['role_id'] = AgentConst::AGENT_ROLE_MP_AGENT; //小游戏渠道 return $this->with('mpagent') ->field('agent_id,user_nicename,share_total') ->where($_map) ->order('share_total desc') ->limit($size) ->select(); } /** * 获取玩家渠道推广金额 * * @param int $size * * @return false|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getMemShareTotalRank($size = 6) { $_map = []; $_map['role_id'] = AgentConst::AGENT_ROLE_MP_MEMBER; //小游戏玩家渠道 return $this->with('mpagent,mem') ->field('mem_id,share_total') ->where($_map) ->order('share_total desc') ->limit($size) ->select(); } /** * 渠道总流水 * * @param $where * * @return float|int */ public function sumMoney($where = []) { return $this->where($where)->sum('sum_money'); } /** * 小游戏渠道总流水 * * @param array $where * * @return float|int * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function sumMpMoney($where = []) { $_field = [ 'agent_id' => 'agent_id', 'sum(share_total)' => 'sum_money' ]; $_data = self::with('mpagent')->where($where)->field($_field)->find(); return $_data['sum_money']; } public function getCnt($where) { return $this->where($where)->count(); } /** * 获取下级的所有总收益 * * @param $agent_id * * @return float */ public function getSubShareTotal($agent_id) { $_sub_ids = (new UserModel())->getIdsByParentId($agent_id); if (empty($_sub_ids)) { return 0.00; } $_map = [ 'agent_id' => ['in', $_sub_ids] ]; $_data = $this->where($_map)->sum('share_total'); if (empty($_data)) { return 0.00; } return $_data; } }