From f655104cddbf70004740139f7639da2ff8a3eef3 Mon Sep 17 00:00:00 2001 From: manghe Date: Mon, 17 Mar 2025 08:46:24 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/User.php | 360 +++++++++++++++++++++--------------- app/common/server/Wx.php | 14 +- 2 files changed, 218 insertions(+), 156 deletions(-) diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 8004b2c..37caaee 100755 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -1,5 +1,5 @@ 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) { $user = $this->getUser(); - $userinfo['ID'] = $user['id']+1260; + $userinfo['ID'] = $user['id'] + 1260; $userinfo['mobile_is'] = $user['mobile'] ? 1 : 0; $userinfo['nickname'] = $user['nickname']; $userinfo['headimg'] = imageUrl($user['headimg']); @@ -41,19 +58,19 @@ class User extends Base $userinfo['vip'] = $this->vip_level($user['id'], $user['vip']); $vip_imgurl = UserVip::field('imgurl')->where('id', '=', $userinfo['vip'])->value('imgurl'); $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(); $base = getConfig('base'); $userinfo['js_is_open'] = 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); $userinfo['day'] = $day; - + #客服 $other = [ -// 'recharge' => [100, 200, 500, 1000, 3000], + // 'recharge' => [100, 200, 500, 1000, 3000], 'jump_appid' => $base['jump_appid'], 'corpid' => $base['corpid'], 'wx_link' => $base['wx_link'], @@ -61,16 +78,16 @@ class User extends Base ]; //主要任务 $where = []; - $where[] = ['is_important','=',1]; + $where[] = ['is_important', '=', 1]; $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每周任务 - if ($v['type'] == 1){ - $start_time = strtotime(date('Y-m-d',time()).' 00:00:00'); - $end_time = strtotime(date('Y-m-d',time()).' 23:59:59'); - }else{ + if ($v['type'] == 1) { + $start_time = strtotime(date('Y-m-d', time()) . ' 00:00:00'); + $end_time = strtotime(date('Y-m-d', time()) . ' 23:59:59'); + } else { $date = date('Y-m-d'); //当前日期 $first = 1; //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期 $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'); //本周结束日期 } //1邀请好友注册 2抽赏任务 - if ($v['cate'] == 1){ - $yao_count = \app\common\model\User::where([['pid','=',$user['id']],['addtime','>=',$start_time]])->count(); + if ($v['cate'] == 1) { + $yao_count = \app\common\model\User::where([['pid', '=', $user['id']], ['addtime', '>=', $start_time]])->count(); if ($yao_count >= $v['number']) { $v['is_complete'] = 1; //进度条 @@ -96,8 +113,8 @@ class User extends Base $v['ywc_count'] = $yao_count; } - }elseif ($v['cate'] == 2){ - $prize_num = Order::where([['user_id','=',$user['id']],['pay_type','<',10],['status','=',1],['addtime','>=',$start_time]])->count(); + } elseif ($v['cate'] == 2) { + $prize_num = Order::where([['user_id', '=', $user['id']], ['pay_type', '<', 10], ['status', '=', 1], ['addtime', '>=', $start_time]])->count(); if ($prize_num >= $v['number']) { $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(); - if ($is_ling){ + $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) { $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(); $nickname = request()->param('nickname', ''); $headimg = request()->param('headimg', ''); + $imagebase = request()->param('imagebase', ''); + if (empty($nickname)) { return $this->renderError("请输入姓名"); } @@ -137,15 +156,52 @@ class User extends Base if ($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) { - $str = explode('/storage',$headimg); - $save['headimg'] = '/storage'.$str[1]; - } else { - $save['headimg'] = $headimg; + $uniqueFileName = $userId . '_' . uniqid('') . '.png'; + $cosKey = 'storage/users/icon/' . $uniqueFileName; // COS 中的文件路径 + + try { + // 上传文件到腾讯云 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); if ($res) { return $this->renderSuccess('修改成功'); @@ -180,11 +236,11 @@ class User extends Base ->where('id', '>', $vip) ->order('id asc') ->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']; - if ($total_order >= $condition['condition']){ + if ($total_order >= $condition['condition']) { $userinfo['jin_du'] = 100; - }else{ + } else { $userinfo['jin_du'] = $total_order / $condition['condition'] * 100; } @@ -196,7 +252,7 @@ class User extends Base $data = UserVip::select()->toArray(); foreach ($data as &$value) { $value['imgurl'] = imageUrl($value['imgurl']); - if ($vip == $value['id']){ + if ($vip == $value['id']) { $userinfo['notice'] = $value['notice']; } } @@ -245,7 +301,7 @@ class User extends Base } $data = ProfitIntegral::field('change_money,content,addtime') ->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) ->order('id desc') @@ -278,7 +334,7 @@ class User extends Base } $data = ProfitMoney::field('change_money,content,addtime') ->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) ->order('id desc') @@ -307,7 +363,7 @@ class User extends Base } $data = ProfitScore::field('change_money,content,addtime') ->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) ->order('id desc') @@ -329,7 +385,7 @@ class User extends Base $whe[] = ['user_id', '=', $user['id']]; $data = ProfitPay::field('change_money,content,addtime') ->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) ->order('id desc') @@ -353,10 +409,10 @@ class User extends Base $where[] = ['user_id', '=', $user_id]; $order_by = 'id desc'; - if ($status == 1){ + if ($status == 1) { $where[] = ['status', '=', 1]; $order_by = 'id desc'; - }elseif ($status == 2){ + } elseif ($status == 2) { $where[] = ['status', '=', 2]; $order_by = 'share_time desc'; } @@ -365,16 +421,16 @@ class User extends Base ->order($order_by) ->paginate(15)->each(function ($itme) { //1特级赏券 2终极赏券 3高级赏券 4普通赏券 - if ($itme['level'] == 1){ + if ($itme['level'] == 1) { $itme['level_text'] = '特级赏券'; $itme['level_img'] = imageUrl('/storage/coupon/coupon_a.png'); - }elseif ($itme['level'] == 2){ + } elseif ($itme['level'] == 2) { $itme['level_text'] = '终极赏券'; $itme['level_img'] = imageUrl('/storage/coupon/coupon_b.png'); - }elseif ($itme['level'] == 3){ + } elseif ($itme['level'] == 3) { $itme['level_text'] = '高级赏券'; $itme['level_img'] = imageUrl('/storage/coupon/coupon_c.png'); - }elseif ($itme['level'] == 4){ + } elseif ($itme['level'] == 4) { $itme['level_text'] = '普通赏券'; $itme['level_img'] = imageUrl('/storage/coupon/coupon_d.png'); } @@ -392,7 +448,7 @@ class User extends Base $sun_hao = '10%'; //损耗 $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\ModelNotFoundException */ - public function coupon_detail(){ + public function coupon_detail() + { $user = $this->getUser(); $user_id = $user['id']; $coupon_id = request()->param("coupon_id/d", 0); @@ -413,50 +470,50 @@ class User extends Base if (empty($info)) { return $this->renderError("参数错误"); } - $info['own2'] = round($info['own2'] - $info['own'],2); - if ($info['level'] == 1){ + $info['own2'] = round($info['own2'] - $info['own'], 2); + if ($info['level'] == 1) { $info['level_text'] = '特级赏券'; $info['level_img'] = imageUrl('/storage/coupon/coupon_a.png'); - }elseif ($info['level'] == 2){ + } elseif ($info['level'] == 2) { $info['level_text'] = '终极赏券'; $info['level_img'] = imageUrl('/storage/coupon/coupon_b.png'); - }elseif ($info['level'] == 3){ + } elseif ($info['level'] == 3) { $info['level_text'] = '高级赏券'; $info['level_img'] = imageUrl('/storage/coupon/coupon_c.png'); - }elseif ($info['level'] == 4){ + } elseif ($info['level'] == 4) { $info['level_text'] = '普通赏券'; $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_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_headimg'] = $share_user ? imageUrl($share_user['headimg']) : ''; $yl_list = UserCoupon::alias('a') ->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]) ->select(); //手气最佳 $yl_max = Db::name('user_coupon') ->alias('a') ->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]) - ->max('a.l_num'); - foreach ($yl_list as $k => &$v){ + ->max('a.l_num'); + foreach ($yl_list as $k => &$v) { $v['headimg'] = imageUrl($v['headimg']); - $v['addtime'] = date('Y-m-d H:i:s',$v['addtime']); - if ($yl_max == $v['l_num']){ + $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']); + if ($yl_max == $v['l_num']) { $v['lucky_king'] = 1; - }else{ + } else { $v['lucky_king'] = 0; } } $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)) { 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)) { return $this->renderError("参数错误"); } @@ -492,7 +549,7 @@ class User extends Base Db::rollback(); return $this->renderError("网络故障,请稍后再试"); } - }catch (\Exception $e){ + } catch (\Exception $e) { Db::rollback(); return $this->renderError("网络故障,请稍后再试!"); } @@ -507,7 +564,7 @@ class User extends Base $user = $this->getUser(); $user_id = $user['id']; $coupon_id = request()->param("coupon_id/d", 0); -writelog(11111111111,$user_id); + writelog(11111111111, $user_id); if (empty($coupon_id)) { return $this->renderError("缺少必要参数"); } @@ -516,14 +573,14 @@ writelog(11111111111,$user_id); return $this->renderError("参数错误"); } if ($info['user_id'] == $user_id) { - return $this->renderError("请勿开启自己的劵",[],2222); + return $this->renderError("请勿开启自己的劵", [], 2222); } $is_ling = UserCoupon::where('user_id', '=', $user['id']) ->where('type', '=', 2) ->where('from_id', '=', $coupon_id) ->find(); - if ($is_ling){ - return $this->renderError("你已经领取过了",[],2222); + if ($is_ling) { + return $this->renderError("你已经领取过了", [], 2222); } $count = UserCoupon::where('user_id', '=', $user['id']) ->where('type', '=', 2) @@ -532,13 +589,13 @@ writelog(11111111111,$user_id); $config = getConfig("base"); if ($config['coupon_ling_max_ci'] && $config['coupon_ling_max_ci'] > 0) { - if($count >= $config['coupon_ling_max_ci']){ - return $this->renderError('每天最多领取'.$config['coupon_ling_max_ci'].'次'); + if ($count >= $config['coupon_ling_max_ci']) { + return $this->renderError('每天最多领取' . $config['coupon_ling_max_ci'] . '次'); } } //其他人可以获得多少 - if ($info['other'] <= 0){ - return $this->renderError("来晚了, 已经被人领完了",[],2222); + if ($info['other'] <= 0) { + return $this->renderError("来晚了, 已经被人领完了", [], 2222); } Db::startTrans(); try { @@ -550,12 +607,12 @@ writelog(11111111111,$user_id); // $key = mt_rand(0, count($data['items']) - 1); //随机取数组中的一个 // $rand_money = $data['items'][$key]; // } - $rand_money_arr = $this->rand_money($info['other'],$info['kl_num'],'1'); - if (count($rand_money_arr) <= 0){ - return $this->renderError("来晚了, 已经被人领完了",[],2222); + $rand_money_arr = $this->rand_money($info['other'], $info['kl_num'], '1'); + if (count($rand_money_arr) <= 0) { + return $this->renderError("来晚了, 已经被人领完了", [], 2222); } $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([ 'user_id' => $user_id, @@ -571,7 +628,7 @@ writelog(11111111111,$user_id); $res[] = UserCoupon::field('status,other,kl_num,updatetime,own,share_time') ->where(['id' => $coupon_id]) - ->dec('kl_num',1) + ->dec('kl_num', 1) ->update([ 'updatetime' => time() ]); @@ -579,12 +636,12 @@ writelog(11111111111,$user_id); $res[] = Usermodel::changeIntegral($user_id, $rand_money, 3, '欧气券领取', $coupon_id); $kl_num = UserCoupon::field('kl_num,own')->where(['id' => $coupon_id])->find(); - if ($kl_num['own'] > 0 && $kl_num['kl_num'] > 1){ - $integral = round($info['own2'] / $info['kl_num2'],2); - $res[] = UserCoupon::field('own')->where(['id' => $coupon_id])->dec('own',floatval($integral))->update(); + if ($kl_num['own'] > 0 && $kl_num['kl_num'] > 1) { + $integral = round($info['own2'] / $info['kl_num2'], 2); + $res[] = UserCoupon::field('own')->where(['id' => $coupon_id])->dec('own', floatval($integral))->update(); $res[] = Usermodel::changeIntegral($info['user_id'], $integral, 5, '欧气券分享', $coupon_id); - }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(); + } 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[] = Usermodel::changeIntegral($info['user_id'], $kl_num['own'], 5, '欧气券分享', $coupon_id); } @@ -593,44 +650,45 @@ writelog(11111111111,$user_id); return $this->renderSuccess("领取成功"); } else { Db::rollback(); - return $this->renderError("人数过多,请稍后再试",[],2222); + return $this->renderError("人数过多,请稍后再试", [], 2222); } - }catch (\Exception $e){ + } catch (\Exception $e) { Db::rollback(); // var_dump($e->getLine()); - return $this->renderError("人数过多,请稍后再试!",[],2222); + return $this->renderError("人数过多,请稍后再试!", [], 2222); } } - + /** * 红包随机金额 */ - public function rand_money($total,$personal_num,$min_money=1){ -// $money_total = $total; //总金额 + public function rand_money($total, $personal_num, $min_money = 1) + { + // $money_total = $total; //总金额 // $personal_num = $personal_num; //总数量 // $min_money = $min_money; //最小金额 - $money_right = $total; - $randMoney = []; - for($i=1;$i<=$personal_num;$i++){ - if($money_right == $personal_num){ + $money_right = $total; + $randMoney = []; + for ($i = 1; $i <= $personal_num; $i++) { + if ($money_right == $personal_num) { $money = 1; - $money = sprintf("%.2f",$money); - }else{ - if($i== $personal_num){ + $money = sprintf("%.2f", $money); + } else { + if ($i == $personal_num) { $money = $money_right; - }else{ - $max = $money_right - ($personal_num - $i) * $min_money; - if($max < 2){ + } else { + $max = $money_right - ($personal_num - $i) * $min_money; + if ($max < 2) { $max = 2; } - $money = mt_rand((int)($min_money),(int)($max/2)) ; - $money = sprintf("%.2f",$money); + $money = mt_rand((int) ($min_money), (int) ($max / 2)); + $money = sprintf("%.2f", $money); } } $randMoney[] = $money; $money_right = $money_right - $money; - $money_right = sprintf("%.2f",$money_right); + $money_right = sprintf("%.2f", $money_right); } shuffle($randMoney); return $randMoney; @@ -644,56 +702,57 @@ writelog(11111111111,$user_id); * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function coupon_ji_suan(Request $request){ + public function coupon_ji_suan(Request $request) + { $user = $this->getUser(); $user_id = $user['id']; $coupon_ids = request()->param("coupon_ids", ''); if (empty($coupon_ids)) { return $this->renderError("缺少必要参数"); } - $coupon_ids = explode(',',trim($coupon_ids)); - if (!$coupon_ids){ + $coupon_ids = explode(',', trim($coupon_ids)); + if (!$coupon_ids) { return $this->renderError("缺少必要参数!"); } $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(); - if (!$is_coupon){ + if (!$is_coupon) { return $this->renderError("数据错误!"); } - if ($is_coupon['level'] < 3){ + if ($is_coupon['level'] < 3) { return $this->renderError("特级,终极赏券不能合成"); } $sum_num += $is_coupon['num']; } //合成损耗10% $sh_num = $sum_num - $sum_num * (10 / 100); - if ($sum_num <= 0){ + if ($sum_num <= 0) { return $this->renderError("网络故障,请稍后再试!!"); } - if (count($coupon_ids) > 20){ + if (count($coupon_ids) > 20) { return $this->renderError("最多只能20个合成"); } $coupon = []; - if ($sum_num > 0 && $sum_num < 500){ + if ($sum_num > 0 && $sum_num < 500) { $coupon['title'] = "普通赏券"; $coupon['level'] = 4; - }elseif ($sum_num >= 500 && $sum_num < 2000){ + } elseif ($sum_num >= 500 && $sum_num < 2000) { $coupon['title'] = "高级赏券"; $coupon['level'] = 3; - }elseif ($sum_num >= 2000 && $sum_num < 5000){ + } elseif ($sum_num >= 2000 && $sum_num < 5000) { $coupon['title'] = "终极赏券"; $coupon['level'] = 2; - }elseif ($sum_num >= 5000){ + } elseif ($sum_num >= 5000) { $coupon['title'] = "特级赏券"; $coupon['level'] = 1; - }else{ + } else { 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\ModelNotFoundException */ - public function coupon_synthesis(){ + public function coupon_synthesis() + { $user = $this->getUser(); $user_id = $user['id']; $coupon_ids = request()->param("coupon_ids", ''); if (empty($coupon_ids)) { return $this->renderError("缺少必要参数"); } - $coupon_ids = explode(',',trim($coupon_ids)); - if (!$coupon_ids){ + $coupon_ids = explode(',', trim($coupon_ids)); + if (!$coupon_ids) { return $this->renderError("缺少必要参数!"); } $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(); - if (!$is_coupon){ + if (!$is_coupon) { return $this->renderError("数据错误!"); } - if ($is_coupon['level'] < 3){ + if ($is_coupon['level'] < 3) { return $this->renderError("特级,终极赏券不能合成"); } $sum_num += $is_coupon['num']; @@ -728,28 +788,28 @@ writelog(11111111111,$user_id); $coupon = []; $config = getConfig("base"); - if ($sum_num > 0 && $sum_num < 500){ + if ($sum_num > 0 && $sum_num < 500) { $coupon['title'] = "普通赏券"; $coupon['level'] = 4; $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['level'] = 3; $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['level'] = 2; $coupon['kl_num'] = $config['coupon_b_xz_max']; - }elseif ($sum_num >= 5000){ + } elseif ($sum_num >= 5000) { $coupon['title'] = "特级赏券"; $coupon['level'] = 1; $coupon['kl_num'] = $config['coupon_a_xz_max']; - }else{ + } else { return $this->renderError("网络故障,请稍后再试!"); } //合成损耗10% $sum_num = $sum_num - $sum_num * (10 / 100); - if ($sum_num <= 0){ + if ($sum_num <= 0) { return $this->renderError("网络故障,请稍后再试!!"); } $coupon['num'] = $sum_num; @@ -760,14 +820,14 @@ writelog(11111111111,$user_id); //其他人获得20% $percentage = 20; $other = $coupon['num'] * ($percentage / 100); - if ($own <= 0 || $other <= 0){ + if ($own <= 0 || $other <= 0) { return $this->renderError("网络故障,请稍后再试!!!"); } Db::startTrans(); $res = []; $res[] = UserCoupon::field('status,updatetime') ->where(['user_id' => $user_id]) - ->whereIn('id',implode(',',$coupon_ids)) + ->whereIn('id', implode(',', $coupon_ids)) ->update([ 'status' => 4, 'updatetime' => time() @@ -802,7 +862,7 @@ writelog(11111111111,$user_id); /** * 潮券开劵 */ -// public function coupon_open() + // public function coupon_open() // { // $user = $this->getUser(); // $user_id = $user['id']; @@ -875,15 +935,16 @@ writelog(11111111111,$user_id); ]; return $this->renderSuccess("请求成功", $new_data); } - - - + + + /* 海报生成器 */ - public function product_img(){ - #海报名称 + public function product_img() + { + #海报名称 $user_info = $this->getUser(); $user_id = $user_info['id']; $share_image = $user_id . '.png'; @@ -892,12 +953,12 @@ writelog(11111111111,$user_id); $path = '/storage/poster/share/'; #海报完整路径 $save_path = $public_path . $path . $share_image; - - if (!file_exists($save_path)) { + + if (!file_exists($save_path)) { if (!file_exists($public_path . $path)) { mkdir($public_path . $path); } - + #小程序二维码 生成 缩放 $param = [ 'scene' => $user_info['id'], @@ -907,24 +968,24 @@ writelog(11111111111,$user_id); //'env_version' => 'release',#要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 'width' => '340px',#默认430,二维码的宽度,单位 px,最小 280px,最大 1280px ]; - + $wxServer = new \app\common\server\Wx($this->app); - + $wxServer->GetShareCode($param, $save_path); - - thumbImage($save_path, 288, 288); + + thumbImage($save_path, 288, 288); #背景图 $share_image = getConfig("base")['share_image']; $poster_bg = $public_path . $share_image; - - + + #生成带背景的海报 (new Qcode())->setBgCode($save_path, $poster_bg, 104, 1180); - + } #海报图片 $share_image = request()->domain() . $path . $share_image; - + return $share_image; } @@ -999,26 +1060,27 @@ writelog(11111111111,$user_id); * 重抽卡列表 * @return \think\response\Json */ - public function item_card_list(){ + public function item_card_list() + { $user = $this->getUser(); $list = Db::name('user_item_card') ->where(['user_id' => $user['id'], 'status' => 1]) ->field('id,type,title,addtime') ->order('id desc') - ->paginate(['list_rows'=>20,'query' => request()->param()]); + ->paginate(['list_rows' => 20, '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; + $data['count'] = $list->total(); + $data['last_page'] = $list->toArray()['last_page']; + $data['page'] = $page; - foreach ($data['list'] as $k => &$v){ - $v['addtime'] = date('Y-m-d H:i:s',$v['addtime']); + foreach ($data['list'] as $k => &$v) { + $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']); } - return $this->renderSuccess('请求成功',$data); + return $this->renderSuccess('请求成功', $data); } } \ No newline at end of file diff --git a/app/common/server/Wx.php b/app/common/server/Wx.php index 48cf78c..6e90b94 100755 --- a/app/common/server/Wx.php +++ b/app/common/server/Wx.php @@ -90,8 +90,8 @@ class Wx extends MyController } - - /** + + /** * * @param string $code * @return int|mixed|\think\response\Json @@ -198,7 +198,7 @@ class Wx extends MyController '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; } @@ -281,8 +281,8 @@ class Wx extends MyController public function post_order($openid, $access_token, $order_num, $title = '订单发货') { $date = new \DateTime(); - //2023-08-07T17:16:31 - //2025-03-04T21:06:59 + //2023-08-07T17:16:31 + //2025-03-04T21:06:59 // 格式化时间为 yyyy-MM-dd HH:mm:ss $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; @@ -318,8 +318,8 @@ class Wx extends MyController { // 创建一个 DateTime 对象,设置为当前时间 $date = new \DateTime(); - //2023-08-07T17:16:31 - //2025-03-04T21:06:59 + //2023-08-07T17:16:31 + //2025-03-04T21:06:59 // 格式化时间为 yyyy-MM-dd HH:mm:ss $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;