提交代码
This commit is contained in:
parent
407269dae6
commit
4772f5e996
6
.env
6
.env
|
|
@ -6,9 +6,9 @@ DEFAULT_TIMEZONE = Asia/Shanghai
|
|||
[DATABASE]
|
||||
TYPE = mysql
|
||||
HOSTNAME = 127.0.0.1
|
||||
DATABASE = youda
|
||||
USERNAME = youda
|
||||
PASSWORD = youda
|
||||
DATABASE = youda_test
|
||||
USERNAME = youda_test
|
||||
PASSWORD = youda_test
|
||||
HOSTPORT = 3306
|
||||
CHARSET = utf8
|
||||
DEBUG = false
|
||||
|
|
|
|||
83
app/admin/controller/GoodsOffshelfController.php
Normal file
83
app/admin/controller/GoodsOffshelfController.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class GoodsOffshelfController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 显示下架日志列表
|
||||
*/
|
||||
public function log(Request $request)
|
||||
{
|
||||
$query = [];
|
||||
|
||||
// 处理搜索条件
|
||||
if ($goodsId = $request->param('goods_id')) {
|
||||
$query[] = ['goods_id', '=', $goodsId];
|
||||
}
|
||||
|
||||
$startTime = $request->param('start_time');
|
||||
$endTime = $request->param('end_time');
|
||||
|
||||
if ($startTime) {
|
||||
$query[] = ['create_time', '>=', strtotime($startTime)];
|
||||
}
|
||||
|
||||
if ($endTime) {
|
||||
$query[] = ['create_time', '<=', strtotime($endTime . ' 23:59:59')];
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
$list = Db::name('goods_offshelf_log')
|
||||
->alias('a')
|
||||
->join('goods g', 'a.goods_id = g.id', 'left')
|
||||
->field('a.*, g.title as goods_title, g.status as goods_status')
|
||||
->where($query)
|
||||
->order('a.id desc')
|
||||
->paginate(15);
|
||||
|
||||
$count = $list->total();
|
||||
|
||||
// 处理数据
|
||||
foreach ($list as &$item) {
|
||||
$item['create_time_text'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
}
|
||||
|
||||
View::assign('list', $list);
|
||||
View::assign('count', $count);
|
||||
View::assign('page', $list->render());
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记下架日志为已读
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
// 获取当前显示的所有未读记录并标记为已读
|
||||
Db::name('goods_offshelf_log')
|
||||
->where('is_read', 0)
|
||||
->update(['is_read' => 1]);
|
||||
|
||||
return json(['status' => 1, 'msg' => '标记成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读下架日志的数量
|
||||
*/
|
||||
public function getUnreadCount()
|
||||
{
|
||||
$count = Db::name('goods_offshelf_log')
|
||||
->where('is_read', 0)
|
||||
->count();
|
||||
|
||||
return json(['status' => 1, 'count' => $count]);
|
||||
}
|
||||
}
|
||||
|
|
@ -429,4 +429,8 @@ Route::rule('statistics_shipmentList', 'Statistics/shipmentList', 'GET');
|
|||
Route::rule('statistics_productsOverview', 'Statistics/productsOverview', 'GET');
|
||||
Route::rule('statistics_getBoxStatistics', 'Statistics/getBoxStatistics', 'GET');
|
||||
Route::rule('statistics_getSummaryStatistics', 'Statistics/getSummaryStatistics', 'GET');
|
||||
Route::rule('statistics_exportProfit', 'Statistics/exportProfit', 'GET');
|
||||
Route::rule('statistics_exportProfit', 'Statistics/exportProfit', 'GET');
|
||||
|
||||
// 盒子下架日志相关路由
|
||||
Route::post('goods_offshelf_read', 'GoodsOffshelfController/read');
|
||||
Route::get('goods_offshelf_unread_count', 'GoodsOffshelfController/getUnreadCount');
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
<input type="number" name="exchange_times"
|
||||
value="{$app_setting.exchange_times|default=0}" autocomplete="off"
|
||||
class="layui-input" min="0">
|
||||
<div class="layui-form-mid layui-word-aux">每天允许兑换几次,0不限次数</div>
|
||||
<div class="layui-form-mid layui-word-aux">每天允许购买几次,0不限次数</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
|
|
@ -150,6 +150,15 @@
|
|||
<div class="layui-form-mid layui-word-aux">每日消费达到此金额后可签到,0表示不限制</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">显示兑换达达卷按钮</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="show_dadajuan_limit"
|
||||
value="{$app_setting.show_dadajuan_limit|default=0}" autocomplete="off"
|
||||
class="layui-input" min="0">
|
||||
<div class="layui-form-mid layui-word-aux">当用户消费满足金额后,才显示兑换达达卷按钮。0不做限制</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">外卖盒子ID</label>
|
||||
<div class="layui-input-block">
|
||||
|
|
|
|||
|
|
@ -35,7 +35,10 @@
|
|||
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
|
||||
</button>
|
||||
<button class="layui-btn" id="addGoodsBtn">添加盒子</button>
|
||||
<button class="layui-btn layui-btn-normal" id="offshelfLogBtn">自动下架日志</button>
|
||||
<button class="layui-btn layui-btn-normal" id="offshelfLogBtn">自动下架日志
|
||||
|
||||
<span class="layui-badge layui-hide" id="offshelfLogCount"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
默认不显示福利屋数据,查看福利屋盒子,请在盒子类型选择福利屋单独查看。
|
||||
|
|
@ -85,6 +88,10 @@
|
|||
<br>
|
||||
<button class="layui-btn layui-btn-warm layui-btn-sm">利润值:{{d.xiajia_lirun}}%</button>
|
||||
<br>
|
||||
{{# if(d.xiajia_jine > 0){ }}
|
||||
<button class="layui-btn layui-btn-warm layui-btn-sm">下架金额:{{d.xiajia_jine}}</button>
|
||||
<br>
|
||||
{{# } }}
|
||||
<button class="layui-btn layui-btn-warm layui-btn-sm">阈值:{{d.xiajia_auto_coushu}}抽</button>
|
||||
{{# } else { }}
|
||||
<button class="layui-btn layui-btn-danger layui-btn-radius layui-btn-sm">未开启</button>
|
||||
|
|
@ -247,6 +254,12 @@
|
|||
layer = layui.layer;
|
||||
laytpl = layui.laytpl;
|
||||
|
||||
// 加载未读下架日志数量
|
||||
loadUnreadOffshelfLogCount();
|
||||
|
||||
// 定时刷新未读数量(每60秒)
|
||||
setInterval(loadUnreadOffshelfLogCount, 60000);
|
||||
|
||||
// 加载盒子类型数据
|
||||
$.ajax({
|
||||
url: '{:url("/admin/api/goods/types")}',
|
||||
|
|
@ -470,6 +483,10 @@
|
|||
shade: 0.3,
|
||||
area: ['90%', '90%'],
|
||||
content: url,
|
||||
end: function() {
|
||||
// 日志页面关闭后刷新未读数量
|
||||
loadUnreadOffshelfLogCount();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -707,6 +724,26 @@
|
|||
content: '<div style="text-align: center;"><img src="' + obj.src + '" style="max-width: 100%;" /></div>'
|
||||
});
|
||||
}
|
||||
|
||||
// 加载未读下架日志数量
|
||||
function loadUnreadOffshelfLogCount() {
|
||||
var $ = layui.$;
|
||||
$.ajax({
|
||||
url: '{:url("/admin/goods_offshelf_unread_count")}',
|
||||
type: 'GET',
|
||||
success: function(res) {
|
||||
if (res.status === 1) {
|
||||
if (res.count > 0) {
|
||||
$('#offshelfLogCount').text(res.count).removeClass('layui-hide');
|
||||
|
||||
} else {
|
||||
$('#offshelfLogCount').addClass('layui-hide');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.combined-values div {
|
||||
|
|
|
|||
|
|
@ -262,6 +262,13 @@
|
|||
placeholder="请输入从多少抽数后开始检测" class="layui-input" style="width: 600px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item xiajia-config" style="display: none;">
|
||||
<label class="layui-form-label">下架金额</label>
|
||||
<div class="layui-input-inline" style="width: 600px">
|
||||
<input type="number" name="xiajia_jine" value="0"
|
||||
placeholder="当盒子利润小于该金额时下架(如-100)" class="layui-input" style="width: 600px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item jiesuojine">
|
||||
<label class="layui-form-label">解锁金额</label>
|
||||
<div class="layui-input-inline" style="width: 600px">
|
||||
|
|
|
|||
|
|
@ -261,13 +261,18 @@
|
|||
<input type="number" name="xiajia_lirun" value="{$info.xiajia_lirun|default=0}" placeholder="请输入下架利润值(百分比,可以为负)" class="layui-input" style="width: 600px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item xiajia-config" {$info['
|
||||
is_auto_xiajia']?'':'style="display:none"'}>
|
||||
<div class="layui-form-item xiajia-config" {$info['is_auto_xiajia']?'':'style="display:none"'}>
|
||||
<label class="layui-form-label">下架抽数阈值</label>
|
||||
<div class="layui-input-inline" style="width: 600px">
|
||||
<input type="number" name="xiajia_auto_coushu" value="{$info.xiajia_auto_coushu|default=0}" placeholder="请输入从多少抽数后开始检测" class="layui-input" style="width: 600px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item xiajia-config" {$info['is_auto_xiajia']?'':'style="display:none"'}>
|
||||
<label class="layui-form-label">下架金额</label>
|
||||
<div class="layui-input-inline" style="width: 600px">
|
||||
<input type="number" name="xiajia_jine" value="{$info.xiajia_jine|default=0}" placeholder="当盒子利润小于该金额时下架(如-100)" class="layui-input" style="width: 600px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item jiesuojine">
|
||||
<label class="layui-form-label">解锁金额</label>
|
||||
<div class="layui-input-inline" style="width: 600px">
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
<th>ID</th>
|
||||
<th>盒子ID</th>
|
||||
<th>盒子名称</th>
|
||||
<th>备注</th>
|
||||
<th>当前利润率(%)</th>
|
||||
<th>配置下架利润(%)</th>
|
||||
<th>订单总价值</th>
|
||||
|
|
@ -55,9 +56,15 @@
|
|||
<tbody>
|
||||
{volist name="list" id="vo"}
|
||||
<tr>
|
||||
<td>{$vo.id}</td>
|
||||
<td>
|
||||
{if condition="$vo.is_read eq 0"}
|
||||
<span class="unread-dot"></span>
|
||||
{/if}
|
||||
{$vo.id}
|
||||
</td>
|
||||
<td>{$vo.goods_id}</td>
|
||||
<td>{$vo.goods_title}</td>
|
||||
<td><div style="max-width:400px;word-break:break-all;white-space:normal;">{$vo.remarks|default=''}</div></td>
|
||||
<td>{$vo.profit_rate}%</td>
|
||||
<td>{$vo.xiajia_lirun}%</td>
|
||||
<td>{$vo.order_total}</td>
|
||||
|
|
@ -94,11 +101,26 @@
|
|||
</div>
|
||||
</div>
|
||||
{include file="Public:footer"/}
|
||||
<style>
|
||||
.unread-dot {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background-color: #FF5722;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
position: relative;
|
||||
top: -2px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer', 'table', 'laydate'], function () {
|
||||
var $ = layui.$;
|
||||
var laydate = layui.laydate;
|
||||
|
||||
// 标记所有未读数据为已读
|
||||
markAsRead();
|
||||
|
||||
// 日期选择器
|
||||
laydate.render({
|
||||
elem: '#start_time'
|
||||
|
|
@ -108,6 +130,21 @@
|
|||
});
|
||||
});
|
||||
|
||||
// 标记所有显示的数据为已读
|
||||
function markAsRead() {
|
||||
var $ = layui.$;
|
||||
$.ajax({
|
||||
url: "{:url('/admin/goods_offshelf_read')}",
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
if(res.status == 1) {
|
||||
console.log("已标记所有数据为已读");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 查看盒子详情
|
||||
function view_goods(id) {
|
||||
var url = "{:url('/admin/goods_edit')}?id=" + id;
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ class Login extends Base
|
|||
return $uid;
|
||||
}
|
||||
/**
|
||||
* 微信授权,登录接口
|
||||
* 微信授权,登录接口 微信登录
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
|
|
@ -435,7 +435,7 @@ class Login extends Base
|
|||
|
||||
|
||||
/**
|
||||
* 微信授权
|
||||
* 微信授权-公众号登录
|
||||
*/
|
||||
public function h5login()
|
||||
{
|
||||
|
|
@ -832,4 +832,256 @@ class Login extends Base
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号登录接口
|
||||
*/
|
||||
public function mobileLogin()
|
||||
{
|
||||
// 初始化日志收集变量
|
||||
$logMessages = [];
|
||||
|
||||
try {
|
||||
// 获取请求参数
|
||||
$mobile = request()->param("mobile", '');
|
||||
$code = request()->param("code", '');
|
||||
$pid_pid = request()->param('pid', 0);
|
||||
|
||||
// 验证必要参数
|
||||
if (empty($mobile) || empty($code)) {
|
||||
$logMessages[] = '手机号或验证码为空: ' . $mobile;
|
||||
Log::error(end($logMessages));
|
||||
return $this->renderError('请求参数错误');
|
||||
}
|
||||
|
||||
$logMessages[] = '用户开始手机号登录: ' . $mobile;
|
||||
$click_id = request()->header('clickid');
|
||||
|
||||
// 验证手机验证码
|
||||
$redis = (new RedisHelper())->getRedis();
|
||||
$redisKey = "VerificationCode:{$mobile}";
|
||||
$redisCode = $redis->get($redisKey);
|
||||
|
||||
if (empty($redisCode) || $redisCode != $code) {
|
||||
$logMessages[] = '验证码错误: ' . $code . ',正确验证码: ' . $redisCode;
|
||||
Log::error(end($logMessages));
|
||||
return $this->renderError('验证码错误');
|
||||
}
|
||||
|
||||
// 验证通过后删除Redis中的验证码
|
||||
$redis->del($redisKey);
|
||||
|
||||
// 检查用户是否已存在
|
||||
$user = User::getInfo(['mobile' => $mobile]);
|
||||
|
||||
// 如果用户已存在
|
||||
if ($user) {
|
||||
if ($user['click_id'] != $click_id) {
|
||||
$res[] = User::where(['id' => $user['id']])->update(['click_id' => $click_id]);
|
||||
}
|
||||
|
||||
// 检查并生成uid
|
||||
$this->processUid($user);
|
||||
|
||||
// token时间戳
|
||||
$time = time();
|
||||
// token字符串
|
||||
$token_num = getRandStr(10);
|
||||
// 加密token
|
||||
$account_token = user_md5($user['id'] . $token_num . $time);
|
||||
// 更新账号信息
|
||||
$last_login_ip1 = $this->getRealIp();
|
||||
$result = $this->ip_location($last_login_ip1);
|
||||
$ip_province = '';
|
||||
$ip_city = '';
|
||||
$ip_adcode = '';
|
||||
if ($result) {
|
||||
$ip_province = $result['province'];
|
||||
$ip_city = $result['city'];
|
||||
$ip_adcode = $result['adcode'];
|
||||
}
|
||||
|
||||
// 检查UserAccount是否存在
|
||||
$userAccount = UserAccount::where(['user_id' => $user['id']])->find();
|
||||
if ($userAccount) {
|
||||
// 存在则更新
|
||||
$res[] = UserAccount::where(['user_id' => $user['id']])->update([
|
||||
'account_token' => $account_token,
|
||||
'token_num' => $token_num,
|
||||
'token_time' => $time,
|
||||
'last_login_time' => $time,
|
||||
'last_login_ip' => ip2long($last_login_ip1),
|
||||
'last_login_ip1' => $last_login_ip1,
|
||||
'ip_adcode' => $ip_adcode,
|
||||
'ip_province' => $ip_province,
|
||||
'ip_city' => $ip_city,
|
||||
]);
|
||||
} else {
|
||||
// 不存在则新增
|
||||
$res[] = UserAccount::insert([
|
||||
'user_id' => $user['id'],
|
||||
'account_token' => $account_token,
|
||||
'token_num' => $token_num,
|
||||
'token_time' => $time,
|
||||
'last_login_time' => $time,
|
||||
'last_login_ip' => ip2long($last_login_ip1),
|
||||
'last_login_ip1' => $last_login_ip1,
|
||||
'ip_adcode' => $ip_adcode,
|
||||
'ip_province' => $ip_province,
|
||||
'ip_city' => $ip_city,
|
||||
]);
|
||||
}
|
||||
|
||||
// 记录用户登录日志(每天只记录一次)
|
||||
UserLoginLog::recordLogin(
|
||||
$user['id'],
|
||||
'mobile',
|
||||
$last_login_ip1,
|
||||
''
|
||||
);
|
||||
|
||||
$logMessages[] = '用户手机号登录成功: ' . $mobile . ' 用户ID: ' . $user['id'];
|
||||
// 输出收集的所有日志
|
||||
Log::info(implode("==》", $logMessages));
|
||||
|
||||
return $this->renderSuccess("登录成功", $account_token);
|
||||
} else {
|
||||
// 用户不存在,创建新用户
|
||||
$pid = 0;
|
||||
if ($pid_pid) {
|
||||
$logMessages[] = "尝试获取推荐人ID: " . $pid_pid;
|
||||
$pid_info = User::where('id', '=', $pid_pid)->value("id");
|
||||
if ($pid_info) {
|
||||
$logMessages[] = "获取推荐人ID成功: " . $pid_info;
|
||||
$pid = $pid_info;
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
Db::startTrans();
|
||||
|
||||
// 生成随机昵称和头像
|
||||
$randx = rand(1000, 9999);
|
||||
$nickname = "手机用户" . $randx;
|
||||
$logMessages[] = $nickname;
|
||||
|
||||
// 使用Identicon生成默认头像
|
||||
$randx = rand(10000, 99999);
|
||||
$identicon = new \Identicon\Identicon();
|
||||
$imageData = $identicon->getImageData($mobile . $nickname);
|
||||
$uploadResult = $this->uploader->uploadFile($imageData, "storage/users/icon/default/" . $randx . ".png");
|
||||
$headimg = $uploadResult['full_url'];
|
||||
|
||||
// 插入用户记录
|
||||
$res[] = $user_id = User::insertGetId([
|
||||
'openid' => '', // 手机号注册无openid
|
||||
'mobile' => $mobile,
|
||||
'nickname' => $nickname,
|
||||
'headimg' => $headimg,
|
||||
'pid' => $pid,
|
||||
'addtime' => time(),
|
||||
'click_id' => $click_id,
|
||||
'uid' => '',
|
||||
]);
|
||||
|
||||
// 生成用户uid
|
||||
$uid = $this->generateUid($user_id);
|
||||
if ($uid) {
|
||||
User::where('id', $user_id)->update(['uid' => $uid]);
|
||||
}
|
||||
|
||||
// 如果是测试环境,给新用户赠送钻石
|
||||
$isTest = \app\common\helper\ConfigHelper::getSystemTestKey("enable_test");
|
||||
if ($isTest == "1") {
|
||||
$userCount = ProfitMoney::where('user_id', $user_id)
|
||||
->where('type', 8)
|
||||
->where('content', '=', '内测免费送')
|
||||
->count();
|
||||
if ($userCount == 0) {
|
||||
// 使用Redis锁防止重复获取
|
||||
$redis = (new RedisHelper())->getRedis();
|
||||
$lockKey = 'user:beta_reward:' . $user_id;
|
||||
if ($redis->set($lockKey, 1, ['nx', 'ex' => 60])) {
|
||||
$res[] = User::changeMoney($user_id, 50000, 8, '内测免费送');
|
||||
$logMessages[] = '赠送钻石: 50000';
|
||||
// 释放锁
|
||||
$redis->del($lockKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成账号token
|
||||
$time = time();
|
||||
$token_num = getRandStr(10);
|
||||
$account_token = user_md5($user_id . $token_num . $time);
|
||||
|
||||
// 获取IP和地理位置信息
|
||||
$last_login_ip1 = $this->getRealIp();
|
||||
$result = $this->ip_location($last_login_ip1);
|
||||
$ip_province = '';
|
||||
$ip_city = '';
|
||||
$ip_adcode = '';
|
||||
if ($result) {
|
||||
$ip_province = $result['province'];
|
||||
$ip_city = $result['city'];
|
||||
$ip_adcode = $result['adcode'];
|
||||
}
|
||||
|
||||
// 插入用户账号信息
|
||||
$res[] = UserAccount::insert([
|
||||
'user_id' => $user_id,
|
||||
'account_token' => $account_token,
|
||||
'token_num' => $token_num,
|
||||
'token_time' => $time,
|
||||
'last_login_time' => $time,
|
||||
'last_login_ip' => ip2long($last_login_ip1),
|
||||
'last_login_ip1' => $last_login_ip1,
|
||||
'ip_adcode' => $ip_adcode,
|
||||
'ip_province' => $ip_province,
|
||||
'ip_city' => $ip_city,
|
||||
]);
|
||||
|
||||
// 推荐成功后获取抽奖券
|
||||
$rule = getConfig('base');
|
||||
$draw_people_num = $rule['draw_people_num'];
|
||||
if (!empty($pid)) {
|
||||
$num = 0;
|
||||
$num = ProfitDraw::where(['type' => 5, 'user_id' => $pid, 'share_uid' => $user_id])->count();
|
||||
if (bccomp("$num", "$draw_people_num") < 0) {
|
||||
// 可以获得一张抽奖券
|
||||
$res[] = User::changeDraw($pid, 1, 5, '获得一张抽奖券', $user_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (resCheck($res)) {
|
||||
// 新用户注册也要记录登录日志
|
||||
UserLoginLog::recordLogin(
|
||||
$user_id,
|
||||
'mobile:v1.0.0',
|
||||
$last_login_ip1,
|
||||
''
|
||||
);
|
||||
|
||||
$logMessages[] = '==》用户手机号注册成功: ' . $mobile . ' 用户ID: ' . $user_id;
|
||||
// 输出收集的所有日志
|
||||
Log::info(implode("==>", $logMessages));
|
||||
|
||||
Db::commit();
|
||||
return $this->renderSuccess("登录成功", $account_token);
|
||||
} else {
|
||||
Db::rollback();
|
||||
|
||||
$logMessages[] = '==》用户手机号注册失败: ' . $mobile . ' 用户ID: ' . $user_id;
|
||||
// 输出收集的所有日志
|
||||
Log::info(implode("==>", $logMessages));
|
||||
|
||||
return $this->renderError("登录失败");
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('手机号登录失败->错误信息' . $e->getMessage());
|
||||
Log::error('手机号登录失败->错误行数' . $e->getLine());
|
||||
return $this->renderError("登录失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,8 @@ use app\common\model\Shang;
|
|||
use app\common\model\User;
|
||||
use think\facade\Db;
|
||||
use think\Request;
|
||||
use app\common\service\CommonService;
|
||||
use app\common\helper\ConfigHelper;
|
||||
|
||||
class Warehouse extends Base
|
||||
{
|
||||
|
|
@ -50,7 +52,7 @@ class Warehouse extends Base
|
|||
#自动变现货=========================
|
||||
|
||||
$type = request()->param('type/d', 0);
|
||||
|
||||
$show_dadajuan = true;
|
||||
// $type = 3;
|
||||
if ($type == 1) {#赏品
|
||||
$keyword = request()->param('keyword', '');
|
||||
|
|
@ -59,6 +61,8 @@ class Warehouse extends Base
|
|||
if ($keyword) {
|
||||
$whe[] = ['goodslist_title', 'like', '%' . $keyword . '%'];
|
||||
}
|
||||
|
||||
|
||||
#总数量
|
||||
$total = 0;
|
||||
#找到所在盒子
|
||||
|
|
@ -120,6 +124,18 @@ class Warehouse extends Base
|
|||
$data_value['orderlist_total'] = $orderlist_total;
|
||||
$data_value['orderlist_length'] = count($orderlist);
|
||||
}
|
||||
if (!$data) {
|
||||
$show_dadajuan = false;
|
||||
} else {
|
||||
$show_dadajuan_limit = ConfigHelper::getAppSettingKey('show_dadajuan_limit');
|
||||
if ($show_dadajuan_limit != null && $show_dadajuan_limit != "0") {
|
||||
$show_dadajuan_limit = intval($show_dadajuan_limit);
|
||||
$user_total_consumption = CommonService::getTotalConsumptionAmount($user_id);
|
||||
if ($user_total_consumption < $show_dadajuan_limit) {
|
||||
$show_dadajuan = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($type == 2) {#预售
|
||||
$keyword = request()->param('keyword', '');
|
||||
#搜索
|
||||
|
|
@ -370,6 +386,7 @@ class Warehouse extends Base
|
|||
'data' => $data,
|
||||
'last_page' => isset($last_page) ? $last_page : 1,
|
||||
'yufei' => $yufei,
|
||||
'show_dadajuan' => $show_dadajuan,
|
||||
];
|
||||
return $this->renderSuccess("请求成功", $new_data);
|
||||
}
|
||||
|
|
@ -582,15 +599,25 @@ class Warehouse extends Base
|
|||
if (empty($recovery_info)) {
|
||||
return $this->renderError("请选择兑换的赏品");
|
||||
}
|
||||
|
||||
$show_dadajuan_limit = ConfigHelper::getAppSettingKey('show_dadajuan_limit');
|
||||
if ($show_dadajuan_limit != null && $show_dadajuan_limit != "0") {
|
||||
$show_dadajuan_limit = intval($show_dadajuan_limit);
|
||||
$user_total_consumption = CommonService::getTotalConsumptionAmount($user_id);
|
||||
if ($user_total_consumption < $show_dadajuan_limit) {
|
||||
return $this->renderError("消费满" . $show_dadajuan_limit . "才能兑换达达卷");
|
||||
}
|
||||
}
|
||||
|
||||
$cabinet_exchange_limit = \app\common\helper\ConfigHelper::getAppSettingKey("cabinet_exchange_limit");
|
||||
if($cabinet_exchange_limit>0){
|
||||
if ($cabinet_exchange_limit > 0) {
|
||||
$today_start = strtotime(date('Y-m-d 00:00:00', time()));
|
||||
$today_end = strtotime(date('Y-m-d 23:59:59', time()));
|
||||
$today_count = OrderListRecovery::where('user_id', '=', $user_id)
|
||||
->where('addtime', '>=', $today_start)
|
||||
->where('addtime', '<=', $today_end)
|
||||
->count();
|
||||
if($today_count>=$cabinet_exchange_limit){
|
||||
if ($today_count >= $cabinet_exchange_limit) {
|
||||
return $this->renderError("今日兑换次数已达上限");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,15 @@ use think\facade\Route;
|
|||
#Login.php登录
|
||||
#============================
|
||||
Route::any('login', 'Login/login');
|
||||
Route::any('h5login', 'Login/h5login');
|
||||
// Route::any('h5login', 'Login/h5login');
|
||||
Route::any('mobileLogin', 'Login/mobileLogin');
|
||||
Route::any('login_bind_mobile', 'Login/login_bind_mobile');
|
||||
Route::any('login_bind_mobile_h5', 'Login/login_bind_mobile_h5');
|
||||
// Route::any('test', 'Login/test');
|
||||
// Route::any('test1', 'Login/test1');
|
||||
// Route::any('aa', 'Login/aa');
|
||||
Route::any('getAccessTokenOffiaccountSign', 'Login/getAccessTokenOffiaccountSign');
|
||||
//Route::any('getAccessTokenOffiaccountSign', 'Login/getAccessTokenOffiaccountSign');
|
||||
|
||||
|
||||
#============================
|
||||
#Upload.php图片上传
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class AutoGoodsOffshelf extends Command
|
|||
(SELECT sum(order_zhe_total) FROM `order` WHERE status = 1 AND goods_id = g.id and user_id not in (select id from `user` where istest>0)) as order_zhe_total,
|
||||
IFNULL((SELECT sum(goodslist_money) FROM order_list WHERE goods_id = g.id and user_id not in (select id from `user` where istest>0)), 0) goodslist_money
|
||||
FROM (
|
||||
SELECT id, xiajia_lirun, xiajia_auto_coushu,
|
||||
SELECT id, xiajia_lirun, xiajia_auto_coushu, xiajia_jine,
|
||||
IFNULL((SELECT count(1) FROM order_list WHERE goods_id = goods.id and user_id not in (select id from `user` where istest>0)), 0) AS choushu
|
||||
FROM goods
|
||||
WHERE is_auto_xiajia = 1 AND `status` = 1
|
||||
|
|
@ -47,15 +47,44 @@ class AutoGoodsOffshelf extends Command
|
|||
continue;
|
||||
}
|
||||
|
||||
// 计算利润率:(订单价值 - 出货价值) / 订单价值 * 100
|
||||
// 计算利润:订单价值 - 出货价值
|
||||
$profit = $goods['order_zhe_total'] - $goods['goodslist_money'];
|
||||
|
||||
// 下架标记
|
||||
$needOffshelf = false;
|
||||
$offshelfReason = '';
|
||||
|
||||
// 计算利润率
|
||||
$profitRate = ($profit / $goods['order_zhe_total']) * 100;
|
||||
|
||||
// 如果利润率小于配置的下架利润值,则下架盒子
|
||||
if ($profitRate < $goods['xiajia_lirun']) {
|
||||
// 基础日志信息
|
||||
$baseLogInfo = "盒子ID: {$goods['id']} | 订单总额: {$goods['order_zhe_total']} | 出货总额: {$goods['goodslist_money']} | 利润: {$profit} | 利润率: ".round($profitRate, 2)."% | 抽数: {$goods['choushu']}";
|
||||
|
||||
// 分别判断下架金额和利润率条件
|
||||
// 1. 下架金额判断
|
||||
if (!empty($goods['xiajia_jine']) && $goods['xiajia_jine'] > 0) {
|
||||
if ($profit < 0 && abs($profit) > $goods['xiajia_jine']) {
|
||||
$needOffshelf = true;
|
||||
$offshelfReason = "{$baseLogInfo} | 下架原因: 利润为{$profit},低于下架金额负{$goods['xiajia_jine']}";
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 利润率判断(即使有下架金额也进行判断)
|
||||
if (!$needOffshelf && $goods['xiajia_lirun'] > 0) {
|
||||
if ($profitRate < $goods['xiajia_lirun']) {
|
||||
$needOffshelf = true;
|
||||
$offshelfReason = "{$baseLogInfo} | 下架原因: 利润率为".round($profitRate, 2)."%,低于下架阈值{$goods['xiajia_lirun']}%";
|
||||
}
|
||||
}
|
||||
|
||||
// 需要下架的处理
|
||||
if ($needOffshelf) {
|
||||
// 更新盒子状态为已下架(状态值为0)
|
||||
Db::name('goods')->where('id', $goods['id'])->update(['status' => 0]);
|
||||
|
||||
// 计算利润率用于记录
|
||||
$profitRate = ($profit / $goods['order_zhe_total']) * 100;
|
||||
|
||||
// 记录下架日志
|
||||
Db::name('goods_offshelf_log')->insert([
|
||||
'goods_id' => $goods['id'],
|
||||
|
|
@ -63,11 +92,13 @@ class AutoGoodsOffshelf extends Command
|
|||
'xiajia_lirun' => $goods['xiajia_lirun'],
|
||||
'order_total' => $goods['order_zhe_total'],
|
||||
'goods_total' => $goods['goodslist_money'],
|
||||
'create_time' => time()
|
||||
'create_time' => time(),
|
||||
'remarks' => $offshelfReason,
|
||||
'is_read'=>0
|
||||
]);
|
||||
|
||||
$count++;
|
||||
$output->writeln("盒子ID: {$goods['id']} 当前利润率: {$profitRate}% 下架阈值: {$goods['xiajia_lirun']}% 已自动下架");
|
||||
$output->writeln("盒子ID: {$goods['id']} {$offshelfReason} 已自动下架");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,23 +150,23 @@ if (!function_exists('getConfig')) {
|
|||
*/
|
||||
function getConfig($type)
|
||||
{
|
||||
// 生成缓存键
|
||||
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
||||
$cache_key = "config:{$type}";
|
||||
// // 生成缓存键
|
||||
// $redis = (new \app\common\server\RedisHelper())->getRedis();
|
||||
// $cache_key = "config:{$type}";
|
||||
|
||||
// 尝试从缓存获取数据
|
||||
$cached_data = $redis->get($cache_key);
|
||||
if ($cached_data) {
|
||||
return json_decode($cached_data, true);
|
||||
}
|
||||
// // 尝试从缓存获取数据
|
||||
// $cached_data = $redis->get($cache_key);
|
||||
// if ($cached_data) {
|
||||
// return json_decode($cached_data, true);
|
||||
// }
|
||||
|
||||
$content = Db::name('config')->where(['key' => $type])->value('value');
|
||||
$config = json_decode($content, true);
|
||||
|
||||
// 将数据存入缓存,设置10分钟过期时间
|
||||
if ($config) {
|
||||
$redis->set($cache_key, json_encode($config), 600);
|
||||
}
|
||||
// if ($config) {
|
||||
// $redis->set($cache_key, json_encode($config), 600);
|
||||
// }
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,19 +40,19 @@ class ConfigHelper
|
|||
if (self::$appSetting !== null) {
|
||||
return self::$appSetting;
|
||||
}
|
||||
$redis = new RedisHelper();
|
||||
$cachedValue = $redis->get('config:app_setting');
|
||||
if ($cachedValue !== false) {
|
||||
self::$appSetting = json_decode($cachedValue, true);
|
||||
return self::$appSetting;
|
||||
}
|
||||
// $redis = new RedisHelper();
|
||||
// $cachedValue = $redis->get('config:app_setting');
|
||||
// if ($cachedValue !== false) {
|
||||
// self::$appSetting = json_decode($cachedValue, true);
|
||||
// return self::$appSetting;
|
||||
// }
|
||||
$app_setting = getConfig('app_setting');
|
||||
if ($app_setting) {
|
||||
self::$appSetting = $app_setting;
|
||||
$redis->set('config:app_setting', json_encode($app_setting), 86400);
|
||||
return self::$appSetting;
|
||||
// $redis->set('config:app_setting', json_encode($app_setting), 86400);
|
||||
// return self::$appSetting;
|
||||
}
|
||||
return [];
|
||||
return self::$appSetting;
|
||||
}
|
||||
/**
|
||||
* 获取应用设置的key值
|
||||
|
|
|
|||
|
|
@ -44,4 +44,55 @@ class CommonService
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户总消费金额
|
||||
*
|
||||
* @param int $userId 用户ID
|
||||
* @return array 包含钻石消费和RMB支付消费的数组
|
||||
*/
|
||||
public static function getUserTotalConsumption($userId)
|
||||
{
|
||||
// 查询用户的总订单消费情况
|
||||
$consumptionData = Order::where('user_id', '=', $userId)
|
||||
->where(function ($query) {
|
||||
$query->where('price', '>', 0)
|
||||
->whereOr('use_money', '>', 0);
|
||||
})
|
||||
->where('status', '=', 1)
|
||||
->field('sum(use_money) as diamond_consumed, sum(price) as rmb_consumed')
|
||||
->find();
|
||||
|
||||
// 处理查询结果
|
||||
$result = [
|
||||
'diamond_consumed' => round(floatval($consumptionData['diamond_consumed'] ?? 0), 2), // 钻石消费
|
||||
'rmb_consumed' => round(floatval($consumptionData['rmb_consumed'] ?? 0), 2), // RMB支付消费
|
||||
'total_consumed' => round(floatval(($consumptionData['diamond_consumed'] ?? 0) + ($consumptionData['rmb_consumed'] ?? 0)), 2) // 总消费
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户总消费金额(只返回总金额数值)
|
||||
*
|
||||
* @param int $userId 用户ID
|
||||
* @return float 用户总消费金额
|
||||
*/
|
||||
public static function getTotalConsumptionAmount($userId)
|
||||
{
|
||||
// 查询用户的总订单消费情况
|
||||
$consumptionData = Order::where('user_id', '=', $userId)
|
||||
->where(function ($query) {
|
||||
$query->where('price', '>', 0)
|
||||
->whereOr('use_money', '>', 0);
|
||||
})
|
||||
->where('status', '=', 1)
|
||||
->field('sum(use_money) as diamond_consumed, sum(price) as rmb_consumed')
|
||||
->find();
|
||||
|
||||
// 计算总消费金额
|
||||
$totalAmount = round(floatval(($consumptionData['diamond_consumed'] ?? 0) + ($consumptionData['rmb_consumed'] ?? 0)), 2);
|
||||
|
||||
return $totalAmount;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user