123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?php
- /**
- * Rate.php UTF-8
- * 折扣类
- *
- * @date : 2016年11月16日下午6:09:12
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 7.0
- * @modified: 2016年11月16日下午6:09:12
- */
- namespace huo\controller\rate;
- use huo\controller\agent\AgentCache;
- use huo\controller\common\Base;
- use huo\controller\game\GameCache;
- use huo\model\agent\AgentGameModel;
- use huo\model\order\OrderModel;
- use huo\model\user\RoleModel;
- use huolib\constant\AgentConst;
- use huolib\constant\GameConst;
- use huolib\constant\OrderConst;
- class Rate extends Base {
- private $rate
- = [
- 'game_rate' => 0,/* 游戏分成比例 */
- 'agent_rebate' => 0,/* 渠道返利比例 */
- 'sub_agent_rebate' => 0,/* 下级渠道返利比例 */
- 'agent_rate' => 1,/* 渠道分成比例 */
- 'sub_agent_rate' => 1,/* 下级渠道分成比例 */
- 'benefit_type' => 1,/* 玩家折扣类型 */
- 'mem_rate' => 1,/* 玩家折扣 */
- 'first_mem_rate' => 1,/* 玩家首充折扣 */
- 'mem_rebate' => 0,/* 玩家返利比例 */
- 'first_mem_rebate' => 0,/* 玩家首充返利比例 */
- 'mem_agent_reward' => 0.00,/* 玩家上级奖励 */
- 'mem_reward' => 0.00,/* 玩家奖励 */
- 'agent_benefit_type' => 0,/* 渠道分成模式 1 cpa 2 cps*/
- 'agent_reward' => 0.00,/* 渠道cpa */
- 'sub_agent_reward' => 0.00,/* 二级渠道cpa */
- ];
- private $promote_switch = 1;
- private $app_id;
- private $agent_id;
- public function __construct($app_id, $agent_id = 0) {
- $this->app_id = $app_id;
- $this->agent_id = $agent_id;
- if (!empty($this->app_id)) {
- $this->setGameRate($this->app_id);
- }
- if (!empty($this->app_id) && !empty($this->agent_id)) {
- $this->setAgRate($this->app_id, $this->agent_id);
- }
- }
- /**
- * @param int $app_id
- *
- * @return array
- */
- public function setGameRate($app_id) {
- $_gr_data = (RateCache::ins())->getInfoByAppId($app_id);
- $_g_data = (GameCache::ins())->getInfoByAppId($app_id);
- if (!empty($_gr_data)) {
- $this->promote_switch = $_g_data['promote_switch'];
- if (GameConst::GAME_PROMOTE_SWITCH_CAN == $_g_data['promote_switch']) {
- $this->rate['game_rate'] = $_gr_data['game_rate'];
- $this->rate['agent_rebate'] = $_gr_data['agent_rebate'];
- $this->rate['sub_agent_rebate'] = $_gr_data['sub_agent_rebate'];
- $this->rate['agent_rate'] = $_gr_data['agent_rate'];
- $this->rate['sub_agent_rate'] = $_gr_data['sub_agent_rate'];
- $this->rate['benefit_type'] = $_gr_data['benefit_type'];
- $this->rate['mem_rate'] = $_gr_data['mem_rate'];
- $this->rate['first_mem_rate'] = $_gr_data['first_mem_rate'];
- $this->rate['mem_rebate'] = $_gr_data['mem_rebate'];
- $this->rate['first_mem_rebate'] = $_gr_data['first_mem_rebate'];
- $this->rate['agent_benefit_type'] = $_gr_data['agent_benefit_type'];
- $this->rate['agent_reward'] = $_gr_data['agent_reward'];
- $this->rate['sub_agent_reward'] = $_gr_data['sub_agent_reward'];
- }
- $this->rate['mem_agent_reward'] = $_gr_data['mem_agent_reward'];
- $this->rate['mem_reward'] = $_gr_data['mem_reward'];
- }
- return $this->rate;
- }
- /**
- * @param int $app_id
- * @param int $agent_id
- *
- */
- public function setAgRate($app_id, $agent_id) {
- if (!empty($app_id) && !empty($agent_id)) {
- $_ag_id = (new AgentGameModel())->getAgIdByAgentIdAppId($agent_id, $app_id);
- $_ag_data = AgentCache::ins()->getAgInfoByAgId($_ag_id);
- $_rc_class = RateCache::ins();
- $_agr_data = $_rc_class->getInfoByAppIdAgentId($app_id, $agent_id);
- if (!empty($_agr_data)) {
- if ((GameConst::GAME_PROMOTE_SWITCH_CAN == $this->promote_switch)
- || (GameConst::GAME_PROMOTE_SWITCH_CHECK == $this->promote_switch
- && !empty($_ag_data['status'])
- && GameConst::GAME_PROMOTE_SWITCH_CAN == $_ag_data['status'])
- ) {
- /* 1. 游戏为需审核才能推广 必须能推广时才能享受优惠
- 2. 游戏直接推广 */
- $this->rate['agent_rebate'] = $_agr_data['agent_rebate'];
- $this->rate['sub_agent_rebate'] = $_agr_data['sub_agent_rebate'];
- $this->rate['agent_rate'] = $_agr_data['agent_rate'];
- $this->rate['sub_agent_rate'] = $_agr_data['sub_agent_rate'];
- $this->rate['benefit_type'] = $_agr_data['benefit_type'];
- $this->rate['mem_rate'] = $_agr_data['mem_rate'];
- $this->rate['first_mem_rate'] = $_agr_data['first_mem_rate'];
- $this->rate['mem_rebate'] = $_agr_data['mem_rebate'];
- $this->rate['first_mem_rebate'] = $_agr_data['first_mem_rebate'];
- $this->rate['agent_benefit_type'] = $_agr_data['agent_benefit_type'];
- $this->rate['agent_reward'] = $_agr_data['agent_reward'];
- $this->rate['sub_agent_reward'] = $_agr_data['sub_agent_reward'];
- }
- } else {
- $_agent_data = AgentCache::ins()->getInfoByAgentId($agent_id);
- $_role_type = (new RoleModel())->getRoleTypeById($_agent_data['role_id']);
- if (AgentConst::ROLE_TYPE_AGENT == $_role_type) {
- /* 本渠道数据为空时 取用上级渠道 或者 默认折扣 */
- $_parent_id = $_agent_data['parent_id'];
- $_pagr_data = $_rc_class->getInfoByAppIdAgentId($app_id, $_parent_id);
- if (!empty($_pagr_data)) {
- /* 取父级优惠 */
- $this->rate['agent_rebate'] = $_pagr_data['sub_agent_rebate'];
- $this->rate['agent_rate'] = $_pagr_data['sub_agent_rate'];
- $this->rate['benefit_type'] = $_pagr_data['benefit_type'];
- $this->rate['mem_rate'] = $_pagr_data['mem_rate'];
- $this->rate['first_mem_rate'] = $_pagr_data['first_mem_rate'];
- $this->rate['mem_rebate'] = $_pagr_data['mem_rebate'];
- $this->rate['first_mem_rebate'] = $_pagr_data['first_mem_rebate'];
- $this->rate['agent_benefit_type'] = $_agr_data['agent_benefit_type'];
- $this->rate['agent_reward'] = $_agr_data['sub_agent_reward'];
- } else {
- /* 渠道折扣 */
- $this->rate['agent_rebate'] = $this->rate['sub_agent_rebate'];
- $this->rate['agent_rate'] = $this->rate['sub_agent_rate'];
- $this->rate['agent_reward'] = $this->rate['sub_agent_reward'];
- }
- }
- }
- }
- }
- /**
- * 获取玩家分享奖励
- *
- * @return int
- */
- public function getMemAgentReward() {
- return $this->rate['mem_agent_reward'];
- }
- /**
- * 获取玩家打开奖励
- *
- * @return float
- */
- public function getMemReward() {
- return $this->rate['mem_reward'];
- }
- /**
- *
- * @return int
- */
- public function getBenefitType() {
- return $this->rate['benefit_type'];
- }
- /**
- * 获取游戏分成比例
- *
- * @return float
- */
- public function getGameRate() {
- return $this->rate['game_rate'];
- }
- /**
- * 获取渠道返利比例
- *
- * @return float
- */
- public function getAgentRebate() {
- return $this->rate['agent_rebate'];
- }
- /**
- * 获取下级渠道返利比例
- *
- * @return float
- */
- public function getSubAgentRebate() {
- return $this->rate['sub_agent_rebate'];
- }
- /**
- * 获取渠道返利比例
- *
- * @return float
- */
- public function getAgentRate() {
- return $this->rate['agent_rate'];
- }
- /**
- * 获取下级渠道返利比例
- *
- * @return float
- */
- public function getSubAgentRate() {
- return $this->rate['sub_agent_rate'];
- }
- /**
- * 获取玩家折扣
- *
- * @param int $mem_id 玩家ID
- *
- * @return float
- */
- public function getMemRate($mem_id = 0) {
- if ($this->getOrderCnt($mem_id) < 1) {
- return $this->rate['first_mem_rate'];
- }
- return $this->rate['mem_rate'];
- }
- /**
- * 获取玩家首充折扣
- *
- * @return float
- */
- public function getFirstMemRate() {
- return $this->rate['first_mem_rate'];
- }
- /**
- * 获取玩家玩家返利比例
- *
- * @param int $mem_id 玩家ID
- *
- * @return float
- */
- public function getMemRebate($mem_id = 0) {
- if ($this->getOrderCnt($mem_id) < 1) {
- return $this->rate['first_mem_rebate'];
- }
- return $this->rate['mem_rebate'];
- }
- /**
- * 获取玩家首充返利比例
- *
- * @return float
- */
- public function getFirstMemRebate() {
- return $this->rate['first_mem_rate'];
- }
- /**
- * 获取渠道分成模式
- */
- public function getAgentBenefitType() {
- return $this->rate['agent_benefit_type'];
- }
- /**
- * 获取渠道CPA
- */
- public function getAgentReward() {
- return $this->rate['agent_reward'];
- }
- /**
- * 获取渠道CPA
- */
- public function getSubAgentReward() {
- return $this->rate['sub_agent_reward'];
- }
- /**
- * @param int $mem_id
- *
- * @return int|string
- */
- public function getOrderCnt($mem_id = 0) {
- $_map['mem_id'] = $mem_id;
- $_map['status'] = OrderConst::PAY_STATUS_SUC;
- return (new OrderModel())->where($_map)->count();
- }
- }
|