修改问题

This commit is contained in:
manghe 2025-03-17 08:46:24 +00:00
parent 1d51fe072a
commit f655104cdd
2 changed files with 218 additions and 156 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
declare (strict_types=1); declare(strict_types=1);
namespace app\api\controller; namespace app\api\controller;
@ -16,12 +16,29 @@ use app\common\model\UserCoupon;
use app\common\model\UserRecharge; use app\common\model\UserRecharge;
use app\common\model\UserVip; use app\common\model\UserVip;
use app\common\server\LiveMoney; use app\common\server\LiveMoney;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use think\facade\Db; use think\facade\Db;
use think\Request; use think\Request;
use app\common\server\Qcode; use app\common\server\Qcode;
use Qcloud\Cos\Client;
class User extends Base class User extends Base
{ {
private $secretId; // 腾讯云 API 密钥 SecretId
private $secretKey; // 腾讯云 API 密钥 SecretKey
private $bucket; // 存储桶名称
private $region; // 存储桶所在地域
private $domain; // 存储桶所在地域
public function initialize()
{
$config = getConfig('uploads');
$this->secretId = $config['AccessKeyId'];
$this->secretKey = $config['AccessKeySecret'];
$this->bucket = $config['Bucket'];
$this->region = $config['Region'];
$this->domain = $config['Domain'];
}
/** /**
* 我的 * 我的
@ -29,7 +46,7 @@ class User extends Base
public function user(Request $request) public function user(Request $request)
{ {
$user = $this->getUser(); $user = $this->getUser();
$userinfo['ID'] = $user['id']+1260; $userinfo['ID'] = $user['id'] + 1260;
$userinfo['mobile_is'] = $user['mobile'] ? 1 : 0; $userinfo['mobile_is'] = $user['mobile'] ? 1 : 0;
$userinfo['nickname'] = $user['nickname']; $userinfo['nickname'] = $user['nickname'];
$userinfo['headimg'] = imageUrl($user['headimg']); $userinfo['headimg'] = imageUrl($user['headimg']);
@ -41,19 +58,19 @@ class User extends Base
$userinfo['vip'] = $this->vip_level($user['id'], $user['vip']); $userinfo['vip'] = $this->vip_level($user['id'], $user['vip']);
$vip_imgurl = UserVip::field('imgurl')->where('id', '=', $userinfo['vip'])->value('imgurl'); $vip_imgurl = UserVip::field('imgurl')->where('id', '=', $userinfo['vip'])->value('imgurl');
$userinfo['vip_imgurl'] = $vip_imgurl ? imageUrl($vip_imgurl) : 0; $userinfo['vip_imgurl'] = $vip_imgurl ? imageUrl($vip_imgurl) : 0;
$userinfo['quan_yi_level'] = \app\common\model\User::ou_qi_level($user['ou_qi_level'],$user['ou_qi']); $userinfo['quan_yi_level'] = \app\common\model\User::ou_qi_level($user['ou_qi_level'], $user['ou_qi']);
$userinfo['coupon'] = UserCoupon::where('user_id', '=', $user['id'])->where('status', '=', 1)->count(); $userinfo['coupon'] = UserCoupon::where('user_id', '=', $user['id'])->where('status', '=', 1)->count();
$base = getConfig('base'); $base = getConfig('base');
$userinfo['js_is_open'] = 0; $userinfo['js_is_open'] = 0;
$userinfo['is_show_js'] = 0; $userinfo['is_show_js'] = 0;
$userinfo['is_exchange'] =$base['is_exchange']; $userinfo['is_exchange'] = $base['is_exchange'];
$day = floor(abs(time() - $user['addtime']) / 86400); $day = floor(abs(time() - $user['addtime']) / 86400);
$userinfo['day'] = $day; $userinfo['day'] = $day;
#客服 #客服
$other = [ $other = [
// 'recharge' => [100, 200, 500, 1000, 3000], // 'recharge' => [100, 200, 500, 1000, 3000],
'jump_appid' => $base['jump_appid'], 'jump_appid' => $base['jump_appid'],
'corpid' => $base['corpid'], 'corpid' => $base['corpid'],
'wx_link' => $base['wx_link'], 'wx_link' => $base['wx_link'],
@ -61,16 +78,16 @@ class User extends Base
]; ];
//主要任务 //主要任务
$where = []; $where = [];
$where[] = ['is_important','=',1]; $where[] = ['is_important', '=', 1];
$field = 'id,type,cate,title,number,z_number'; $field = 'id,type,cate,title,number,z_number';
$task_list = \app\common\model\TaskList::getAllList($where,$field,'sort desc,id desc'); $task_list = \app\common\model\TaskList::getAllList($where, $field, 'sort desc,id desc');
foreach ($task_list as $k => &$v){ foreach ($task_list as $k => &$v) {
//1每日任务 2每周任务 //1每日任务 2每周任务
if ($v['type'] == 1){ if ($v['type'] == 1) {
$start_time = strtotime(date('Y-m-d',time()).' 00:00:00'); $start_time = strtotime(date('Y-m-d', time()) . ' 00:00:00');
$end_time = strtotime(date('Y-m-d',time()).' 23:59:59'); $end_time = strtotime(date('Y-m-d', time()) . ' 23:59:59');
}else{ } else {
$date = date('Y-m-d'); //当前日期 $date = date('Y-m-d'); //当前日期
$first = 1; //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期 $first = 1; //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
$w = date('w', strtotime($date)); //获取当前周的第几天 周日是 0 周一到周六是 1 - 6 $w = date('w', strtotime($date)); //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
@ -80,8 +97,8 @@ class User extends Base
$end_time = strtotime(date('Y-m-d', strtotime("$to_day2 + 6 days")) . ' 23:59:59'); //本周结束日期 $end_time = strtotime(date('Y-m-d', strtotime("$to_day2 + 6 days")) . ' 23:59:59'); //本周结束日期
} }
//1邀请好友注册 2抽赏任务 //1邀请好友注册 2抽赏任务
if ($v['cate'] == 1){ if ($v['cate'] == 1) {
$yao_count = \app\common\model\User::where([['pid','=',$user['id']],['addtime','>=',$start_time]])->count(); $yao_count = \app\common\model\User::where([['pid', '=', $user['id']], ['addtime', '>=', $start_time]])->count();
if ($yao_count >= $v['number']) { if ($yao_count >= $v['number']) {
$v['is_complete'] = 1; $v['is_complete'] = 1;
//进度条 //进度条
@ -96,8 +113,8 @@ class User extends Base
$v['ywc_count'] = $yao_count; $v['ywc_count'] = $yao_count;
} }
}elseif ($v['cate'] == 2){ } elseif ($v['cate'] == 2) {
$prize_num = Order::where([['user_id','=',$user['id']],['pay_type','<',10],['status','=',1],['addtime','>=',$start_time]])->count(); $prize_num = Order::where([['user_id', '=', $user['id']], ['pay_type', '<', 10], ['status', '=', 1], ['addtime', '>=', $start_time]])->count();
if ($prize_num >= $v['number']) { if ($prize_num >= $v['number']) {
$v['is_complete'] = 1; $v['is_complete'] = 1;
//进度条 //进度条
@ -113,13 +130,13 @@ class User extends Base
} }
} }
//是否已领取 //是否已领取
$is_ling = Db::name('user_task_list')->field('id')->where([['user_id','=',$user['id']],['task_list_id','=',$v['id']],['addtime','>=',$start_time],['addtime','<=',$end_time]])->whereNull('deltime')->find(); $is_ling = Db::name('user_task_list')->field('id')->where([['user_id', '=', $user['id']], ['task_list_id', '=', $v['id']], ['addtime', '>=', $start_time], ['addtime', '<=', $end_time]])->whereNull('deltime')->find();
if ($is_ling){ if ($is_ling) {
$v['is_complete'] = 2; $v['is_complete'] = 2;
} }
} }
return $this->renderSuccess("请求成功", compact('userinfo', 'other','task_list')); return $this->renderSuccess("请求成功", compact('userinfo', 'other', 'task_list'));
} }
/** /**
@ -130,6 +147,8 @@ class User extends Base
$user = $this->getUser(); $user = $this->getUser();
$nickname = request()->param('nickname', ''); $nickname = request()->param('nickname', '');
$headimg = request()->param('headimg', ''); $headimg = request()->param('headimg', '');
$imagebase = request()->param('imagebase', '');
if (empty($nickname)) { if (empty($nickname)) {
return $this->renderError("请输入姓名"); return $this->renderError("请输入姓名");
} }
@ -137,15 +156,52 @@ class User extends Base
if ($nickname) { if ($nickname) {
$save['nickname'] = $nickname; $save['nickname'] = $nickname;
} }
if ($headimg) { if ($imagebase && $imagebase != "") {
$base64Image = str_replace('data:image/png;base64,', '', $imagebase);
// 解码 Base64 数据为二进制数据
$binaryData = base64_decode($base64Image);
// 初始化腾讯云 COS 客户端
$cosClient = new Client([
'region' => $this->region,
'schema' => 'https', // 协议
'credentials' => [
'secretId' => $this->secretId,
'secretKey' => $this->secretKey,
],
]);
// 生成唯一文件名
$userId = $user['id'];
$date = date('Ymd');
if (strpos($headimg, '/storage') !== false) { $uniqueFileName = $userId . '_' . uniqid('') . '.png';
$str = explode('/storage',$headimg); $cosKey = 'storage/users/icon/' . $uniqueFileName; // COS 中的文件路径
$save['headimg'] = '/storage'.$str[1];
} else { try {
$save['headimg'] = $headimg; // 上传文件到腾讯云 COS
$result = $cosClient->putObject([
'Bucket' => $this->bucket,
'Key' => $cosKey,
'Body' => $binaryData, // 文件内容
]);
// 获取文件访问 URL
// $cosUrl = $result['Location'];
$imgurl = $this->domain . $cosKey;
$save['headimg'] = $imgurl;
} catch (\Exception $e) {
return $this->renderError('头像上传失败' . $e->getMessage());
} }
} }
// if ($headimg) {
// if (strpos($headimg, '/storage') !== false) {
// $str = explode('/storage', $headimg);
// $save['headimg'] = '/storage' . $str[1];
// } else {
// $save['headimg'] = $headimg;
// }
// }
$res = Usermodel::field('nickname,headimg')->where('id', '=', $user['id'])->update($save); $res = Usermodel::field('nickname,headimg')->where('id', '=', $user['id'])->update($save);
if ($res) { if ($res) {
return $this->renderSuccess('修改成功'); return $this->renderSuccess('修改成功');
@ -180,11 +236,11 @@ class User extends Base
->where('id', '>', $vip) ->where('id', '>', $vip)
->order('id asc') ->order('id asc')
->find(); ->find();
$userinfo['upgrade_money'] = bcsub((string)$condition['condition'], "$total_order", 2); $userinfo['upgrade_money'] = bcsub((string) $condition['condition'], "$total_order", 2);
$userinfo['last_vip'] = $condition['id']; $userinfo['last_vip'] = $condition['id'];
if ($total_order >= $condition['condition']){ if ($total_order >= $condition['condition']) {
$userinfo['jin_du'] = 100; $userinfo['jin_du'] = 100;
}else{ } else {
$userinfo['jin_du'] = $total_order / $condition['condition'] * 100; $userinfo['jin_du'] = $total_order / $condition['condition'] * 100;
} }
@ -196,7 +252,7 @@ class User extends Base
$data = UserVip::select()->toArray(); $data = UserVip::select()->toArray();
foreach ($data as &$value) { foreach ($data as &$value) {
$value['imgurl'] = imageUrl($value['imgurl']); $value['imgurl'] = imageUrl($value['imgurl']);
if ($vip == $value['id']){ if ($vip == $value['id']) {
$userinfo['notice'] = $value['notice']; $userinfo['notice'] = $value['notice'];
} }
} }
@ -245,7 +301,7 @@ class User extends Base
} }
$data = ProfitIntegral::field('change_money,content,addtime') $data = ProfitIntegral::field('change_money,content,addtime')
->withAttr('addtime', function ($value, $data) { ->withAttr('addtime', function ($value, $data) {
return date('Y-m-d H:i:s', (int)$data['addtime']); return date('Y-m-d H:i:s', (int) $data['addtime']);
}) })
->where($whe) ->where($whe)
->order('id desc') ->order('id desc')
@ -278,7 +334,7 @@ class User extends Base
} }
$data = ProfitMoney::field('change_money,content,addtime') $data = ProfitMoney::field('change_money,content,addtime')
->withAttr('addtime', function ($value, $data) { ->withAttr('addtime', function ($value, $data) {
return date('Y-m-d H:i:s', (int)$data['addtime']); return date('Y-m-d H:i:s', (int) $data['addtime']);
}) })
->where($whe) ->where($whe)
->order('id desc') ->order('id desc')
@ -307,7 +363,7 @@ class User extends Base
} }
$data = ProfitScore::field('change_money,content,addtime') $data = ProfitScore::field('change_money,content,addtime')
->withAttr('addtime', function ($value, $data) { ->withAttr('addtime', function ($value, $data) {
return date('Y-m-d H:i:s', (int)$data['addtime']); return date('Y-m-d H:i:s', (int) $data['addtime']);
}) })
->where($whe) ->where($whe)
->order('id desc') ->order('id desc')
@ -329,7 +385,7 @@ class User extends Base
$whe[] = ['user_id', '=', $user['id']]; $whe[] = ['user_id', '=', $user['id']];
$data = ProfitPay::field('change_money,content,addtime') $data = ProfitPay::field('change_money,content,addtime')
->withAttr('addtime', function ($value, $data) { ->withAttr('addtime', function ($value, $data) {
return date('Y-m-d H:i:s', (int)$data['addtime']); return date('Y-m-d H:i:s', (int) $data['addtime']);
}) })
->where($whe) ->where($whe)
->order('id desc') ->order('id desc')
@ -353,10 +409,10 @@ class User extends Base
$where[] = ['user_id', '=', $user_id]; $where[] = ['user_id', '=', $user_id];
$order_by = 'id desc'; $order_by = 'id desc';
if ($status == 1){ if ($status == 1) {
$where[] = ['status', '=', 1]; $where[] = ['status', '=', 1];
$order_by = 'id desc'; $order_by = 'id desc';
}elseif ($status == 2){ } elseif ($status == 2) {
$where[] = ['status', '=', 2]; $where[] = ['status', '=', 2];
$order_by = 'share_time desc'; $order_by = 'share_time desc';
} }
@ -365,16 +421,16 @@ class User extends Base
->order($order_by) ->order($order_by)
->paginate(15)->each(function ($itme) { ->paginate(15)->each(function ($itme) {
//1特级赏券 2终极赏券 3高级赏券 4普通赏券 //1特级赏券 2终极赏券 3高级赏券 4普通赏券
if ($itme['level'] == 1){ if ($itme['level'] == 1) {
$itme['level_text'] = '特级赏券'; $itme['level_text'] = '特级赏券';
$itme['level_img'] = imageUrl('/storage/coupon/coupon_a.png'); $itme['level_img'] = imageUrl('/storage/coupon/coupon_a.png');
}elseif ($itme['level'] == 2){ } elseif ($itme['level'] == 2) {
$itme['level_text'] = '终极赏券'; $itme['level_text'] = '终极赏券';
$itme['level_img'] = imageUrl('/storage/coupon/coupon_b.png'); $itme['level_img'] = imageUrl('/storage/coupon/coupon_b.png');
}elseif ($itme['level'] == 3){ } elseif ($itme['level'] == 3) {
$itme['level_text'] = '高级赏券'; $itme['level_text'] = '高级赏券';
$itme['level_img'] = imageUrl('/storage/coupon/coupon_c.png'); $itme['level_img'] = imageUrl('/storage/coupon/coupon_c.png');
}elseif ($itme['level'] == 4){ } elseif ($itme['level'] == 4) {
$itme['level_text'] = '普通赏券'; $itme['level_text'] = '普通赏券';
$itme['level_img'] = imageUrl('/storage/coupon/coupon_d.png'); $itme['level_img'] = imageUrl('/storage/coupon/coupon_d.png');
} }
@ -392,7 +448,7 @@ class User extends Base
$sun_hao = '10%'; //损耗 $sun_hao = '10%'; //损耗
$user_integral = $user['integral']; $user_integral = $user['integral'];
return $this->renderSuccess("请求成功", compact('data','y_count','z_count','user_integral','ke_hc_count','sun_hao')); return $this->renderSuccess("请求成功", compact('data', 'y_count', 'z_count', 'user_integral', 'ke_hc_count', 'sun_hao'));
} }
/** /**
@ -402,7 +458,8 @@ class User extends Base
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function coupon_detail(){ public function coupon_detail()
{
$user = $this->getUser(); $user = $this->getUser();
$user_id = $user['id']; $user_id = $user['id'];
$coupon_id = request()->param("coupon_id/d", 0); $coupon_id = request()->param("coupon_id/d", 0);
@ -413,50 +470,50 @@ class User extends Base
if (empty($info)) { if (empty($info)) {
return $this->renderError("参数错误"); return $this->renderError("参数错误");
} }
$info['own2'] = round($info['own2'] - $info['own'],2); $info['own2'] = round($info['own2'] - $info['own'], 2);
if ($info['level'] == 1){ if ($info['level'] == 1) {
$info['level_text'] = '特级赏券'; $info['level_text'] = '特级赏券';
$info['level_img'] = imageUrl('/storage/coupon/coupon_a.png'); $info['level_img'] = imageUrl('/storage/coupon/coupon_a.png');
}elseif ($info['level'] == 2){ } elseif ($info['level'] == 2) {
$info['level_text'] = '终极赏券'; $info['level_text'] = '终极赏券';
$info['level_img'] = imageUrl('/storage/coupon/coupon_b.png'); $info['level_img'] = imageUrl('/storage/coupon/coupon_b.png');
}elseif ($info['level'] == 3){ } elseif ($info['level'] == 3) {
$info['level_text'] = '高级赏券'; $info['level_text'] = '高级赏券';
$info['level_img'] = imageUrl('/storage/coupon/coupon_c.png'); $info['level_img'] = imageUrl('/storage/coupon/coupon_c.png');
}elseif ($info['level'] == 4){ } elseif ($info['level'] == 4) {
$info['level_text'] = '普通赏券'; $info['level_text'] = '普通赏券';
$info['level_img'] = imageUrl('/storage/coupon/coupon_d.png'); $info['level_img'] = imageUrl('/storage/coupon/coupon_d.png');
} }
$info['share_time'] = $info['share_time'] ? date('Y-m-d H:i:s',$info['share_time']) : ''; $info['share_time'] = $info['share_time'] ? date('Y-m-d H:i:s', $info['share_time']) : '';
$info['yl_count'] = UserCoupon::where(['status' => 3, 'from_id' => $coupon_id])->count(); $info['yl_count'] = UserCoupon::where(['status' => 3, 'from_id' => $coupon_id])->count();
$info['yl_integral_count'] = UserCoupon::where(['status' => 3, 'from_id' => $coupon_id])->sum('l_num'); $info['yl_integral_count'] = UserCoupon::where(['status' => 3, 'from_id' => $coupon_id])->sum('l_num');
$share_user = Usermodel::field('nickname,headimg')->where('id',$info['user_id'])->find(); $share_user = Usermodel::field('nickname,headimg')->where('id', $info['user_id'])->find();
$info['share_user_nickname'] = $share_user ? $share_user['nickname'] : ''; $info['share_user_nickname'] = $share_user ? $share_user['nickname'] : '';
$info['share_user_headimg'] = $share_user ? imageUrl($share_user['headimg']) : ''; $info['share_user_headimg'] = $share_user ? imageUrl($share_user['headimg']) : '';
$yl_list = UserCoupon::alias('a') $yl_list = UserCoupon::alias('a')
->field('a.user_id,a.addtime,a.l_num,b.nickname,b.headimg') ->field('a.user_id,a.addtime,a.l_num,b.nickname,b.headimg')
->join('user b','a.user_id = b.id') ->join('user b', 'a.user_id = b.id')
->where(['a.status' => 3, 'a.from_id' => $coupon_id]) ->where(['a.status' => 3, 'a.from_id' => $coupon_id])
->select(); ->select();
//手气最佳 //手气最佳
$yl_max = Db::name('user_coupon') $yl_max = Db::name('user_coupon')
->alias('a') ->alias('a')
->field('a.user_id,a.addtime,a.l_num,b.nickname,b.headimg') ->field('a.user_id,a.addtime,a.l_num,b.nickname,b.headimg')
->join('user b','a.user_id = b.id') ->join('user b', 'a.user_id = b.id')
->where(['a.status' => 3, 'a.from_id' => $coupon_id]) ->where(['a.status' => 3, 'a.from_id' => $coupon_id])
->max('a.l_num'); ->max('a.l_num');
foreach ($yl_list as $k => &$v){ foreach ($yl_list as $k => &$v) {
$v['headimg'] = imageUrl($v['headimg']); $v['headimg'] = imageUrl($v['headimg']);
$v['addtime'] = date('Y-m-d H:i:s',$v['addtime']); $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
if ($yl_max == $v['l_num']){ if ($yl_max == $v['l_num']) {
$v['lucky_king'] = 1; $v['lucky_king'] = 1;
}else{ } else {
$v['lucky_king'] = 0; $v['lucky_king'] = 0;
} }
} }
$info['yl_list'] = $yl_list; $info['yl_list'] = $yl_list;
return $this->renderSuccess('请求成功',$info); return $this->renderSuccess('请求成功', $info);
} }
/** /**
@ -470,7 +527,7 @@ class User extends Base
if (empty($coupon_id)) { if (empty($coupon_id)) {
return $this->renderError("缺少必要参数"); return $this->renderError("缺少必要参数");
} }
$info = UserCoupon::where([['id', '=', $coupon_id],['user_id','=',$user_id]])->find(); $info = UserCoupon::where([['id', '=', $coupon_id], ['user_id', '=', $user_id]])->find();
if (empty($info)) { if (empty($info)) {
return $this->renderError("参数错误"); return $this->renderError("参数错误");
} }
@ -492,7 +549,7 @@ class User extends Base
Db::rollback(); Db::rollback();
return $this->renderError("网络故障,请稍后再试"); return $this->renderError("网络故障,请稍后再试");
} }
}catch (\Exception $e){ } catch (\Exception $e) {
Db::rollback(); Db::rollback();
return $this->renderError("网络故障,请稍后再试!"); return $this->renderError("网络故障,请稍后再试!");
} }
@ -507,7 +564,7 @@ class User extends Base
$user = $this->getUser(); $user = $this->getUser();
$user_id = $user['id']; $user_id = $user['id'];
$coupon_id = request()->param("coupon_id/d", 0); $coupon_id = request()->param("coupon_id/d", 0);
writelog(11111111111,$user_id); writelog(11111111111, $user_id);
if (empty($coupon_id)) { if (empty($coupon_id)) {
return $this->renderError("缺少必要参数"); return $this->renderError("缺少必要参数");
} }
@ -516,14 +573,14 @@ writelog(11111111111,$user_id);
return $this->renderError("参数错误"); return $this->renderError("参数错误");
} }
if ($info['user_id'] == $user_id) { if ($info['user_id'] == $user_id) {
return $this->renderError("请勿开启自己的劵",[],2222); return $this->renderError("请勿开启自己的劵", [], 2222);
} }
$is_ling = UserCoupon::where('user_id', '=', $user['id']) $is_ling = UserCoupon::where('user_id', '=', $user['id'])
->where('type', '=', 2) ->where('type', '=', 2)
->where('from_id', '=', $coupon_id) ->where('from_id', '=', $coupon_id)
->find(); ->find();
if ($is_ling){ if ($is_ling) {
return $this->renderError("你已经领取过了",[],2222); return $this->renderError("你已经领取过了", [], 2222);
} }
$count = UserCoupon::where('user_id', '=', $user['id']) $count = UserCoupon::where('user_id', '=', $user['id'])
->where('type', '=', 2) ->where('type', '=', 2)
@ -532,13 +589,13 @@ writelog(11111111111,$user_id);
$config = getConfig("base"); $config = getConfig("base");
if ($config['coupon_ling_max_ci'] && $config['coupon_ling_max_ci'] > 0) { if ($config['coupon_ling_max_ci'] && $config['coupon_ling_max_ci'] > 0) {
if($count >= $config['coupon_ling_max_ci']){ if ($count >= $config['coupon_ling_max_ci']) {
return $this->renderError('每天最多领取'.$config['coupon_ling_max_ci'].'次'); return $this->renderError('每天最多领取' . $config['coupon_ling_max_ci'] . '次');
} }
} }
//其他人可以获得多少 //其他人可以获得多少
if ($info['other'] <= 0){ if ($info['other'] <= 0) {
return $this->renderError("来晚了, 已经被人领完了",[],2222); return $this->renderError("来晚了, 已经被人领完了", [], 2222);
} }
Db::startTrans(); Db::startTrans();
try { try {
@ -550,12 +607,12 @@ writelog(11111111111,$user_id);
// $key = mt_rand(0, count($data['items']) - 1); //随机取数组中的一个 // $key = mt_rand(0, count($data['items']) - 1); //随机取数组中的一个
// $rand_money = $data['items'][$key]; // $rand_money = $data['items'][$key];
// } // }
$rand_money_arr = $this->rand_money($info['other'],$info['kl_num'],'1'); $rand_money_arr = $this->rand_money($info['other'], $info['kl_num'], '1');
if (count($rand_money_arr) <= 0){ if (count($rand_money_arr) <= 0) {
return $this->renderError("来晚了, 已经被人领完了",[],2222); return $this->renderError("来晚了, 已经被人领完了", [], 2222);
} }
$rand_money = $rand_money_arr[0]; $rand_money = $rand_money_arr[0];
$res[] = UserCoupon::field('other')->where(['id' => $coupon_id])->dec('other',floatval($rand_money))->update(); $res[] = UserCoupon::field('other')->where(['id' => $coupon_id])->dec('other', floatval($rand_money))->update();
$res[] = UserCoupon::insert([ $res[] = UserCoupon::insert([
'user_id' => $user_id, 'user_id' => $user_id,
@ -571,7 +628,7 @@ writelog(11111111111,$user_id);
$res[] = UserCoupon::field('status,other,kl_num,updatetime,own,share_time') $res[] = UserCoupon::field('status,other,kl_num,updatetime,own,share_time')
->where(['id' => $coupon_id]) ->where(['id' => $coupon_id])
->dec('kl_num',1) ->dec('kl_num', 1)
->update([ ->update([
'updatetime' => time() 'updatetime' => time()
]); ]);
@ -579,12 +636,12 @@ writelog(11111111111,$user_id);
$res[] = Usermodel::changeIntegral($user_id, $rand_money, 3, '欧气券领取', $coupon_id); $res[] = Usermodel::changeIntegral($user_id, $rand_money, 3, '欧气券领取', $coupon_id);
$kl_num = UserCoupon::field('kl_num,own')->where(['id' => $coupon_id])->find(); $kl_num = UserCoupon::field('kl_num,own')->where(['id' => $coupon_id])->find();
if ($kl_num['own'] > 0 && $kl_num['kl_num'] > 1){ if ($kl_num['own'] > 0 && $kl_num['kl_num'] > 1) {
$integral = round($info['own2'] / $info['kl_num2'],2); $integral = round($info['own2'] / $info['kl_num2'], 2);
$res[] = UserCoupon::field('own')->where(['id' => $coupon_id])->dec('own',floatval($integral))->update(); $res[] = UserCoupon::field('own')->where(['id' => $coupon_id])->dec('own', floatval($integral))->update();
$res[] = Usermodel::changeIntegral($info['user_id'], $integral, 5, '欧气券分享', $coupon_id); $res[] = Usermodel::changeIntegral($info['user_id'], $integral, 5, '欧气券分享', $coupon_id);
}elseif ($kl_num['own'] > 0 && $kl_num['kl_num'] == 1){ } elseif ($kl_num['own'] > 0 && $kl_num['kl_num'] == 1) {
$res[] = UserCoupon::field('own')->where(['id' => $coupon_id])->dec('own',floatval($kl_num['own']))->update(); $res[] = UserCoupon::field('own')->where(['id' => $coupon_id])->dec('own', floatval($kl_num['own']))->update();
$res[] = Usermodel::changeIntegral($info['user_id'], $kl_num['own'], 5, '欧气券分享', $coupon_id); $res[] = Usermodel::changeIntegral($info['user_id'], $kl_num['own'], 5, '欧气券分享', $coupon_id);
} }
@ -593,44 +650,45 @@ writelog(11111111111,$user_id);
return $this->renderSuccess("领取成功"); return $this->renderSuccess("领取成功");
} else { } else {
Db::rollback(); Db::rollback();
return $this->renderError("人数过多,请稍后再试",[],2222); return $this->renderError("人数过多,请稍后再试", [], 2222);
} }
}catch (\Exception $e){ } catch (\Exception $e) {
Db::rollback(); Db::rollback();
// var_dump($e->getLine()); // var_dump($e->getLine());
return $this->renderError("人数过多,请稍后再试!",[],2222); return $this->renderError("人数过多,请稍后再试!", [], 2222);
} }
} }
/** /**
* 红包随机金额 * 红包随机金额
*/ */
public function rand_money($total,$personal_num,$min_money=1){ public function rand_money($total, $personal_num, $min_money = 1)
// $money_total = $total; //总金额 {
// $money_total = $total; //总金额
// $personal_num = $personal_num; //总数量 // $personal_num = $personal_num; //总数量
// $min_money = $min_money; //最小金额 // $min_money = $min_money; //最小金额
$money_right = $total; $money_right = $total;
$randMoney = []; $randMoney = [];
for($i=1;$i<=$personal_num;$i++){ for ($i = 1; $i <= $personal_num; $i++) {
if($money_right == $personal_num){ if ($money_right == $personal_num) {
$money = 1; $money = 1;
$money = sprintf("%.2f",$money); $money = sprintf("%.2f", $money);
}else{ } else {
if($i== $personal_num){ if ($i == $personal_num) {
$money = $money_right; $money = $money_right;
}else{ } else {
$max = $money_right - ($personal_num - $i) * $min_money; $max = $money_right - ($personal_num - $i) * $min_money;
if($max < 2){ if ($max < 2) {
$max = 2; $max = 2;
} }
$money = mt_rand((int)($min_money),(int)($max/2)) ; $money = mt_rand((int) ($min_money), (int) ($max / 2));
$money = sprintf("%.2f",$money); $money = sprintf("%.2f", $money);
} }
} }
$randMoney[] = $money; $randMoney[] = $money;
$money_right = $money_right - $money; $money_right = $money_right - $money;
$money_right = sprintf("%.2f",$money_right); $money_right = sprintf("%.2f", $money_right);
} }
shuffle($randMoney); shuffle($randMoney);
return $randMoney; return $randMoney;
@ -644,56 +702,57 @@ writelog(11111111111,$user_id);
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function coupon_ji_suan(Request $request){ public function coupon_ji_suan(Request $request)
{
$user = $this->getUser(); $user = $this->getUser();
$user_id = $user['id']; $user_id = $user['id'];
$coupon_ids = request()->param("coupon_ids", ''); $coupon_ids = request()->param("coupon_ids", '');
if (empty($coupon_ids)) { if (empty($coupon_ids)) {
return $this->renderError("缺少必要参数"); return $this->renderError("缺少必要参数");
} }
$coupon_ids = explode(',',trim($coupon_ids)); $coupon_ids = explode(',', trim($coupon_ids));
if (!$coupon_ids){ if (!$coupon_ids) {
return $this->renderError("缺少必要参数!"); return $this->renderError("缺少必要参数!");
} }
$sum_num = 0; $sum_num = 0;
foreach ($coupon_ids as $k => $v){ foreach ($coupon_ids as $k => $v) {
$is_coupon = UserCoupon::where(['user_id' => $user_id, 'status' => 1, 'id' => $v])->find(); $is_coupon = UserCoupon::where(['user_id' => $user_id, 'status' => 1, 'id' => $v])->find();
if (!$is_coupon){ if (!$is_coupon) {
return $this->renderError("数据错误!"); return $this->renderError("数据错误!");
} }
if ($is_coupon['level'] < 3){ if ($is_coupon['level'] < 3) {
return $this->renderError("特级,终极赏券不能合成"); return $this->renderError("特级,终极赏券不能合成");
} }
$sum_num += $is_coupon['num']; $sum_num += $is_coupon['num'];
} }
//合成损耗10% //合成损耗10%
$sh_num = $sum_num - $sum_num * (10 / 100); $sh_num = $sum_num - $sum_num * (10 / 100);
if ($sum_num <= 0){ if ($sum_num <= 0) {
return $this->renderError("网络故障,请稍后再试!!"); return $this->renderError("网络故障,请稍后再试!!");
} }
if (count($coupon_ids) > 20){ if (count($coupon_ids) > 20) {
return $this->renderError("最多只能20个合成"); return $this->renderError("最多只能20个合成");
} }
$coupon = []; $coupon = [];
if ($sum_num > 0 && $sum_num < 500){ if ($sum_num > 0 && $sum_num < 500) {
$coupon['title'] = "普通赏券"; $coupon['title'] = "普通赏券";
$coupon['level'] = 4; $coupon['level'] = 4;
}elseif ($sum_num >= 500 && $sum_num < 2000){ } elseif ($sum_num >= 500 && $sum_num < 2000) {
$coupon['title'] = "高级赏券"; $coupon['title'] = "高级赏券";
$coupon['level'] = 3; $coupon['level'] = 3;
}elseif ($sum_num >= 2000 && $sum_num < 5000){ } elseif ($sum_num >= 2000 && $sum_num < 5000) {
$coupon['title'] = "终极赏券"; $coupon['title'] = "终极赏券";
$coupon['level'] = 2; $coupon['level'] = 2;
}elseif ($sum_num >= 5000){ } elseif ($sum_num >= 5000) {
$coupon['title'] = "特级赏券"; $coupon['title'] = "特级赏券";
$coupon['level'] = 1; $coupon['level'] = 1;
}else{ } else {
return $this->renderError("网络故障,请稍后再试!"); return $this->renderError("网络故障,请稍后再试!");
} }
return $this->renderSuccess('请求成功',compact('coupon','sum_num','sh_num')); return $this->renderSuccess('请求成功', compact('coupon', 'sum_num', 'sh_num'));
} }
/** /**
@ -703,24 +762,25 @@ writelog(11111111111,$user_id);
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function coupon_synthesis(){ public function coupon_synthesis()
{
$user = $this->getUser(); $user = $this->getUser();
$user_id = $user['id']; $user_id = $user['id'];
$coupon_ids = request()->param("coupon_ids", ''); $coupon_ids = request()->param("coupon_ids", '');
if (empty($coupon_ids)) { if (empty($coupon_ids)) {
return $this->renderError("缺少必要参数"); return $this->renderError("缺少必要参数");
} }
$coupon_ids = explode(',',trim($coupon_ids)); $coupon_ids = explode(',', trim($coupon_ids));
if (!$coupon_ids){ if (!$coupon_ids) {
return $this->renderError("缺少必要参数!"); return $this->renderError("缺少必要参数!");
} }
$sum_num = 0; $sum_num = 0;
foreach ($coupon_ids as $k => $v){ foreach ($coupon_ids as $k => $v) {
$is_coupon = UserCoupon::where(['user_id' => $user_id, 'status' => 1, 'id' => $v])->find(); $is_coupon = UserCoupon::where(['user_id' => $user_id, 'status' => 1, 'id' => $v])->find();
if (!$is_coupon){ if (!$is_coupon) {
return $this->renderError("数据错误!"); return $this->renderError("数据错误!");
} }
if ($is_coupon['level'] < 3){ if ($is_coupon['level'] < 3) {
return $this->renderError("特级,终极赏券不能合成"); return $this->renderError("特级,终极赏券不能合成");
} }
$sum_num += $is_coupon['num']; $sum_num += $is_coupon['num'];
@ -728,28 +788,28 @@ writelog(11111111111,$user_id);
$coupon = []; $coupon = [];
$config = getConfig("base"); $config = getConfig("base");
if ($sum_num > 0 && $sum_num < 500){ if ($sum_num > 0 && $sum_num < 500) {
$coupon['title'] = "普通赏券"; $coupon['title'] = "普通赏券";
$coupon['level'] = 4; $coupon['level'] = 4;
$coupon['kl_num'] = $config['coupon_d_xz_max']; $coupon['kl_num'] = $config['coupon_d_xz_max'];
}elseif ($sum_num >= 500 && $sum_num < 2000){ } elseif ($sum_num >= 500 && $sum_num < 2000) {
$coupon['title'] = "高级赏券"; $coupon['title'] = "高级赏券";
$coupon['level'] = 3; $coupon['level'] = 3;
$coupon['kl_num'] = $config['coupon_c_xz_max']; $coupon['kl_num'] = $config['coupon_c_xz_max'];
}elseif ($sum_num >= 2000 && $sum_num < 5000){ } elseif ($sum_num >= 2000 && $sum_num < 5000) {
$coupon['title'] = "终极赏券"; $coupon['title'] = "终极赏券";
$coupon['level'] = 2; $coupon['level'] = 2;
$coupon['kl_num'] = $config['coupon_b_xz_max']; $coupon['kl_num'] = $config['coupon_b_xz_max'];
}elseif ($sum_num >= 5000){ } elseif ($sum_num >= 5000) {
$coupon['title'] = "特级赏券"; $coupon['title'] = "特级赏券";
$coupon['level'] = 1; $coupon['level'] = 1;
$coupon['kl_num'] = $config['coupon_a_xz_max']; $coupon['kl_num'] = $config['coupon_a_xz_max'];
}else{ } else {
return $this->renderError("网络故障,请稍后再试!"); return $this->renderError("网络故障,请稍后再试!");
} }
//合成损耗10% //合成损耗10%
$sum_num = $sum_num - $sum_num * (10 / 100); $sum_num = $sum_num - $sum_num * (10 / 100);
if ($sum_num <= 0){ if ($sum_num <= 0) {
return $this->renderError("网络故障,请稍后再试!!"); return $this->renderError("网络故障,请稍后再试!!");
} }
$coupon['num'] = $sum_num; $coupon['num'] = $sum_num;
@ -760,14 +820,14 @@ writelog(11111111111,$user_id);
//其他人获得20% //其他人获得20%
$percentage = 20; $percentage = 20;
$other = $coupon['num'] * ($percentage / 100); $other = $coupon['num'] * ($percentage / 100);
if ($own <= 0 || $other <= 0){ if ($own <= 0 || $other <= 0) {
return $this->renderError("网络故障,请稍后再试!!!"); return $this->renderError("网络故障,请稍后再试!!!");
} }
Db::startTrans(); Db::startTrans();
$res = []; $res = [];
$res[] = UserCoupon::field('status,updatetime') $res[] = UserCoupon::field('status,updatetime')
->where(['user_id' => $user_id]) ->where(['user_id' => $user_id])
->whereIn('id',implode(',',$coupon_ids)) ->whereIn('id', implode(',', $coupon_ids))
->update([ ->update([
'status' => 4, 'status' => 4,
'updatetime' => time() 'updatetime' => time()
@ -802,7 +862,7 @@ writelog(11111111111,$user_id);
/** /**
* 潮券开劵 * 潮券开劵
*/ */
// public function coupon_open() // public function coupon_open()
// { // {
// $user = $this->getUser(); // $user = $this->getUser();
// $user_id = $user['id']; // $user_id = $user['id'];
@ -875,15 +935,16 @@ writelog(11111111111,$user_id);
]; ];
return $this->renderSuccess("请求成功", $new_data); return $this->renderSuccess("请求成功", $new_data);
} }
/* /*
海报生成器 海报生成器
*/ */
public function product_img(){ public function product_img()
#海报名称 {
#海报名称
$user_info = $this->getUser(); $user_info = $this->getUser();
$user_id = $user_info['id']; $user_id = $user_info['id'];
$share_image = $user_id . '.png'; $share_image = $user_id . '.png';
@ -892,12 +953,12 @@ writelog(11111111111,$user_id);
$path = '/storage/poster/share/'; $path = '/storage/poster/share/';
#海报完整路径 #海报完整路径
$save_path = $public_path . $path . $share_image; $save_path = $public_path . $path . $share_image;
if (!file_exists($save_path)) { if (!file_exists($save_path)) {
if (!file_exists($public_path . $path)) { if (!file_exists($public_path . $path)) {
mkdir($public_path . $path); mkdir($public_path . $path);
} }
#小程序二维码 生成 缩放 #小程序二维码 生成 缩放
$param = [ $param = [
'scene' => $user_info['id'], 'scene' => $user_info['id'],
@ -907,24 +968,24 @@ writelog(11111111111,$user_id);
//'env_version' => 'release',#要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 //'env_version' => 'release',#要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
'width' => '340px',#默认430二维码的宽度单位 px最小 280px最大 1280px 'width' => '340px',#默认430二维码的宽度单位 px最小 280px最大 1280px
]; ];
$wxServer = new \app\common\server\Wx($this->app); $wxServer = new \app\common\server\Wx($this->app);
$wxServer->GetShareCode($param, $save_path); $wxServer->GetShareCode($param, $save_path);
thumbImage($save_path, 288, 288); thumbImage($save_path, 288, 288);
#背景图 #背景图
$share_image = getConfig("base")['share_image']; $share_image = getConfig("base")['share_image'];
$poster_bg = $public_path . $share_image; $poster_bg = $public_path . $share_image;
#生成带背景的海报 #生成带背景的海报
(new Qcode())->setBgCode($save_path, $poster_bg, 104, 1180); (new Qcode())->setBgCode($save_path, $poster_bg, 104, 1180);
} }
#海报图片 #海报图片
$share_image = request()->domain() . $path . $share_image; $share_image = request()->domain() . $path . $share_image;
return $share_image; return $share_image;
} }
@ -999,26 +1060,27 @@ writelog(11111111111,$user_id);
* 重抽卡列表 * 重抽卡列表
* @return \think\response\Json * @return \think\response\Json
*/ */
public function item_card_list(){ public function item_card_list()
{
$user = $this->getUser(); $user = $this->getUser();
$list = Db::name('user_item_card') $list = Db::name('user_item_card')
->where(['user_id' => $user['id'], 'status' => 1]) ->where(['user_id' => $user['id'], 'status' => 1])
->field('id,type,title,addtime') ->field('id,type,title,addtime')
->order('id desc') ->order('id desc')
->paginate(['list_rows'=>20,'query' => request()->param()]); ->paginate(['list_rows' => 20, 'query' => request()->param()]);
$page = $list->render(); $page = $list->render();
$data['list'] = $list->toArray()['data']; $data['list'] = $list->toArray()['data'];
$data['count']=$list->total(); $data['count'] = $list->total();
$data['last_page']=$list->toArray()['last_page']; $data['last_page'] = $list->toArray()['last_page'];
$data['page']=$page; $data['page'] = $page;
foreach ($data['list'] as $k => &$v){ foreach ($data['list'] as $k => &$v) {
$v['addtime'] = date('Y-m-d H:i:s',$v['addtime']); $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
} }
return $this->renderSuccess('请求成功',$data); return $this->renderSuccess('请求成功', $data);
} }
} }

View File

@ -90,8 +90,8 @@ class Wx extends MyController
} }
/** /**
* *
* @param string $code * @param string $code
* @return int|mixed|\think\response\Json * @return int|mixed|\think\response\Json
@ -198,7 +198,7 @@ class Wx extends MyController
'access_token_time' => $access_token_time, 'access_token_time' => $access_token_time,
]; ];
$redis->set($redis_key, json_encode($data), $expires_in); $redis->set($redis_key, json_encode($data), $expires_in - 1800);
return $access_token; return $access_token;
} }
@ -281,8 +281,8 @@ class Wx extends MyController
public function post_order($openid, $access_token, $order_num, $title = '订单发货') public function post_order($openid, $access_token, $order_num, $title = '订单发货')
{ {
$date = new \DateTime(); $date = new \DateTime();
//2023-08-07T17:16:31 //2023-08-07T17:16:31
//2025-03-04T21:06:59 //2025-03-04T21:06:59
// 格式化时间为 yyyy-MM-dd HH:mm:ss // 格式化时间为 yyyy-MM-dd HH:mm:ss
$formattedDate = $date->format('Y-m-d\TH:i:s'); $formattedDate = $date->format('Y-m-d\TH:i:s');
$request_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $access_token; $request_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $access_token;
@ -318,8 +318,8 @@ class Wx extends MyController
{ {
// 创建一个 DateTime 对象,设置为当前时间 // 创建一个 DateTime 对象,设置为当前时间
$date = new \DateTime(); $date = new \DateTime();
//2023-08-07T17:16:31 //2023-08-07T17:16:31
//2025-03-04T21:06:59 //2025-03-04T21:06:59
// 格式化时间为 yyyy-MM-dd HH:mm:ss // 格式化时间为 yyyy-MM-dd HH:mm:ss
$formattedDate = $date->format('Y-m-d\TH:i:s'); $formattedDate = $date->format('Y-m-d\TH:i:s');
$request_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $access_token; $request_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $access_token;