423 lines
16 KiB
PHP
Executable File
423 lines
16 KiB
PHP
Executable File
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\common\model\OrderList;
|
||
use app\admin\controller\Base;
|
||
use \think\Request;
|
||
use think\facade\View;
|
||
use app\common\model\User;
|
||
use app\common\model\ProfitMoney;
|
||
use app\common\model\ProfitIntegral;
|
||
use app\common\model\ProfitScore;
|
||
use app\common\model\UserRecharge;
|
||
use app\common\model\ProfitDraw;
|
||
use app\common\model\Order;
|
||
use app\common\model\WxpayLog;
|
||
|
||
class Finance extends Base
|
||
{
|
||
/**
|
||
* 消费排行榜
|
||
*/
|
||
public function record(Request $request)
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$whe = [];
|
||
// $whe[] = ['order_type', '<', 12];
|
||
$whe[] = ['status', '=', 1];
|
||
if ($user_id) {
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $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)];
|
||
}
|
||
$field = "id,user_id,sum(order_total) as order_total,sum(price) as price,sum(use_money) as use_money,sum(use_integral) as use_integral";
|
||
$list = Order::where($whe)
|
||
->field($field)
|
||
->group("user_id")
|
||
->order("order_total desc")
|
||
->paginate(['list_rows' => $this->page, 'query' => request()->param()]);
|
||
$page = $list->render();
|
||
$data = [];
|
||
$data['list'] = $list->toArray()['data'];
|
||
$data['count'] = $list->total();
|
||
$data['page'] = $page;
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where('id', '=', $value['user_id'])->find();
|
||
if (empty($user_info)) {
|
||
$user_info['nickname'] ='';
|
||
$user_info['headimg'] = '';
|
||
$user_info['mobile'] = '';
|
||
$user_info['uid'] = '';
|
||
}
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
return View::fetch("Finance/record");
|
||
}
|
||
|
||
/**
|
||
* 余额明细
|
||
*/
|
||
public function money_list(Request $request)
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$whe = [];
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $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)];
|
||
}
|
||
$data = ProfitMoney::getList($whe, '*', 'id desc', $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
if ($user_info != null) {
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
} else {
|
||
$value['nickname'] = '';
|
||
$value['headimg'] = '';
|
||
$value['mobile'] = '';
|
||
$value['uid'] = '';
|
||
}
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
return View::fetch("Finance/money_list");
|
||
}
|
||
|
||
|
||
/**
|
||
* 吧唧币明细
|
||
*/
|
||
public function integral_list(Request $request)
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$whe = [];
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $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)];
|
||
}
|
||
$data = ProfitIntegral::getList($whe, '*', 'id desc', $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
if (empty($user_info)) {
|
||
$user_info['nickname'] ='';
|
||
$user_info['headimg'] = '';
|
||
$user_info['mobile'] = '';
|
||
$user_info['uid'] = '';
|
||
}
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
return View::fetch("Finance/integral_list");
|
||
}
|
||
|
||
/**
|
||
* 积分明细
|
||
*/
|
||
public function score_list(Request $request)
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$whe = [];
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $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)];
|
||
}
|
||
$data = ProfitScore::getList($whe, '*', 'id desc', $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
if (empty($user_info)) {
|
||
$user_info['nickname'] ='';
|
||
$user_info['headimg'] = '';
|
||
$user_info['mobile'] = '';
|
||
$user_info['uid'] = '';
|
||
}
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
return View::fetch("Finance/score_list");
|
||
}
|
||
|
||
/**
|
||
* 抽奖券明细
|
||
*/
|
||
public function draw_list(Request $request)
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$type = trim(input('get.type'));
|
||
$whe = [];
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $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 ($type) {
|
||
$whe[] = ['type', '=', $type];
|
||
}
|
||
$data = ProfitDraw::getList($whe, '*', 'id desc', $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
if (empty($user_info)) {
|
||
$user_info['nickname'] ='';
|
||
$user_info['headimg'] = '';
|
||
$user_info['mobile'] = '';
|
||
$user_info['uid'] = '';
|
||
}
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
$share_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['share_uid']])->find();
|
||
if (empty($share_info)) {
|
||
$share_info['nickname'] = '';
|
||
$share_info['headimg'] = '';
|
||
$share_info['mobile'] = '';
|
||
$share_info['uid'] = '';
|
||
}
|
||
$value['share_nickname'] = $share_info['nickname'];
|
||
$value['share_headimg'] = $share_info['headimg'];
|
||
$value['share_mobile'] = $share_info['mobile'];
|
||
$value['share_uid_display'] = $share_info['uid'] ?: $value['share_uid'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
return View::fetch("Finance/draw_list");
|
||
}
|
||
|
||
/**
|
||
* 充值记录
|
||
*/
|
||
public function recharge_list()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$pay_time = trim(input('get.pay_time'));
|
||
$whe = [];
|
||
|
||
if ($user_id) {
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($pay_time) {
|
||
$time = explode(' - ', $pay_time);
|
||
$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)];
|
||
}
|
||
|
||
// 从profit_pay表获取充值记录,而不是从WxpayLog表
|
||
$data = \app\common\model\ProfitPay::getList($whe, '*', 'id desc', $this->page);
|
||
$total_money = 0;
|
||
|
||
foreach ($data['list'] as &$value) {
|
||
$total_money += $value['change_money'];
|
||
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
if ($user_info != null) {
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
} else {
|
||
$value['nickname'] = '';
|
||
$value['headimg'] = '';
|
||
$value['mobile'] = '';
|
||
$value['uid'] = '';
|
||
}
|
||
}
|
||
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
View::assign('total_money', $total_money);
|
||
return View::fetch("Finance/recharge_list");
|
||
}
|
||
/**
|
||
* 无限令消费统计
|
||
*created by Admin at 2022/12/30 9:14
|
||
*/
|
||
public function infinite_list()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$where = [];
|
||
if ($user_id) {
|
||
$where[] = ['id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$where[] = ['user_id', '=', $mobile];
|
||
}
|
||
$pageSize = 15;
|
||
$list = \app\common\model\Goods::where('type', 2)->where($where)
|
||
->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
|
||
// dd($list);field('user_id,sum(goodslist_money) as goods_money,sum(goodslist_price) as goods_price,(sum(goodslist_price) - sum(goodslist_money)) as price,addtime')
|
||
$goods_price_total = 0;
|
||
$goods_money_total = 0;
|
||
$ks_money_total = 0;
|
||
foreach ($list as $value) {
|
||
$goods_price = OrderList::where('order_type', 2)
|
||
->where('goods_id', $value['id'])
|
||
->count();
|
||
$goods_money = OrderList::where('order_type', 2)
|
||
->where('goods_id', $value['id'])
|
||
->sum('goodslist_money');
|
||
$value['goods_price'] = $goods_price * $value['price'];
|
||
$value['goods_money'] = $goods_money;
|
||
$value['ks_money'] = $value['goods_price'] - $goods_money;
|
||
|
||
$goods_price_total += $value['goods_price'];
|
||
$goods_money_total += $goods_money;
|
||
$ks_money_total += $value['ks_money'];
|
||
}
|
||
$total_money[1]['goods_price_total'] = $goods_price_total;
|
||
$total_money[1]['goods_money_total'] = $goods_money_total;
|
||
$total_money[1]['ks_money_total'] = $ks_money_total;
|
||
|
||
|
||
// $list = OrderList::field('user_id,sum(goodslist_money) as goods_money,sum(goodslist_price) as goods_price,(sum(goodslist_price) - sum(goodslist_money)) as price,addtime')
|
||
// ->where($where)
|
||
// ->where('order_type',2)
|
||
// ->group('user_id')
|
||
// ->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
|
||
$page = $list->render();
|
||
$data['list'] = $list->toArray()['data'];
|
||
$data['count'] = $list->total();
|
||
$data['last_page'] = $list->toArray()['last_page'];
|
||
$data['page'] = $page;
|
||
// return $data;
|
||
// foreach ($data['list'] as &$value) {
|
||
// $user_info = User::field('nickname,headimg,mobile')->where(['id' => $value['user_id']])->find();
|
||
// $value['nickname'] = $user_info['nickname'];
|
||
// $value['headimg'] = $user_info['headimg'];
|
||
// $value['mobile'] = $user_info['mobile'];
|
||
// }
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
View::assign('total_money', $total_money);
|
||
return View::fetch("Finance/infinite_list");
|
||
}
|
||
|
||
/**
|
||
* 数据迁移:从WxpayLog迁移到ProfitPay
|
||
*/
|
||
public function migrate_payment_logs()
|
||
{
|
||
$page = input('page/d', 1);
|
||
$limit = input('limit/d', 100);
|
||
$offset = ($page - 1) * $limit;
|
||
|
||
$result = \app\common\model\WxpayLog::migrateToNewTable($limit, $offset);
|
||
|
||
if ($result['status'] == 1) {
|
||
return $this->renderSuccess($result['message'], $result);
|
||
} else {
|
||
return $this->renderError($result['message']);
|
||
}
|
||
}
|
||
}
|