提交
This commit is contained in:
parent
58fdb35f3c
commit
a6a5bf03fa
|
|
@ -921,10 +921,10 @@ class User extends Base
|
|||
->sum('change_money');
|
||||
#配置
|
||||
$rule = getConfig('base');
|
||||
$share_image = $this->product_img();
|
||||
// $share_image = $this->product_img();
|
||||
$new_data = [
|
||||
'share_title' => $rule['share_title'],
|
||||
'share_image' => $share_image,
|
||||
'share_image' => '',
|
||||
'count' => $data->total(),
|
||||
'money' => $money,
|
||||
'data' => $data->items(),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ use app\common\model\CouponReceive as CouponReceiveModel;
|
|||
use app\common\model\Goods;
|
||||
use app\common\model\GoodsList;
|
||||
use app\common\model\OrderList;
|
||||
use app\common\model\CouponReceive;
|
||||
|
||||
use app\common\helper\ConfigHelper;
|
||||
/**
|
||||
* 盒子服务类
|
||||
*
|
||||
|
|
@ -32,6 +35,12 @@ class GoodsService
|
|||
): array {
|
||||
$globalLimit = 0;
|
||||
$dailyLimit = 0;
|
||||
$daily_coupon_limit = ConfigHelper::getAppSettingKey("daily_coupon_limit");
|
||||
if ($daily_coupon_limit == "") {
|
||||
$daily_coupon_limit = 0;
|
||||
} else {
|
||||
$daily_coupon_limit = intval($daily_coupon_limit);
|
||||
}
|
||||
// 初始化返回数据
|
||||
$limitInfo = [
|
||||
'global_limit' => $globalLimit, // 全局限购数量
|
||||
|
|
@ -41,6 +50,9 @@ class GoodsService
|
|||
'user_daily_purchased' => 0, // 用户今日已购买数
|
||||
'user_daily_remaining' => $dailyLimit, // 用户今日剩余可购买数
|
||||
'user_test' => 0,
|
||||
'coupon_limit' => $daily_coupon_limit,
|
||||
'user_coupon_purchased' => 0, // 用户今日已购买数
|
||||
'user_coupon_remaining' => $daily_coupon_limit, // 用户今日剩余可购买数
|
||||
];
|
||||
|
||||
if ($userId <= 0 || $goods == null) {
|
||||
|
|
@ -69,18 +81,30 @@ class GoodsService
|
|||
$limitInfo['user_global_purchased'] = $userGlobalPurchased;
|
||||
$limitInfo['user_global_remaining'] = max(0, $globalLimit - $userGlobalPurchased);
|
||||
}
|
||||
|
||||
$day = strtotime(date('Y-m-d'));
|
||||
// 处理每日限购
|
||||
if ($dailyLimit > 0) {
|
||||
$userDailyPurchased = OrderList::field('id')
|
||||
->where($commonConditions)
|
||||
->where('shang_id', 'between', $shangCountId)
|
||||
->where('addtime', '>=', strtotime(date('Y-m-d')))
|
||||
->where('addtime', '>=', $day)
|
||||
->count();
|
||||
$limitInfo['user_daily_purchased'] = $userDailyPurchased;
|
||||
$limitInfo['user_daily_remaining'] = max(0, $dailyLimit - $userDailyPurchased);
|
||||
$limitInfo['daily_limit'] = $dailyLimit;
|
||||
}
|
||||
if ($daily_coupon_limit > 0) {
|
||||
$user_coupon_purchased = Order::field('id')
|
||||
->where('status', '=', 1)
|
||||
->where('coupon_id', '>', 0)
|
||||
->where('user_id', '=', $userId)
|
||||
->where('pay_time', '>=', $day)
|
||||
->count();
|
||||
|
||||
$limitInfo['user_coupon_purchased'] = $user_coupon_purchased;
|
||||
$limitInfo['user_coupon_remaining'] = max(0, $daily_coupon_limit - $user_coupon_purchased);
|
||||
$limitInfo['coupon_limit'] = $daily_coupon_limit;
|
||||
}
|
||||
|
||||
return $limitInfo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,10 +96,11 @@ class PaymentCalculator
|
|||
$today_count = CouponReceiveModel::where('user_id', '=', $user['id'])
|
||||
->where('addtime', '>=', $today_start)
|
||||
->where('addtime', '<=', $today_end)
|
||||
->where('status', '=', 1)
|
||||
->count();
|
||||
if ($today_count >= $daily_coupon_limit) {
|
||||
return ['status' => 0, 'msg' => '今日优惠券次数已达上限'];
|
||||
// $is_daily_coupon = false;
|
||||
// return ['status' => 0, 'msg' => '今日优惠券次数已达上限'];
|
||||
$is_daily_coupon = false;
|
||||
}
|
||||
}
|
||||
if ($is_daily_coupon) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use app\common\model\CouponReceive;
|
|||
use app\common\model\Coupon;
|
||||
use app\common\model\Order;
|
||||
use think\facade\Db;
|
||||
use app\common\model\OrderListRecovery;
|
||||
|
||||
/**
|
||||
* 排行榜服务类
|
||||
|
|
@ -20,11 +21,11 @@ class RankService
|
|||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getRankList($type,$page,$limit)
|
||||
public function getRankList($type, $page, $limit)
|
||||
{
|
||||
|
||||
|
||||
// 验证排行榜类型是否有效
|
||||
$validTypes = ['diamond', 'integral', 'dadajuan', 'invite', 'loss','loss_desc'];
|
||||
$validTypes = ['diamond', 'integral', 'dadajuan', 'invite', 'loss', 'loss_desc'];
|
||||
if (!in_array($type, $validTypes)) {
|
||||
throw new \Exception('无效的排行榜类型');
|
||||
}
|
||||
|
|
@ -34,7 +35,7 @@ class RankService
|
|||
$startTime = !empty($timeSettings['start_time']) ? strtotime($timeSettings['start_time']) : 0;
|
||||
$endTime = !empty($timeSettings['end_time']) ? strtotime($timeSettings['end_time']) : time();
|
||||
|
||||
|
||||
|
||||
$rankService = new \app\common\service\RankService();
|
||||
// 初始化返回数据
|
||||
$data = [];
|
||||
|
|
@ -56,12 +57,12 @@ class RankService
|
|||
case 'invite': // 邀请新人排行榜
|
||||
$data = $rankService->getInviteRank($startTime, $endTime, $page, $limit);
|
||||
break;
|
||||
|
||||
|
||||
case 'loss': // 亏损补贴排行榜
|
||||
$data = $rankService->getLossRank($startTime, $endTime, $page, $limit);
|
||||
break;
|
||||
case 'loss_desc'://亏损率排行榜
|
||||
$data = $rankService->getLossRank($startTime, $endTime, $page, $limit,'loss_rate');
|
||||
$data = $rankService->getLossRank($startTime, $endTime, $page, $limit, 'loss_rate');
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ class RankService
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取钻石排行榜数据
|
||||
*
|
||||
* @param int $startTime 开始时间戳
|
||||
|
|
@ -202,8 +203,7 @@ class RankService
|
|||
{
|
||||
// 构建查询条件
|
||||
$where = [
|
||||
['status', '=', 1],
|
||||
['use_money2', '>', 0],
|
||||
['money', '>', 0],
|
||||
[
|
||||
'user_id',
|
||||
'not in',
|
||||
|
|
@ -215,21 +215,28 @@ class RankService
|
|||
|
||||
// 添加时间范围条件
|
||||
if ($startTime > 0) {
|
||||
$where[] = ['pay_time', '>=', $startTime];
|
||||
$where[] = ['addtime', '>=', $startTime];
|
||||
}
|
||||
if ($endTime > 0) {
|
||||
$where[] = ['pay_time', '<=', $endTime];
|
||||
$where[] = ['addtime', '<=', $endTime];
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
$list = Order::where($where)
|
||||
->field('user_id, sum(use_money2) as use_money')
|
||||
$list = OrderListRecovery::where($where)
|
||||
->field('user_id, sum(money) as use_money')
|
||||
->group('user_id')
|
||||
->order('use_money desc')
|
||||
->page($page, $limit)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// // 查询数据
|
||||
// $list = Order::where($where)
|
||||
// ->field('user_id, sum(use_money2) as use_money')
|
||||
// ->group('user_id')
|
||||
// ->order('use_money desc')
|
||||
// ->page($page, $limit)
|
||||
// ->select()
|
||||
// ->toArray();
|
||||
|
||||
// 处理用户信息
|
||||
$rankList = [];
|
||||
foreach ($list as $index => $item) {
|
||||
|
|
@ -240,7 +247,7 @@ class RankService
|
|||
'user_id' => $item['user_id'],
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'headimg' => imageUrl($userInfo['headimg']),
|
||||
'value' => $item['use_money'],
|
||||
'value' => $item['use_money']*100,
|
||||
'unit' => '达达卷'
|
||||
];
|
||||
}
|
||||
|
|
@ -354,18 +361,18 @@ class RankService
|
|||
// 查询用户出货金额
|
||||
$usersWithOutputMoney = [];
|
||||
$users = Order::where($orderWhere)->field('DISTINCT user_id')->select()->toArray();
|
||||
|
||||
|
||||
foreach ($users as $user) {
|
||||
$userId = $user['user_id'];
|
||||
|
||||
|
||||
// 构建特定用户的查询条件
|
||||
$userOrderListWhere = $orderListWhere;
|
||||
$userOrderListWhere[] = ['user_id', '=', $userId];
|
||||
|
||||
|
||||
// 查询用户出货金额
|
||||
$outputMoney = \app\common\model\OrderList::where($userOrderListWhere)
|
||||
->sum('goodslist_money');
|
||||
|
||||
|
||||
if ($outputMoney > 0) {
|
||||
$usersWithOutputMoney[$userId] = $outputMoney;
|
||||
}
|
||||
|
|
@ -374,22 +381,22 @@ class RankService
|
|||
// 计算亏损数据
|
||||
$rankList = [];
|
||||
$index = 0;
|
||||
|
||||
|
||||
// 从订单总金额查询结果中获取数据
|
||||
$moneyResult = Db::table($orderSubQuery . ' as t')->where('money', '>', 0)->select()->toArray();
|
||||
|
||||
|
||||
foreach ($moneyResult as $item) {
|
||||
$userId = $item['user_id'];
|
||||
$consumeMoney = $item['money']; // 消耗金额
|
||||
|
||||
|
||||
// 如果有出货金额数据
|
||||
if (isset($usersWithOutputMoney[$userId])) {
|
||||
$outputMoney = $usersWithOutputMoney[$userId]; // 出货金额
|
||||
|
||||
|
||||
// 计算亏损金额和亏损率
|
||||
$lossMoney = $consumeMoney - $outputMoney;
|
||||
$lossRate = $consumeMoney > 0 ? round(($lossMoney / $consumeMoney) * 100, 2) : 0;
|
||||
|
||||
|
||||
// 只有亏损的才纳入排行
|
||||
if ($lossMoney > 0) {
|
||||
$rankList[] = [
|
||||
|
|
@ -402,24 +409,24 @@ class RankService
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 根据排序字段对结果进行排序
|
||||
if ($sortField == 'loss_rate') {
|
||||
// 按亏损率降序排序
|
||||
usort($rankList, function($a, $b) {
|
||||
usort($rankList, function ($a, $b) {
|
||||
return $b['loss_rate'] <=> $a['loss_rate'];
|
||||
});
|
||||
} else {
|
||||
// 默认按亏损金额降序排序
|
||||
usort($rankList, function($a, $b) {
|
||||
usort($rankList, function ($a, $b) {
|
||||
return $b['loss_money'] <=> $a['loss_money'];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 分页处理
|
||||
$offset = ($page - 1) * $limit;
|
||||
$rankList = array_slice($rankList, $offset, $limit);
|
||||
|
||||
|
||||
// 处理用户信息和排名
|
||||
$result = [];
|
||||
foreach ($rankList as $index => $item) {
|
||||
|
|
@ -438,7 +445,7 @@ class RankService
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
public/img_poster.jpg
Executable file → Normal file
BIN
public/img_poster.jpg
Executable file → Normal file
Binary file not shown.
|
Before Width: | Height: | Size: 540 KiB After Width: | Height: | Size: 820 KiB |
BIN
public/ueditor/php/upload/image/20250412/1744454475267522.png
Normal file
BIN
public/ueditor/php/upload/image/20250412/1744454475267522.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 87 KiB |
BIN
public/ueditor/php/upload/image/20250412/1744454510677887.png
Normal file
BIN
public/ueditor/php/upload/image/20250412/1744454510677887.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
BIN
public/ueditor/php/upload/image/20250412/1744462057231256.jpg
Normal file
BIN
public/ueditor/php/upload/image/20250412/1744462057231256.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 869 KiB |
Loading…
Reference in New Issue
Block a user