770 lines
28 KiB
PHP
Executable File
770 lines
28 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\admin\controller\Base;
|
|
use app\common\model\Coupon;
|
|
use app\common\model\UserVip;
|
|
use \think\Request;
|
|
use think\facade\View;
|
|
use app\common\model\User as UserModel;
|
|
use app\common\model\ProfitMoney;
|
|
use app\common\model\ProfitMoney2;
|
|
use app\common\model\ProfitIntegral;
|
|
use app\common\model\Shang;
|
|
use app\common\model\GoodsList;
|
|
use app\common\model\Order;
|
|
use app\common\model\OrderList;
|
|
use app\common\model\UserAccount;
|
|
use app\common\model\UserLoginIp;
|
|
use think\facade\Db;
|
|
use think\helper\Str;
|
|
class User extends Base
|
|
{
|
|
/**
|
|
* 用户列表
|
|
*/
|
|
public function index()
|
|
{
|
|
$user_id = trim(input('get.user_id'));
|
|
$mobile = trim(input('get.mobile'));
|
|
$nickname = trim(input('get.nickname'));
|
|
$addtime = trim(input('get.addtime'));
|
|
$last_login_ip = trim(input('get.last_login_ip'));
|
|
$whe = [];
|
|
if ($user_id) {
|
|
$user_id = $user_id - 1260;
|
|
$whe[] = ['id', '=', $user_id];
|
|
}
|
|
if ($nickname) {
|
|
$whe[] = ['nickname', 'like', '%' . $nickname . '%'];
|
|
}
|
|
if ($mobile) {
|
|
$whe[] = ['mobile', '=', $mobile];
|
|
}
|
|
if ($addtime) {
|
|
$time = explode(' - ', $addtime);
|
|
$start_time = strtotime($time[0]);
|
|
$end_time = strtotime($time[1]) - 1;
|
|
if ($start_time > $end_time) {
|
|
$this->err('开始时间不能大于结束时间');
|
|
}
|
|
$whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
|
}
|
|
if ($last_login_ip) {
|
|
$last_login_ip = ip2long($last_login_ip);
|
|
$user_id_arr = UserAccount::where(['last_login_ip' => $last_login_ip])->column('user_id');
|
|
|
|
if ($user_id_arr) {
|
|
|
|
$whe[] = ['id', 'in', $user_id_arr];
|
|
} else {
|
|
$whe[] = ['id', '=', 0];
|
|
}
|
|
}
|
|
$field = '*';
|
|
$order = 'id desc';
|
|
$data = UserModel::getList($whe, $field, $order, $this->page);
|
|
foreach ($data['list'] as &$value) {
|
|
$pid_info = UserModel::field('id,nickname,headimg')->where(['id' => $value['pid']])->find();
|
|
$value['pid_info'] = $pid_info;
|
|
#关联user_account
|
|
$user_account = UserAccount::where(['user_id' => $value['id']])->field('last_login_ip1,last_login_ip,ip_adcode,ip_province,ip_city')->find();
|
|
$user_hegui = OrderList::where('user_id', '=', $value['id'])->where('status', '=', 0)->sum('goodslist_money');
|
|
// SELECT sum(goodslist_money) FROM xinglanmh_shequt_test.order_list where user_id=4490 and status=0 and goodslist_type=1
|
|
$last_login_ip = 0;
|
|
if ($user_account) {
|
|
if ($user_account['last_login_ip']) {
|
|
if ($user_account['last_login_ip1']) {
|
|
$last_login_ip = $user_account['last_login_ip1'];
|
|
} else {
|
|
$last_login_ip = long2ip($user_account['last_login_ip']);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$value['user_hegui'] = $user_hegui;
|
|
$value['last_login_ip'] = $last_login_ip;
|
|
$value['ip_adcode'] = $user_account['ip_adcode'];
|
|
$value['ip_province'] = $user_account['ip_province'];
|
|
$value['ip_city'] = $user_account['ip_city'];
|
|
}
|
|
View::assign('list', $data['list']);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
return View::fetch('User/index');
|
|
}
|
|
|
|
/**
|
|
* 资金变动
|
|
*/
|
|
public function chongzhi()
|
|
{
|
|
$id = request()->param('id', '');
|
|
$type = request()->param('type', '');
|
|
$user_info = UserModel::find($id);
|
|
if (!$user_info) {
|
|
$this->renderError('请求参数错误');
|
|
}
|
|
if (\request()->IsGet()) {
|
|
if ($type == 1) {
|
|
$money = $user_info['money'];
|
|
} elseif ($type == 2) {
|
|
$money = $user_info['integral'];
|
|
} elseif ($type == 3) {
|
|
$money = $user_info['score'];
|
|
} else {
|
|
$this->renderError('请求参数错误1');
|
|
}
|
|
View::assign('id', $id);
|
|
View::assign('type', $type);
|
|
View::assign('money', $money);
|
|
return View::fetch('User/chongzhi');
|
|
} else {
|
|
$money = request()->param('money', '');
|
|
$type_is = request()->param('type_is', '');
|
|
if ($type_is != 1 && $type_is != 2) {
|
|
$this->renderError('请求参数错误1');
|
|
}
|
|
if (empty($money)) {
|
|
return $this->renderError('请输入修改数量');
|
|
}
|
|
Db::startTrans();
|
|
if ($type == 1) {#余额
|
|
if (RegMoney($money)) {
|
|
return $this->renderError('修改数量不规范,最多保留两位小数');
|
|
}
|
|
if ($type_is == 2) {
|
|
if ($money > $user_info['money']) {
|
|
return $this->renderError('账号余额扣除数量不足');
|
|
}
|
|
$money = $money * -1;
|
|
}
|
|
$res[] = UserModel::changeMoney($id, $money, 1, '后台变动');
|
|
} elseif ($type == 2) {#吧唧币
|
|
if (RegInt($money)) {
|
|
return $this->renderError('修改数量不规范,请输入大于0的整数');
|
|
}
|
|
if ($type_is == 2) {
|
|
if ($money > $user_info['integral']) {
|
|
return $this->renderError('账号吧唧币扣除数量不足');
|
|
}
|
|
$money = $money * -1;
|
|
}
|
|
$res[] = UserModel::changeIntegral($id, $money, 1, '后台变动');
|
|
} elseif ($type == 3) {#积分
|
|
if (RegInt($money)) {
|
|
return $this->renderError('修改数量不规范,请输入大于0的整数');
|
|
}
|
|
if ($type_is == 2) {
|
|
if ($money > $user_info['score']) {
|
|
return $this->renderError('账号积分扣除数量不足');
|
|
}
|
|
$money = $money * -1;
|
|
}
|
|
$res[] = UserModel::changeScore($id, $money, 1, '后台变动');
|
|
} else {
|
|
$this->renderError('请求参数错误2');
|
|
}
|
|
if (resCheck($res)) {
|
|
Db::commit();
|
|
return $this->renderSuccess("操作成功");
|
|
} else {
|
|
Db::rollback();
|
|
return $this->renderError("操作失败");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 封号、解封处理
|
|
*/
|
|
public function userdel(Request $request)
|
|
{
|
|
$id = request()->post('id/d', 0);
|
|
$type = request()->post('type/d', 0);
|
|
if ($type != 1 && $type != 2) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
$user = UserModel::getInfo(['id' => $id]);
|
|
if (!$user) {
|
|
return $this->err('数据不存在');
|
|
}
|
|
$result = $user->save(["status" => $type]);
|
|
if ($result) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 封号、解封处理
|
|
*/
|
|
public function usertest(Request $request)
|
|
{
|
|
$id = request()->post('id/d', 0);
|
|
$type = request()->post('type/d', 0);
|
|
if ($type != 1 && $type != 0) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
$user = UserModel::getInfo(['id' => $id]);
|
|
if (!$user) {
|
|
return $this->err('数据不存在');
|
|
}
|
|
$result = $user->save(["istest" => $type]);
|
|
if ($result) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 清空手机号
|
|
*/
|
|
public function usermobileclear(Request $request)
|
|
{
|
|
$id = request()->post('id/d', 0);
|
|
|
|
$user = UserModel::getInfo(['id' => $id]);
|
|
if (!$user) {
|
|
return $this->err('数据不存在');
|
|
}
|
|
$result = $user->save(["mobile" => '']);
|
|
|
|
if ($result) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 清空微信登录数据
|
|
*/
|
|
public function userwxclear(Request $request)
|
|
{
|
|
$id = request()->post('id/d', 0);
|
|
|
|
$user = UserModel::getInfo(['id' => $id]);
|
|
if (!$user) {
|
|
return $this->err('数据不存在');
|
|
}
|
|
$result = $user->save(["openid" => Str::random(32)]);
|
|
$useraccount = UserAccount::getInfo(['user_id' => $id]);
|
|
if ($useraccount != null) {
|
|
$useraccount->save(['account_token' => '']);
|
|
}
|
|
if ($result) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
ip转换
|
|
*/
|
|
public function ipzh(Request $request)
|
|
{
|
|
|
|
$id = request()->post('id/d', 0);
|
|
$user_account = UserAccount::where(['user_id' => $id])->field('last_login_ip1,ip_province,last_login_ip')->find();
|
|
if ($user_account) {
|
|
if (empty($user_account['ip_province'])) {
|
|
$last_login_ip = long2ip($user_account['last_login_ip']);
|
|
//$last_login_ip = $user_account['last_login_ip1'];
|
|
var_dump($last_login_ip);
|
|
$url = "https://restapi.amap.com/v3/ip?key=6a46ad822120e393956e89d498e8c40b&ip=" . "$last_login_ip" . "";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$result = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$result = json_decode($result, true);
|
|
var_dump($result);
|
|
exit;
|
|
if ($result['status'] == '1') {
|
|
|
|
$res = UserAccount::where(['user_id' => $id])->update([
|
|
'ip_adcode' => $result['adcode'],
|
|
'ip_province' => $result['province'],
|
|
'ip_city' => $result['city']
|
|
]);
|
|
} else {
|
|
$res = false;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
$res = false;
|
|
}
|
|
if ($res) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 赠送卡牌查找
|
|
*/
|
|
public function give_goodslist_info()
|
|
{
|
|
$card_no = request()->param('card_no', '');
|
|
$goodslist = GoodsList::where('card_no', '=', $card_no)
|
|
->find();
|
|
if (!$goodslist) {
|
|
return $this->renderError('输入错误,未找到奖品信息');
|
|
}
|
|
#验证是否赠送是卡册盒子
|
|
$good_info = Goods::field('id,type')->where('id', '=', $goodslist['goods_id'])->find();
|
|
if ($good_info['type'] != 4) {
|
|
return $this->renderError('只可赠送卡册盒子');
|
|
}
|
|
$data = [
|
|
'title' => $goodslist['title'],
|
|
'imgurl' => imageUrl($goodslist['imgurl']),
|
|
];
|
|
return $this->renderSuccess('查找成功', $data);
|
|
}
|
|
|
|
/**
|
|
* 赠送卡牌
|
|
*/
|
|
public function give_goodslist()
|
|
{
|
|
$user_id = request()->param('id/d', 0);
|
|
$user_info = UserModel::find($user_id);
|
|
if (!$user_info) {
|
|
$this->renderError('请求参数错误');
|
|
}
|
|
if (request()->IsGet()) {
|
|
View::assign('id', $user_id);
|
|
return View::fetch('User/give_goodslist');
|
|
} else {
|
|
$card_no = request()->param('card_no', '');
|
|
$num = request()->param('num/d', 0);
|
|
$goodslist = GoodsList::where('card_no', '=', $card_no)
|
|
->find();
|
|
if (!$goodslist) {
|
|
return $this->renderError('输入错误,未找到奖品信息');
|
|
}
|
|
if (RegInt($num)) {
|
|
return $this->renderError('数量输入错误,请输入大于0的整数');
|
|
}
|
|
#验证是否赠送是卡册盒子
|
|
$good_info = Goods::field('id,type')->where('id', '=', $goodslist['goods_id'])->find();
|
|
if ($good_info['type'] != 4) {
|
|
return $this->renderError('只可赠送卡册盒子');
|
|
}
|
|
$save_prize = [
|
|
'order_id' => 0,
|
|
'user_id' => $user_id,
|
|
'status' => 0,#0未操作 1选择兑换 2选择发货
|
|
'goods_id' => $goodslist['goods_id'],
|
|
'num' => 0,
|
|
'shang_id' => $goodslist['shang_id'],
|
|
'goodslist_id' => $goodslist['id'],
|
|
'goodslist_title' => $goodslist['title'],
|
|
'goodslist_imgurl' => $goodslist['imgurl'],
|
|
'goodslist_price' => $goodslist['price'],
|
|
'goodslist_money' => $goodslist['money'],
|
|
'goodslist_type' => $goodslist['goods_type'],
|
|
'goodslist_sale_time' => $goodslist['sale_time'],
|
|
'addtime' => time(),
|
|
'prize_code' => $goodslist['prize_code'],
|
|
'order_type' => 9,
|
|
];
|
|
$all_save_prize = [];
|
|
for ($i = 0; $i < $num; $i++) {
|
|
$all_save_prize[] = $save_prize;
|
|
}
|
|
$res = OrderList::insertAll($all_save_prize);
|
|
if ($res) {
|
|
return $this->renderSuccess("操作成功");
|
|
} else {
|
|
return $this->renderError("操作失败");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 赠送
|
|
*/
|
|
public function give_add(Request $request)
|
|
{
|
|
if (!$request->isPost()) {
|
|
$w = [];
|
|
$w[] = ['status', '=', 0];
|
|
$coupon = Coupon::getAllList($w, 'id,title,price,man_price,ttype');
|
|
View::assign('coupon', $coupon);
|
|
|
|
$user_id = $request->param("user_id");
|
|
View::assign("user_id", $user_id);
|
|
return View::fetch("User/give_add");
|
|
} else {
|
|
$data = input('post.');
|
|
if (empty($data['give_id'])) {
|
|
return $this->renderError("请选择赠送的物品");
|
|
}
|
|
$coupon = Coupon::getInfo(['id' => $data['give_id']]);
|
|
if (!$coupon || $coupon['status'] != 0) {
|
|
return $this->renderError("优惠券不存在或者已下架");
|
|
}
|
|
|
|
//赠送优惠卷
|
|
$data2 = [];
|
|
for ($i = 0; $i < $data['num']; $i++) {
|
|
$data2[$i]['title'] = $coupon['title'];
|
|
$data2[$i]['price'] = $coupon['price'];
|
|
$data2[$i]['man_price'] = $coupon['man_price'];
|
|
$data2[$i]['end_time'] = $coupon['effective_day'] * 86400 + time();
|
|
$data2[$i]['addtime'] = time();
|
|
$data2[$i]['status'] = 0;
|
|
$data2[$i]['user_id'] = $data['user_id'];
|
|
$data2[$i]['coupon_id'] = $data['give_id'];
|
|
$data2[$i]['state'] = $coupon['ttype'];
|
|
}
|
|
$dd = Db::name('coupon_receive')->insertAll($data2);
|
|
if ($dd) {
|
|
return $this->renderSuccess("赠送成功");
|
|
} else {
|
|
return $this->renderError("赠送失败");
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户盈亏
|
|
*/
|
|
public function user_profit_loss()
|
|
{
|
|
$whe = [];
|
|
$where = [];
|
|
$addtime = trim(input('get.addtime'));
|
|
$uid = trim(input('get.uid'));
|
|
if (!empty($uid)) {
|
|
$uid = $uid - 1260;
|
|
$whe[] = ['id', '=', $uid];
|
|
}
|
|
if (!empty($addtime)) {
|
|
$addtime = explode(' - ', $addtime);
|
|
$start_time = strtotime($addtime[0]);
|
|
$end_time = strtotime($addtime[1]) - 1;
|
|
$where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]];
|
|
}
|
|
// else {
|
|
// $start_time = strtotime(date('Y-m-d', time()));
|
|
// $end_time = $start_time + 86399;
|
|
// $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]];
|
|
// }
|
|
$data = UserModel::getList($whe, 'id,nickname,headimg,money', 'id desc', 20);
|
|
$cz_money_total = 0;
|
|
$wx_money_total = 0;
|
|
$cz_yue_total = 0;
|
|
$cz_integral_total = 0;
|
|
$price_total = 0;
|
|
$shang_money_total = 0;
|
|
$fh_money_total = 0;
|
|
$tx_money_total = 0;
|
|
$profit_loss_total = 0;
|
|
$money = 0;
|
|
foreach ($data['list'] as $k => &$v) {
|
|
#公式 (充值余额 + 吧唧币 + 微信支付 - 余额 - 背包赏品
|
|
$cz_money = ProfitMoney::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 1)->where('change_money', '>', 0)->where($where)->sum('change_money');
|
|
$wx_money = ProfitMoney::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 2)->where('change_money', '>', 0)->where($where)->sum('change_money');
|
|
$cz_yue = $cz_money + $wx_money;
|
|
$cz_integral = ProfitIntegral::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 1)->where('change_money', '>', 0)->where($where)->sum('change_money');
|
|
$price = Order::field('price')->where('user_id', '=', $v['id'])->where('status', '=', 1)->where('price', '>', 0)->where($where)->sum('price');
|
|
$shang_money = OrderList::field('goodslist_money')->where('user_id', '=', $v['id'])->whereIn('status', [0])->where('goodslist_money', '>', 0)->where($where)->sum('goodslist_money');
|
|
$fh_money = OrderList::field('goodslist_money')->where('user_id', '=', $v['id'])->where('status', '=', 2)->where('goodslist_money', '>', 0)->where($where)->sum('goodslist_money');
|
|
$tx_money = ProfitMoney2::field('change_money')->where('user_id', '=', $v['id'])->where('type', '=', 5)->where('change_money', '<', 0)->where($where)->sum('change_money');
|
|
$profit_loss = $cz_yue + $price - $v['money'] - $shang_money - $fh_money;
|
|
$profit_loss = $profit_loss + $tx_money;
|
|
$v['cz_money'] = $cz_yue;
|
|
$v['wx_money'] = $wx_money;
|
|
$v['cz_integral'] = $cz_integral;
|
|
$v['price'] = $price;
|
|
$v['shang_money'] = $shang_money;
|
|
$v['fh_money'] = $fh_money;
|
|
$v['tx_money'] = $tx_money;
|
|
$v['profit_loss'] = $profit_loss;
|
|
|
|
|
|
$cz_money_total += $cz_yue;
|
|
$wx_money_total += $wx_money;
|
|
$cz_yue_total += $cz_yue;
|
|
$cz_integral_total += $cz_integral;
|
|
$price_total += $price;
|
|
$shang_money_total += $shang_money;
|
|
$fh_money_total += $fh_money;
|
|
$tx_money_total += $tx_money;
|
|
$profit_loss_total += $profit_loss;
|
|
$money += $v['money'];
|
|
|
|
}
|
|
$total_money[1]['cz_money_total'] = $cz_money_total;
|
|
$total_money[1]['cz_integral_total'] = $cz_integral_total;
|
|
// $total_money[1]['wx_money_total'] = $wx_money_total;
|
|
$total_money[1]['price_total'] = $price_total;
|
|
$total_money[1]['total_money'] = $money;
|
|
|
|
// $total_money[1]['cz_yue_total'] = $cz_yue_total;
|
|
|
|
|
|
$total_money[1]['shang_money_total'] = $shang_money_total;
|
|
$total_money[1]['fh_money_total'] = $fh_money_total;
|
|
$total_money[1]['tx_money_total'] = $tx_money_total;
|
|
$total_money[1]['profit_loss_total'] = $profit_loss_total;
|
|
View::assign('list', $data['list']);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
View::assign('total_money', $total_money);
|
|
return View::fetch("User/user_profit_loss");
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* vip管理
|
|
*/
|
|
public function vip()
|
|
{
|
|
$list = UserVip::order('id asc')->select();
|
|
View::assign('list', $list);
|
|
View::assign('count', count($list));
|
|
return View::fetch("User/vip");
|
|
}
|
|
|
|
|
|
/**
|
|
* vip编辑
|
|
*/
|
|
public function vip_edit(Request $request)
|
|
{
|
|
if (!$request->isPost()) {
|
|
$id = request()->param('id/d', 0);
|
|
$info = UserVip::where(['id' => $id])->find();
|
|
if (!$info) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
View::assign('info', $info);
|
|
return View::fetch('User/vip_edit');
|
|
} else {
|
|
$data = input('post.');
|
|
if (empty($data['id'])) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
$info = UserVip::where(['id' => $data['id']])->find();
|
|
if (!$info) {
|
|
return $this->renderError('请求参数错误1');
|
|
}
|
|
if (empty($data['title'])) {
|
|
return $this->renderError('请输入vip名称');
|
|
}
|
|
if (RegZero($data['condition'])) {
|
|
return $this->renderError('升级消费设置错误,请设置整数');
|
|
}
|
|
if (RegMoney($data['discount'])) {
|
|
return $this->renderError('vip折扣设置错误,最多保留两位小数');
|
|
}
|
|
// if (empty($data['imgurl'])) {
|
|
// return $this->renderError('请上传图标');
|
|
// }
|
|
$data['update_time'] = time();
|
|
unset($data['id']);
|
|
$dd = $info->allowField([])->save($data);
|
|
if ($dd) {
|
|
return $this->renderSuccess('编辑成功');
|
|
} else {
|
|
return $this->renderError('编辑失败');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 流水明细
|
|
*created by Admin at 2023/2/10 14:23
|
|
*/
|
|
public function detailed_flow()
|
|
{
|
|
$whe = [];
|
|
$where = [];
|
|
// $addtime = trim(input('get.addtime'));
|
|
$uid = trim(input('get.uid'));
|
|
if (!empty($uid)) {
|
|
$whe[] = ['user_id', '=', $uid];
|
|
}
|
|
// if (!empty($addtime)) {
|
|
// $addtime = explode(' - ', $addtime);
|
|
// $start_time = strtotime($addtime[0]);
|
|
// $end_time = strtotime($addtime[1]) - 1;
|
|
// $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]];
|
|
// } else {
|
|
// $start_time = strtotime(date('Y-m-d', time()));
|
|
// $end_time = $start_time + 86399;
|
|
// $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]];
|
|
// }
|
|
|
|
// $data = ProfitMoney::getList($whe, 'id,user_id,change_money,addtime', '', 20);
|
|
$list = ProfitMoney::field('user_id,sum(change_money) as new_money')
|
|
// ->whereIn('type',[])
|
|
->group('user_id')
|
|
->order('new_money desc')
|
|
->paginate(20);
|
|
$page = $list->render();
|
|
$data['list'] = $list->toArray()['data'];
|
|
$data['count'] = $list->total();
|
|
$data['page'] = $page;
|
|
$num = 1;
|
|
foreach ($data['list'] as &$value) {
|
|
// dd($value['user_id']);
|
|
$user = \app\common\model\User::where('id', $value['user_id'])->find();
|
|
$value['nick_name'] = $user['nickname'];
|
|
$value['headimg'] = $user['headimg'];
|
|
$value['openid'] = $user['openid'];
|
|
$value['num'] = $num;
|
|
// $value['addtime'] =$user['addtime'];
|
|
$num++;
|
|
}
|
|
// dd($data);
|
|
View::assign('list', $data['list']);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
return View::fetch("User/detailed_flow");
|
|
}
|
|
|
|
/**
|
|
* 下级用户
|
|
*created by Admin at 2023/2/16 15:55
|
|
*/
|
|
public function user_team(Request $request)
|
|
{
|
|
$id = $request->param('id');
|
|
// dd($id);
|
|
$list = \app\common\model\User::where('pid', $id)->paginate(20);
|
|
$page = $list->render();
|
|
$data['list'] = $list->toArray()['data'];
|
|
$data['count'] = $list->total();
|
|
$data['page'] = $page;
|
|
foreach ($data['list'] as &$value) {
|
|
$value['total'] = ProfitMoney::where('type', 5)
|
|
->where('user_id', $id)
|
|
->where('share_uid', $value['id'])
|
|
->sum('change_money');
|
|
// dd();
|
|
}
|
|
// dd($data['list']);
|
|
View::assign('list', $data['list']);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
return View::fetch("User/user_team");
|
|
}
|
|
|
|
public function ip_list(Request $request)
|
|
{
|
|
$id = $request->param('id');
|
|
// dd($id);
|
|
$list = UserLoginIp::where('user_id', $id)->order('id desc')->paginate(20);
|
|
$page = $list->render();
|
|
$data['list'] = $list->toArray()['data'];
|
|
$data['count'] = $list->total();
|
|
$data['page'] = $page;
|
|
View::assign('list', $data['list']);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
return View::fetch("User/ip_list");
|
|
}
|
|
|
|
public function user_invite(Request $request)
|
|
{
|
|
|
|
$profit_date = trim(input('get.profit_date'));
|
|
$user_id = trim(input('get.user_id'));
|
|
$whe = array();
|
|
$whe1 = array();
|
|
if ($profit_date) {
|
|
|
|
$whe[] = ['addtime', '>=', strtotime($profit_date)];
|
|
$whe1[] = ['addtime', '>=', strtotime($profit_date)];
|
|
}
|
|
if ($user_id) {
|
|
$user_id = $user_id - 1260;
|
|
$whe[] = ['pid', '=', $user_id];
|
|
}
|
|
//select * from ( SELECT pid,count(1) n FROM xinglanmh_shequt_test.`user` where pid>0 group by pid ) t where n>1 order by n desc LIMIT 10
|
|
$list = UserModel::where($whe)->
|
|
where('pid', '>', 0)
|
|
->field('pid, COUNT(1) as n') // 选取 pid 和 计数字段
|
|
->group('pid')
|
|
// ->having('n', '>', 1) // `having` 需要使用 `as` 取别名
|
|
->order('n desc')
|
|
->limit(1000) // 添加限制条数
|
|
->select();
|
|
|
|
$count = UserModel::where($whe)->where('pid', '>', 0)
|
|
->field('pid, COUNT(1) as n') // 选取 pid 和 计数字段
|
|
->group('pid')
|
|
->count();
|
|
$data = array();
|
|
$index = 1;
|
|
foreach ($list as $item) {
|
|
$pid = $item['pid'];
|
|
$user_info = UserModel::field('nickname,headimg,mobile')->where('id', '=', $pid)->find();
|
|
if ($user_info != null) {
|
|
|
|
$user_list = UserModel::field('id,nickname,addtime,mobile')->where($whe1)->where('pid', '=', $pid)->order('addtime desc')->select();
|
|
$u_index = 1;
|
|
$u_price = 0;
|
|
$u_order = 0;
|
|
$u_mobile_count = 0;
|
|
foreach ($user_list as $user_item) {
|
|
$user_item['adddate'] = date('Y-m-d H:i:s', $user_item['addtime']);
|
|
$user_item['index'] = $u_index;
|
|
$user_item['id'] = $user_item['id'] + 1260;
|
|
$user_item_order = Order::where('user_id', '=', $user_item['id'])->where('status', '=', $user_item['id'])->count();
|
|
$user_item_price = Order::where('user_id', '=', $user_item['id'])->where('status', '=', $user_item['id'])->sum('price');
|
|
$user_item['user_item_order'] = $user_item_order;
|
|
$user_item['user_item_price'] = $user_item_price;
|
|
$u_index++;
|
|
$u_price += $user_item_price;
|
|
if ($user_item_order && $user_item_order > 0) {
|
|
$u_order++;
|
|
}
|
|
if ($user_item['mobile'] && $user_item['mobile'] != "") {
|
|
$u_mobile_count++;
|
|
}
|
|
}
|
|
$data[] = [
|
|
'index' => $index,
|
|
'user_id' => $pid + 1260,
|
|
'invitenumber' => $item['n'],
|
|
'nickname' => $user_info['nickname'],
|
|
'headimg' => imageUrl($user_info['headimg']),
|
|
'info' => $user_list,
|
|
'sum_order' => $u_order,
|
|
'sum_price' => $u_price,
|
|
'count_mobile' => $u_mobile_count,
|
|
];
|
|
$index++;
|
|
}
|
|
|
|
}
|
|
View::assign('data', $data);
|
|
View::assign('count', $count);
|
|
return View::fetch("User/user_invite");
|
|
}
|
|
}
|