IncomeOut.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * IncomeOut.php UTF-8
  4. * 获取收益
  5. *
  6. * @date : 2017/9/29 22:55
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 7.5
  11. */
  12. namespace huomp\controller\finance;
  13. use huo\controller\agent\AgentCache;
  14. use huo\controller\common\Base;
  15. use huo\controller\common\CommonFunc;
  16. use huo\controller\integral\IaCache;
  17. use huo\controller\integral\MemIa;
  18. use huo\controller\member\MemCache;
  19. use huo\model\user\UserModel;
  20. use huolib\constant\IaConst;
  21. use huolib\status\IntegralStatus;
  22. use huolib\tool\StrUtils;
  23. use huomp\controller\member\MemberOut;
  24. class IncomeOut extends Base {
  25. /**
  26. * 获取分享收益
  27. *
  28. * @param int $mem_id 玩家ID
  29. * @param int $app_id 应用ID
  30. *
  31. * @return array
  32. */
  33. public function getShareIncome($mem_id, $app_id = 0) {
  34. $_ia_id = IaConst::IA_INVITE_3;
  35. $_mem_out = new MemberOut();
  36. $_share_cnt = $_mem_out->getShareCnt($mem_id);
  37. if (IaConst::IA_STATUS_REWARD == $_share_cnt['status']) {
  38. $_code = IntegralStatus::ITG_IA_DONE;
  39. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  40. }
  41. if (IaConst::IA_STATUS_SUC != $_share_cnt['status']) {
  42. $_code = IntegralStatus::ITG_IA_NOT_DONE;
  43. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  44. }
  45. $_ext = [
  46. 'app_id' => $app_id,
  47. 'game_id' => $app_id
  48. ];
  49. $_rs = (new MemIa($mem_id))->doItgAct($_ia_id, $_ext);
  50. if (IntegralStatus::NO_ERROR != $_rs['code']) {
  51. return $this->huoReturn($_rs);
  52. }
  53. $_ia_data = IaCache::ins()->getIa($_ia_id);
  54. $_integral = $_ia_data['integral'];
  55. $_mem_out->setShareCnt($mem_id, 0, IaConst::IA_STATUS_REWARD);
  56. return $this->getReturnData($mem_id, $_integral);
  57. }
  58. /**
  59. * 获取领取试玩奖励
  60. *
  61. * @param int $mem_id 玩家ID
  62. * @param int $app_id 应用ID
  63. *
  64. * @return array
  65. */
  66. public function getPlayIncome($mem_id, $app_id = 0) {
  67. $_ia_id = IaConst::IA_PLAY_3;
  68. $_mem_out = new MemberOut();
  69. $_play_cnt = $_mem_out->getPlayCnt($mem_id);
  70. if (IaConst::IA_STATUS_REWARD == $_play_cnt['status']) {
  71. $_code = IntegralStatus::ITG_IA_DONE;
  72. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  73. }
  74. if (IaConst::IA_STATUS_SUC != $_play_cnt['status']) {
  75. $_code = IntegralStatus::ITG_IA_NOT_DONE;
  76. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  77. }
  78. $_ext = [
  79. 'app_id' => $app_id,
  80. 'game_id' => $app_id
  81. ];
  82. $_rs = (new MemIa($mem_id))->doItgAct($_ia_id, $_ext);
  83. if (IntegralStatus::NO_ERROR != $_rs['code'] && IntegralStatus::ITG_IA_NOT_DONE != $_rs['code']) {
  84. return $this->huoReturn($_rs);
  85. }
  86. $_ia_data = IaCache::ins()->getIa($_ia_id);
  87. $_integral = $_ia_data['integral'];
  88. $_mem_out->setPlayCnt($mem_id, 0, IaConst::IA_STATUS_REWARD, $_ext);
  89. if (IntegralStatus::ITG_IA_NOT_DONE == $_rs['code']) {
  90. return $this->huoReturn($_rs);
  91. }
  92. return $this->getReturnData($mem_id, $_integral);
  93. }
  94. /**
  95. * 获取游戏奖励
  96. *
  97. * @param int $mem_id 玩家ID
  98. *
  99. * @return array
  100. */
  101. public function getGameIncome($mem_id) {
  102. $_ia_id = IaConst::IA_PLAY_3;
  103. $_play_cnt = (new MemberOut())->getPlayCnt($mem_id);
  104. if (IaConst::IA_STATUS_REWARD == $_play_cnt['status']) {
  105. $_code = IntegralStatus::ITG_IA_DONE;
  106. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  107. }
  108. if (IaConst::IA_STATUS_SUC != $_play_cnt['status']) {
  109. $_code = IntegralStatus::ITG_IA_NOT_DONE;
  110. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  111. }
  112. $_rs = (new MemIa($mem_id))->doItgAct($_ia_id);
  113. if (IntegralStatus::NO_ERROR != $_rs['code']) {
  114. return $this->huoReturn($_rs);
  115. }
  116. $_ia_data = IaCache::ins()->getIa($_ia_id);
  117. $_integral = $_ia_data['integral'];
  118. return $this->getReturnData($mem_id, $_integral);
  119. }
  120. /**
  121. * 领取签到奖励
  122. *
  123. * @param int $mem_id 玩家ID
  124. * @param int $app_id 应用ID
  125. *
  126. * @return array
  127. */
  128. public function getSignIncome($mem_id, $app_id = 0) {
  129. $_ia_id = IaConst::IA_SIGN;
  130. $_rs = (new MemIa($mem_id))->doItgAct($_ia_id, $app_id);
  131. if (IntegralStatus::NO_ERROR != $_rs['code']) {
  132. return $this->huoReturn($_rs);
  133. }
  134. $_integral = $_rs['data']['gain_integral'];
  135. return $this->getReturnData($mem_id, $_integral);
  136. }
  137. /**
  138. * 领取签到奖励
  139. *
  140. * @param int $mem_id 玩家ID
  141. * @param int $app_id 应用ID
  142. *
  143. * @return array
  144. */
  145. public function getFavoriteIncome($mem_id, $app_id = 0) {
  146. $_ia_id = IaConst::IA_FAVORITE;
  147. $_ext = [
  148. 'app_id' => $app_id,
  149. 'game_id' => $app_id
  150. ];
  151. $_rs = (new MemIa($mem_id))->doItgAct($_ia_id, $_ext);
  152. if (IntegralStatus::NO_ERROR != $_rs['code']) {
  153. return $this->huoReturn($_rs);
  154. }
  155. $_ia_data = IaCache::ins()->getIa($_ia_id);
  156. $_integral = $_ia_data['integral'];
  157. return $this->getReturnData($mem_id, $_integral);
  158. }
  159. /**
  160. * 获取返回信息
  161. *
  162. * @param int $mem_id 玩家ID
  163. * @param int $itg 积分
  164. *
  165. * @return array
  166. */
  167. public function getReturnData($mem_id, $itg = 0) {
  168. $_agent_id = (new UserModel())->getIdByMemId($mem_id);
  169. $_agent_ext_info = AgentCache::ins()->getAgentExtByAgentId($_agent_id);
  170. if (empty($_agent_ext_info)) {
  171. $_code = IntegralStatus::INVALID_PARAMS;
  172. return $this->huoError($_code, IntegralStatus::getMsg($_code));
  173. }
  174. $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
  175. $_me_data = MemCache::ins()->getMeInfoById($mem_id);
  176. $_rdata = [
  177. 'my_integral' => $_me_data['my_integral'],
  178. 'gain_integral' => $itg,
  179. 'balance' => !empty($_agent_ext_info) ? $_agent_ext_info['share_remain'] : 0,
  180. 'gain_amount' => StrUtils::formatNumber($itg / $_gold_rmb_rate)
  181. ];
  182. $_code = IntegralStatus::NO_ERROR;
  183. return $this->huoSuccess($_code, IntegralStatus::getMsg($_code), $_rdata);
  184. }
  185. }