FinancialController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * FinancialController.php UTF-8
  4. * 财务
  5. *
  6. * @date : 2018/8/16 20:57
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace box\api\controller;
  13. use box\common\controller\V2ApiBaseController;
  14. use huo\controller\agent\AgentCache;
  15. use huo\controller\finance\Settle;
  16. use huo\controller\member\MemCache;
  17. use huo\controller\wap\Option;
  18. use huo\model\finance\SettleModel;
  19. use huo\model\user\UserModel;
  20. use huolib\constant\AgentConst;
  21. use huolib\constant\CommonConst;
  22. use huolib\constant\DataConst;
  23. use huolib\constant\MemItgConst;
  24. use huolib\constant\OptionConst;
  25. use huolib\constant\PaywayConst;
  26. use huolib\constant\WalletConst;
  27. use huolib\status\CommonStatus;
  28. use huomp\logic\finance\IncomeListLogic;
  29. use huomp\logic\finance\SettleLogic;
  30. class FinancialController extends V2ApiBaseController {
  31. /**
  32. * 获取提现配置信息
  33. * http://doc.1tsdk.com/159?page_id=4461
  34. * 【域名】/financial/withdraw/info
  35. */
  36. public function getWithdrawInfo() {
  37. $this->checkLogin();
  38. $_agent_id = (new UserModel())->getIdByMemId($this->mem_id);
  39. $_agent_ext_info = (new AgentCache())->getAgentExtByAgentId($_agent_id);
  40. if (empty($_agent_ext_info)) {
  41. $_code = CommonStatus::INVALID_PARAMS;
  42. $this->error(CommonStatus::getMsg($_code), [], $_code);
  43. }
  44. $_withdraw_cnt = (new SettleModel())->getCnt($_agent_id);
  45. $_option = new Option();
  46. $_settle_set = OptionConst::NAME_SETTLE_SET;
  47. $_settle_set_item = $_option->getOptionData($_settle_set);
  48. $_settle_set_item_value = [];
  49. if (!empty($_settle_set_item['option_value'])) {
  50. $_settle_set_item_value = json_decode($_settle_set_item['option_value'], true);
  51. }
  52. $_settle_tip = OptionConst::NAME_SETTLE_TIP;
  53. $_settle_tip_item = $_option->getOptionData($_settle_tip);
  54. $_settle_tip_item_value = [];
  55. if (!empty($_settle_tip_item['option_value'])) {
  56. $_settle_tip_item_value = json_decode($_settle_tip_item['option_value'], true);
  57. }
  58. $_data = [
  59. 'withdraw_cnt' => $_withdraw_cnt,
  60. 'balance' => !empty($_agent_ext_info) ? $_agent_ext_info['share_remain'] : 0,
  61. 'amount_mapping' => $_settle_set_item_value,
  62. 'notice' => $_settle_tip_item_value,
  63. ];
  64. $_code = CommonStatus::NO_ERROR;
  65. $this->success(CommonStatus::getMsg($_code), $_data, $_code);
  66. }
  67. /**
  68. * 申请提现
  69. * http://doc.1tsdk.com/159?page_id=4462
  70. * 【域名】/financial/withdraw
  71. */
  72. public function withdraw() {
  73. $this->checkLogin();
  74. $_agent_id = (new UserModel())->getIdByMemId($this->mem_id);
  75. $_agent_ext_info = (new AgentCache())->getAgentExtByAgentId($_agent_id);
  76. if (empty($_agent_ext_info)) {
  77. $_code = CommonStatus::INVALID_PARAMS;
  78. $this->error(CommonStatus::getMsg($_code), [], $_code);
  79. }
  80. $_amount = get_val($this->rq_data, 'amount');
  81. $_type = PaywayConst::PAYWAY_WXPAY;
  82. $_withdraw_cnt = (new SettleModel())->getCnt($_agent_id);
  83. if (empty($_withdraw_cnt)) {
  84. //首次提现,提现所有余额
  85. $_amount = $_agent_ext_info['share_remain'];
  86. }
  87. $_rs = (new Settle())->doSettle($_agent_id, $_amount, $_type);
  88. $this->returnData($_rs);
  89. }
  90. /**
  91. * 提现列表
  92. * http://doc.1tsdk.com/159?page_id=4405
  93. * 【域名】/financial/withdraw/list
  94. */
  95. public function withdrawList() {
  96. $this->checkLogin();
  97. $_agent_id = (new UserModel())->getIdByMemId($this->mem_id);
  98. $_agent_info = (new AgentCache())->getInfoByAgentId($_agent_id);
  99. if (empty($_agent_info)) {
  100. $_code = CommonStatus::INVALID_PARAMS;
  101. $this->error(CommonStatus::getMsg($_code), [], $_code);
  102. }
  103. $_page = get_val($this->rq_data, 'page', 1);
  104. $_offset = get_val($this->rq_data, 'offset', 10);
  105. $_param = ['agent_id' => $_agent_info['id']];
  106. $_page = $_page.','.$_offset;
  107. $_data = (new SettleLogic())->getWithdrawList($_param, $_page);
  108. $_code = CommonStatus::NO_ERROR;
  109. $this->success(CommonStatus::getMsg($_code), $_data, $_code);
  110. }
  111. /**
  112. * 收益列表
  113. * http://doc.1tsdk.com/159?page_id=4404
  114. * 【域名】/financial/income/list
  115. */
  116. public function incomeList() {
  117. $this->checkLogin();
  118. $_agent_id = (new UserModel())->getIdByMemId($this->mem_id);
  119. $_agent_info = (new AgentCache())->getInfoByAgentId($_agent_id);
  120. if (empty($_agent_info)) {
  121. $_code = CommonStatus::INVALID_PARAMS;
  122. $this->error(CommonStatus::getMsg($_code), [], $_code);
  123. }
  124. $_itg_type = get_val($this->rq_data, 'itg_type', MemItgConst::MEM_ITG_ADD);
  125. $_page = get_val($this->rq_data, 'page', 1);
  126. $_offset = get_val($this->rq_data, 'offset', 10);
  127. $_start_time = get_val($this->rq_data, 'start_time', '');
  128. $_end_time = get_val($this->rq_data, 'end_time', '');
  129. $_game_rq = $this->setGameData();
  130. $_param = [
  131. 'itg_type' => $_itg_type,
  132. 'mem_id' => $this->mem_id,
  133. 'start_time' => $_start_time,
  134. 'end_time' => $_end_time,
  135. 'app_id' => $_game_rq->getHAppId()
  136. ];
  137. $_page = $_page.','.$_offset;
  138. $_data = (new IncomeListLogic())->incomeList($_param, $_page);
  139. $_agent_ext_data = (new AgentCache())->getAgentExtByAgentId($_agent_id);
  140. $_balance = !empty($_agent_ext_data) ? $_agent_ext_data['share_remain'] : 0;
  141. $_data['sum']['sum_agent_gain'] = $_balance;
  142. $_me_data = MemCache::ins()->getMeInfoById($this->mem_id);
  143. $_data['sum']['my_integral'] = !empty($_me_data) ? intval($_me_data['my_integral']) : 0;
  144. $_code = CommonStatus::NO_ERROR;
  145. $this->success(CommonStatus::getMsg($_code), $_data, $_code);
  146. }
  147. /**
  148. * 收益排行列表
  149. * http://doc.1tsdk.com/159?page_id=4406
  150. * 【域名】/financial/income/rank/list
  151. */
  152. public function incomeRankList() {
  153. $this->checkLogin();
  154. $_agent_id = (new UserModel())->getIdByMemId($this->mem_id);
  155. $_agent_info = (new AgentCache())->getInfoByAgentId($_agent_id);
  156. if (empty($_agent_info)) {
  157. $_code = CommonStatus::INVALID_PARAMS;
  158. $this->error(CommonStatus::getMsg($_code), [], $_code);
  159. }
  160. $_range = get_val($this->rq_data, 'range', DataConst::RANK_RANGE_WEEK);
  161. $_page = get_val($this->rq_data, 'page', 1);
  162. $_offset = get_val($this->rq_data, 'offset', 10);
  163. if ($_page * $_offset > CommonConst::CONST_MAX_TASK_CNT) { //最多查找100个数据
  164. $_code = CommonStatus::NO_ERROR;
  165. $this->success(CommonStatus::getMsg($_code), [], $_code);
  166. }
  167. $_type = get_val($this->rq_data, 'type', WalletConst::WALLET_RP);
  168. $_param = [
  169. 'range' => $_range,
  170. 'role_id' => AgentConst::AGENT_ROLE_MP_MEMBER,
  171. 'type' => $_type
  172. ];
  173. $_page = $_page.','.$_offset;
  174. $_data = (new IncomeListLogic())->incomeRankList($_agent_info['id'], $_param, $_page);
  175. $_code = CommonStatus::NO_ERROR;
  176. $this->success(CommonStatus::getMsg($_code), $_data, $_code);
  177. }
  178. }