RebateOut.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * RebateOut.php UTF-8
  4. * 返利对外
  5. *
  6. * @date : 2018/7/27 11:14
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : Huosdk 8.0
  11. */
  12. namespace huoRebate\controller;
  13. use huo\controller\common\Base;
  14. use huo\controller\game\GameCache;
  15. use huolib\status\CommonStatus;
  16. use huolib\status\RebateStatus;
  17. use huolib\tool\StrUtils;
  18. use huoRebate\logic\RebateLogic;
  19. class RebateOut extends Base {
  20. /**
  21. * 获取可返利游戏列表
  22. *
  23. * @param int $mem_id 玩家ID
  24. *
  25. * @param int $page
  26. * @param int $offset
  27. *
  28. * @return array
  29. */
  30. public function getGameList($mem_id, $page = 1, $offset = 10) {
  31. $_rebate_logic = new RebateLogic();
  32. $_gas = $_rebate_logic->getGameAmount($mem_id);
  33. if (empty($_gas)) {
  34. $_code = CommonStatus::NO_ERROR;
  35. return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
  36. }
  37. $_count = count($_gas);
  38. $_data['count'] = $_count;
  39. $_start = ($page - 1) * $offset;
  40. if ($_start >= $_count) {
  41. $_code = CommonStatus::NO_ERROR;
  42. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
  43. }
  44. $_end = $_start + $offset;
  45. if ($_end > $_count) {
  46. $_end = $_count;
  47. }
  48. $_list = [];
  49. for ($_k = $_start; $_k < $_end; $_k++) {
  50. if (!isset($_gas[$_k])) {
  51. continue;
  52. }
  53. $_game_data = GameCache::ins()->getInfoByAppId($_gas[$_k]['app_id']);
  54. $_list[$_k]['game_id'] = $_gas[$_k]['app_id'];
  55. $_list[$_k]['gamename'] = $_game_data['name'];
  56. $_list[$_k]['icon'] = $_game_data['icon'];
  57. $_list[$_k]['amount'] = $_gas[$_k]['amount'];
  58. $_list[$_k]['min_amount'] = $this->getMinAmount();
  59. }
  60. $_code = CommonStatus::NO_ERROR;
  61. $_data['list'] = $_list;
  62. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
  63. }
  64. public function getMinAmount() {
  65. return (new RebateLogic())->getMinSet();
  66. }
  67. /**
  68. * 获取区服角色
  69. *
  70. * @param int $mem_id 玩家ID
  71. * @param int $app_id 应用ID
  72. *
  73. * @return array
  74. */
  75. public function getServerRoles($mem_id, $app_id) {
  76. $_data = (new RebateLogic())->getServerRoles($mem_id, $app_id);
  77. $_code = CommonStatus::NO_ERROR;
  78. if (empty($_data)) {
  79. return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
  80. }
  81. $_rdata['count'] = count($_data);
  82. $_rdata['list'] = $_data;
  83. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  84. }
  85. /**
  86. * @param int $mem_id 玩家ID
  87. * @param int $app_id 应用ID
  88. * @param int $start_time 查询开始时间戳
  89. * @param int $end_time 查询结束时间戳
  90. *
  91. * @return array
  92. */
  93. public function getAmount($mem_id, $app_id, $start_time, $end_time) {
  94. $_rebate_logic = new RebateLogic();
  95. $_gas = $_rebate_logic->getGameAmount($mem_id, $app_id, $start_time, $end_time);
  96. if (empty($_gas)) {
  97. $_rdata['real_amount'] = 0;
  98. } else {
  99. $_rdata['real_amount'] = $_gas[0]['amount'];
  100. }
  101. $_code = CommonStatus::NO_ERROR;
  102. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  103. }
  104. /**
  105. * 获取申请返利的列表
  106. *
  107. * @param $mem_id
  108. * @param array $param
  109. * @param $page
  110. *
  111. * @return array
  112. */
  113. public function getRebateList($mem_id, $param = [], $page) {
  114. $_map['mem_id'] = $mem_id;
  115. if (!empty($param['app_id'])) {
  116. $_map['app_id'] = $param['app_id'];
  117. }
  118. $_rdata = (new RebateLogic())->getList($_map, $page);
  119. $_code = CommonStatus::NO_ERROR;
  120. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  121. }
  122. /**
  123. * @param int $mem_id
  124. * @param array $param
  125. * [
  126. * app_id
  127. * server_id
  128. * server_name
  129. * role_id
  130. * role_name
  131. * mobile
  132. * remark
  133. * ]
  134. *
  135. * @return array
  136. */
  137. public function addRebate($mem_id, $param = []) {
  138. /* 1 获取可返利订单列表 */
  139. $_app_id = $param['app_id'];
  140. $_rebate_logic = new RebateLogic();
  141. $_gas = $_rebate_logic->getGameAmount($mem_id, $_app_id, $param['start_time'], $param['end_time']);
  142. if (empty($_gas)) {
  143. $_amount = 0;
  144. } else {
  145. $_amount = $_gas[0]['amount'];
  146. }
  147. if (empty($_amount)) {
  148. $_code = RebateStatus::REBATE_AMOUNT_IS_ZERO;
  149. return $this->huoError($_code, RebateStatus::getMsg($_code));
  150. }
  151. $_min = $this->getMinAmount();
  152. if (StrUtils::compareNumber($_amount, $_min) < 0) {
  153. $_code = RebateStatus::REBATE_AMOUNT_MUST_LARGER_MIN;
  154. return $this->huoError($_code, RebateStatus::getMsg($_code).$_min);
  155. }
  156. $_orders = $_rebate_logic->getNotRebateOrders($mem_id, $_app_id, $param['start_time'], $param['end_time']);
  157. if (empty($_orders)) {
  158. $_code = RebateStatus::REBATE_ORDER_IS_NULL;
  159. return $this->huoError($_code, RebateStatus::getMsg($_code));
  160. }
  161. $_rs = $_rebate_logic->addRebate($mem_id, $_amount, $_orders, $param);
  162. if (false == $_rs) {
  163. $_code = RebateStatus::INNER_ERROR;
  164. return $this->huoError($_code, RebateStatus::getMsg($_code));
  165. }
  166. $_code = RebateStatus::NO_ERROR;
  167. return $this->huoSuccess($_code, RebateStatus::getMsg($_code));
  168. }
  169. /**
  170. * 获取返利详情
  171. *
  172. * @param int $mem_id 玩家ID
  173. * @param int $ro_id 返利ID
  174. *
  175. * @return array
  176. */
  177. public function getRoDetail($mem_id, $ro_id) {
  178. $_rdata = (new RebateLogic())->getRoDetail($mem_id, $ro_id);
  179. $_code = CommonStatus::NO_ERROR;
  180. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
  181. }
  182. }