初始化项目:添加后端代码、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
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use think\Lang;
use think\Response;
/**
* Ajax异步请求接口
* @internal
*/
class Ajax extends Frontend
{
protected $noNeedLogin = ['lang', 'upload'];
protected $noNeedRight = ['*'];
protected $layout = '';
/**
* 加载语言包
*/
public function lang()
{
$this->request->get(['callback' => 'define']);
$header = ['Content-Type' => 'application/javascript'];
if (!config('app_debug')) {
$offset = 30 * 60 * 60 * 24; // 缓存一个月
$header['Cache-Control'] = 'public';
$header['Pragma'] = 'cache';
$header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
}
$controllername = input("controllername");
$this->loadlang($controllername);
//强制输出JSON Object
return jsonp(Lang::get(), 200, $header, ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
}
/**
* 生成后缀图标
*/
public function icon()
{
$suffix = $this->request->request("suffix");
$suffix = $suffix ? $suffix : "FILE";
$data = build_suffix_image($suffix);
$header = ['Content-Type' => 'image/svg+xml'];
$offset = 30 * 60 * 60 * 24; // 缓存一个月
$header['Cache-Control'] = 'public';
$header['Pragma'] = 'cache';
$header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
$response = Response::create($data, '', 200, $header);
return $response;
}
/**
* 上传文件
*/
public function upload()
{
return action('api/common/upload');
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\common\model\order\Order;
class Alipay extends Frontend
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
protected $layout = '';
/**
* 支付宝支付页面
* @return void
*/
public function pay()
{
$orderNo = $this->request->param('order_no', '');
if (empty($orderNo)) {
return $this->errorPage('订单号不能为空');
}
$order = Order::where('order_no', $orderNo)->find();
if (!$order) {
return $this->errorPage('订单不存在');
}
if ($order->status != \app\common\constant\order\Status::STATUS_UNPAID) {
return $this->errorPage('当前订单状态不支持付款');
}
try {
$alipayConfig = \app\common\model\config\System::getConfig('alipay');
if (!$alipayConfig || empty($alipayConfig['app_id'])) {
return $this->errorPage('支付宝支付未配置');
}
$notify_url = MODULE_URL . '/api/pay/notifyx/pay_type/alipay/platform/url/open_id//uniacid/' . UNIACID;
$userAgent = strtolower($this->request->server('HTTP_USER_AGENT', ''));
$isMobile = preg_match('/(mobile|android|iphone|ipad|ipod|windows phone)/i', $userAgent);
$platform = $isMobile ? 'url' : 'pc';
$pay = new \app\common\library\pay\PayService('alipay', $platform, $notify_url);
$domain = $this->request->domain();
$uniacid = UNIACID;
$order_data = [
'out_trade_no' => $order->order_no,
'total_amount' => $order->real_price,
'subject' => '商城订单支付',
'return_url' => $domain . '/index/alipay/return?order_no=' . $orderNo . '&i=' . $uniacid,
];
if ($isMobile) {
$order_data['quit_url'] = $domain . '/index.php?route=index&i=' . $uniacid;
}
$result = $pay->create($order_data);
$html = $result->getContent();
$pay_url = $this->request->root(true) . '/index/alipay/pay?order_no=' . $orderNo;
$this->view->assign('form', $html);
$this->view->assign('pay_url', $pay_url);
return $this->view->fetch();
} catch (\Exception $e) {
return $this->errorPage('支付创建失败:' . $e->getMessage());
}
}
/**
* 支付宝支付返回
* @return void
*/
public function return()
{
$orderNo = $this->request->param('order_no', '');
$uniacid = $this->request->param('i', UNIACID);
$domain = $this->request->domain();
if (!empty($orderNo)) {
$this->redirect($domain . '/index.php?route=index&i=' . $uniacid . '#/pages/order/detail/detail?order_no=' . $orderNo);
} else {
$this->redirect($domain . '/index.php?route=index&i=' . $uniacid);
}
}
/**
* 错误页面
* @param string $msg 错误信息
* @return mixed
*/
protected function errorPage($msg)
{
$this->view->assign('msg', $msg);
return $this->view->fetch('error_page');
}
}
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
class Index extends Frontend
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
protected $layout = '';
public function index()
{
$config = \app\common\model\config\System::getConfig('system');
if(isset($config['mobile_pc_route']) && $config['mobile_pc_route'] == 'open'){
//判断当前是PC还是移动端
if(!isMobile()){
//thinkphp5重定向
$this->redirect(request()->domain().'/index.php?i='.UNIACID.'&route=pc#/page/index');
exit;
}
}
if($config['status'] == 'close'){
return $this->errorPage('店铺暂不可用,请稍后再试');
}
if(isWeixin()){
$wxOfficialAccountConfig = \app\common\model\config\System::getConfig('wxOfficialAccount');
if(isset($wxOfficialAccountConfig['status']) && $wxOfficialAccountConfig['status'] != 'open'){
return $this->errorPage('该终端暂不可用');
}
}else{
$h5Config = \app\common\model\config\System::getConfig('H5');
if(isset($h5Config['status']) && $h5Config['status'] != 'open'){
return $this->errorPage('该终端暂不可用');
}
}
$this->view->assign('config',$this->getPageConfig());
return $this->view->fetch();
}
/**
* 获取配置
* @return false|string
*/
public function getPageConfig(){
global $_W,$_GPC;
if(\app\common\library\Platform::getSystemType() == 'single'){
$data['apiUrl'] = $_W['siteroot'].'/index.php?i='.$_W['uniacid'].'&route=api/';
}else{
$data['apiUrl'] = $_W['siteroot'].'/app/index.php?i='.$_W['uniacid'].'&c=entry&m=tuzi_v1&do=index&route=api/';
}
return json_encode($data);
}
/**
* 错误页面
* @param $message
* @return mixed
*/
public function errorPage($message){
$this->view->assign('message',$message);
return $this->view->fetch('error_page');
}
public function exportConfig(){
(new \app\common\model\fill\Handle())->export('config_system');
}
}
+337
View File
@@ -0,0 +1,337 @@
<?php
namespace app\index\controller;
use addons\wechat\model\WechatCaptcha;
use app\common\controller\Frontend;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\Attachment;
use think\Config;
use think\Cookie;
use think\Hook;
use think\Session;
use think\Validate;
/**
* 会员中心
*/
class User extends Frontend
{
protected $layout = 'default';
protected $noNeedLogin = ['login', 'register', 'third'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$auth = $this->auth;
if (!Config::get('fastadmin.usercenter')) {
$this->error(__('User center already closed'), '/');
}
//监听注册登录退出的事件
Hook::add('user_login_successed', function ($user) use ($auth) {
$expire = input('post.keeplogin') ? 30 * 86400 : 0;
Cookie::set('uid', $user->id, $expire);
Cookie::set('token', $auth->getToken(), $expire);
});
Hook::add('user_register_successed', function ($user) use ($auth) {
Cookie::set('uid', $user->id);
Cookie::set('token', $auth->getToken());
});
Hook::add('user_delete_successed', function ($user) use ($auth) {
Cookie::delete('uid');
Cookie::delete('token');
});
Hook::add('user_logout_successed', function ($user) use ($auth) {
Cookie::delete('uid');
Cookie::delete('token');
});
}
/**
* 会员中心
*/
public function index()
{
$this->view->assign('title', __('User center'));
return $this->view->fetch();
}
/**
* 注册会员
*/
public function register()
{
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'), $url ? $url : url('user/index'));
}
if ($this->request->isPost()) {
$username = $this->request->post('username');
$password = $this->request->post('password');
$email = $this->request->post('email');
$mobile = $this->request->post('mobile', '');
$captcha = $this->request->post('captcha');
$token = $this->request->post('__token__');
$rule = [
'username' => 'require|length:3,30',
'password' => 'require|length:6,30',
'email' => 'require|email',
'mobile' => 'regex:/^1\d{10}$/',
'__token__' => 'require|token',
];
$msg = [
'username.require' => 'Username can not be empty',
'username.length' => 'Username must be 3 to 30 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
'email' => 'Email is incorrect',
'mobile' => 'Mobile is incorrect',
];
$data = [
'username' => $username,
'password' => $password,
'email' => $email,
'mobile' => $mobile,
'__token__' => $token,
];
//验证码
$captchaResult = true;
$captchaType = config("fastadmin.user_register_captcha");
if ($captchaType) {
if ($captchaType == 'mobile') {
$captchaResult = Sms::check($mobile, $captcha, 'register');
} elseif ($captchaType == 'email') {
$captchaResult = Ems::check($email, $captcha, 'register');
} elseif ($captchaType == 'wechat') {
$captchaResult = WechatCaptcha::check($captcha, 'register');
} elseif ($captchaType == 'text') {
$captchaResult = \think\Validate::is($captcha, 'captcha');
}
}
if (!$captchaResult) {
$this->error(__('Captcha is incorrect'));
}
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
if ($this->auth->register($username, $password, $email, $mobile)) {
$this->success(__('Sign up successful'), $url ? $url : url('user/index'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('captchaType', config('fastadmin.user_register_captcha'));
$this->view->assign('url', $url);
$this->view->assign('title', __('Register'));
return $this->view->fetch();
}
/**
* 会员登录
*/
public function login()
{
$url = $this->request->request('url', '', 'trim');
if ($this->auth->id) {
$this->success(__('You\'ve logged in, do not login again'), $url ? $url : url('user/index'));
}
if ($this->request->isPost()) {
$account = $this->request->post('account');
$password = $this->request->post('password');
$keeplogin = (int)$this->request->post('keeplogin');
$token = $this->request->post('__token__');
$rule = [
'account' => 'require|length:3,50',
'password' => 'require|length:6,30',
'__token__' => 'require|token',
];
$msg = [
'account.require' => 'Account can not be empty',
'account.length' => 'Account must be 3 to 50 characters',
'password.require' => 'Password can not be empty',
'password.length' => 'Password must be 6 to 30 characters',
];
$data = [
'account' => $account,
'password' => $password,
'__token__' => $token,
];
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
return false;
}
if ($this->auth->login($account, $password)) {
$this->success(__('Logged in successful'), $url ? $url : url('user/index'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
//判断来源
$referer = $this->request->server('HTTP_REFERER');
if (!$url && (strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
&& !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
$url = $referer;
}
$this->view->assign('url', $url);
$this->view->assign('title', __('Login'));
return $this->view->fetch();
}
/**
* 退出登录
*/
public function logout()
{
if ($this->request->isPost()) {
$this->token();
//退出本站
$this->auth->logout();
$this->success(__('Logout successful'), url('user/index'));
}
$html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>";
$html .= "<script>document.forms['logout_submit'].submit();</script>";
return $html;
}
/**
* 个人信息
*/
public function profile()
{
$this->view->assign('title', __('Profile'));
return $this->view->fetch();
}
/**
* 修改密码
*/
public function changepwd()
{
if ($this->request->isPost()) {
$oldpassword = $this->request->post("oldpassword");
$newpassword = $this->request->post("newpassword");
$renewpassword = $this->request->post("renewpassword");
$token = $this->request->post('__token__');
$rule = [
'oldpassword' => 'require|regex:\S{6,30}',
'newpassword' => 'require|regex:\S{6,30}',
'renewpassword' => 'require|regex:\S{6,30}|confirm:newpassword',
'__token__' => 'token',
];
$msg = [
'renewpassword.confirm' => __('Password and confirm password don\'t match')
];
$data = [
'oldpassword' => $oldpassword,
'newpassword' => $newpassword,
'renewpassword' => $renewpassword,
'__token__' => $token,
];
$field = [
'oldpassword' => __('Old password'),
'newpassword' => __('New password'),
'renewpassword' => __('Renew password')
];
$validate = new Validate($rule, $msg, $field);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
return false;
}
$ret = $this->auth->changepwd($newpassword, $oldpassword);
if ($ret) {
$this->success(__('Reset password successful'), url('user/login'));
} else {
$this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
}
}
$this->view->assign('title', __('Change password'));
return $this->view->fetch();
}
public function attachment()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
$mimetypeQuery = [];
$where = [];
$filter = $this->request->request('filter');
$filterArr = (array)json_decode($filter, true);
if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) {
$this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['mimetype' => '']))]);
$mimetypeQuery = function ($query) use ($filterArr) {
$mimetypeArr = array_filter(explode(',', $filterArr['mimetype']));
foreach ($mimetypeArr as $index => $item) {
$query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%');
}
};
} elseif (isset($filterArr['mimetype'])) {
$where['mimetype'] = ['like', '%' . $filterArr['mimetype'] . '%'];
}
if (isset($filterArr['filename'])) {
$where['filename'] = ['like', '%' . $filterArr['filename'] . '%'];
}
if (isset($filterArr['createtime'])) {
$timeArr = explode(' - ', $filterArr['createtime']);
$where['createtime'] = ['between', [strtotime($timeArr[0]), strtotime($timeArr[1])]];
}
$search = $this->request->get('search');
if ($search) {
$where['filename'] = ['like', '%' . $search . '%'];
}
$model = new Attachment();
$offset = $this->request->get("offset", 0);
$limit = $this->request->get("limit", 0);
$total = $model
->where($where)
->where($mimetypeQuery)
->where('user_id', $this->auth->id)
->order("id", "DESC")
->count();
$list = $model
->where($where)
->where($mimetypeQuery)
->where('user_id', $this->auth->id)
->order("id", "DESC")
->limit($offset, $limit)
->select();
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
foreach ($list as $k => &$v) {
$v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
}
unset($v);
$result = array("total" => $total, "rows" => $list);
return json($result);
}
$mimetype = $this->request->get('mimetype', '');
$mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype;
$this->view->assign('mimetype', $mimetype);
$this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
return $this->view->fetch();
}
}