123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- /**
- * RebateOut.php UTF-8
- * 返利对外
- *
- * @date : 2018/7/27 11:14
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : Huosdk 8.0
- */
- namespace huoRebate\controller;
- use huo\controller\common\Base;
- use huo\controller\game\GameCache;
- use huolib\status\CommonStatus;
- use huolib\status\RebateStatus;
- use huolib\tool\StrUtils;
- use huoRebate\logic\RebateLogic;
- class RebateOut extends Base {
- /**
- * 获取可返利游戏列表
- *
- * @param int $mem_id 玩家ID
- *
- * @param int $page
- * @param int $offset
- *
- * @return array
- */
- public function getGameList($mem_id, $page = 1, $offset = 10) {
- $_rebate_logic = new RebateLogic();
- $_gas = $_rebate_logic->getGameAmount($mem_id);
- if (empty($_gas)) {
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
- }
- $_count = count($_gas);
- $_data['count'] = $_count;
- $_start = ($page - 1) * $offset;
- if ($_start >= $_count) {
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
- }
- $_end = $_start + $offset;
- if ($_end > $_count) {
- $_end = $_count;
- }
- $_list = [];
- for ($_k = $_start; $_k < $_end; $_k++) {
- if (!isset($_gas[$_k])) {
- continue;
- }
- $_game_data = GameCache::ins()->getInfoByAppId($_gas[$_k]['app_id']);
- $_list[$_k]['game_id'] = $_gas[$_k]['app_id'];
- $_list[$_k]['gamename'] = $_game_data['name'];
- $_list[$_k]['icon'] = $_game_data['icon'];
- $_list[$_k]['amount'] = $_gas[$_k]['amount'];
- $_list[$_k]['min_amount'] = $this->getMinAmount();
- }
- $_code = CommonStatus::NO_ERROR;
- $_data['list'] = $_list;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
- }
- public function getMinAmount() {
- return (new RebateLogic())->getMinSet();
- }
- /**
- * 获取区服角色
- *
- * @param int $mem_id 玩家ID
- * @param int $app_id 应用ID
- *
- * @return array
- */
- public function getServerRoles($mem_id, $app_id) {
- $_data = (new RebateLogic())->getServerRoles($mem_id, $app_id);
- $_code = CommonStatus::NO_ERROR;
- if (empty($_data)) {
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
- }
- $_rdata['count'] = count($_data);
- $_rdata['list'] = $_data;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * @param int $mem_id 玩家ID
- * @param int $app_id 应用ID
- * @param int $start_time 查询开始时间戳
- * @param int $end_time 查询结束时间戳
- *
- * @return array
- */
- public function getAmount($mem_id, $app_id, $start_time, $end_time) {
- $_rebate_logic = new RebateLogic();
- $_gas = $_rebate_logic->getGameAmount($mem_id, $app_id, $start_time, $end_time);
- if (empty($_gas)) {
- $_rdata['real_amount'] = 0;
- } else {
- $_rdata['real_amount'] = $_gas[0]['amount'];
- }
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * 获取申请返利的列表
- *
- * @param $mem_id
- * @param array $param
- * @param $page
- *
- * @return array
- */
- public function getRebateList($mem_id, $param = [], $page) {
- $_map['mem_id'] = $mem_id;
- if (!empty($param['app_id'])) {
- $_map['app_id'] = $param['app_id'];
- }
- $_rdata = (new RebateLogic())->getList($_map, $page);
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * @param int $mem_id
- * @param array $param
- * [
- * app_id
- * server_id
- * server_name
- * role_id
- * role_name
- * mobile
- * remark
- * ]
- *
- * @return array
- */
- public function addRebate($mem_id, $param = []) {
- /* 1 获取可返利订单列表 */
- $_app_id = $param['app_id'];
- $_rebate_logic = new RebateLogic();
- $_gas = $_rebate_logic->getGameAmount($mem_id, $_app_id, $param['start_time'], $param['end_time']);
- if (empty($_gas)) {
- $_amount = 0;
- } else {
- $_amount = $_gas[0]['amount'];
- }
- if (empty($_amount)) {
- $_code = RebateStatus::REBATE_AMOUNT_IS_ZERO;
- return $this->huoError($_code, RebateStatus::getMsg($_code));
- }
- $_min = $this->getMinAmount();
- if (StrUtils::compareNumber($_amount, $_min) < 0) {
- $_code = RebateStatus::REBATE_AMOUNT_MUST_LARGER_MIN;
- return $this->huoError($_code, RebateStatus::getMsg($_code).$_min);
- }
- $_orders = $_rebate_logic->getNotRebateOrders($mem_id, $_app_id, $param['start_time'], $param['end_time']);
- if (empty($_orders)) {
- $_code = RebateStatus::REBATE_ORDER_IS_NULL;
- return $this->huoError($_code, RebateStatus::getMsg($_code));
- }
- $_rs = $_rebate_logic->addRebate($mem_id, $_amount, $_orders, $param);
- if (false == $_rs) {
- $_code = RebateStatus::INNER_ERROR;
- return $this->huoError($_code, RebateStatus::getMsg($_code));
- }
- $_code = RebateStatus::NO_ERROR;
- return $this->huoSuccess($_code, RebateStatus::getMsg($_code));
- }
- /**
- * 获取返利详情
- *
- * @param int $mem_id 玩家ID
- * @param int $ro_id 返利ID
- *
- * @return array
- */
- public function getRoDetail($mem_id, $ro_id) {
- $_rdata = (new RebateLogic())->getRoDetail($mem_id, $ro_id);
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- }
|