init: 项目初始代码

This commit is contained in:
2026-10-14 14:00:29 +08:00
commit cc434cf89f
464 changed files with 66984 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
/**
* 关于我们
*/
class About extends Base
{
public function initialize()
{
parent::initialize();
$this->model = new \app\index\model\About();
}
/**
* 显示资源列表
*
*/
public function index()
{
$inputData = $this->request->param();
$resource = [];
// $resource['banner'] = $this->model->getAboutBanner($this->languageId,'关于我们页面-banner');
// $resource['banner_mobile'] = $this->model->getAboutBanner($this->languageId,'关于我们页面-手机-banner');
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'about');
View::assign('meta',$metaTitle);
View::assign('resource',$resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'about/about_us');
}
public function mileage(){
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'about/mileage');
}
}

View File

@@ -0,0 +1,249 @@
<?php
declare(strict_types=1);
namespace app\index\controller;
use app\library\LogToKafka;
use app\BaseController;
use app\index\model\Navigator;
use app\index\model\SystemConfig;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\AbstractDeviceParser;
use GeoIp2\Database\Reader;
use think\facade\Cache;
use think\facade\Env;
use think\facade\Lang;
use think\facade\View;
/**
* 控制器基类
*/
class Base extends BaseController
{
use LogToKafka;
/**
* 平台固定为1.不是多平台
* @var int
*/
protected $platformId = 1;
/**
* 查询条件,模糊字段与值。格式 ['name'=>'test']
* @var array
*/
protected $vague = [];
/**
* 精准查询,精确字段,格式['language_id'=> 1]
* @var array
*/
protected $focus = [];
/**
* 排序字段。格式 ['sort'=>'desc']
* @var array
*/
protected $sort = [];
/**
* 模型
* @var array
*/
protected $model = null;
/**
* 语言ID
* @var int|mixed
*/
protected $languageId = 1;
/**
* 导航栏模型
* @var null
*/
protected $navModel = null;
/**
* 系统配置模型
* @var null
*/
protected $systemConfigModel = null;
/**
* 接口监控数据
* @var string[]
*/
protected $apiLog = [
'items' => '', /*项目名称*/
'forum' => '', /*模块*/
'forum_code' => '', /*模块日志编码*/
'url' => '', /*访问页*/
'refer' => '', /*访问来源*/
'click' => '', /*点击次数*/
'content' => '', /*访问内容*/
'ip' => '', /*访客IP*/
'country' => '', /*国家*/
'province' => '', /*省*/
'city' => '', /*市*/
'start_time' => '', /*点击时间*/
'drive' => '', /*PC OR 移动端*/
'system' => '', /*设备系统*/
'brower' => '', /*浏览器*/
'models' => '', /*设备型号*/
'date_time' => '' /*生成时间*/
];
/**
* 判断请求来源是否是手机设备
* @return bool
*/
private function isMobile() : bool
{
//如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if (isset($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], 'wap')) {
return true;
}
//野蛮方法,判断手机发送的客户端标志,兼容性有待提高
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientKeywords = ['nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile'];
//从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(".implode('|', $clientKeywords).")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
//协议法,因为有可能不准确,放到最后判断
if (isset($_SERVER['HTTP_ACCEPT'])) {
//如果只支持wml并且不支持html那一定是移动设备
//如果支持wml和html但是wml在html之前则是移动设备
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
/**
* 初始化
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function initialize()
{
$controller = $this->request->controller();
$this->languageId = $this->request->language_id??1;
//通过中间件过来的语言包,动态设置
Lang::setLangSet($this->request->language_code??'zh-cn');
//重新加载动态设置的语言包
$this->app->loadLangPack(Lang::getLangSet());
// 初始化公共模型
$this->navModel = new Navigator();
$this->systemConfigModel = new SystemConfig();
// 初始化公共页面,判断语言包
// 导航
$navInfo = $this->navModel->getNavInfo($this->languageId,$this->platformId,$controller);
$navInfo = recursion_func($navInfo);
$footerNavInfo = $this->navModel->getFootNavInfo($this->languageId,$this->platformId);
$footerNavInfo = recursion_func($footerNavInfo);
// 头部版本号
// 静态版本号
$version = Env::get('front.version');
// 尾部数据
$footerInfo = $this->systemConfigModel->getFooterInfo($this->languageId);
// 首页多网站切换
$multiLanguage = $this->systemConfigModel->getWebSiteInfo($this->languageId);
// 其他公共数据
// 增加标签显示
$metaTitle = $this->systemConfigModel->getMetaTitle($this->languageId,'common');
View::assign('meta',$metaTitle);
View::assign('nav_info',$navInfo);
View::assign('nav_footer_info',$footerNavInfo);
View::assign('footer_info',$footerInfo);
View::assign('multi_lang',$multiLanguage);
View::assign('ver',$version);
View::assign('is_dev',Env::get('APP_DEBUG'));
View::assign('is_mobile',$this->isMobile());
}
/**
* 访问日志监控,提交kafka生产者接口
* @return \think\response\Json
* @throws \GeoIp2\Exception\AddressNotFoundException
* @throws \MaxMind\Db\Reader\InvalidDatabaseException
*/
public function submitActionLog()
{
$inputData = $this->request->param();
$model = explode('//',$inputData['url']);
$model = explode('/',$model[1]);
$this->apiLog['items'] = Env::get('platform_name','官网');
$this->apiLog['forum'] = count($model) > 1 && $model[1] != '' ? $model[1] : 'index';
$this->apiLog['forum_code'] = 200;
$this->apiLog['url'] = $inputData['url'];
$this->apiLog['refer'] = $inputData['url'];
$this->apiLog['content'] = $inputData['content'];
$this->apiLog['click'] = $inputData['click'];
$this->apiLog['start_time'] = date('Y-m-d H:i:s',(int)ceil(($inputData['date_time'] - (int)ceil((int)$inputData['start_time'])) / 1000) );
$this->apiLog['date_time'] = date('Y-m-d H:i:s',(int)ceil($inputData['date_time'] / 1000) );
//获取应用启动时间
//获取访问设备,系统版本,浏览器,设备型号
$userAgent = $inputData['drive'];
AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE);
$dd = new DeviceDetector($userAgent);
$dd->parse();
if ($dd->isBot()) {
$this->apiLog['brower'] = '未知';
$this->apiLog['system'] = '未知';
$this->apiLog['drive'] = '未知';
$this->apiLog['models'] = '爬虫';
} else {
$clientInfo = $dd->getClient();
$osInfo = $dd->getOs();
$device = $dd->getDeviceName();
$brand = $dd->getBrandName();
$model = $dd->getModel();
$this->apiLog['brower'] = !empty($clientInfo) ? $clientInfo['name'].' '.$clientInfo['version'] : '未知';
$this->apiLog['system'] = !empty($osInfo) ? $osInfo['name'].' '.$osInfo['version'] : '未知';
$this->apiLog['models'] = $device . " " . $brand . " ". $model;
$this->apiLog['drive'] = $device;
}
//解析IP地址,得到国家,城市,地址,
$this->apiLog['ip'] = $inputData['ip'];
if (!filter_var($inputData['ip'],FILTER_VALIDATE_IP,FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_NULL_ON_FAILURE)) {
$this->apiLog['country'] = '本地';
$this->apiLog['province'] = '本地';
$this->apiLog['city'] = '本地';
} else {
$readerCity = new Reader(public_path() . 'GeoLite2-City.mmdb');
$record = $readerCity->city($inputData['ip']);
$country = $record->country->names['zh-CN'];
$province = $record->subdivisions[0]->names['zh-CN']??'';
$city = $record->city->names['zh-CN']??$record->city->names['en'];
$china = ['香港','澳门','台湾'];
if (in_array($country,$china)) {
$province = $city = $country;
$country = '中国';
}
$this->apiLog['country'] = $country;
$this->apiLog['province'] = $province;
$this->apiLog['city'] = $city;
}
// Cache::set('this-api-log',$this->apiLog);
// 返回信息前,写入kafka log日志
$result = $this->sendLogsToKafkaProduce($this->apiLog,'action_logs',Env::get('database.database'),'add');
return $result ? json('提交成功') : json('提交失败',504);
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
/**
* 联系我们
*/
class Contact extends Base
{
public function initialize()
{
parent::initialize();
$this->model = new \app\index\model\About();
}
/**
* 显示资源列表
*
*/
public function index()
{
$inputData = $this->request->param();
$resource = [];
// $resource['banner'] = $this->model->getAboutBanner($this->languageId,'关于我们页面-banner');
// $resource['banner_mobile'] = $this->model->getAboutBanner($this->languageId,'关于我们页面-手机-banner');
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'contact');
View::assign('meta',$metaTitle);
View::assign('resource',$resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'contact/contact');
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace app\index\controller;
use app\index\model\SoftManual as SoftManualModel;
use app\index\validate\SoftManual as SoftManualValidate;
use think\facade\Lang;
use think\facade\View;
/**
* Class Download
* @package app\index\controller
*/
class Download extends Base
{
public function initialize()
{
parent::initialize();
$this->model = new SoftManualModel();
}
public function index()
{
$resource = [];
$inputData = $this->request->param();
$resource['type'] = $this->model->getDownloadType();
if (isset($inputData['keyword']) && $inputData['keyword'] != '') {
$this->vague['name'] = ($inputData['keyword']);
}
// $this->request->pathinfo()
if (isset($inputData['file_type_id']) && $inputData['file_type_id'] != '' && $inputData['file_type_id'] != 0) {
$this->focus['file_type_id'] = $inputData['file_type_id'];
}
$this->sort['sort'] = 'desc';
$this->focus['status'] = "0";
$result = $this->model->getAllList($inputData,$this->vague,$this->focus,$this->sort);
// dump($result);
//构建数据
if ((isset($result['page']) && !empty($result['page'])) && !empty($result)) {
$resource['list'] = $result;
} else {
if (isset($inputData['keyword']) && $inputData['keyword'] != '') {
$this->vague['introduce'] = ($inputData['keyword']);
}
$result = $this->model->getAllList($inputData,$this->vague,$this->focus,$this->sort);
$resource['list'] = $result;
}
// dump($this->model->getLastSql());
// dump($resource);
// $resource['page'] = $result->render();
// $resource['list'] = $result->toArray();
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'download');
View::assign('meta',$metaTitle);
View::assign('resource',$resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'download/download');
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
class Goods extends Base
{
public function initialize()
{
parent::initialize();
$this->model = new \app\index\model\Goods();
}
/**
* 显示资源列表
*/
public function index()
{
$inputData = $this->request->param();
$resource = [];
$query = [];
if (isset($inputData['model_number']) && $inputData['model_number'] != '') {
$query['model_number'] = $inputData['model_number'];
}
//分类
$resource['category'] = $this->model->getFirstLeveCategory($inputData);
$resource['checked1'] = 0;
$resource['url'] = explode('.html', $this->request->query())[0];
if (isset($inputData['cate1']) && $inputData['cate1'] != '') {
$categoryTwo = $this->model->getSecondLevelCategory($inputData);
$resource['category_two'] = $categoryTwo;
$resource['checked2'] = $inputData['cate2']??0;
}
if (isset($inputData['cate2']) && $inputData['cate2'] != '') {
$categoryThree = $this->model->getThreeLevelCategory($inputData);
$resource['category_three'] = $categoryThree;
$resource['checked3'] = $inputData['cate3']??0;
}
$forth = [
'is_all','is_recommend','is_hot','is_new'
];
//
$url = 'index/goods/index?';
for ($i=1;$i<=3;$i++) {
$cate = 'cate'.$i;
if (isset($inputData[$cate]) && $inputData[$cate] != '') {
$url .= http_build_query([$cate =>$inputData[$cate]])."&";
$resource['checked'.$i] = $inputData[$cate];
$resource['url'.$i] = rtrim($url, '&');
$query['cate'.$i] = $inputData[$cate];
}
$resource['url'] = rtrim($url, '&');
}
$resource['checked4'] = '';
foreach ($forth as $fort) {
if (isset($inputData[$fort]) && $inputData[$fort] != '') {
if ($inputData[$fort] == 1) {
$resource['checked4'] = $fort;
$query[$fort] = $inputData[$fort];
}
}
}
// 查询对应的
$goodsPaginate = $this->model->getGoodsList($query, $resource['url']);
//dump($goodsPaginate);
$resource['page'] = $goodsPaginate->render();
$resource['list'] = $goodsPaginate->toArray();
// dump($this->model->getLastSql());
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'goods_list');
View::assign('meta',$metaTitle);
View::assign('resource', $resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'goods/list');
}
/**
* 显示资源列表
*/
public function detail()
{
$inputData = $this->request->param();
$resource = [];
if (isset($inputData['id']) && $inputData['id'] > 0) {
$resource['bread'] = $this->model->getCategoryToParent($inputData['id']);
// dump($resource);
$goodsInfo = $this->model->getInfo($inputData);
$goodsInfo['details'] = htmlspecialchars_decode($goodsInfo['details']);
// dump($goodsInfo);
if (empty($goodsInfo) || $goodsInfo['status'] == 1) {
View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'goods/404');
}
}
$resource['goodsInfo'] = $goodsInfo;
// dump($goodsInfo);
View::assign('resource', $resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'goods/detail');
}
}

View File

@@ -0,0 +1,53 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
use app\index\model\Index as IndexModel;
/**
* 首页控制器
*/
class Index extends Base
{
public function initialize()
{
$this->model = new IndexModel();
parent::initialize();
}
/**
* @return string
*/
public function index():string
{
$inputData = $this->request->param();
// banner
$bannerList = $this->model->getIndexBanner($this->languageId,$inputData);
// 商品banner
$goodsBanner = $this->model->getGoodsBanner($this->languageId,$inputData);
// 获取推荐商品
$bannerListMobile = $this->model->getIndexBannerMobile($this->languageId,$inputData);
// 商品分类
$goodsCategoryList = $this->model->getIndexGoodsCategoryList($this->languageId,$inputData);
// 推荐商品
$goodsCommandList = $this->model->getIndexGoodsRecommandList($this->languageId,$inputData);
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'index');
// 首页4张图
$forthImg = $this->model->getGoodsBanner($this->languageId);
View::assign('meta',$metaTitle);
View::assign('f_image',$forthImg);
View::assign('banner_list',$bannerList);
View::assign('banner_list_mobile',$bannerListMobile);
View::assign('goods_category',$goodsCategoryList);
View::assign('goods_is_new',$goodsCommandList);
View::assign('goods_banner',$goodsBanner);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'index/index');
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
use app\index\model\Join as JoinModel;
/**
* 加入我们
*/
class Join extends Base
{
public function initialize()
{
$this->model = new JoinModel();
parent::initialize();
}
/**
* 显示资源列表
*/
public function index():string
{
$inputData = $this->request->param();
$join = [];
$join['banner'] = $this->model->getJoinBanner($this->languageId,'加入我们-banner');
$join['list'] = $this->model->getJoinList($this->languageId,$inputData);
$join['type'] = $this->model->getJoinTypeList($this->languageId,$inputData);
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'join');
View::assign('meta',$metaTitle);
View::assign('join',$join);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'join/join_us');
}
/**
* 显示详情资源列表
*/
public function detail():string
{
$inputData = $this->request->param();
//banner
$join = $this->model->getInfo($inputData);
View::assign('join',$join);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'join/join_detail');
}
/**
* 更多列表页
*/
public function list():string
{
$inputData = $this->request->param();
$where = [
'site_id' => $this->languageId,
'status' => 0,
];
if (isset($inputData['join_type_id']) && $inputData['join_type_id'] != 0) {
$where['join_type_id'] = $inputData['join_type_id'];
}
$listRow = [
'query' => ['join_type_id'=>$inputData['join_type_id']], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'list_rows' => $inputData['size']??4, //每页数量
];
$result = $this->model->where($where)->paginate($listRow);
View::assign('join',$result->render());
View::assign('list',$result->toArray());
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'join/join_list');
}
}

View File

@@ -0,0 +1,62 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
use app\index\model\News as NewsModel;
/**
* 新闻动态
*/
class News extends Base
{
public function initialize()
{
$this->model = new NewsModel();
parent::initialize();
}
/**
* 显示资源列表
*/
public function index()
{
$inputData = $this->request->param();
$news = [];
$news['banner_list'] = $this->model->getNewsBanner($this->languageId,'新闻列表页面-banner');
$news['banner_list_mobile'] = $this->model->getNewsBanner($this->languageId,'新闻列表页面-手机-banner');
$newsPaginate = $this->model->getNewsList($this->languageId,$inputData);
$news['page'] = $newsPaginate->render();
$news['list'] = $newsPaginate->toArray();
$news['type'] = $this->model->getNewsTypeList($this->languageId,$inputData);
if (!empty($news['list']['data'])) {
foreach ($news['list']['data'] as $key => $item) {
$news['list']['data'][$key]['create_time'] = date('Y年m月d日',strtotime($item['create_time']));
}
}
View::assign('news',$news);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'news/news');
}
/**
* 显示资源列表
*/
public function detail()
{
$inputData = $this->request->param();
//banner
$news = $this->model->getInfo($inputData);
$news['banner_detail'] = $this->model->getNewsBanner($this->languageId,'新闻详情页面-banner');
$news['banner_detail_mobile'] = $this->model->getNewsBanner($this->languageId,'新闻详情页面-手机-banner');
$news['create_time'] = date('Y年m月d日',strtotime($news['create_time']));
// 获取上一篇下一篇
$news['extra'] = $this->model->getPreNexInfo($inputData);
View::assign('news',$news);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'news/news_detail');
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
/**
* 关于我们
*/
class Test extends Base
{
public function initialize()
{
parent::initialize();
$this->model = new \app\index\model\Test();
}
/**
* 显示资源列表
*
*/
public function index()
{
$inputData = $this->request->param();
$resource = [];
// $resource['banner'] = $this->model->getAboutBanner($this->languageId,'关于我们页面-banner');
// $resource['banner_mobile'] = $this->model->getAboutBanner($this->languageId,'关于我们页面-手机-banner');
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'about');
View::assign('meta',$metaTitle);
View::assign('resource',$resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'about/test');
}
}