318 lines
12 KiB
PHP
318 lines
12 KiB
PHP
<?php
|
|
/*
|
|
* @Descripttion:
|
|
* @version:
|
|
* @Author: kangkang
|
|
* @Date: 2020-10-13 19:52:37
|
|
* @LastEditors: Please set LastEditors
|
|
* @LastEditTime: 2020-11-24 14:55:57
|
|
*/
|
|
|
|
namespace app\manager\controller;
|
|
|
|
use app\manager\model\FollowRecord;
|
|
use app\manager\model\Manager;
|
|
use app\manager\model\ProductAccount;
|
|
use app\manager\model\ProductOrder;
|
|
use app\manager\model\User;
|
|
use app\manager\model\UserScore;
|
|
use enum\account\ProductAccount as ProductAccountEnum;
|
|
use enum\order\ProductOrder as ProductOrderEnum;
|
|
use enum\order\UserScore as UserScoreEnum;
|
|
use enum\user\User as UserEnum;
|
|
use fastphp\base\Controller;
|
|
|
|
class UserFollow extends Controller
|
|
{
|
|
/**
|
|
* @description: 获取消费统计页面列表数据
|
|
* @param {*}
|
|
* @return {*}
|
|
*/
|
|
public function getList()
|
|
{
|
|
$page = 0;
|
|
$search = [];
|
|
$where = [];
|
|
$sort_where = [];
|
|
$cost_where = '';
|
|
$time_where1 = '';
|
|
$time_where2 = '';
|
|
$time_where3 = '';
|
|
$user_search_id = [];
|
|
$user_search_id_list = [];
|
|
|
|
//判断是否是筛选
|
|
$is_screen = false;
|
|
|
|
$user_model = new User;
|
|
$manager_model = new Manager;
|
|
$user_score_enum = new UserScoreEnum;
|
|
$user_score_model = new UserScore;
|
|
$product_order_model = new ProductOrder;
|
|
$product_account_model = new ProductAccount;
|
|
$product_account_enum = new ProductAccountEnum;
|
|
$user_enum = new UserEnum;
|
|
|
|
$manager_info = $manager_model->getOne(['id' => $this->userinfo['OperaterID']]);
|
|
if (!$manager_info['IsRoot']) {
|
|
$where['ManagerId'] = $this->userinfo['OperaterID'];
|
|
$sort_where['ManagerId'] = $this->userinfo['OperaterID'];
|
|
$cost_where .= " ManagerId=" . $this->userinfo['OperaterID'] . ' ';
|
|
}
|
|
|
|
if (isset($_GET['PageIndex'])) {
|
|
$page = ($_GET['PageIndex'] - 1) * 50;
|
|
}
|
|
if (isset($_GET['search'])) {
|
|
$search = $_GET['search'];
|
|
if (!empty($search['profile'])) {
|
|
$where['follow_status'] = $search['profile'];
|
|
}
|
|
if (!empty($search['keyWord'])) {
|
|
$where['LoginCode'] = ['like', '%' . $search['keyWord'] . '%'];
|
|
}
|
|
$flag = date("d", time()) == date("t", time());
|
|
$date1 = date("Y-m-01", strtotime("-1 month"));
|
|
$date2 = $flag ? date("Y-m-t H:i:s", strtotime("-1 month")) : date("Y-m-d H:i:s", strtotime("-1 month"));
|
|
$date3 = date("Y-m-01", time());
|
|
$date4 = date("Y-m-d H:i:s", time());
|
|
if (!empty($search['last_month']['s_time'])) {
|
|
$date1 = date('Y-m-d',strtotime($search['last_month']['s_time']));
|
|
$date2 = date('Y-m-d 23:59:59',strtotime($search['last_month']['e_time']));
|
|
$is_screen = true;
|
|
} elseif (!empty($search['new_month']['s_time'])) {
|
|
$date3 = date('Y-m-d',strtotime($search['new_month']['s_time']));
|
|
$date4 = date('Y-m-d 23:59:59',strtotime($search['new_month']['e_time']));
|
|
$is_screen = true;
|
|
}
|
|
|
|
|
|
//上月
|
|
$time_where1 .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
|
|
//本月
|
|
$time_where2 .= " UpdateTime>='" . $date3 . "' and UpdateTime<='" . $date4 . "' ";
|
|
|
|
if (!empty($search['money1'])) {
|
|
$is_screen = true;
|
|
switch ($search['cost_type']) {
|
|
case 0:
|
|
$time_where3 = '';
|
|
break;
|
|
case 1:
|
|
$time_where3 .= " product_order.UpdateTime>='" . $date1 . "' and product_order.UpdateTime<='" . $date2 . "' ";
|
|
break;
|
|
case 2:
|
|
$time_where3 .= " product_order.UpdateTime>='" . $date3 . "' and product_order.UpdateTime<='" . $date4 . "' ";
|
|
break;
|
|
}
|
|
$cost_where .= "having money >=" . $search['money1'] . " and money <=" . $search['money2'] . ' ';
|
|
$user_search_id = $product_order_model->getScreenCost($time_where3, $cost_where, "$page,50");
|
|
}
|
|
if (!empty($search['sortLable'])) {
|
|
$is_screen = true;
|
|
switch ($search['sortLable']) {
|
|
case 'all_amount':
|
|
$user_search_id = $product_order_model->getSort($sort_where, $search['sortOrder'], "$page,50");
|
|
break;
|
|
case 'PrevMonthAmount':
|
|
$user_search_id = $product_order_model->getMonthSort($sort_where, $search['sortOrder'], "$page,50");
|
|
break;
|
|
case 'MonthAmount':
|
|
$user_search_id = $product_order_model->getMonthSort($sort_where, $search['sortOrder'], "$page,50", false);
|
|
break;
|
|
case 'account_count':
|
|
$user_search_id = $product_account_model->getSort($sort_where, $search['sortOrder'], "$page,50", 1);
|
|
break;
|
|
case 'account_used':
|
|
$user_search_id = $product_account_model->getSort($sort_where, $search['sortOrder'], "$page,50", 3);
|
|
break;
|
|
case 'account_expire':
|
|
$user_search_id = $product_account_model->getSort($sort_where, $search['sortOrder'], "$page,50", 2);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($is_screen && empty($user_search_id)) {
|
|
\result([
|
|
'list' => [],
|
|
'count' => 0,
|
|
'types' => [],
|
|
]);
|
|
}
|
|
|
|
//将筛选出来额的userid进行处理
|
|
if (!empty($user_search_id)) {
|
|
foreach ($user_search_id as $v) {
|
|
$user_search_id_list[] = $v['UserId'];
|
|
}
|
|
$where['Id'] = ['in', $user_search_id_list];
|
|
}
|
|
$user_list = $user_model->getListPage($where, 'Id,follow_status,LoginCode,CreateTime,Wx,QQ', 'id desc', "$page,50");
|
|
$list = [];
|
|
$user_id_list = [];
|
|
|
|
//获取用户列表
|
|
foreach ($user_list as $info) {
|
|
|
|
$info['last_pay_time'] = '无消费';
|
|
$pay_time = $product_order_model->getNewOne('UpdateTime', ['UserId' => $info['Id'], 'ScoreType' => ProductOrderEnum::$PayComplete]);
|
|
if ($pay_time) {
|
|
$info['last_pay_time'] = $pay_time['UpdateTime'];
|
|
}
|
|
$info['follow_status'] = $user_enum::$FollowStatus[$info['follow_status']];
|
|
$info['UserName'] = substr($info['LoginCode'], 0, 3) . '***' . substr($info['LoginCode'], -3);
|
|
$info['all_amount'] = 0;
|
|
$info['PrevMonthAmount'] = 0;
|
|
$info['MonthAmount'] = 0;
|
|
$info['AddAmount'] = 0;
|
|
$info['persent'] = '0%';
|
|
$info['account_count'] = 0;
|
|
$info['account_used'] = 0;
|
|
$info['account_expire'] = 0;
|
|
$list[$info['Id']] = $info;
|
|
$user_id_list[] = $info['Id'];
|
|
}
|
|
//获取总消费金额
|
|
$all_cost = $product_order_model->getAllCost($user_id_list);
|
|
foreach ($all_cost as $info) {
|
|
$list[$info['UserId']]['all_amount'] = $info['money'];
|
|
}
|
|
//获取上一个月、本月消费
|
|
$last_month_cost = $product_order_model->getPreMonthCost($user_id_list, $time_where1);
|
|
$new_month_cost = $product_order_model->getPreMonthCost($user_id_list, $time_where2);
|
|
foreach ($last_month_cost as $info) {
|
|
$list[$info['UserId']]['PrevMonthAmount'] = $info['money'];
|
|
$list[$info['UserId']]['AddAmount'] = -$info['money'];
|
|
}
|
|
//消费统计比对
|
|
foreach ($new_month_cost as $info) {
|
|
$list[$info['UserId']]['MonthAmount'] = $info['money'];
|
|
$list[$info['UserId']]['AddAmount'] = $info['money'] - $list[$info['UserId']]['PrevMonthAmount'];
|
|
if ($list[$info['UserId']]['PrevMonthAmount'] != 0) {
|
|
$list[$info['UserId']]['persent'] = round(($info['money'] - $list[$info['UserId']]['PrevMonthAmount']) / $list[$info['UserId']]['PrevMonthAmount'] * 100, 2) . '%';
|
|
} else {
|
|
$list[$info['UserId']]['persent'] = '100%';
|
|
}
|
|
}
|
|
//帐号计算
|
|
$account_use_where = ['DeleteTag' => 0, 'UserID' => ['in', $user_id_list], 'EndTime' => ['>', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]];
|
|
$account_expire_where = ['DeleteTag' => 0, 'UserID' => ['in', $user_id_list], 'EndTime' => ['<=', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]];
|
|
$account_used = $product_account_model->getUesdAccount($account_use_where);
|
|
$account_expire = $product_account_model->getUesdAccount($account_expire_where);
|
|
foreach ($account_used as $info) {
|
|
$list[$info['UserId']]['account_used'] = $info['used_count'];
|
|
}
|
|
foreach ($account_expire as $info) {
|
|
$list[$info['UserId']]['account_expire'] = $info['used_count'];
|
|
$list[$info['UserId']]['account_count'] = $info['used_count'] + $list[$info['UserId']]['account_used'];
|
|
}
|
|
|
|
if (!empty($search['sortLable'])) {
|
|
$sort = $search['sortOrder'] ? SORT_ASC : SORT_DESC;
|
|
$field = array_column($list, $search['sortLable']);
|
|
array_multisort($field, $sort, $list);
|
|
}
|
|
|
|
$data_count = 0;
|
|
if (empty($search['sortLable'])) {
|
|
$data_count = $user_model->getCount($where)['count'];
|
|
}
|
|
|
|
$data = [
|
|
'list' => array_merge($list),
|
|
'count' => $data_count,
|
|
'types' => $user_enum->getFormatList($user_enum::$FollowStatus),
|
|
];
|
|
\result($data);
|
|
}
|
|
|
|
/**
|
|
* @description: 获取跟进记录
|
|
* @param {*}
|
|
* @return {*}
|
|
*/
|
|
public function getFollowRecord()
|
|
{
|
|
if (!isset($_GET['id'])) {
|
|
die;
|
|
}
|
|
$id = $_GET['id'];
|
|
$follow_rcord = new FollowRecord;
|
|
$list = $follow_rcord->getNewRecord(['user_id' => $id]);
|
|
\result($list);
|
|
}
|
|
|
|
/**
|
|
* @description: 更改跟进状态
|
|
* @param {*}
|
|
* @return {*}
|
|
*/
|
|
public function changeFolowStatus()
|
|
{
|
|
$data = json_decode(file_get_contents("php://input"), true)['data'];
|
|
$follow_rcord = new FollowRecord;
|
|
$user_model = new User;
|
|
$user_enum = new UserEnum;
|
|
if ($user_model->updateOne(['Id' => $data['user_id']], ['follow_status' => $data['status']])) {
|
|
$follow_rcord->updateOne(['user_id'=>$data['user_id']],['active' => 0]);
|
|
$info = [];
|
|
$info['user_id'] = $data['user_id'];
|
|
$info['op_user'] = $this->userinfo['OperaterID'];
|
|
$info['follow_status'] = $data['status'];
|
|
$info['record'] = $data['old_status'] . '=>' . $user_enum::$FollowStatus[$data['status']];
|
|
$info['remark'] = $data['remark'];
|
|
$follow_rcord->add($info);
|
|
}
|
|
\result();
|
|
}
|
|
|
|
/**
|
|
* @description: 获取用户信息
|
|
* @param {*}
|
|
* @return {*}
|
|
*/
|
|
public function getUserInfo()
|
|
{
|
|
if (!isset($_GET['id'])) {
|
|
die;
|
|
}
|
|
$id = $_GET['id'];
|
|
$user_model = new User;
|
|
\result($user_model->getOne(['Id' => $id], 'LoginCode as UserName,Wx,QQ'));
|
|
}
|
|
|
|
/**
|
|
* @description: 获取用户消费记录
|
|
* @param {*}
|
|
* @return {*}
|
|
*/
|
|
public function getCostList()
|
|
{
|
|
if (!isset($_GET['id'])) {
|
|
die;
|
|
}
|
|
$id = $_GET['id'];
|
|
$index = $_GET['index'];
|
|
$user_score_model = new UserScore;
|
|
\result($user_score_model->getUserCost($id, $index));
|
|
}
|
|
|
|
/**
|
|
* @description: 获取用户帐号
|
|
* @param {*}
|
|
* @return {*}
|
|
*/
|
|
public function getAccountList()
|
|
{
|
|
if (!isset($_GET['id'])) {
|
|
die;
|
|
}
|
|
$id = $_GET['id'];
|
|
$index = $_GET['index'];
|
|
$product_account_model = new ProductAccount;
|
|
\result($product_account_model->getUserAccount($id, $index));
|
|
}
|
|
}
|