初始化项目:添加后端代码、ThinkPHP框架、前端资源

This commit is contained in:
amb
2026-09-03 12:42:39 +08:00
commit 482bece22e
3726 changed files with 416708 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace app\api\controller\data;
use app\common\controller\Api;
use app\admin\model\data\Area as AreaModel;
/**
* 省市区数据控制器
*/
class Area extends Api
{
protected $noNeedLogin = ['index'];
protected $noNeedRight = ['*'];
/**
* 获取省市区树形数据
* @return void
*/
public function index()
{
$list = AreaModel::where('pid', 0)
->order('id', 'asc')
->field('id, pid, level, name')
->with(['children' => function ($query) {
return $query->field('id, pid, level, name')->with(['children' => function ($query) {
return $query->field('id, pid, level, name');
}]);
}])
->select();
$this->success('获取成功', $list);
}
/**
* 获取下级地区
* @return void
*/
public function children()
{
$pid = $this->request->param('pid', 0);
$list = AreaModel::where('pid', $pid)
->order('id', 'asc')
->field('id, pid, level, name')
->select();
$this->success('获取成功', $list);
}
/**
* 根据名称搜索地区
* @return void
*/
public function search()
{
$keyword = $this->request->param('keyword');
if (empty($keyword)) {
$this->error('请输入搜索关键词');
}
$list = AreaModel::whereLike('name', '%' . $keyword . '%')
->order('id', 'asc')
->field('id, pid, level, name')
->limit(20)
->select();
$this->success('获取成功', $list);
}
}
@@ -0,0 +1,38 @@
<?php
namespace app\api\controller\data;
use app\common\controller\Api;
use app\api\model\data\Express as ExpressModel;
/**
* 快递公司接口
*/
class Express extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new ExpressModel;
}
/**
* 获取快递公司列表
*/
public function index()
{
$list = $this->model
->order('weigh', 'asc')
->order('id', 'asc')
->select();
$result = array("total" => count($list), "rows" => $list->toArray());
return $this->success("获取成功", $result);
}
}
+147
View File
@@ -0,0 +1,147 @@
<?php
namespace app\api\controller\data;
use app\common\controller\Api;
use Jenssegers\Agent\Agent;
use think\Cache;
/**
* 商品列表
* 区别于课程列表,这里展示的是处理课程外的所有商品,如会员卡、活动
*/
class Record extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
}
public function log(){
$url = input('url');
if(!$url){
$this->success("1");
}
// 过滤掉登录页和外部浏览器页面的记录
if(strpos($url, "login") !== false || strpos($url, "****") !== false){
$this->success("1");
}
$pageInfo = $this->getPageInfo($url);
$agent = new Agent();
$data = [
'uniacid' => UNIACID,
'ip' => $_SERVER['REMOTE_ADDR'],
'url' => $url,
'user_id' => 0,
'platform' => \app\common\library\Platform::getPlatform(),
'is_desktop' => $agent->isDesktop() ? 1 : 0,
'is_mobile' => $agent->isMobile() ? 1 : 0,
'browser' => $agent->browser(),
'is_android' => $agent->isAndroidOS() ? 1 : 0,
'is_ios' => $agent->isIOS() ? 1 : 0,
'device' => $agent->device(),
'page_type' => $pageInfo['type'],
'page_id' => $pageInfo['id'],
'createtime' => time()
];
if($this->auth->isLogin()){
$data['user_id'] = $this->auth->id;
}
try{
$cacheKey = \app\common\constant\cache\Keys::RECORD_LOG;
// 从缓存中获取当前队列
$queue = Cache::get($cacheKey) ?: [];
// 将新日志数据加入队列(从数组尾部添加)
$queue[] = $data;
// 将更新后的队列写回缓存
Cache::set($cacheKey, $queue);
}catch (\Exception $e){
}
$this->success("1");
}
/**
* 获取页面信息
* @param $url
* @return array
*/
public function getPageInfo($url){
$urlInfo = $this->parseUrl($url);
$data = [
'type'=>'other',
'id'=>0
];
if(!isset($urlInfo['url'])){
return $data;
}
switch ($urlInfo['url']){
case 'pages/app/exam/detail/detail':
$data['type'] = 'exercise';
break;
case 'pages/app/activity/detail/detail':
$data['type'] = 'activity';
break;
case 'pages/course/live/live':
case 'pages/course/detail/detail':
$data['type'] = 'course';
break;
case 'pages/app/vip/center/center':
$data['type'] = 'vipcard';
break;
}
if(isset($urlInfo['params']['id'])){
$data['id'] = $urlInfo['params']['id'];
}
return $data;
}
/**
* 解析路由
* @return void
*/
public function parseUrl($url){
// 删除URL前的'/'或'#/'前缀
$url = preg_replace('/^\/?#?\//', '', $url);
// 解析URL
$parts = parse_url($url);
// 提取路径部分
$result = [];
if (isset($parts['path'])) {
$result['url'] = $parts['path'];
}
// 解析查询字符串
$params = [];
if (isset($parts['query'])) {
parse_str($parts['query'], $params);
}
// 将参数数组添加到结果中
$result['params'] = $params;
return $result;
}
}