123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- /**
- * AgentExtModel.php UTF-8
- * 渠道扩展表
- *
- * @date : 2018/5/9 14:17
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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;
- }
- }
|