123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- <?php
- namespace huoRate\controller;
- use huo\logic\agent\AgentLogic;
- use huo\logic\order\OrderLogic;
- use huo\model\user\UserModel;
- use huolib\constant\AgentConst;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\constant\OrderConst;
- use huoRate\model\AgentGameRateModel;
- class Rate {
- private $rate
- = [
- 'game_rate' => 0,
- 'agent_rebate' => 0,
- 'sub_agent_rebate' => 0,
- 'gp_agent_rebate' => 0,
- 'agent_rate' => 1,
- 'sub_agent_rate' => 1,
- 'gp_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,
- 'promote_switch' => 1,
- 'agent_benefit_type' => 1,
- 'agent_reward' => 0.00,
- 'sub_agent_reward' => 0.00,
- ];
- private $promote_switch = GameConst::GAME_PROMOTE_SWITCH_CHECK;
- private $app_id;
- private $agent_id;
- const GAME_RATE_STR = 'game_rate';
- public function __construct($app_id, $agent_id = 0) {
- if ($agent_id < 0) {
- $agent_id = 0;
- }
- if ($app_id < 0) {
- $app_id = 0;
- }
- $this->app_id = $app_id;
- $this->agent_id = $agent_id;
- if (!empty($this->app_id)) {
- $this->setRate($this->app_id, $this->agent_id);
- }
- }
-
- public function setRate($app_id, $agent_id = 0) {
-
- if (empty($app_id)) {
- return true;
- }
- $_agr_model = new AgentGameRateModel();
- $this->rate[self::GAME_RATE_STR] = $_agr_model->getGameRateByGameAgent($app_id, 0);
-
- $_rate_data = $_agr_model->getInfoByGameAgent($app_id, $agent_id);
- if (!empty($_rate_data)) {
- return $this->setRateFromDb($app_id, $agent_id);
- }
-
- $_user_model = new UserModel();
- $_parent_agent_id = $_user_model->getParentIdById($agent_id);
- $_rate_data = $_agr_model->getInfoByGameAgent($app_id, $_parent_agent_id);
- if (!empty($_rate_data)) {
-
- $_rs = $this->setRateFromDb($app_id, $_parent_agent_id);
- } else {
-
- $_rs = $this->setRateFromDb($app_id, CommonConst::CONST_ZERO);
- }
- if (false == $_rs) {
- return $_rs;
- }
-
- $_role_type = (new AgentLogic())->getRoleTypeById($agent_id);
- if (AgentConst::ROLE_TYPE_AGENT == $_role_type) {
- $this->rate['agent_rate'] = $this->rate['sub_agent_rate'];
- $this->rate['agent_rebate'] = $this->rate['sub_agent_rebate'];
- $this->rate['agent_reward'] = $this->rate['sub_agent_reward'];
- }
- return true;
- }
-
- public function setRateFromDb($app_id, $agent_id) {
- if (empty($app_id)) {
- return true;
- }
- $_agr_model = new AgentGameRateModel();
- $this->promote_switch = $_agr_model->getPromoteSwitchByGameAgent($app_id, $agent_id);
-
- if (GameConst::GAME_PROMOTE_SWITCH_NO == $this->promote_switch
- || (!empty($agent_id) && GameConst::GAME_PROMOTE_SWITCH_CHECK == $this->promote_switch)) {
- return true;
- }
- $_agr_data = $_agr_model->getInfoByGameAgent($app_id, $agent_id);
- if (empty($_agr_data)) {
- return true;
- }
- foreach ($this->rate as $_k => $_v) {
- if (self::GAME_RATE_STR == $_k) {
-
- continue;
- }
- $this->rate[$_k] = $_agr_data[$_k];
- }
- if (GameConst::RATE_BENEFIT_RATE == $this->rate['benefit_type']) {
-
- $this->rate['mem_rebate'] = 0;
- $this->rate['first_mem_rebate'] = 0;
- } elseif (GameConst::RATE_BENEFIT_REBATE == $this->rate['benefit_type']) {
-
- $this->rate['mem_rate'] = 1;
- $this->rate['first_mem_rate'] = 1;
- } elseif (GameConst::RATE_BENEFIT_NO == $this->rate['benefit_type']) {
-
- $this->rate['mem_rate'] = 1;
- $this->rate['first_mem_rate'] = 1;
- $this->rate['mem_rebate'] = 0;
- $this->rate['first_mem_rebate'] = 0;
- }
- if (GameConst::RATE_AGENT_BENEFIT_CPA == $this->rate['agent_benefit_type']) {
-
- $this->rate['agent_rate'] = 1;
- $this->rate['sub_agent_rate'] = 1;
- $this->rate['agent_rebate'] = 0;
- $this->rate['sub_agent_rebate'] = 0;
- } elseif (GameConst::RATE_AGENT_BENEFIT_CPS == $this->rate['agent_benefit_type']) {
-
- $this->rate['agent_reward'] = 0;
- $this->rate['sub_agent_reward'] = 0;
- } elseif (GameConst::RATE_BENEFIT_NO == $this->rate['agent_benefit_type']) {
-
- $this->rate['agent_rate'] = 1;
- $this->rate['sub_agent_rate'] = 1;
- $this->rate['agent_rebate'] = 0;
- $this->rate['sub_agent_rebate'] = 0;
- $this->rate['agent_reward'] = 0;
- $this->rate['sub_agent_reward'] = 0;
- }
- return true;
- }
-
- public function getRate() {
- return $this->rate;
- }
-
- public function getPromoteSwitch() {
- return $this->promote_switch;
- }
-
- public function setPromoteSwitch($promote_switch) {
- $this->promote_switch = $promote_switch;
- $this->rate['promote_switch'] = $promote_switch;
- }
-
- public function getAgentReward() {
- return $this->rate['agent_reward'];
- }
-
- public function getSubAgentReward() {
- return $this->rate['sub_agent_reward'];
- }
-
- public function getMemReward() {
- return $this->rate['mem_reward'];
- }
-
- public function getBenefitType() {
- return $this->rate['benefit_type'];
- }
-
- public function getAgentBenefitType() {
- return $this->rate['agent_benefit_type'];
- }
-
- public function getGameRate() {
- return $this->rate['game_rate'];
- }
-
- public function getAgentRebate() {
- return $this->rate['agent_rebate'];
- }
-
- public function getSubAgentRebate() {
- return $this->rate['sub_agent_rebate'];
- }
-
- public function getAgentRate() {
- return $this->rate['agent_rate'];
- }
-
- public function getSubAgentRate() {
- return $this->rate['sub_agent_rate'];
- }
-
- public function getMemRate($mem_id = 0) {
- if (empty($mem_id) || true == $this->isFirstCharge($this->app_id, $mem_id)) {
- return $this->rate['first_mem_rate'];
- }
- return $this->rate['mem_rate'];
- }
-
- public function getFirstMemRate() {
- return $this->rate['first_mem_rate'];
- }
-
- public function getMemRebate($mem_id = 0) {
- if (empty($mem_id) || true == $this->isFirstCharge($this->app_id, $mem_id)) {
- return $this->rate['first_mem_rebate'];
- }
- return $this->rate['mem_rebate'];
- }
-
- public function getFirstMemRebate() {
- return $this->rate['first_mem_rate'];
- }
-
- public function isFirstCharge($app_id, $mem_id = 0) {
- if (empty($mem_id)) {
- return false;
- }
- $_map = [
- 'mem_id' => $mem_id,
- 'status' => OrderConst::PAY_STATUS_SUC
- ];
- if (!empty($app_id)) {
- $_map['app_id'] = $app_id;
- }
- $_rs = (new OrderLogic())->isFirstCharge($_map, false);
- return $_rs;
- }
- }
|