123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * PtbAgentChargeLogic.php UTF-8
- * 渠道平台币收入逻辑
- *
- * @date : 2018/5/18 17:22
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\finance;
- use huo\logic\agent\AgentLogic;
- use huo\model\common\CommonModel;
- use huo\model\finance\PtbAgentChargeModel;
- use huolib\constant\CommonConst;
- use huolib\tool\StrUtils;
- class PtbAgentChargeLogic extends CommonModel {
- /**
- * @param array $param
- *
- * @return array
- */
- protected function getWhere($param = []) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['start_time'])) {
- $_map['ptb_agent_charge_model.create_time'] = ['between', [strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime(
- $param['end_time']
- )]];
- } else if (!empty($param['start_time'])) {
- $_map['ptb_agent_charge_model.create_time'] = ['gt', strtotime($param['start_time'])];
- } else if (!empty($param['end_time'])) {
- $_map['ptb_agent_charge_model.create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime(
- $param['end_time']
- )];
- }
- if (!empty($param['order_id'])) {
- $_map['order_id'] = $param['order_id'];
- }
- if (!empty($param['status'])) {
- $_map['status'] = $param['status'];
- }
- if (!empty($param['type'])) {
- $_map['type'] = $param['type'];
- }
- if (!empty($param['parent_id'])) {
- $_agent_ids = (new AgentLogic())->getAgentIds($param['parent_id']);
- $_map['ptb_agent_charge_model.agent_id'] = ['in', $_agent_ids];
- }
- if (!empty($param['agent_id'])) {
- $_map['ptb_agent_charge_model.agent_id'] = $param['agent_id'];
- }
- return $_map;
- }
- public function getField($agent_id) {
- return [];
- }
- /**
- * 获取获取记录
- *
- * @param $agent_id
- * @param $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getAgentList($agent_id, $param, $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($param);
- $field = $this->getField($agent_id);
- if (!empty($agent_id)) {
- $_map['agent_id'] = $agent_id;
- }
- return $this->getList($field, $_map, $page, $order);
- }
- /**
- * 获取列表
- *
- * @param array $field
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getList($field = [], $where, $page = '1,10', $order = '-create_time') {
- $_map = $where;
- $_model = new PtbAgentChargeModel();
- $_count = $_model->alias('ptb_agent_charge_model')->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'sum' => [],
- 'list' => []
- ];
- }
- $_field = $field;
- if (empty($field)) {
- $_field = [];
- }
- $_order = $_model->orderFilter($order);
- $_datas = $_model->alias('ptb_agent_charge_model')
- ->with('agent,back')
- ->where($where)
- ->field($_field)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return [
- 'count' => $_count,
- 'sum' => [],
- 'list' => []
- ];
- }
- $_data = [];
- foreach ($_datas as $_k => $_v) {
- foreach ($_field as $_f) {
- $_data[$_k][$_f] = $_v[$_f];
- }
- }
- $_sum_field = [
- 'sum(amount)' => 'sum_amount',
- 'sum(real_amount)' => 'sum_real_amount',
- 'sum(rebate_cnt)' => 'sum_rebate_cnt',
- 'sum(ptb_cnt)' => 'sum_ptb_cnt'
- ];
- $_sum_data = $_model->alias('ptb_agent_charge_model')
- ->field($_sum_field)
- ->where($where)
- ->find();
- if (is_object($_sum_data)) {
- $_sum_data = $_sum_data->toArray();
- }
- $_sum = [];
- foreach ($_sum_data as $_k => $_v) {
- $_sum[$_k] = StrUtils::formatNumber($_v);
- }
- return [
- 'count' => $_count,
- 'sum' => $_sum,
- 'list' => $_datas
- ];
- }
- /**
- * 获取收入列表
- *
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getIncomeList($where = [], $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($where);
- $field = [];
- return $this->getList($field, $_map, $page, $order);
- }
- /**
- * @param $order_id
- *
- * @return array|false|\PDOStatement|string|PtbAgentChargeModel
- */
- public function getDetailByOrderId($order_id) {
- $_ptb_agent_charge = (new PtbAgentChargeModel())->where('order_id', '=', $order_id)->find();
- return $_ptb_agent_charge;
- }
- }
|