403 lines
18 KiB
PHP
Executable File
403 lines
18 KiB
PHP
Executable File
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once(dirname(__DIR__) . '/AppBase.php');
|
|
|
|
/**
|
|
* Notes:分销管理
|
|
* Created on: 2020/7/15 15:26
|
|
* Created by: dengbw
|
|
*/
|
|
class Distribution extends AppBase
|
|
{
|
|
private $statisticalAry = array();
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('app/User_account_model', 'mdUserAccount');
|
|
$this->load->model('app/User_accountlog_model', 'mdUserAccountLog');
|
|
$this->load->model('app/Deal_log_model', 'mdDealLog');
|
|
$this->load->model('receiver/order/receiver_orders_model', 'mdOrders');
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
if ($this->app_id) {
|
|
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
|
|
if ($this->app_info()['lock_fans'] == 1) {
|
|
$this->statisticalAry = array(1 => '团队', 2 => '粉丝');
|
|
} else {
|
|
$this->statisticalAry = array(1 => '团队');
|
|
}
|
|
}
|
|
}
|
|
|
|
//首页信息
|
|
public function index()
|
|
{
|
|
$this->lists();
|
|
}
|
|
|
|
//数据列表
|
|
public function lists()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 10;
|
|
$params['statistical'] = $params['statistical'] ? intval($params['statistical']) : 1;
|
|
$res = $this->teamSelect($params);
|
|
$lists = $res['lists'];
|
|
$count = $res['count'];
|
|
$this->data['params'] = $res['params'];
|
|
|
|
$this->data['_title'] = '分销用户列表';
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
$this->data['statistical_ary'] = $this->statisticalAry;
|
|
$this->data['statistical_name'] = $this->statisticalAry[$params['statistical']];
|
|
$this->data['lists'] = $lists;
|
|
return $this->show_view('appdistribution/team/lists', true);
|
|
}
|
|
|
|
/**
|
|
* Notes:分销用户
|
|
* Created on: 2020/7/15 10:45
|
|
* Created by: dengbw
|
|
* @param $params
|
|
* @return mixed
|
|
*/
|
|
private function teamSelect($params)
|
|
{
|
|
$lists = array();
|
|
$count = 0;
|
|
$where = array('dealer' => 1, 'up_uid' => 0);
|
|
if ($params['nickname']) {
|
|
$where['nickname LIKE "%' . trim($params['nickname']) . '%"'] = NULL;
|
|
}
|
|
if ($params['mobile']) {
|
|
$where['mobile LIKE "%' . trim($params['mobile']) . '%"'] = NULL;
|
|
}
|
|
$res = $this->mdAppUser->select($where, "id desc", $params['page'], $params['size'], 'id,mobile,nickname');
|
|
if ($res) {
|
|
if (!$params['export']) {
|
|
$count = $this->mdAppUser->count($where);
|
|
}
|
|
foreach ($res as $key => $value) {
|
|
$setValue = array();
|
|
$setValue['id'] = $value['id'];
|
|
$setValue['mobile'] = $value['mobile'];
|
|
$setValue['nickname'] = $value['nickname'];
|
|
if ($params['statistical'] == 1) {
|
|
$setValue['nums'] = $this->mdAppUser->count(array('dealer' => 1, 'up_uid' => $value['id'])) + 1;
|
|
$orders = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id']));
|
|
$orders_suc = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'status' => 1));
|
|
$orders_suc > $orders && $orders = $orders_suc;
|
|
$setValue['orders'] = $orders;
|
|
$setValue['orders_suc'] = $orders_suc;
|
|
$sum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'status' => 1));
|
|
$setValue['money'] = number_format_com($sum['money']);
|
|
} else if ($params['statistical'] == 2) {
|
|
$setValue['nums'] = $this->mdAppUser->count(array('dealer' => 0, 'up_uid' => $value['id']));
|
|
$orders = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2));
|
|
$orders_suc = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2, 'status' => 1));
|
|
$orders_suc > $orders && $orders = $orders_suc;
|
|
$setValue['orders'] = $orders;
|
|
$setValue['orders_suc'] = $orders_suc;
|
|
$sum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2, 'status' => 1));
|
|
$setValue['money'] = number_format_com($sum['money']);
|
|
}
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$data['lists'] = $lists;
|
|
$data['count'] = $count;
|
|
$data['params'] = $params;
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:分销团队
|
|
* Created on: 2020/7/20 17:48
|
|
* Created by: dengbw
|
|
* @return bool
|
|
* @throws Hd_exception
|
|
*/
|
|
public function get_team()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 10;
|
|
$up_uid = $params['up_uid'];
|
|
$this->app_id = $params['app_id'];
|
|
if (!$up_uid || !$this->app_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$reU = $this->mdAppUser->get(array('id' => $up_uid));
|
|
if ($reU['dealer'] != 1 || $reU['up_uid'] != 0) {
|
|
throw new Hd_exception('不是团长', API_CODE_FAIL);
|
|
}
|
|
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
|
|
$lists = $where = array();
|
|
$_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】分销团队' : '分销团队';
|
|
$where_base = array('app_id' => $this->app_id, 'app_uid' => $up_uid);
|
|
if ($params['time']) {
|
|
$time = explode(' ~ ', $params['time']);
|
|
$time[0] && $where_base["c_time >="] = strtotime($time[0] . ' 00:00:00');
|
|
$time[1] && $where_base["c_time <="] = strtotime($time[1] . ' 23:59:59');
|
|
$params['time_str'] = str_replace(" ~ ", " 至 ", $params['time']);
|
|
}
|
|
if ($params['statistical'] == 1) {//团员
|
|
$where = array('dealer' => 1, 'up_uid' => $up_uid);
|
|
if ($params['page'] == 1) {
|
|
$where1 = $where2 = $where_base;
|
|
$where1['type in(0,2)'] = null;
|
|
$where2['type in(0,2)'] = null;
|
|
$where2['status'] = 1;
|
|
$myValue['id'] = $up_uid;
|
|
$myValue['type'] = 0;
|
|
$myValue['mobile'] = $reU['mobile'];
|
|
$myValue['nickname'] = $reU['nickname'] . '<span style="color: red;">(团长)</span>';
|
|
$myValue['orders'] = $this->mdDealLog->count($where1);
|
|
$myValue['orders_suc'] = $this->mdDealLog->count($where2);
|
|
$mySum = $this->mdDealLog->sum('money', $where2);
|
|
$myValue['bring_money'] = number_format_com($mySum['money']);
|
|
$lists[] = $myValue;
|
|
}
|
|
} else if ($params['statistical'] == 2) {//粉丝
|
|
$where = array('dealer' => 0, 'up_uid' => $up_uid);
|
|
}
|
|
if ($params['mobile']){
|
|
$where["mobile like '%{$params['mobile']}%'"] = null;
|
|
}
|
|
$resU = $this->mdAppUser->select($where, 'id DESC', $params['page'], $params['size'], 'id,nickname,mobile');
|
|
$count = $this->mdAppUser->count($where);
|
|
$params['statistical'] == 1 && $count += 1;
|
|
if ($count) {
|
|
foreach ($resU as $key => $value) {
|
|
$setValue = array();
|
|
$setValue['id'] = $value['id'];
|
|
$setValue['type'] = 1;
|
|
$setValue['mobile'] = $value['mobile'];
|
|
$setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户';
|
|
if ($params['statistical'] == 1) {
|
|
$where1 = $where2 = $where_base;
|
|
$where1['t_uid'] = $value['id'];
|
|
$where1['type in(1,3)'] = null;
|
|
$where2['t_uid'] = $value['id'];
|
|
$where2['type in(1,3)'] = null;
|
|
$where2['status'] = 1;
|
|
$orders = $this->mdDealLog->count($where1);
|
|
$orders_suc = $this->mdDealLog->count($where2);
|
|
$orders_suc > $orders && $orders = $orders_suc;
|
|
$setValue['orders'] = $orders;
|
|
$setValue['orders_suc'] = $orders_suc;
|
|
$sum = $this->mdDealLog->sum('money', $where2);
|
|
$setValue['bring_money'] = number_format_com($sum['money']);
|
|
} else if ($params['statistical'] == 2) {
|
|
$where1 = $where_base;
|
|
$where1['t_uid'] = $value['id'];
|
|
$where1['type'] = 2;
|
|
$where1['status'] = 1;
|
|
$setValue['orders'] = $this->mdDealLog->count($where1);
|
|
$sum = $this->mdDealLog->sum('money', $where1);
|
|
$setValue['bring_money'] = number_format_com($sum['money']);
|
|
}
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
if($params['mobile']){
|
|
$uids = 0;
|
|
$resU && $uids = implode(',',array_column($resU,'id'));
|
|
$where_base["t_uid in ({$uids})"] = null;
|
|
}
|
|
$this->data['team_orders'] = $this->mdDealLog->count($where_base);
|
|
$where3 = $where_base;
|
|
$where3['status'] = 1;
|
|
$this->data['team_orders_suc'] = $this->mdDealLog->count($where3);
|
|
$sum = $this->mdDealLog->sum('money', $where3);
|
|
$this->data['team_money'] = number_format_com($sum['money']);
|
|
$this->data['_title'] = $_title;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
return $this->show_view('appdistribution/team/get_team', true);
|
|
}
|
|
|
|
/**
|
|
* Notes:佣金明细
|
|
* Created on: 2020/7/20 17:48
|
|
* Created by: dengbw
|
|
* @return bool
|
|
*/
|
|
public function get_commission()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$status = $params['status'];
|
|
$app_uid = $params['app_uid'];
|
|
$this->app_id = $params['app_id'];
|
|
if (!$app_uid || !$this->app_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
|
|
|
|
$lists = array();
|
|
$statusAry = array(0 => '进行中', 1 => '已完成', -1 => '已失效');
|
|
$reU = $this->mdAppUser->get(array('id' => $app_uid));
|
|
$_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】佣金明细' : '佣金明细';
|
|
$where['app_id'] = $this->app_id;
|
|
$where['app_uid'] = $app_uid;
|
|
if (status_verify($status)) {
|
|
$where['status'] = $status;
|
|
}
|
|
if ($params['time']) {
|
|
$time = explode(' ~ ', $params['time']);
|
|
$time[0] && $where["c_time >="] = strtotime($time[0] . ' 00:00:00');
|
|
$time[1] && $where["c_time <="] = strtotime($time[1] . ' 23:59:59');
|
|
}
|
|
$count = $this->mdDealLog->count($where);
|
|
if ($count) {
|
|
$res = $this->mdDealLog->select($where, 'id DESC', $params['page'], $params['size'], 'cf_sid,type,status,money,c_time');
|
|
$o_ids = array_column($res,'cf_sid') ? implode("','",array_column($res,'cf_sid')) : '';
|
|
if($o_ids){
|
|
$o_where = [
|
|
"sid in ('{$o_ids}')" => null
|
|
];
|
|
$order_rows = $this->mdOrders->map('sid','',$o_where,'','','','id,sid,name,mobile,brand_id,s_id,v_id,cor_id,incor_id,c_time');
|
|
}
|
|
foreach ($res as $key => $value) {
|
|
$setValue = array();
|
|
$order = $order_rows[$value['cf_sid']] ? $order_rows[$value['cf_sid']][0] : [];
|
|
$expect_money = 0.00;
|
|
$setValue['name'] = $order['name'];
|
|
$setValue['mobile'] = $order['mobile'];
|
|
$setValue['order_time'] = $order['c_time'] ? date('Y.m.d H:i',$order['c_time']) : '';
|
|
$car = '';
|
|
if($order){
|
|
$brand = $this->auto_brand_model->get(['id'=>$order['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$order['s_id']],'name');
|
|
$version = $this->auto_attr_model->get(["id"=>$order['v_id']]);
|
|
$car = "{$brand['name']}·{$series['name']}·{$version['title']}";
|
|
}
|
|
$setValue['car'] = $car;
|
|
$setValue['cf_sid'] = $value['cf_sid'];
|
|
$setValue['status'] = $value['status'];
|
|
$setValue['status_name'] = $statusAry[$value['status']];
|
|
$setValue['expect_money'] = $value['money'];
|
|
$setValue['total_price'] = number_format_com($total_price);
|
|
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$this->data['_title'] = $_title;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
return $this->show_view('appdistribution/team/get_commission', true);
|
|
}
|
|
|
|
/**
|
|
* Notes:账户资金流水
|
|
* Created on: 2020/7/20 17:51
|
|
* Created by: dengbw
|
|
* @return bool
|
|
*/
|
|
public function get_accountlog()
|
|
{
|
|
$trade_type_ary = array(1 => '入账', 2 => '提现', 3 => '冲正');
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$this->app_id = $params['app_id'];
|
|
$app_uid = $params['app_uid'];
|
|
if (!$app_uid || !$this->app_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
|
|
$reAc = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $app_uid));
|
|
$account_id = $reAc['id'];
|
|
if (!$account_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '无此用户');
|
|
}
|
|
$reU = $this->mdAppUser->get(array('id' => $app_uid));
|
|
$_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】资金流水' : '资金流水';
|
|
$where['account_id'] = $account_id;
|
|
if ($params['trade_type']) {
|
|
$where['trade_type'] = $params['trade_type'];
|
|
}
|
|
if ($params['time']) {
|
|
$time = explode(' ~ ', $params['time']);
|
|
$time[0] && $where["c_time >="] = strtotime($time[0] . ' 00:00:00');
|
|
$time[1] && $where["c_time <="] = strtotime($time[1] . ' 23:59:59');
|
|
}
|
|
$where2 = $where3 = $where;
|
|
$where2['trade_type'] = 1;
|
|
$sum2 = $this->mdUserAccountLog->sum('money_in', $where2);
|
|
$this->data['money_in'] = number_format_com($sum2['money_in']);
|
|
$where3['trade_type'] = 2;
|
|
$sum3 = $this->mdUserAccountLog->sum('money_out', $where3);
|
|
$this->data['money_out'] = number_format_com($sum3['money_out']);
|
|
$lists = array();
|
|
$count = $this->mdUserAccountLog->count($where);
|
|
if ($count) {
|
|
$res = $this->mdUserAccountLog->select($where, 'id DESC', $params['page'], $params['size'], '');
|
|
foreach ($res as $key => $value) {
|
|
$setValue = array();
|
|
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
|
|
$setValue['sid'] = $value['sid'] ? $value['sid'] : '-';
|
|
$setValue['trade_type_name'] = $trade_type_ary[$value['trade_type']];
|
|
$setValue['money_in'] = number_format_com($value['money_in']);
|
|
$setValue['money_out'] = number_format_com($value['money_out']);
|
|
$setValue['money_left'] = number_format_com($value['money_left']);
|
|
$lists[] = $setValue;
|
|
}
|
|
}
|
|
$this->data['_title'] = $_title;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['trade_type_ary'] = $trade_type_ary;
|
|
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
|
|
return $this->show_view('appdistribution/team/get_accountlog', true);
|
|
}
|
|
|
|
//设为分销/取消分销
|
|
public function edit_team_dealer()
|
|
{
|
|
$id = $this->input->post('id');
|
|
$dealer = $this->input->post('dealer');
|
|
$this->mdAppUser->update(array('dealer' => $dealer, 'up_uid' => 0), array('id' => $id));
|
|
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
|
|
}
|
|
|
|
//展示单条数据
|
|
public function get()
|
|
{
|
|
}
|
|
|
|
//添加单条数据
|
|
public function add()
|
|
{
|
|
}
|
|
|
|
//编辑单条数据
|
|
public function edit()
|
|
{
|
|
}
|
|
|
|
//删除单条数据
|
|
public function del()
|
|
{
|
|
}
|
|
|
|
//批量操作(默认修改状态)
|
|
public function batch()
|
|
{
|
|
}
|
|
|
|
//导出数据列表
|
|
public function export()
|
|
{
|
|
}
|
|
}
|