123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /**
- * PtbBackLogic.php UTF-8
- *
- *
- * @date : 5/19/2018 3:54 PM
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\finance;
- use huo\logic\agent\AgentLogic;
- use huo\logic\member\MemberLogic;
- use huo\model\common\CommonModel;
- use huo\model\finance\PtbBackModel;
- use huolib\constant\CommonConst;
- use huolib\tool\StrUtils;
- class PtbBackLogic extends CommonModel {
- /**
- * @param array $param
- *
- * @return array
- */
- protected function getWhere($param = []) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['ptb_back_model.create_time'] = ['between', [strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime(
- $param['end_time']
- )]];
- } else if (!empty($param['start_time'])) {
- $_map['ptb_back_model.create_time'] = ['gt', strtotime($param['start_time'])];
- } else if (!empty($param['end_time'])) {
- $_map['ptb_back_model.create_time'] = ['lt',
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($param['order_id'])) {
- $_map['back_order_id'] = $param['order_id'];
- }
- if (!empty($param['mem_id'])) {
- $_map['mem_id'] = $param['mem_id'];
- }
- if (!empty($param['app_id'])) {
- $_map['app_id'] = $param['app_id'];
- }
- if (!empty($param['status'])) {
- $_map['status'] = $param['status'];
- }
- if (!empty($param['user_type'])) {
- $_map['user_type'] = $param['user_type'];
- }
- if (!empty($param['agent_id'])) {
- $_map['agent_id'] = $param['agent_id'];
- }
- if (!empty($param['belong_agent_id'])) {
- $_mem_ids = (new MemberLogic())->getIdsByAgentId($param['belong_agent_id']);
- $_map['ptb_back_model.mem_id'] = ['in', $_mem_ids];
- }
- if (!empty($param['username'])) {
- $_mem_ids = (new MemberLogic())->getIdsByUsername($param['username']);
- $_map['ptb_back_model.mem_id'] = ['in', $_mem_ids];
- }
- if (!empty($param['parent_id'])) {
- $_agent_ids = (new AgentLogic())->getAgentIds($param['parent_id']);
- $_map['ptb_back_model.agent_id'] = ['in', $_agent_ids];
- }
- return $_map;
- }
- public function getBackList($where = [], $page = '1,10', $order = '-create_time') {
- $_where = $this->getWhere($where);
- $_field = [];
- return $this->getlist($_field, $_where, $page, $order);
- }
- public function getList($field = [], $where = [], $page = '1,10', $order = '-create_time') {
- $_map = $where;
- $_model = new PtbBackModel();
- $_count = $_model->alias('ptb_back_model')->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'sum' => [],
- 'list' => []
- ];
- }
- $_sum_field = [
- 'sum(ptb_cnt)' => 'sum_ptb_cnt',
- 'sum(back_ptb_cnt)' => 'sum_back_ptb_cnt',
- ];
- $_sum_data = $_model
- ->alias('ptb_back_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);
- }
- $_field = $field;
- if (empty($field)) {
- $_field = [];
- }
- $_order = $_model->orderFilter($order);
- $_datas = $_model
- ->alias('ptb_back_model')
- ->with('mem,agent')
- ->where($where)
- ->field($_field)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return [
- 'count' => $_count,
- 'sum' => $_sum,
- 'list' => []
- ];
- }
- return [
- 'count' => $_count,
- 'sum' => $_sum,
- 'list' => $_datas
- ];
- }
- }
|