Rate.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. /**
  3. * Rate.php UTF-8
  4. * 折扣类
  5. *
  6. * @date : 2016年11月16日下午6:09:12
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 7.0
  11. * @modified: 2016年11月16日下午6:09:12
  12. */
  13. namespace huo\controller\rate;
  14. use huo\controller\agent\AgentCache;
  15. use huo\controller\common\Base;
  16. use huo\controller\game\GameCache;
  17. use huo\model\agent\AgentGameModel;
  18. use huo\model\order\OrderModel;
  19. use huo\model\user\RoleModel;
  20. use huolib\constant\AgentConst;
  21. use huolib\constant\GameConst;
  22. use huolib\constant\OrderConst;
  23. class Rate extends Base {
  24. private $rate
  25. = [
  26. 'game_rate' => 0,/* 游戏分成比例 */
  27. 'agent_rebate' => 0,/* 渠道返利比例 */
  28. 'sub_agent_rebate' => 0,/* 下级渠道返利比例 */
  29. 'agent_rate' => 1,/* 渠道分成比例 */
  30. 'sub_agent_rate' => 1,/* 下级渠道分成比例 */
  31. 'benefit_type' => 1,/* 玩家折扣类型 */
  32. 'mem_rate' => 1,/* 玩家折扣 */
  33. 'first_mem_rate' => 1,/* 玩家首充折扣 */
  34. 'mem_rebate' => 0,/* 玩家返利比例 */
  35. 'first_mem_rebate' => 0,/* 玩家首充返利比例 */
  36. 'mem_agent_reward' => 0.00,/* 玩家上级奖励 */
  37. 'mem_reward' => 0.00,/* 玩家奖励 */
  38. 'agent_benefit_type' => 0,/* 渠道分成模式 1 cpa 2 cps*/
  39. 'agent_reward' => 0.00,/* 渠道cpa */
  40. 'sub_agent_reward' => 0.00,/* 二级渠道cpa */
  41. ];
  42. private $promote_switch = 1;
  43. private $app_id;
  44. private $agent_id;
  45. public function __construct($app_id, $agent_id = 0) {
  46. $this->app_id = $app_id;
  47. $this->agent_id = $agent_id;
  48. if (!empty($this->app_id)) {
  49. $this->setGameRate($this->app_id);
  50. }
  51. if (!empty($this->app_id) && !empty($this->agent_id)) {
  52. $this->setAgRate($this->app_id, $this->agent_id);
  53. }
  54. }
  55. /**
  56. * @param int $app_id
  57. *
  58. * @return array
  59. */
  60. public function setGameRate($app_id) {
  61. $_gr_data = (RateCache::ins())->getInfoByAppId($app_id);
  62. $_g_data = (GameCache::ins())->getInfoByAppId($app_id);
  63. if (!empty($_gr_data)) {
  64. $this->promote_switch = $_g_data['promote_switch'];
  65. if (GameConst::GAME_PROMOTE_SWITCH_CAN == $_g_data['promote_switch']) {
  66. $this->rate['game_rate'] = $_gr_data['game_rate'];
  67. $this->rate['agent_rebate'] = $_gr_data['agent_rebate'];
  68. $this->rate['sub_agent_rebate'] = $_gr_data['sub_agent_rebate'];
  69. $this->rate['agent_rate'] = $_gr_data['agent_rate'];
  70. $this->rate['sub_agent_rate'] = $_gr_data['sub_agent_rate'];
  71. $this->rate['benefit_type'] = $_gr_data['benefit_type'];
  72. $this->rate['mem_rate'] = $_gr_data['mem_rate'];
  73. $this->rate['first_mem_rate'] = $_gr_data['first_mem_rate'];
  74. $this->rate['mem_rebate'] = $_gr_data['mem_rebate'];
  75. $this->rate['first_mem_rebate'] = $_gr_data['first_mem_rebate'];
  76. $this->rate['agent_benefit_type'] = $_gr_data['agent_benefit_type'];
  77. $this->rate['agent_reward'] = $_gr_data['agent_reward'];
  78. $this->rate['sub_agent_reward'] = $_gr_data['sub_agent_reward'];
  79. }
  80. $this->rate['mem_agent_reward'] = $_gr_data['mem_agent_reward'];
  81. $this->rate['mem_reward'] = $_gr_data['mem_reward'];
  82. }
  83. return $this->rate;
  84. }
  85. /**
  86. * @param int $app_id
  87. * @param int $agent_id
  88. *
  89. */
  90. public function setAgRate($app_id, $agent_id) {
  91. if (!empty($app_id) && !empty($agent_id)) {
  92. $_ag_id = (new AgentGameModel())->getAgIdByAgentIdAppId($agent_id, $app_id);
  93. $_ag_data = AgentCache::ins()->getAgInfoByAgId($_ag_id);
  94. $_rc_class = RateCache::ins();
  95. $_agr_data = $_rc_class->getInfoByAppIdAgentId($app_id, $agent_id);
  96. if (!empty($_agr_data)) {
  97. if ((GameConst::GAME_PROMOTE_SWITCH_CAN == $this->promote_switch)
  98. || (GameConst::GAME_PROMOTE_SWITCH_CHECK == $this->promote_switch
  99. && !empty($_ag_data['status'])
  100. && GameConst::GAME_PROMOTE_SWITCH_CAN == $_ag_data['status'])
  101. ) {
  102. /* 1. 游戏为需审核才能推广 必须能推广时才能享受优惠
  103. 2. 游戏直接推广 */
  104. $this->rate['agent_rebate'] = $_agr_data['agent_rebate'];
  105. $this->rate['sub_agent_rebate'] = $_agr_data['sub_agent_rebate'];
  106. $this->rate['agent_rate'] = $_agr_data['agent_rate'];
  107. $this->rate['sub_agent_rate'] = $_agr_data['sub_agent_rate'];
  108. $this->rate['benefit_type'] = $_agr_data['benefit_type'];
  109. $this->rate['mem_rate'] = $_agr_data['mem_rate'];
  110. $this->rate['first_mem_rate'] = $_agr_data['first_mem_rate'];
  111. $this->rate['mem_rebate'] = $_agr_data['mem_rebate'];
  112. $this->rate['first_mem_rebate'] = $_agr_data['first_mem_rebate'];
  113. $this->rate['agent_benefit_type'] = $_agr_data['agent_benefit_type'];
  114. $this->rate['agent_reward'] = $_agr_data['agent_reward'];
  115. $this->rate['sub_agent_reward'] = $_agr_data['sub_agent_reward'];
  116. }
  117. } else {
  118. $_agent_data = AgentCache::ins()->getInfoByAgentId($agent_id);
  119. $_role_type = (new RoleModel())->getRoleTypeById($_agent_data['role_id']);
  120. if (AgentConst::ROLE_TYPE_AGENT == $_role_type) {
  121. /* 本渠道数据为空时 取用上级渠道 或者 默认折扣 */
  122. $_parent_id = $_agent_data['parent_id'];
  123. $_pagr_data = $_rc_class->getInfoByAppIdAgentId($app_id, $_parent_id);
  124. if (!empty($_pagr_data)) {
  125. /* 取父级优惠 */
  126. $this->rate['agent_rebate'] = $_pagr_data['sub_agent_rebate'];
  127. $this->rate['agent_rate'] = $_pagr_data['sub_agent_rate'];
  128. $this->rate['benefit_type'] = $_pagr_data['benefit_type'];
  129. $this->rate['mem_rate'] = $_pagr_data['mem_rate'];
  130. $this->rate['first_mem_rate'] = $_pagr_data['first_mem_rate'];
  131. $this->rate['mem_rebate'] = $_pagr_data['mem_rebate'];
  132. $this->rate['first_mem_rebate'] = $_pagr_data['first_mem_rebate'];
  133. $this->rate['agent_benefit_type'] = $_agr_data['agent_benefit_type'];
  134. $this->rate['agent_reward'] = $_agr_data['sub_agent_reward'];
  135. } else {
  136. /* 渠道折扣 */
  137. $this->rate['agent_rebate'] = $this->rate['sub_agent_rebate'];
  138. $this->rate['agent_rate'] = $this->rate['sub_agent_rate'];
  139. $this->rate['agent_reward'] = $this->rate['sub_agent_reward'];
  140. }
  141. }
  142. }
  143. }
  144. }
  145. /**
  146. * 获取玩家分享奖励
  147. *
  148. * @return int
  149. */
  150. public function getMemAgentReward() {
  151. return $this->rate['mem_agent_reward'];
  152. }
  153. /**
  154. * 获取玩家打开奖励
  155. *
  156. * @return float
  157. */
  158. public function getMemReward() {
  159. return $this->rate['mem_reward'];
  160. }
  161. /**
  162. *
  163. * @return int
  164. */
  165. public function getBenefitType() {
  166. return $this->rate['benefit_type'];
  167. }
  168. /**
  169. * 获取游戏分成比例
  170. *
  171. * @return float
  172. */
  173. public function getGameRate() {
  174. return $this->rate['game_rate'];
  175. }
  176. /**
  177. * 获取渠道返利比例
  178. *
  179. * @return float
  180. */
  181. public function getAgentRebate() {
  182. return $this->rate['agent_rebate'];
  183. }
  184. /**
  185. * 获取下级渠道返利比例
  186. *
  187. * @return float
  188. */
  189. public function getSubAgentRebate() {
  190. return $this->rate['sub_agent_rebate'];
  191. }
  192. /**
  193. * 获取渠道返利比例
  194. *
  195. * @return float
  196. */
  197. public function getAgentRate() {
  198. return $this->rate['agent_rate'];
  199. }
  200. /**
  201. * 获取下级渠道返利比例
  202. *
  203. * @return float
  204. */
  205. public function getSubAgentRate() {
  206. return $this->rate['sub_agent_rate'];
  207. }
  208. /**
  209. * 获取玩家折扣
  210. *
  211. * @param int $mem_id 玩家ID
  212. *
  213. * @return float
  214. */
  215. public function getMemRate($mem_id = 0) {
  216. if ($this->getOrderCnt($mem_id) < 1) {
  217. return $this->rate['first_mem_rate'];
  218. }
  219. return $this->rate['mem_rate'];
  220. }
  221. /**
  222. * 获取玩家首充折扣
  223. *
  224. * @return float
  225. */
  226. public function getFirstMemRate() {
  227. return $this->rate['first_mem_rate'];
  228. }
  229. /**
  230. * 获取玩家玩家返利比例
  231. *
  232. * @param int $mem_id 玩家ID
  233. *
  234. * @return float
  235. */
  236. public function getMemRebate($mem_id = 0) {
  237. if ($this->getOrderCnt($mem_id) < 1) {
  238. return $this->rate['first_mem_rebate'];
  239. }
  240. return $this->rate['mem_rebate'];
  241. }
  242. /**
  243. * 获取玩家首充返利比例
  244. *
  245. * @return float
  246. */
  247. public function getFirstMemRebate() {
  248. return $this->rate['first_mem_rate'];
  249. }
  250. /**
  251. * 获取渠道分成模式
  252. */
  253. public function getAgentBenefitType() {
  254. return $this->rate['agent_benefit_type'];
  255. }
  256. /**
  257. * 获取渠道CPA
  258. */
  259. public function getAgentReward() {
  260. return $this->rate['agent_reward'];
  261. }
  262. /**
  263. * 获取渠道CPA
  264. */
  265. public function getSubAgentReward() {
  266. return $this->rate['sub_agent_reward'];
  267. }
  268. /**
  269. * @param int $mem_id
  270. *
  271. * @return int|string
  272. */
  273. public function getOrderCnt($mem_id = 0) {
  274. $_map['mem_id'] = $mem_id;
  275. $_map['status'] = OrderConst::PAY_STATUS_SUC;
  276. return (new OrderModel())->where($_map)->count();
  277. }
  278. }