123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- /**
- * AgentOrderLogic.php UTF-8
- * 收入订单逻辑处理
- *
- * @date : 2018/5/21 16:36
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\finance;
- use huo\controller\agent\Agent;
- use huo\model\agent\AgentOrderModel;
- use huo\model\common\CommonModel;
- use huolib\constant\AgentConst;
- use huolib\constant\CommonConst;
- use huolib\constant\PaywayConst;
- use huolib\tool\StrUtils;
- use huolib\tool\Time;
- class AgentOrderLogic extends CommonModel {
- /**
- * 统计总收入 今日收入 昨日收入
- *
- * @param int $agent_id 渠道ID
- * @param int $role_type 角色类型
- *
- * @return array
- * sum_share_total 统计总收入
- * today_share_total 今日收入
- * yesterday_share_total 昨日收入
- */
- public function getStaticShareMoney($agent_id, $role_type = AgentConst::ROLE_TYPE_AGENT) {
- $_sum = 'agent_gain';
- if (AgentConst::ROLE_TYPE_GROUP == $role_type) {
- $_sum = 'parent_gain';
- }
- $_map['agent_id'] = $agent_id;
- $_order_model = new AgentOrderModel();
- $_rdata['sum_share_total'] = $_order_model->where($_map)->sum($_sum);
- list($today_start, $today_end) = Time::today();
- $_map['create_time'] = ['gt', $today_start];
- $_rdata['today_share_total'] = $_order_model->where($_map)->sum($_sum);
- $_map['create_time'] = ['between', [$today_start - CommonConst::CONST_DAY_SECONDS, $today_start]];
- $_rdata['yesterday_share_total'] = $_order_model->where($_map)->sum($_sum);
- return $_rdata;
- }
- /**
- * @param array $param
- *
- * @param int $agent_id
- *
- * @return array
- */
- protected function getWhere($param = [], $agent_id = 0) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['start_time'])) {
- $_map['agent_order_model.create_time'] = ['between',
- [strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])]];
- } else if (!empty($param['start_time'])) {
- $_map['agent_order_model.create_time'] = ['gt', strtotime($param['start_time'])];
- } else if (!empty($param['end_time'])) {
- $_map['agent_order_model.create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($param['mem_id'])) {
- $_map['mem_id'] = $param['mem_id'];
- }
- if (!empty($param['status'])) {
- $_map['status'] = $param['status'];
- }
- if (!empty($param['from_id'])) {
- $_map['from_id'] = $param['from_id'];
- }
- if (!empty($param['agent_id'])) {
- $_map['agent_order_model.agent_id'] = $param['agent_id'];
- }
- if (!empty($param['parent_id'])) {
- $_map['agent_order_model.parent_id'] = $param['parent_id'];
- }
- if (!empty($param['order_id'])) {
- $_map['agent_order_model.order_id'] = $param['order_id'];
- }
- if (!empty($param['app_id'])) {
- $_map['agent_order_model.app_id'] = $param['app_id'];
- }
- if (!empty($param['username'])) {
- $_map['username'] = $param['username'];
- }
- if (!empty($param['agent_id'])) {
- $_map['agent_order_model.agent_id'] = $param['agent_id'];
- }
- if (!empty($agent_id)) {
- $_role_type = (new Agent())->getRoleType($agent_id);
- if (AgentConst::ROLE_TYPE_GROUP == $_role_type) {
- $_map['agent_order_model.parent_id'] = $agent_id;
- } elseif (AgentConst::ROLE_TYPE_AGENT == $_role_type) {
- $_map['agent_order_model.agent_id'] = $agent_id;
- }
- }
- /*平台币、游戏币支付的不显示*/
- if (!empty($param['pay_ignore'])) {
- $_map['agent_order_model.payway'] = $param['pay_ignore'];
- }
- return $_map;
- }
- public function getField($agent_id = '') {
- return [
- 'order_id' => 'order_id',
- 'payway' => 'payway',
- 'mem_id' => 'mem_id',
- 'username' => 'username',
- 'from_id' => 'from_id',
- 'agent_order_model.agent_id' => 'agent_id',
- 'agent_order_model.app_id' => 'app_id',
- 'amount' => 'amount',
- 'real_amount' => 'real_amount',
- 'rebate_cnt' => 'rebate_cnt',
- 'agent_order_model.create_time' => 'create_time',
- 'agent_gain' => 'agent_gain',
- 'parent_gain' => 'parent_gain',
- ];
- }
- /**
- * 获取玩家带来的收益
- *
- * @param int $agent_id
- * @param array $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getMemOrderList($agent_id, $param, $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($param, $agent_id);
- $_map['agent_order_model.from_id'] = 0;
- $field = $this->getField($agent_id);
- return $this->getList($field, $_map, $page, $order);
- }
- /**
- * 获取下级带来的收益
- *
- * @param $agent_id
- * @param $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getSubAgentOrderList($agent_id, $param, $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($param, $agent_id);
- $_map['agent_order_model.from_id'] = ['gt', 0];
- $field = $this->getField($agent_id);
- return $this->getList($field, $_map, $page, $order);
- }
- /**
- * 获取收入记录
- *
- * @param $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getIncomeList($param, $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($param);
- $_field = [
- 'order_id' => 'order_id',
- 'mem_id' => 'mem_id',
- 'username' => 'username',
- 'from_id' => 'from_id',
- 'agent_order_model.agent_id' => 'agent_id',
- 'agent_order_model.app_id' => 'app_id',
- 'amount' => 'amount',
- 'real_amount' => 'real_amount',
- 'rebate_cnt' => 'rebate_cnt',
- 'payway' => 'payway',
- 'agent_order_model.create_time' => 'create_time',
- 'agent_order_model.agent_gain' => 'agent_gain',
- 'agent_order_model.parent_gain' => 'parent_gain',
- ];
- return $this->getList($_field, $_map, $page, $order);
- }
- /**
- * @param array $field
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getList($field, $where, $page = '1,10', $order = '-create_time') {
- $_sum_data['amount'] = 0;
- $_sum_data['real_amount'] = 0;
- $_sum_data['rebate_cnt'] = 0;
- $_sum_data['agent_gain'] = 0;
- $_sum_data['parent_gain'] = 0;
- $_map = $where;
- $_ao_model = new AgentOrderModel();
- $_count = $_ao_model->with('mem')->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'sum' => $_sum_data,
- 'list' => []
- ];
- }
- $_sum_field = [
- 'sum(amount)' => 'sum_amount',
- 'sum(real_amount)' => 'sum_real_amount',
- 'sum(rebate_cnt)' => 'sum_rebate_cnt',
- 'sum(agent_gain)' => 'sum_agent_gain',
- 'sum(parent_gain)' => 'sum_parent_gain',
- ];
- $_ao_sum_data = $_ao_model
- ->with('mem')
- ->field($_sum_field)
- ->where($where)
- ->find();
- if (is_object($_ao_sum_data)) {
- $_ao_sum_data = $_ao_sum_data->toArray();
- }
- $_sum_data['amount'] = StrUtils::formatNumber($_ao_sum_data['sum_amount']);
- $_sum_data['real_amount'] = StrUtils::formatNumber($_ao_sum_data['sum_real_amount']);
- $_sum_data['rebate_cnt'] = StrUtils::formatNumber($_ao_sum_data['sum_rebate_cnt']);
- $_sum_data['agent_gain'] = StrUtils::formatNumber($_ao_sum_data['sum_agent_gain']);
- $_sum_data['parent_gain'] = StrUtils::formatNumber($_ao_sum_data['sum_parent_gain']);
- $_sum_data['sum_amount'] = StrUtils::formatNumber($_ao_sum_data['sum_amount']);
- $_sum_data['sum_real_amount'] = StrUtils::formatNumber($_ao_sum_data['sum_real_amount']);
- $_sum_data['sum_rebate_cnt'] = StrUtils::formatNumber($_ao_sum_data['sum_rebate_cnt']);
- $_sum_data['sum_agent_gain'] = StrUtils::formatNumber($_ao_sum_data['sum_agent_gain']);
- $_sum_data['sum_parent_gain'] = StrUtils::formatNumber($_ao_sum_data['sum_parent_gain']);
- $_field = [];
- $_field = array_merge($_field, $field);
- $_order = $_ao_model->orderFilter($order);
- $_ao_datas = $_ao_model
- ->with('mem')
- ->with('game')
- ->with('agent')
- ->with('parentagent')
- ->with('fromagent')
- ->field($_field)
- ->where($where)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_ao_datas)) {
- $_ao_datas = $_ao_datas->toArray();
- }
- if (empty($_ao_datas)) {
- return [
- 'count' => $_count,
- 'sum' => $_sum_data,
- 'list' => []
- ];
- }
- $_data = [];
- foreach ($_ao_datas as $_ao_data) {
- foreach ($_field as $_v) {
- $_list[$_v] = $_ao_data[$_v];
- }
- $_list['payway'] = PaywayConst::getMsg($_ao_data['payway']);
- $_list['agent_name'] = $_ao_data['agent']['user_login'];
- $_list['from_name'] = !empty($_ao_data['fromagent']) ? $_ao_data['fromagent']['user_login'] : '';
- $_list['from_nicename'] = !empty($_ao_data['fromagent']) ? $_ao_data['fromagent']['user_nicename'] : '';
- $_list['parent_name'] = !empty($_ao_data['parentagent']) ? $_ao_data['parentagent']['user_login'] : '';
- $_list['gamename'] = !empty($_ao_data['game']) ? $_ao_data['game']['name'] : '';
- $_data[] = $_list;
- }
- return [
- 'count' => $_count,
- 'sum' => $_sum_data,
- 'list' => $_data
- ];
- }
- }
|