486 lines
16 KiB
PHP
Executable File
486 lines
16 KiB
PHP
Executable File
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\api\controller\Base;
|
||
use app\common\model\Advert;
|
||
use app\common\model\Danye;
|
||
use app\common\model\Goods;
|
||
use app\common\model\GoodsList;
|
||
use app\common\model\OrderList;
|
||
use app\common\model\User;
|
||
use app\common\model\Yushou;
|
||
use think\facade\Db;
|
||
use \think\Request;
|
||
use app\common\model\Order;
|
||
use app\common\model\ProfitMoney;
|
||
|
||
|
||
class Index extends Base
|
||
{
|
||
//首页
|
||
public function index(Request $request)
|
||
{
|
||
#首页轮播图
|
||
$advert = Advert::field('imgurl,ttype,coupon_id,goods_id,url')->where(['type' => 1])->order('sort desc,id desc')->select();
|
||
foreach ($advert as &$advert_value) {
|
||
$advert_value['imgurl'] = imageUrl($advert_value['imgurl']);
|
||
}
|
||
$tuijian = Advert::field('imgurl,ttype,coupon_id,goods_id,url')->where(['type' => 5])->order('sort desc,id desc')->select();
|
||
foreach ($tuijian as &$advert_value) {
|
||
$advert_value['imgurl'] = imageUrl($advert_value['imgurl']);
|
||
}
|
||
#公告
|
||
$notice = Danye::field('title,content')->where(['id' => 3])->find();
|
||
$notice['content'] = contentUrl($notice['content']);
|
||
|
||
#客服
|
||
$rule = getConfig('base');
|
||
$other = [
|
||
'is_shou_tan' => $rule['is_shou_tan'],
|
||
'jump_appid' => $rule['jump_appid'],
|
||
'corpid' => $rule['corpid'],
|
||
'wx_link' => $rule['wx_link'],
|
||
'erweima' => imageUrl($rule['erweima']),
|
||
];
|
||
return $this->renderSuccess('请求成功', compact('advert', 'notice', 'other', 'tuijian'));
|
||
}
|
||
|
||
/**
|
||
* 预售日历
|
||
*/
|
||
public function yushourili()
|
||
{
|
||
|
||
$data = Yushou::field('id,title,imgurl,sale_time,goods_id')->order('sort desc,id desc')->limit(10)->select()->toArray();
|
||
foreach ($data as &$value) {
|
||
$goods = Goods::field('id')
|
||
->where('id', '=', $value['goods_id'])
|
||
->where('status', 'in', [1, 3])
|
||
->find();
|
||
if (!$goods) {
|
||
Yushou::field('goods_id')->where('id', '=', $value['id'])->update(['goods_id' => 0]);
|
||
$value['goods_id'] = 0;
|
||
}
|
||
$value['imgurl'] = imageUrl($value['imgurl']);
|
||
$value['month'] = date('m月', $value['sale_time']);
|
||
$value['day'] = date('d', $value['sale_time']);
|
||
}
|
||
return $this->renderSuccess("请求成功", $data);
|
||
}
|
||
|
||
/**
|
||
* 单页
|
||
*/
|
||
public function danye()
|
||
{
|
||
$type = \request()->param('type/d', 0);
|
||
$info = Danye::where(['id' => $type])->find();
|
||
if ($info) {
|
||
$content = contentUrl($info['content']);
|
||
} else {
|
||
$content = '';
|
||
}
|
||
return $this->renderSuccess("请求成功", $content);
|
||
}
|
||
|
||
/**
|
||
* 获取轮播图
|
||
* @return \think\response\Json
|
||
*/
|
||
public function getAdvert()
|
||
{
|
||
$type = request()->param('type_id/d', 1);
|
||
#首页轮播图
|
||
$advert = Advert::field('imgurl,ttype,coupon_id,goods_id')->where(['type' => $type])->order('sort desc,id desc')->select();
|
||
foreach ($advert as &$advert_value) {
|
||
$advert_value['imgurl'] = imageUrl($advert_value['imgurl']);
|
||
}
|
||
return $this->renderSuccess('请求成功', $advert);
|
||
}
|
||
|
||
public function record(Request $request)
|
||
{
|
||
|
||
$whe = [];
|
||
// $whe[] = ['order_type', '<', 5];
|
||
$whe[] = ['status', '=', 1];
|
||
$whe[] = ['price', '>', 0];
|
||
// 获取当前月份的第一天
|
||
$firstDayOfMonth = date('Y-m-01');
|
||
|
||
// 获取当前月份的最后一天
|
||
$lastDayOfMonth = date('Y-m-t');
|
||
;
|
||
$start_time = strtotime($firstDayOfMonth);
|
||
$end_time = strtotime($lastDayOfMonth);
|
||
// if ($start_time > $end_time) {
|
||
// $this->err('开始时间不能大于结束时间');
|
||
// }
|
||
$whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
||
$field = "id,user_id,sum(price) as price";
|
||
$list = Order::where($whe)
|
||
->field($field)
|
||
->group("user_id")
|
||
->order("price desc")
|
||
->paginate(['list_rows' => $this->page]);
|
||
$page = $list->render();
|
||
$data = [];
|
||
$data['list'] = $list->toArray()['data'];
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile')->where('id', '=', $value['user_id'])->find();
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = imageUrl($user_info['headimg']);
|
||
// if (!strpos($$value['headimg'], 'http:') && !strpos($$value['headimg'], 'https:')) {
|
||
// $value['headimg'] = imageUrl($value['headimg']);
|
||
// ;
|
||
// }
|
||
$value['mobile'] = $user_info['mobile'];
|
||
}
|
||
return $this->renderSuccess('请求成功', $data);
|
||
}
|
||
/**
|
||
* 邀请排行
|
||
*/
|
||
|
||
public function get_user_yaoqing()
|
||
{
|
||
//select * from ( SELECT pid,count(1) n FROM `user` where pid>0 group by pid ) t where n>1 order by n desc
|
||
$list = User::where('pid', '>', 0)
|
||
->field('pid, COUNT(1) as n') // 选取 pid 和 计数字段
|
||
->group('pid')
|
||
->having('n > 30') // `having` 需要使用 `as` 取别名
|
||
->order('n desc')
|
||
// ->limit(10) // 添加限制条数
|
||
->select();
|
||
$data = array();
|
||
$index = 1;
|
||
foreach ($list as $item) {
|
||
$pid = $item['pid'];
|
||
// $count = $item['n'];
|
||
// $item['user_id'] = $pid;
|
||
$user_info = User::field('nickname,headimg,mobile')->where('id', '=', $pid)->find();
|
||
if ($user_info != null) {
|
||
$data[] = [
|
||
'index' => $index,
|
||
'user_id' => $pid,
|
||
'invitenumber' => $item['n'],
|
||
'nickname' => $user_info['nickname'],
|
||
'headimg' => imageUrl($user_info['headimg'])
|
||
];
|
||
$index++;
|
||
}
|
||
}
|
||
return $this->renderSuccess('请求成功', $data);
|
||
}
|
||
|
||
public function generate_urllink()
|
||
{
|
||
$wxServer = new \app\common\server\Wx($this->app);
|
||
$user_base = $wxServer->generateUrlLink();
|
||
header("Location: " . $user_base);
|
||
exit();
|
||
// return $this->renderSuccess('请求成功', $user_base );
|
||
}
|
||
|
||
|
||
public function generate_urllinks()
|
||
{
|
||
$userId = request()->param('userId/d', 0);
|
||
$wxServer = new \app\common\server\Wx($this->app);
|
||
$user_base = $wxServer->generateUrlLinks($userId);
|
||
$autoload = new \app\common\server\autoload();
|
||
$currentDir = getcwd();
|
||
// $absolutePath = $currentDir . '/public/img_poster.jpg';
|
||
// ///www/wwwroot/testbaji.onelight.vip/app/public/img_poster.jpg
|
||
// //www/wwwroot/testbaji.onelight.vip/public/public/img_poster.jpg
|
||
$imageData = $autoload->generatePosterWithQR($currentDir . '/img_poster.jpg', $user_base);
|
||
if ($imageData) {
|
||
header('Content-Type: image/png');
|
||
header('Content-Length: ' . strlen($imageData)); // 设置图像长度,帮助浏览器处理流式内容
|
||
echo $imageData;
|
||
exit();
|
||
}
|
||
return $this->renderSuccess('请求成功', $user_base);
|
||
}
|
||
|
||
/**
|
||
* 获取排行榜数据
|
||
* 支持:diamond(钻石排行榜)、integral(UU币排行榜)、dadajuan(达达卷排行榜)、invite(邀请新人排行榜)
|
||
*
|
||
* @return \think\response\Json
|
||
*/
|
||
public function getRankList()
|
||
{
|
||
// 获取排行榜类型参数
|
||
$type = request()->param('type', '');
|
||
|
||
// 验证排行榜类型是否有效
|
||
$validTypes = ['diamond', 'integral', 'dadajuan', 'invite'];
|
||
if (!in_array($type, $validTypes)) {
|
||
return $this->renderError('无效的排行榜类型');
|
||
}
|
||
|
||
// 从配置助手获取排行榜时间设置
|
||
$timeSettings = \app\common\helper\ConfigHelper::getRankTime($type);
|
||
$startTime = !empty($timeSettings['start_time']) ? strtotime($timeSettings['start_time']) : 0;
|
||
$endTime = !empty($timeSettings['end_time']) ? strtotime($timeSettings['end_time']) : time();
|
||
|
||
// 设置分页参数
|
||
$page = request()->param('page/d', 1);
|
||
$limit = request()->param('limit/d', 10);
|
||
|
||
// 初始化返回数据
|
||
$data = [];
|
||
|
||
// 根据不同排行榜类型查询数据
|
||
switch ($type) {
|
||
case 'diamond': // 钻石排行榜
|
||
$data = $this->getDiamondRank($startTime, $endTime, $page, $limit);
|
||
break;
|
||
|
||
case 'integral': // UU币排行榜
|
||
$data = $this->getIntegralRank($startTime, $endTime, $page, $limit);
|
||
break;
|
||
|
||
case 'dadajuan': // 达达卷排行榜
|
||
$data = $this->getDadajuanRank($startTime, $endTime, $page, $limit);
|
||
break;
|
||
|
||
case 'invite': // 邀请新人排行榜
|
||
$data = $this->getInviteRank($startTime, $endTime, $page, $limit);
|
||
break;
|
||
}
|
||
|
||
// 返回数据
|
||
return $this->renderSuccess('请求成功', $data);
|
||
}
|
||
|
||
/**
|
||
* 获取钻石排行榜数据
|
||
*
|
||
* @param int $startTime 开始时间戳
|
||
* @param int $endTime 结束时间戳
|
||
* @param int $page 页码
|
||
* @param int $limit 每页数量
|
||
* @return array 排行榜数据
|
||
*/
|
||
private function getDiamondRank($startTime, $endTime, $page, $limit)
|
||
{
|
||
// 构建查询条件
|
||
$where = [
|
||
['status', '=', 1],
|
||
['use_money', '>', 0],
|
||
['user_id', 'not in', function ($query) {
|
||
$query->name('user')->where('istest', '>', 0)->where('status', '=', 1)->field('id');
|
||
}]
|
||
];
|
||
|
||
// 添加时间范围条件
|
||
if ($startTime > 0) {
|
||
$where[] = ['pay_time', '>=', $startTime];
|
||
}
|
||
if ($endTime > 0) {
|
||
$where[] = ['pay_time', '<=', $endTime];
|
||
}
|
||
|
||
// 查询数据
|
||
$list = Order::where($where)
|
||
->field('user_id, sum(use_money) as use_money')
|
||
->group('user_id')
|
||
->order('use_money desc')
|
||
->page($page, $limit)
|
||
->select()
|
||
->toArray();
|
||
|
||
// 处理用户信息
|
||
$rankList = [];
|
||
foreach ($list as $index => $item) {
|
||
$userInfo = User::field('nickname, headimg, mobile')->where('id', $item['user_id'])->find();
|
||
if ($userInfo) {
|
||
$rankList[] = [
|
||
'rank' => ($page - 1) * $limit + $index + 1,
|
||
'user_id' => $item['user_id'],
|
||
'nickname' => $userInfo['nickname'],
|
||
'headimg' => imageUrl($userInfo['headimg']),
|
||
'value' => $item['use_money'],
|
||
'unit' => '钻石'
|
||
];
|
||
}
|
||
}
|
||
|
||
return $rankList;
|
||
}
|
||
|
||
/**
|
||
* 获取UU币排行榜数据
|
||
*
|
||
* @param int $startTime 开始时间戳
|
||
* @param int $endTime 结束时间戳
|
||
* @param int $page 页码
|
||
* @param int $limit 每页数量
|
||
* @return array 排行榜数据
|
||
*/
|
||
private function getIntegralRank($startTime, $endTime, $page, $limit)
|
||
{
|
||
// 构建查询条件
|
||
$where = [
|
||
['status', '=', 1],
|
||
['use_integral', '>', 0],
|
||
['user_id', 'not in', function ($query) {
|
||
$query->name('user')->where('istest', '>', 0)->where('status', '=', 1)->field('id');
|
||
}]
|
||
];
|
||
|
||
// 添加时间范围条件
|
||
if ($startTime > 0) {
|
||
$where[] = ['pay_time', '>=', $startTime];
|
||
}
|
||
if ($endTime > 0) {
|
||
$where[] = ['pay_time', '<=', $endTime];
|
||
}
|
||
|
||
// 查询数据
|
||
$list = Order::where($where)
|
||
->field('user_id, sum(use_integral) as use_money')
|
||
->group('user_id')
|
||
->order('use_money desc')
|
||
->page($page, $limit)
|
||
->select()
|
||
->toArray();
|
||
|
||
// 处理用户信息
|
||
$rankList = [];
|
||
foreach ($list as $index => $item) {
|
||
$userInfo = User::field('nickname, headimg, mobile')->where('id', $item['user_id'])->find();
|
||
if ($userInfo) {
|
||
$rankList[] = [
|
||
'rank' => ($page - 1) * $limit + $index + 1,
|
||
'user_id' => $item['user_id'],
|
||
'nickname' => $userInfo['nickname'],
|
||
'headimg' => imageUrl($userInfo['headimg']),
|
||
'value' => $item['use_money'],
|
||
'unit' => 'UU币'
|
||
];
|
||
}
|
||
}
|
||
|
||
return $rankList;
|
||
}
|
||
|
||
/**
|
||
* 获取达达卷排行榜数据
|
||
*
|
||
* @param int $startTime 开始时间戳
|
||
* @param int $endTime 结束时间戳
|
||
* @param int $page 页码
|
||
* @param int $limit 每页数量
|
||
* @return array 排行榜数据
|
||
*/
|
||
private function getDadajuanRank($startTime, $endTime, $page, $limit)
|
||
{
|
||
// 构建查询条件
|
||
$where = [
|
||
['status', '=', 1],
|
||
['use_money2', '>', 0],
|
||
['user_id', 'not in', function ($query) {
|
||
$query->name('user')->where('istest', '>', 0)->where('status', '=', 1)->field('id');
|
||
}]
|
||
];
|
||
|
||
// 添加时间范围条件
|
||
if ($startTime > 0) {
|
||
$where[] = ['pay_time', '>=', $startTime];
|
||
}
|
||
if ($endTime > 0) {
|
||
$where[] = ['pay_time', '<=', $endTime];
|
||
}
|
||
|
||
// 查询数据
|
||
$list = Order::where($where)
|
||
->field('user_id, sum(use_money2) as use_money')
|
||
->group('user_id')
|
||
->order('use_money desc')
|
||
->page($page, $limit)
|
||
->select()
|
||
->toArray();
|
||
|
||
// 处理用户信息
|
||
$rankList = [];
|
||
foreach ($list as $index => $item) {
|
||
$userInfo = User::field('nickname, headimg, mobile')->where('id', $item['user_id'])->find();
|
||
if ($userInfo) {
|
||
$rankList[] = [
|
||
'rank' => ($page - 1) * $limit + $index + 1,
|
||
'user_id' => $item['user_id'],
|
||
'nickname' => $userInfo['nickname'],
|
||
'headimg' => imageUrl($userInfo['headimg']),
|
||
'value' => $item['use_money'],
|
||
'unit' => '达达卷'
|
||
];
|
||
}
|
||
}
|
||
|
||
return $rankList;
|
||
}
|
||
|
||
/**
|
||
* 获取邀请新人排行榜数据
|
||
*
|
||
* @param int $startTime 开始时间戳
|
||
* @param int $endTime 结束时间戳
|
||
* @param int $page 页码
|
||
* @param int $limit 每页数量
|
||
* @return array 排行榜数据
|
||
*/
|
||
private function getInviteRank($startTime, $endTime, $page, $limit)
|
||
{
|
||
// 构建查询条件
|
||
$where = [
|
||
['pid', '>', 0],
|
||
['istest', '=', 0], // 排除测试用户
|
||
['status', '=', 1] // 只查询状态正常的用户
|
||
];
|
||
|
||
// 添加时间范围条件
|
||
if ($startTime > 0) {
|
||
$where[] = ['addtime', '>=', $startTime];
|
||
}
|
||
if ($endTime > 0) {
|
||
$where[] = ['addtime', '<=', $endTime];
|
||
}
|
||
|
||
// 查询数据
|
||
$list = User::where($where)
|
||
->field('pid, COUNT(1) as invite_count')
|
||
->group('pid')
|
||
->having('invite_count > 0')
|
||
->order('invite_count desc')
|
||
->page($page, $limit)
|
||
->select()
|
||
->toArray();
|
||
|
||
// 处理用户信息
|
||
$rankList = [];
|
||
foreach ($list as $index => $item) {
|
||
$userInfo = User::field('nickname, headimg, mobile')->where('id', $item['pid'])->find();
|
||
if ($userInfo) {
|
||
$rankList[] = [
|
||
'rank' => ($page - 1) * $limit + $index + 1,
|
||
'user_id' => $item['pid'],
|
||
'nickname' => $userInfo['nickname'],
|
||
'headimg' => imageUrl($userInfo['headimg']),
|
||
'value' => $item['invite_count'],
|
||
'unit' => '人'
|
||
];
|
||
}
|
||
}
|
||
|
||
return $rankList;
|
||
}
|
||
|
||
|
||
}
|