Income.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Income.php UTF-8
  4. * 计算收益
  5. *
  6. * @date : 2018/9/17 14:24
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huomp\controller\agent;
  13. use huo\controller\common\CommonFunc;
  14. use huo\controller\member\MemCache;
  15. use huo\controller\rate\Rate;
  16. use huo\model\integral\MemItgLogModel;
  17. use huolib\constant\CommonConst;
  18. use huolib\constant\IaConst;
  19. use huolib\status\IntegralStatus;
  20. use huolib\tool\StrUtils;
  21. use think\Log;
  22. class Income {
  23. /**
  24. * 获取打开游戏收益
  25. *
  26. * @param int $mem_id 玩家ID
  27. * @param int $app_id 游戏ID
  28. *
  29. * @param int $game_id
  30. *
  31. * @return array|int
  32. */
  33. public function getOpenGain($mem_id, $app_id, $game_id = 0) {
  34. if (empty($mem_id) || empty($app_id)) {
  35. Log::write(
  36. "func=".__FUNCTION__."&class=".__CLASS__."&step=1&mem_id=".$mem_id."&app_id=".$app_id,
  37. LOG::ERROR
  38. );
  39. return IntegralStatus::ITG_MEM_NOT_EXISTS;
  40. }
  41. /* 判断是否打开过游戏 */
  42. if ($app_id == $game_id) {
  43. $_cnt = (new MemItgLogModel())->getSubCnt($mem_id, IaConst::IA_OPEN_GAME);
  44. } else {
  45. $_cnt = (new MemItgLogModel())->getSubCnt($mem_id, IaConst::IA_OPEN_GAME, $app_id);
  46. }
  47. if ($_cnt > CommonConst::CONST_ZERO) {
  48. return IntegralStatus::ITG_IA_DONE;
  49. }
  50. $_rmb_gain = (new Rate($app_id))->getMemReward();
  51. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  52. $_gain = StrUtils::formatNumber($_gold_rmb_rate * $_rmb_gain);
  53. return ['integral' => $_gain];
  54. }
  55. /**
  56. * 获取下级打开游戏收益
  57. *
  58. * @param int $mem_id 玩家ID
  59. * @param int $app_id 游戏ID
  60. *
  61. * @return array|int [parent_id,gain]
  62. */
  63. public function getShareGain($mem_id, $app_id) {
  64. if (empty($mem_id) || empty($app_id)) {
  65. Log::write(
  66. "func=".__FUNCTION__."&class=".__CLASS__."&step=1&mem_id=".$mem_id."&app_id=".$app_id,
  67. LOG::ERROR
  68. );
  69. return IntegralStatus::ITG_MEM_NOT_EXISTS;
  70. }
  71. $_parent_id = MemCache::ins()->getParentIdByMemId($mem_id);
  72. if (empty($_parent_id)) {
  73. return [
  74. 'parent_id' => 0,
  75. 'integral' => 0
  76. ];
  77. }
  78. /* 查询是否已计算过收益 */
  79. $_cnt = (new MemItgLogModel())->getShareCnt($_parent_id, $app_id, $mem_id);
  80. if ($_cnt > CommonConst::CONST_ZERO) {
  81. return IntegralStatus::ITG_IA_DONE;
  82. }
  83. $_rmb_gain = (new Rate($app_id))->getMemAgentReward();
  84. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  85. $_gain = StrUtils::formatNumber($_gold_rmb_rate * $_rmb_gain);
  86. return [
  87. 'parent_id' => $_parent_id,
  88. 'integral' => $_gain
  89. ];
  90. }
  91. }