manghe/app/api/controller/Index.php
2025-04-13 21:57:55 +08:00

254 lines
8.5 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
use PhpOffice\PhpSpreadsheet\Chart\Title;
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);
}
/**
* 单页
*/
public function getDanye()
{
$type = \request()->param('type/d', 0);
$info = Danye::where(['id' => $type])->find();
if ($info) {
$content = contentUrl($info['content']);
} else {
$content = '';
}
return $this->renderSuccess("请求成功", [
'content' => $content,
'title' => $info['title']
]);
}
/**
* 获取轮播图
* @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();
$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(邀请新人排行榜)、loss(亏损补贴排行榜)
*
* @return \think\response\Json
*/
public function getRankList()
{
// 获取排行榜类型参数
$type = request()->param('type', '');
// 验证排行榜类型是否有效
$validTypes = ['diamond', 'integral', 'dadajuan', 'invite', 'loss'];
if (!in_array($type, $validTypes)) {
return $this->renderError('无效的排行榜类型');
}
// 设置分页参数
$page = request()->param('page/d', 1);
$limit = request()->param('limit/d', 10);
// 初始化排行榜服务类
$rankService = new \app\common\service\RankService();
$data = $rankService->getRankList($type, $page, $limit);
// 返回数据
return $this->renderSuccess('请求成功', $data);
}
}