add
This commit is contained in:
270
app/admin/controller/Cash.php
Normal file
270
app/admin/controller/Cash.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\PayDetails;
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\WithDraw;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\SysException;
|
||||
use think\facade\Db;
|
||||
|
||||
class Cash extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
public function selectUserRechargeByUserId()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->successWithData(DatabaseRoute::paginateAllDb('pay_details', function ($query) use ($params) {
|
||||
$query->alias('s')
|
||||
->leftJoin('tb_user u', 'u.user_id = s.user_id')
|
||||
->field([
|
||||
's.id', 's.classify',
|
||||
's.order_id' => 'orderId',
|
||||
's.money',
|
||||
's.user_id' => 'userId',
|
||||
's.pay_diamond' => 'payDiamond',
|
||||
's.diamond',
|
||||
's.state',
|
||||
's.create_time' => 'createTime',
|
||||
's.pay_time' => 'payTime',
|
||||
'u.user_name' => 'userName',
|
||||
'u.phone',
|
||||
]);
|
||||
// 动态条件拼接
|
||||
if (!empty($params['startTime']) && !empty($params['endTime'])) {
|
||||
$query->whereBetween('s.create_time', [$params['startTime'], $params['endTime']]);
|
||||
}
|
||||
|
||||
if (!empty($params['userName'])) {
|
||||
$query->whereLike('u.user_name', '%' . $params['userName'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($params['orderId'])) {
|
||||
$query->whereLike('s.order_id', '%' . $params['orderId'] . '%');
|
||||
}
|
||||
|
||||
if (isset($params['userId'])) {
|
||||
$query->where('u.user_id', $params['userId']);
|
||||
}
|
||||
|
||||
if (isset($params['state']) && $params['state'] !== -1) {
|
||||
$query->where('s.state', $params['state']);
|
||||
} else {
|
||||
$query->where('s.state', '<>', -1);
|
||||
}
|
||||
|
||||
|
||||
return $query;
|
||||
}, $params['page'], $params['limit'], 's.create_time'));
|
||||
}
|
||||
|
||||
|
||||
public function statisticsIncomeMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
// 调用统计服务方法
|
||||
$sumMoney = \app\admin\model\Cash::statisticsIncomeMoney($get['time'], $get['flag'], null);
|
||||
$courseMoney = \app\admin\model\Cash::statisticsIncomeMoney($get['time'], $get['flag'], 1);
|
||||
$vipMoney = \app\admin\model\Cash::statisticsIncomeMoney($get['time'], $get['flag'], 2);
|
||||
|
||||
// 构建返回数据
|
||||
$map = [
|
||||
'sumMoney' => is_null($sumMoney) ? 0.00 : $sumMoney,
|
||||
'courseMoney' => is_null($courseMoney) ? 0.00 : $courseMoney,
|
||||
'vipMoney' => is_null($vipMoney) ? 0.00 : $vipMoney
|
||||
];
|
||||
$this->n_success(['data' => $map]); ;
|
||||
}
|
||||
|
||||
// 财务提现统计
|
||||
public function statisticsCashMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$time = $get['time'];
|
||||
$flag = $get['flag'];
|
||||
// 验证时间格式并转换为时间戳
|
||||
$timestamp = strtotime($time);
|
||||
if ($timestamp === false) {
|
||||
$this->error('无效的时间格式,请使用 yyyy-MM-dd 格式');
|
||||
}
|
||||
|
||||
// 初始化开始和结束时间(默认按日)
|
||||
$startTime = date('Y-m-d 00:00:00', $timestamp);
|
||||
$endTime = date('Y-m-d 23:59:59', $timestamp);
|
||||
|
||||
// 根据flag调整时间范围
|
||||
if ($flag == 2) {
|
||||
// 按月:当月第一天 00:00:00 至 当月最后一天 23:59:59
|
||||
$startTime = date('Y-m-01 00:00:00', $timestamp); // 当月1号
|
||||
$lastDay = date('t', $timestamp); // 获取当月总天数(t是原生格式化符)
|
||||
$endTime = date('Y-m-' . $lastDay . ' 23:59:59', $timestamp);
|
||||
} elseif ($flag == 3) {
|
||||
// 按年:当年第一天 00:00:00 至 当年最后一天 23:59:59
|
||||
$startTime = date('Y-01-01 00:00:00', $timestamp); // 当年1月1号
|
||||
$endTime = date('Y-12-31 23:59:59', $timestamp); // 当年12月31号
|
||||
}
|
||||
|
||||
$sumMoney = DatabaseRoute::getAllDbData('cash_out', function($query) use ($startTime, $endTime) {
|
||||
$query->where(['state' => 1]);
|
||||
$query->whereBetween('create_at', [$startTime, $endTime]);
|
||||
return $query;
|
||||
})->sum('money');
|
||||
|
||||
$countMoney = DatabaseRoute::getAllDbData('cash_out', function($query) use ($startTime, $endTime) {
|
||||
$query->whereBetween('create_at', [$startTime, $endTime]);
|
||||
return $query;
|
||||
})->count();
|
||||
|
||||
$stayMoney = DatabaseRoute::getAllDbData('cash_out', function($query) use ($startTime, $endTime) {
|
||||
$query->where(['state' => 0]);
|
||||
$query->whereBetween('create_at', [$startTime, $endTime]);
|
||||
return $query;
|
||||
})->count();
|
||||
|
||||
$map = [
|
||||
// 金额字段,若为null则赋值0.00(保留两位小数)
|
||||
'sumMoney' => is_null($sumMoney) ? 0.00 : (float)$sumMoney,
|
||||
// 计数字段,若为null则赋值0(整数)
|
||||
'countMoney' => is_null($countMoney) ? 0 : (int)$countMoney,
|
||||
// 待处理金额字段,处理逻辑同上
|
||||
'stayMoney' => is_null($stayMoney) ? 0 : (int)$stayMoney
|
||||
];
|
||||
$this->n_success(['data' => $map]);
|
||||
}
|
||||
|
||||
// 查询所有用户充值信息列表
|
||||
public function selectUserRecharge()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(!empty($get['state']) && $get['state'] == -1) {
|
||||
$get['state'] = null;
|
||||
}
|
||||
$get['startTime'] = date('Y-m-d 00:00:00', strtotime($get['startTime']));
|
||||
$get['endTime'] = date('Y-m-d 23:59:59', strtotime($get['endTime']));
|
||||
$this->n_success(['data' => \app\admin\model\Cash::selectPayDetails($get)]);
|
||||
}
|
||||
|
||||
|
||||
public function payMember()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$time = $get['time'];$flag = $get['flag'];$payClassify = empty($get['payClassify'])?null:$get['payClassify'];
|
||||
// 1. 统计总支付金额(不指定分类)
|
||||
$sumMoney = PayDetails::selectSumPayByClassify(null, $flag, $time, $payClassify);
|
||||
|
||||
// 2. 按支付渠道分别统计(1-8对应不同渠道)
|
||||
$channelMoneys = [
|
||||
1 => PayDetails::selectSumPayByClassify(1, $flag, $time, $payClassify), // 微信App
|
||||
2 => PayDetails::selectSumPayByClassify(2, $flag, $time, $payClassify), // 微信公众号
|
||||
3 => PayDetails::selectSumPayByClassify(3, $flag, $time, $payClassify), // 微信小程序
|
||||
4 => PayDetails::selectSumPayByClassify(4, $flag, $time, $payClassify), // 支付宝App
|
||||
5 => PayDetails::selectSumPayByClassify(5, $flag, $time, $payClassify), // 支付宝H5
|
||||
6 => PayDetails::selectSumPayByClassify(6, $flag, $time, $payClassify), // 抖音
|
||||
7 => PayDetails::selectSumPayByClassify(7, $flag, $time, $payClassify), // 苹果
|
||||
8 => PayDetails::selectSumPayByClassify(8, $flag, $time, $payClassify) // 快手
|
||||
];
|
||||
|
||||
// 3. 构建结果映射(处理null值,默认为0.00)
|
||||
$result = [
|
||||
'sumMoney' => $sumMoney ?? 0.00,
|
||||
'weiXinAppMoney' => $channelMoneys[1] ?? 0.00,
|
||||
'weiXinGZHMoney' => $channelMoneys[2] ?? 0.00,
|
||||
'weiXinXCXMoney' => $channelMoneys[3] ?? 0.00,
|
||||
'zhiFuBaoAppMoney' => $channelMoneys[4] ?? 0.00,
|
||||
'zhiFuBaoH5Money' => $channelMoneys[5] ?? 0.00,
|
||||
'dyMoney' => $channelMoneys[6] ?? 0.00,
|
||||
'iosMoney' => $channelMoneys[7] ?? 0.00,
|
||||
'ksMoney' => $channelMoneys[8] ?? 0.00
|
||||
];
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
public static function send($userInfo, $title, $content)
|
||||
{
|
||||
if (!empty($userInfo['client_id'])) {
|
||||
|
||||
}
|
||||
|
||||
Db::name('message_info')->insert([
|
||||
'content' => $content,
|
||||
'title' => $title,
|
||||
'state' => 5,
|
||||
'is_see' => 0,
|
||||
'user_name' => $userInfo['user_name'],
|
||||
'user_id' => $userInfo['user_id']
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function sendMsg()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
if ($params['flag'] == 1) {
|
||||
$userInfo = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params) {
|
||||
return $query->where([
|
||||
'phone' => $params['phone']
|
||||
]);
|
||||
})->find();
|
||||
|
||||
if (!$userInfo) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
$this->send($userInfo, $params['title'], $params['content']);
|
||||
|
||||
}else{
|
||||
$userList = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params) {
|
||||
return $query;
|
||||
})->list();
|
||||
$chunks = array_chunk($userList, ceil(count($userList) / 3));
|
||||
pushQueue($chunks[0]);
|
||||
pushQueue($chunks[1]);
|
||||
pushQueue($chunks[2]);
|
||||
|
||||
}
|
||||
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 用户提现记录
|
||||
public function selectPayDetails()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$cashOut = [];
|
||||
if(isset($get['userId'])) {
|
||||
$cashOut['userId'] = $get['userId'];
|
||||
}
|
||||
$res = \app\admin\model\Cash::selectCashOutList($get['page'], $get['limit'], $cashOut);
|
||||
$this->n_success(['data' => $res]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提现接口
|
||||
*/
|
||||
public function withdraw()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$userId = $get['userId'] ?? null;
|
||||
$money = $get['money'] ?? null;
|
||||
$msg = $get['msg'] ?? null;
|
||||
// 验证验证码是否为空
|
||||
if (empty($msg)) {
|
||||
$this->error('请输入验证码');
|
||||
}
|
||||
debounce("withdraw:".$userId, 30);
|
||||
runWithLock("lock:withdraw:{$userId}", 300, function () use ($userId, $money, $msg) {
|
||||
WithDraw::goWithDraw($userId, $money, $msg, true, true);
|
||||
});
|
||||
$this->success('提现成功,将在三个工作日内到账,请耐心等待!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user