211 lines
7.3 KiB
PHP
Executable File
211 lines
7.3 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')->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')->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);
|
|
}
|
|
|
|
|
|
}
|