Fanli2
4 years ago
191 changed files with 5925 additions and 7569 deletions
-
2.env.example
-
27.gitignore
-
4API文档.html
-
4README.md
-
2README.txt
-
24app/Common/function.php
-
36app/Console/Commands/SendEmail.php
-
38app/Console/Commands/UnpayOrderSetInvalid.php
-
20app/Console/Kernel.php
-
8app/Events/Event.php
-
25app/Events/OrderShipped.php
-
4app/Http/Controllers/Admin/AdminController.php
-
2app/Http/Controllers/Admin/AdminRoleController.php
-
366app/Http/Controllers/Admin/ArticleController.php
-
90app/Http/Controllers/Admin/BaseController.php
-
2app/Http/Controllers/Admin/BonusController.php
-
2app/Http/Controllers/Admin/CategoryController.php
-
110app/Http/Controllers/Admin/CommonController.php
-
2app/Http/Controllers/Admin/FeedbackController.php
-
2app/Http/Controllers/Admin/FriendlinkController.php
-
3app/Http/Controllers/Admin/GoodsBrandController.php
-
7app/Http/Controllers/Admin/GoodsController.php
-
3app/Http/Controllers/Admin/GoodstypeController.php
-
3app/Http/Controllers/Admin/GuestbookController.php
-
6app/Http/Controllers/Admin/IndexController.php
-
3app/Http/Controllers/Admin/KeywordController.php
-
2app/Http/Controllers/Admin/KuaidiController.php
-
117app/Http/Controllers/Admin/LogController.php
-
25app/Http/Controllers/Admin/LoginController.php
-
2app/Http/Controllers/Admin/MenuController.php
-
2app/Http/Controllers/Admin/OrderController.php
-
2app/Http/Controllers/Admin/PageController.php
-
2app/Http/Controllers/Admin/SearchController.php
-
2app/Http/Controllers/Admin/SearchwordController.php
-
2app/Http/Controllers/Admin/SlideController.php
-
2app/Http/Controllers/Admin/SysconfigController.php
-
2app/Http/Controllers/Admin/TagController.php
-
2app/Http/Controllers/Admin/UserController.php
-
2app/Http/Controllers/Admin/UserRankController.php
-
2app/Http/Controllers/Admin/UserWithdrawController.php
-
2app/Http/Controllers/Admin/WeixinMenuController.php
-
2app/Http/Controllers/Api/ArctypeController.php
-
2app/Http/Controllers/Api/ArticleController.php
-
10app/Http/Controllers/Api/BaseController.php
-
2app/Http/Controllers/Api/BonusController.php
-
2app/Http/Controllers/Api/CartController.php
-
2app/Http/Controllers/Api/CollectGoodsController.php
-
2app/Http/Controllers/Api/CommentController.php
-
32app/Http/Controllers/Api/CommonController.php
-
2app/Http/Controllers/Api/FeedBackController.php
-
2app/Http/Controllers/Api/GoodsBrandController.php
-
2app/Http/Controllers/Api/GoodsController.php
-
2app/Http/Controllers/Api/GoodsSearchwordController.php
-
2app/Http/Controllers/Api/GoodsTypeController.php
-
2app/Http/Controllers/Api/ImageController.php
-
2app/Http/Controllers/Api/IndexController.php
-
2app/Http/Controllers/Api/NotifyController.php
-
2app/Http/Controllers/Api/OrderController.php
-
2app/Http/Controllers/Api/PageController.php
-
2app/Http/Controllers/Api/PaymentController.php
-
2app/Http/Controllers/Api/PaymentNotifyController.php
-
2app/Http/Controllers/Api/QrcodeController.php
-
2app/Http/Controllers/Api/RegionController.php
-
2app/Http/Controllers/Api/SlideController.php
-
2app/Http/Controllers/Api/UserAddressController.php
-
2app/Http/Controllers/Api/UserBonusController.php
-
2app/Http/Controllers/Api/UserController.php
-
2app/Http/Controllers/Api/UserGoodsHistoryController.php
-
2app/Http/Controllers/Api/UserMessageController.php
-
2app/Http/Controllers/Api/UserMoneyController.php
-
2app/Http/Controllers/Api/UserPointController.php
-
2app/Http/Controllers/Api/UserRechargeController.php
-
2app/Http/Controllers/Api/UserWithdrawController.php
-
2app/Http/Controllers/Api/VerifyCodeController.php
-
64app/Http/Controllers/Controller.php
-
114app/Http/Controllers/Home/ArticleController.php
-
11app/Http/Controllers/Home/BaseController.php
-
35app/Http/Controllers/Home/CommonController.php
-
107app/Http/Controllers/Home/GoodsController.php
-
544app/Http/Controllers/Home/IndexController.php
-
444app/Http/Controllers/Home/IndexController企业.php
-
43app/Http/Controllers/Home/PageController.php
-
526app/Http/Controllers/Home/SearchController.php
-
526app/Http/Controllers/Home/TagController.php
-
311app/Http/Controllers/Home/TestController.php
-
126app/Http/Controllers/Wap/ArticleController.php
-
11app/Http/Controllers/Wap/BaseController.php
-
33app/Http/Controllers/Wap/CommonController.php
-
108app/Http/Controllers/Wap/GoodsController.php
-
429app/Http/Controllers/Wap/IndexController.php
-
42app/Http/Controllers/Wap/PageController.php
-
79app/Http/Controllers/Weixin/AddressController.php
-
76app/Http/Controllers/Weixin/ArticleController.php
-
14app/Http/Controllers/Weixin/BaseController.php
-
2app/Http/Controllers/Weixin/BonusController.php
-
2app/Http/Controllers/Weixin/CartController.php
-
2app/Http/Controllers/Weixin/CollectGoodsController.php
-
66app/Http/Controllers/Weixin/CommonController.php
-
9app/Http/Controllers/Weixin/FeedbackController.php
-
27app/Http/Controllers/Weixin/GoodsBrandController.php
@ -1,15 +1,18 @@ |
|||
/node_modules |
|||
/public/hot |
|||
/public/storage |
|||
/storage |
|||
/vendor |
|||
/public/uploads |
|||
/.idea |
|||
/.vagrant |
|||
Homestead.json |
|||
Homestead.yaml |
|||
npm-debug.log |
|||
|
|||
public/uploads |
|||
.idea |
|||
.vagrant |
|||
.git |
|||
node_modules |
|||
.svn |
|||
build |
|||
.project |
|||
.settings |
|||
release |
|||
composer.lock |
|||
*.log |
|||
vendor |
|||
.vscode |
|||
.env |
|||
/.svn |
|||
/build |
|||
/.project |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
|
|||
class SendEmail extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'email:send {user}'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Send e-mail to a user'; |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
// 获取指定参数
|
|||
// $user_id = $this->argument('user');
|
|||
|
|||
// 获取指定选项
|
|||
// $user_id = $this->option('user');
|
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use DB; |
|||
use Log; |
|||
|
|||
class UnpayOrderSetInvalid extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'unpay_order_set_invalid'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = '订单24小时未支付,设为无效订单'; |
|||
|
|||
// 订单多久超时,单位:秒
|
|||
protected $timeout = 86400; |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
DB::table('order')->where([['order_status', '=', 0], ['is_delete', '=', 0], ['add_time', '<', (time() - $timeout)]])->update(['order_status' => 2]); |
|||
Log::info('订单24小时未支付,设为无效订单:操作成功'); |
|||
} |
|||
} |
@ -0,0 +1,8 @@ |
|||
<?php |
|||
|
|||
namespace App\Events; |
|||
|
|||
abstract class Event |
|||
{ |
|||
//
|
|||
} |
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
namespace App\Events; |
|||
|
|||
use App\Http\Model\Order; |
|||
use Illuminate\Queue\SerializesModels; |
|||
|
|||
class OrderShipped |
|||
{ |
|||
use SerializesModels; |
|||
|
|||
public $order_id; |
|||
|
|||
/** |
|||
* 创建一个新的事件实例 |
|||
* |
|||
* @param Order $order |
|||
* @return void |
|||
*/ |
|||
public function __construct($order_id) |
|||
{ |
|||
$this->order_id = $order_id; |
|||
\Log::info('----OrderShipped Event Init----'); |
|||
} |
|||
} |
@ -0,0 +1,90 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use DB; |
|||
|
|||
class BaseController extends CommonController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
//判断是否登录
|
|||
if (isset($_SESSION['admin_info'])) { |
|||
$this->admin_info = $_SESSION['admin_info']; |
|||
} else { |
|||
header("Location:" . route('page404')); |
|||
exit(); |
|||
} |
|||
|
|||
//判断是否拥有权限
|
|||
if ($_SESSION['admin_info']['role_id'] <> 1) { |
|||
$uncheck = array('admin_jump', 'admin', 'admin_index_upconfig', 'admin_index_upcache', 'admin_welcome'); |
|||
|
|||
if (in_array(\Route::currentRouteName(), $uncheck)) { |
|||
|
|||
} else { |
|||
$menu_id = DB::table('menu')->where('action', \Route::currentRouteName())->value('id'); |
|||
$check = DB::table('access')->where(['role_id' => $_SESSION['admin_info']['role_id'], 'menu_id' => $menu_id])->first(); |
|||
|
|||
if (!$check) { |
|||
error_jump('你没有权限访问,请联系管理员', route('admin')); |
|||
} |
|||
} |
|||
} |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* 获取分页数据及分页导航 |
|||
* @param string $modelname 模块名与数据库表名对应 |
|||
* @param array $where 查询条件 |
|||
* @param string $orderby 查询排序 |
|||
* @param string $field 要返回数据的字段 |
|||
* @param int $listRows 每页数量,默认30条 |
|||
* |
|||
* @return 格式化后输出的数据。内容格式为: |
|||
* - "code" (string):代码 |
|||
* - "info" (string):信息提示 |
|||
* |
|||
* - "result" array |
|||
* |
|||
* - "img_list" (array) :图片队列,默认8张 |
|||
* - "img_title" (string):车图名称 |
|||
* - "img_url" (string):车图片url地址 |
|||
* - "car_name" (string):车名称 |
|||
*/ |
|||
public function pageList($modelname, $where = '', $orderby = '', $field = '*', $listRows = 30) |
|||
{ |
|||
$model = \DB::table($modelname); |
|||
|
|||
//查询条件
|
|||
if (!empty($where)) { |
|||
$model = $model->where($where); |
|||
} |
|||
|
|||
//排序
|
|||
if ($orderby != '') { |
|||
if ($orderby == 'rand()') { |
|||
$model = $model->orderBy(\DB::raw('rand()')); |
|||
} else { |
|||
if (count($orderby) == count($orderby, 1)) { |
|||
$model = $model->orderBy($orderby[0], $orderby[1]); |
|||
} else { |
|||
foreach ($orderby as $row) { |
|||
$model = $model->orderBy($row[0], $row[1]); |
|||
} |
|||
} |
|||
} |
|||
} else { |
|||
$model = $model->orderBy('id', 'desc'); |
|||
} |
|||
|
|||
//要返回的字段
|
|||
if ($field != '*') { |
|||
$model = $model->select(\DB::raw($field)); |
|||
} |
|||
|
|||
return $model->paginate($listRows); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,117 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use DB; |
|||
use App\Common\Helper; |
|||
use App\Common\ReturnData; |
|||
use Illuminate\Http\Request; |
|||
use App\Http\Logic\LogLogic; |
|||
use App\Http\Model\Log; |
|||
|
|||
class LogController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
public function getLogic() |
|||
{ |
|||
return new LogLogic(); |
|||
} |
|||
|
|||
public function index(Request $request) |
|||
{ |
|||
$res = ''; |
|||
$where = function ($query) use ($res) { |
|||
if (!empty($_REQUEST["keyword"])) { |
|||
$query->where('login_name', 'like', '%' . $_REQUEST['keyword'] . '%')->orWhere('ip', 'like', '%' . $_REQUEST['keyword'] . '%')->orWhere('url', 'like', '%' . $_REQUEST['keyword'] . '%')->orWhere('content', 'like', '%' . $_REQUEST['keyword'] . '%'); |
|||
} |
|||
//用户ID
|
|||
if (isset($_REQUEST['login_id'])) { |
|||
$query->where('login_id', $_REQUEST["login_id"]); |
|||
} |
|||
//IP
|
|||
if (isset($_REQUEST['ip'])) { |
|||
$query->where('ip', $_REQUEST["ip"]); |
|||
} |
|||
//模块
|
|||
if (isset($_REQUEST['type']) && $_REQUEST['type'] !== '') { |
|||
$query->where('type', $_REQUEST["type"]); |
|||
} |
|||
//请求方式
|
|||
if (isset($_REQUEST['http_method'])) { |
|||
$query->where('http_method', $_REQUEST["http_method"]); |
|||
} |
|||
}; |
|||
|
|||
$list = $this->getLogic()->getPaginate($where, array('id', 'desc')); |
|||
$data['list'] = $list; |
|||
return view('admin.log.index', $data); |
|||
} |
|||
|
|||
public function add(Request $request) |
|||
{ |
|||
return view('admin.log.add'); |
|||
} |
|||
|
|||
public function doadd(Request $request) |
|||
{ |
|||
if (Helper::isPostRequest()) { |
|||
$res = $this->getLogic()->add($_POST); |
|||
if ($res['code'] == ReturnData::SUCCESS) { |
|||
success_jump($res['msg'], route('admin_slide')); |
|||
} |
|||
|
|||
error_jump($res['msg']); |
|||
} |
|||
} |
|||
|
|||
public function edit(Request $request) |
|||
{ |
|||
if (!checkIsNumber($request->input('id', null))) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$id = $request->input('id'); |
|||
|
|||
$data['id'] = $where['id'] = $id; |
|||
$data['post'] = $this->getLogic()->getOne($where); |
|||
|
|||
return view('admin.log.edit', $data); |
|||
} |
|||
|
|||
public function doedit(Request $request) |
|||
{ |
|||
if (!checkIsNumber($request->input('id', null))) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$id = $request->input('id'); |
|||
|
|||
if (Helper::isPostRequest()) { |
|||
$where['id'] = $id; |
|||
$res = $this->getLogic()->edit($_POST, $where); |
|||
if ($res['code'] == ReturnData::SUCCESS) { |
|||
success_jump($res['msg'], route('admin_slide')); |
|||
} |
|||
|
|||
error_jump($res['msg']); |
|||
} |
|||
} |
|||
|
|||
public function del(Request $request) |
|||
{ |
|||
if (!checkIsNumber($request->input('id', null))) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$id = $request->input('id'); |
|||
|
|||
$where['id'] = $id; |
|||
$res = $this->getLogic()->del($where); |
|||
if ($res['code'] == ReturnData::SUCCESS) { |
|||
success_jump($res['msg']); |
|||
} |
|||
|
|||
error_jump($res['msg']); |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
<?php |
|||
namespace App\Http\Controllers\Api; |
|||
|
|||
class BaseController extends CommonController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
} |
@ -1,47 +1,47 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers; |
|||
|
|||
use Illuminate\Routing\Controller as BaseController; |
|||
use Illuminate\Routing\Controller as BasisController; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Log; |
|||
|
|||
class Controller extends BaseController |
|||
class Controller extends BasisController |
|||
{ |
|||
public function __construct() |
|||
public function __construct() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 获取当前控制器名 |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCurrentControllerName() |
|||
{ |
|||
return self::getCurrentAction()['controller']; |
|||
} |
|||
* 获取当前控制器名 |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCurrentControllerName() |
|||
{ |
|||
return self::getCurrentAction()['controller']; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前方法名 |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCurrentMethodName() |
|||
{ |
|||
return self::getCurrentAction()['method']; |
|||
} |
|||
/** |
|||
* 获取当前方法名 |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCurrentMethodName() |
|||
{ |
|||
return self::getCurrentAction()['method']; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前控制器与方法 |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function getCurrentAction() |
|||
{ |
|||
$action = \Route::current()->getActionName(); |
|||
list($class, $method) = explode('@', $action); |
|||
/** |
|||
* 获取当前控制器与方法 |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function getCurrentAction() |
|||
{ |
|||
$action = \Route::current()->getActionName(); |
|||
list($class, $method) = explode('@', $action); |
|||
|
|||
return ['controller' => $class, 'method' => $method]; |
|||
} |
|||
return ['controller' => $class, 'method' => $method]; |
|||
} |
|||
} |
@ -0,0 +1,114 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class ArticleController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//文章列表页
|
|||
public function index(Request $request) |
|||
{ |
|||
$pagesize = 10; |
|||
$offset = 0; |
|||
|
|||
//文章分类
|
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata = array( |
|||
'id' => $request->input('typeid') |
|||
); |
|||
$url = env('APP_API_URL') . "/arctype_detail"; |
|||
$arctype_detail = curl_request($url, $postdata, 'GET'); |
|||
$data['post'] = $arctype_detail['data']; |
|||
} |
|||
|
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//文章列表
|
|||
$postdata2 = array( |
|||
'limit' => $pagesize, |
|||
'offset' => $offset |
|||
); |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata2['typeid'] = $request->input('typeid'); |
|||
} |
|||
|
|||
$url = env('APP_API_URL') . "/article_list"; |
|||
$res = curl_request($url, $postdata2, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<div class="list">'; |
|||
if (!empty($v['litpic'])) { |
|||
$html .= '<a class="limg" href="' . get_front_url(array("id" => $v['id'], "catid" => $v['typeid'], "type" => 'content')) . '"><img alt="' . $v['title'] . '" src="' . $v['litpic'] . '"></a>'; |
|||
} |
|||
$html .= '<strong class="tit"><a href="' . get_front_url(array("id" => $v['id'], "catid" => $v['typeid'], "type" => 'content')) . '">' . $v['title'] . '</a></strong><p>' . mb_strcut($v['description'], 0, 150, 'UTF-8') . '..</p>'; |
|||
$html .= '<div class="info"><span class="fl">'; |
|||
$taglist = taglist($v['id']); |
|||
if ($taglist) { |
|||
foreach ($taglist as $row) { |
|||
$html .= '<a href="' . get_front_url(array("tagid" => $row['id'], "type" => 'tags')) . '">' . $row['tag'] . '</a>'; |
|||
} |
|||
} |
|||
$html .= '<em>' . date("m-d H:i", $v['pubdate']) . '</em></span><span class="fr"><em>' . $v['click'] . '</em>人阅读</span></div><div class="cl"></div></div>'; |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
return view('home.article.index', $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = cache("detailid$id"); |
|||
if (!$post) { |
|||
$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name'); |
|||
cache(["detailid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
if (!$post) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
|
|||
$post = cache("catid$cat"); |
|||
if (!$post) { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
return view('home.article.detail', $data); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,11 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
class BaseController extends CommonController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
} |
@ -1,12 +1,47 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
|
|||
class CommonController extends Controller |
|||
{ |
|||
protected $login_info; |
|||
|
|||
/** |
|||
* 初始化 |
|||
* @param void |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
|
|||
// 添加操作记录
|
|||
$this->operation_log_add(); |
|||
} |
|||
|
|||
// 添加操作记录
|
|||
public function operation_log_add($login_info = []) |
|||
{ |
|||
$time = time(); |
|||
// 记录操作
|
|||
if ($login_info) { |
|||
$data['login_id'] = $login_info['id']; |
|||
$data['login_name'] = $login_info['user_name']; |
|||
} |
|||
$data['type'] = 2; |
|||
$data['ip'] = request()->ip(); |
|||
$data['url'] = mb_strcut(request()->url(), 0, 255, 'UTF-8'); |
|||
$data['http_method'] = request()->method(); |
|||
$data['domain_name'] = mb_strcut($_SERVER['SERVER_NAME'], 0, 60, 'UTF-8'); |
|||
if ($data['http_method'] != 'GET') { |
|||
$data['content'] = mb_strcut(json_encode(request()->toArray(), JSON_UNESCAPED_SLASHES), 0, 255, 'UTF-8'); |
|||
} |
|||
if (!empty($_SERVER['HTTP_REFERER'])) { |
|||
$data['http_referer'] = mb_strcut($_SERVER['HTTP_REFERER'], 0, 255, 'UTF-8'); |
|||
} |
|||
$data['add_time'] = $time; |
|||
logic('Log')->add($data); |
|||
} |
|||
} |
@ -0,0 +1,107 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class GoodsController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
// 商品列表页
|
|||
public function index(Request $request) |
|||
{ |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata['typeid'] = $request->input('typeid'); |
|||
} |
|||
if ($request->input('orderby', null) != null) { |
|||
$postdata['orderby'] = $request->input('orderby'); |
|||
} |
|||
if ($request->input('tuijian', null) != null) { |
|||
$postdata['tuijian'] = $request->input('tuijian'); |
|||
} |
|||
|
|||
$pagesize = 15; |
|||
$offset = 0; |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//商品列表
|
|||
$postdata['limit'] = $pagesize; |
|||
$postdata['offset'] = $offset; |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . route('home_goods', array('id' => $v['id'])) . '" target="_blank"><img src="' . $v['litpic'] . '" alt="' . $v['title'] . '">'; |
|||
$html .= '<p class="title">' . $v['title'] . '</p>'; |
|||
$html .= '<p class="desc"><span class="price-point"><i></i>库存(' . $v['goods_number'] . ')</span> ' . $v['description'] . '</p>'; |
|||
$html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">' . ceil($v['price']) . '</span></em></div>'; |
|||
$html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥' . $v['market_price'] . '</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>' . $v['sale'] . '</em> 件已付款</div></div></div></div></div></a></li>'; |
|||
|
|||
/* if($v['is_promote_goods']>0) |
|||
{ |
|||
$html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>'; |
|||
} |
|||
|
|||
$html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>'; |
|||
$html .= '</li>'; */ |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
//商品分类列表
|
|||
$postdata = array( |
|||
'pid' => 0, |
|||
'limit' => 15, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goodstype_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['goodstype_list'] = $res['data']['list']; |
|||
|
|||
return view('home.goods.index', $data); |
|||
} |
|||
|
|||
// 商品详情页
|
|||
public function detail($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$where['id'] = $id; |
|||
$where['status'] = 0; |
|||
$data['post'] = logic('Goods')->getOne($where); |
|||
if (!$data['post']) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['tj_list'] = DB::table('goods')->where(['tuijian' => 1, 'status' => 0])->orderBy('id', 'desc')->get(); |
|||
|
|||
return view('home.goods.detail', $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function brand_list(Request $request) |
|||
{ |
|||
$data['brand_list'] = object_to_array(DB::table('goods_brand')->where(['status' => 0])->take(30)->orderBy('listorder', 'asc')->get()); |
|||
|
|||
return view('home.index.brandList', $data); |
|||
} |
|||
|
|||
} |
@ -1,276 +1,378 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class IndexController extends CommonController |
|||
class IndexController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//首页
|
|||
//首页
|
|||
public function index() |
|||
{ |
|||
{ |
|||
//商品列表
|
|||
$where['status'] = 0; |
|||
$data['goods_list'] = object_to_array(DB::table('goods')->where($where)->select('id','title','price','litpic','description','shipping_fee','market_price','goods_number','sale')->take(30)->orderBy('pubdate','desc')->get()); |
|||
$data['goods_type_list'] = object_to_array(DB::table('goods_type')->where(['pid'=>0,'status'=>1])->select('id','name')->take(30)->orderBy('listorder','asc')->get()); |
|||
$data['slide_list'] = object_to_array(DB::table('slide')->where(['group_id'=>0,'type'=>0,'is_show'=>0])->take(30)->orderBy('listorder','asc')->get()); |
|||
$data['ztad_list'] = object_to_array(DB::table('slide')->where(['group_id'=>1,'type'=>0,'is_show'=>0])->take(30)->orderBy('listorder','asc')->get()); |
|||
$data['goods_list'] = object_to_array(DB::table('goods')->where($where)->select('id', 'title', 'price', 'litpic', 'description', 'shipping_fee', 'market_price', 'goods_number', 'sale')->take(30)->orderBy('pubdate', 'desc')->get()); |
|||
$data['goods_type_list'] = object_to_array(DB::table('goods_type')->where(['pid' => 0, 'status' => 1])->select('id', 'name')->take(30)->orderBy('listorder', 'asc')->get()); |
|||
$data['slide_list'] = object_to_array(DB::table('slide')->where(['group_id' => 0, 'type' => 0, 'is_show' => 0])->take(30)->orderBy('listorder', 'asc')->get()); |
|||
$data['ztad_list'] = object_to_array(DB::table('slide')->where(['group_id' => 1, 'type' => 0, 'is_show' => 0])->take(30)->orderBy('listorder', 'asc')->get()); |
|||
|
|||
return view('home.index.index',$data); |
|||
return view('home.index.index', $data); |
|||
} |
|||
|
|||
//列表页
|
|||
public function category($cat, $page=0) |
|||
{ |
|||
public function category($cat, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} |
|||
if (empty($cat) || !preg_match('/[0-9]+/', $cat)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("catid$cat")){$post = cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat="";$sql=""; |
|||
$post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); |
|||
if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} |
|||
$subcat=$subcat."typeid=".$cat; |
|||
$sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit;
|
|||
$data['sql'] = $sql; |
|||
|
|||
$counts = DB::table("article")->whereRaw($sql)->count(); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} |
|||
$pagesize = sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page*$pagesize; |
|||
|
|||
$data['posts'] = arclist(array("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表
|
|||
|
|||
if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
|
|||
return view('home.index.'.$post['templist'], $data); |
|||
} |
|||
$subcat = ""; |
|||
$sql = ""; |
|||
$post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); |
|||
if (!empty($post2)) { |
|||
foreach ($post2 as $row) { |
|||
$subcat = $subcat . "typeid=" . $row["id"] . " or "; |
|||
} |
|||
} |
|||
$subcat = $subcat . "typeid=" . $cat; |
|||
$sql = $subcat . " or typeid2 in (" . $cat . ")";//echo $subcat2;exit;
|
|||
$data['sql'] = $sql; |
|||
|
|||
$counts = DB::table("article")->whereRaw($sql)->count(); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
dd($counts); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$data['posts'] = arclist(array("sql" => $sql, "limit" => "$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $cat)); //获取分页列表
|
|||
|
|||
if ($post['templist'] == 'category2') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('home.index.' . $post['templist'], $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("detailid$id")){$post = cache("detailid$id");}else{$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name');cache(["detailid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if($post) |
|||
{ |
|||
$cat = $post['typeid']; |
|||
if (cache("detailid$id")) { |
|||
$post = cache("detailid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name'); |
|||
cache(["detailid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); |
|||
} |
|||
else |
|||
{ |
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("catid$cat")){$post=cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
return view('home.index.'.$post['temparticle'], $data); |
|||
return view('home.index.' . $post['temparticle'], $data); |
|||
} |
|||
|
|||
//标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
|
|||
public function tag($tag, $page=0) |
|||
{ |
|||
public function tag($tag, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');} |
|||
if (empty($tag) || !preg_match('/[0-9]+/', $tag)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1); |
|||
$post = object_to_array(DB::table('tagindex')->where('id', $tag)->first(), 1); |
|||
$data['post'] = $post; |
|||
|
|||
$counts=DB::table("taglist")->where('tid',$tag)->count('aid'); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');} |
|||
$pagesize=sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start=$page*$pagesize; |
|||
|
|||
$posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach($posts as $row) |
|||
{ |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
$aid = isset($aid)?implode(',',$aid):""; |
|||
|
|||
if($aid!="") |
|||
{ |
|||
if($post['template']=='tag2') |
|||
{ |
|||
$data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
|
|||
} |
|||
else |
|||
{ |
|||
$data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
|
|||
$counts = DB::table("taglist")->where('tid', $tag)->count('aid'); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$posts = object_to_array(DB::table("taglist")->where('tid', $tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach ($posts as $row) { |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
else |
|||
{ |
|||
$aid = isset($aid) ? implode(',', $aid) : ""; |
|||
|
|||
if ($aid != "") { |
|||
if ($post['template'] == 'tag2') { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize", "field" => "title,body")); //获取列表
|
|||
} else { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize")); //获取列表
|
|||
} |
|||
} else { |
|||
$data['posts'] = ''; //获取列表
|
|||
} |
|||
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $tag, "urltype" => "tag")); //获取分页列表
|
|||
|
|||
if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
if ($post['template'] == 'tag2' || $post['template'] == 'tag3') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('home.index.'.$post['template'], $data); |
|||
return view('home.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//标签页
|
|||
//标签页
|
|||
public function tags() |
|||
{ |
|||
return view('home.index.tags'); |
|||
{ |
|||
return view('home.index.tags'); |
|||
} |
|||
|
|||
//搜索页
|
|||
public function search($keyword) |
|||
{ |
|||
if(empty($keyword)) |
|||
{ |
|||
echo '请输入正确的关键词';exit; |
|||
} |
|||
public function search($keyword) |
|||
{ |
|||
if (empty($keyword)) { |
|||
echo '请输入正确的关键词'; |
|||
exit; |
|||
} |
|||
|
|||
if(strstr($keyword,"&")) exit; |
|||
if (strstr($keyword, "&")) exit; |
|||
|
|||
$data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword']= $keyword; |
|||
$data['posts'] = object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword'] = $keyword; |
|||
|
|||
return view('home.index.search', $data); |
|||
return view('home.index.search', $data); |
|||
} |
|||
|
|||
//单页面
|
|||
public function page($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if(!empty($id) && preg_match('/[a-z0-9]+/',$id)) |
|||
{ |
|||
$map['filename']=$id; |
|||
if(cache("pageid$id")){$post=cache("pageid$id");}else{$post = object_to_array(DB::table('page')->where($map)->first(), 1);cache("pageid$id", $post, 2592000);cache(["pageid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
{ |
|||
$data = []; |
|||
|
|||
if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) { |
|||
$map['filename'] = $id; |
|||
if (cache("pageid$id")) { |
|||
$post = cache("pageid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('page')->where($map)->first(), 1); |
|||
cache("pageid$id", $post, 2592000); |
|||
cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
if($post) |
|||
{ |
|||
if ($post) { |
|||
$data['post'] = $post; |
|||
} |
|||
else |
|||
{ |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
} |
|||
else |
|||
{ |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('home.index.'.$post['template'], $data); |
|||
return view('home.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function goodstype($cat, $page=0) |
|||
{ |
|||
//商品列表页
|
|||
public function goodstype($cat, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} |
|||
if (empty($cat) || !preg_match('/[0-9]+/', $cat)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} |
|||
$post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat=""; |
|||
$post2 = object_to_array(DB::table('goods_type')->select('id')->where('pid', $cat)->get()); |
|||
if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} |
|||
$subcat=$subcat."typeid=".$cat; |
|||
$data['sql'] = $subcat; |
|||
$subcat = ""; |
|||
$post2 = object_to_array(DB::table('goods_type')->select('id')->where('pid', $cat)->get()); |
|||
if (!empty($post2)) { |
|||
foreach ($post2 as $row) { |
|||
$subcat = $subcat . "typeid=" . $row["id"] . " or "; |
|||
} |
|||
} |
|||
$subcat = $subcat . "typeid=" . $cat; |
|||
$data['sql'] = $subcat; |
|||
|
|||
$counts = DB::table("goods")->whereRaw($subcat)->count(); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} |
|||
$pagesize = sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page*$pagesize; |
|||
$counts = DB::table("goods")->whereRaw($subcat)->count(); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
dd($counts); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$data['posts'] = arclist(array("table"=>"goods","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"goods")); //获取分页列表
|
|||
$data['posts'] = arclist(array("table" => "goods", "sql" => $subcat, "limit" => "$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $cat, "urltype" => "goods")); //获取分页列表
|
|||
|
|||
if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
if ($post['templist'] == 'category2') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('home.index.'.$post['templist'], $data); |
|||
} |
|||
return view('home.index.' . $post['templist'], $data); |
|||
} |
|||
|
|||
//商品详情页
|
|||
public function goods($id) |
|||
{ |
|||
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} |
|||
|
|||
$post = object_to_array(DB::table('goods')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name'); |
|||
if($post) |
|||
{ |
|||
$cat = $post['typeid']; |
|||
if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); |
|||
$post = object_to_array(DB::table('goods')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
else |
|||
{ |
|||
$post['name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name'); |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1); |
|||
$post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1); |
|||
|
|||
return view('home.index.goods', $data); |
|||
} |
|||
|
|||
//sitemap页面
|
|||
//sitemap页面
|
|||
public function sitemap() |
|||
{ |
|||
return view('home.index.sitemap'); |
|||
return view('home.index.sitemap'); |
|||
} |
|||
|
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
|
|||
//测试页面
|
|||
public function test() |
|||
{return view('home.index.test'); |
|||
public function test() |
|||
{ |
|||
return view('home.index.test'); |
|||
//return base_path('resources/org');
|
|||
//$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
|
|||
//return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
|
|||
//return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
|
|||
//set_exception_handler('myException');
|
|||
//return uniqid();
|
|||
//return \App\Common\Helper::formatPrice(1.2346);
|
|||
//set_exception_handler('myException');
|
|||
//return uniqid();
|
|||
//return \App\Common\Helper::formatPrice(1.2346);
|
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class PageController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//单页面
|
|||
public function detail($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) { |
|||
$map['filename'] = $id; |
|||
$post = cache("pageid$id"); |
|||
if (!$post) { |
|||
$post = object_to_array(DB::table('page')->where($map)->first(), 1); |
|||
//cache("pageid$id", $post, 2592000);
|
|||
cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
if (!$post) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$data['post'] = $post; |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('home.page.detail', $data); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,526 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class IndexController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//首页
|
|||
public function index() |
|||
{ |
|||
//推荐商品列表
|
|||
$postdata = array( |
|||
'tuijian' => 1, |
|||
'status' => 0, |
|||
'limit' => 6, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['tjlist'] = $res['data']['list']; |
|||
|
|||
//商品列表
|
|||
$pagesize = 15; |
|||
$offset = 0; |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
$postdata = array( |
|||
'status' => 0, |
|||
'limit' => $pagesize, |
|||
'offset' => $offset |
|||
); |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . route('home_goods', array('id' => $v['id'])) . '" target="_blank"><img src="' . $v['litpic'] . '" alt="' . $v['title'] . '">'; |
|||
$html .= '<p class="title">' . $v['title'] . '</p>'; |
|||
$html .= '<p class="desc"><span class="price-point"><i></i>库存(' . $v['goods_number'] . ')</span> ' . $v['description'] . '</p>'; |
|||
$html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">' . ceil($v['price']) . '</span></em></div>'; |
|||
$html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥' . $v['market_price'] . '</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>' . $v['sale'] . '</em> 件已付款</div></div></div></div></div></a></li>'; |
|||
|
|||
/* if($v['is_promote_goods']>0) |
|||
{ |
|||
$html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>'; |
|||
} |
|||
|
|||
$html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>'; |
|||
$html .= '</li>'; */ |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
//商品分类列表
|
|||
$postdata = array( |
|||
'pid' => 0, |
|||
'limit' => 15, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goodstype_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['goodstype_list'] = $res['data']['list']; |
|||
|
|||
//banner轮播图
|
|||
$postdata = array( |
|||
'type' => 0, |
|||
'limit' => 5, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/slide_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['slide_list'] = $res['data']['list']; |
|||
|
|||
return view('home.index.index', $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function goodslist(Request $request) |
|||
{ |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata['typeid'] = $request->input('typeid'); |
|||
} |
|||
if ($request->input('orderby', null) != null) { |
|||
$postdata['orderby'] = $request->input('orderby'); |
|||
} |
|||
if ($request->input('tuijian', null) != null) { |
|||
$postdata['tuijian'] = $request->input('tuijian'); |
|||
} |
|||
|
|||
$pagesize = 15; |
|||
$offset = 0; |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//商品列表
|
|||
$postdata['limit'] = $pagesize; |
|||
$postdata['offset'] = $offset; |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . route('home_goods', array('id' => $v['id'])) . '" target="_blank"><img src="' . $v['litpic'] . '" alt="' . $v['title'] . '">'; |
|||
$html .= '<p class="title">' . $v['title'] . '</p>'; |
|||
$html .= '<p class="desc"><span class="price-point"><i></i>库存(' . $v['goods_number'] . ')</span> ' . $v['description'] . '</p>'; |
|||
$html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">' . ceil($v['price']) . '</span></em></div>'; |
|||
$html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥' . $v['market_price'] . '</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>' . $v['sale'] . '</em> 件已付款</div></div></div></div></div></a></li>'; |
|||
|
|||
/* if($v['is_promote_goods']>0) |
|||
{ |
|||
$html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>'; |
|||
} |
|||
|
|||
$html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>'; |
|||
$html .= '</li>'; */ |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
//商品分类列表
|
|||
$postdata = array( |
|||
'pid' => 0, |
|||
'limit' => 15, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goodstype_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['goodstype_list'] = $res['data']['list']; |
|||
|
|||
return view('home.index.goodslist', $data); |
|||
} |
|||
|
|||
//商品详情页
|
|||
public function goods($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$where['id'] = $id; |
|||
$where['status'] = 0; |
|||
$data['post'] = logic('Goods')->getOne($where); |
|||
if (!$data['post']) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['tj_list'] = DB::table('goods')->where(['tuijian' => 1, 'status' => 0])->orderBy('id', 'desc')->get(); |
|||
|
|||
return view('home.index.goods', $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function brandList(Request $request) |
|||
{ |
|||
$data['brand_list'] = object_to_array(DB::table('goods_brand')->where(['status' => 0])->take(30)->orderBy('listorder', 'asc')->get()); |
|||
|
|||
return view('home.index.brandList', $data); |
|||
} |
|||
|
|||
//网址组装
|
|||
public function listpageurl($http_host, $query_string, $page = 0) |
|||
{ |
|||
$res = ''; |
|||
foreach (explode("&", $query_string) as $row) { |
|||
if ($row) { |
|||
$canshu = explode("=", $row); |
|||
$res[$canshu[0]] = $canshu[1]; |
|||
} |
|||
} |
|||
|
|||
if (isset($res['page'])) { |
|||
unset($res['page']); |
|||
} |
|||
|
|||
if ($page == 1 || $page == 0) { |
|||
} else { |
|||
$res['page'] = $page; |
|||
} |
|||
|
|||
if ($res) { |
|||
$res = $http_host . '?' . http_build_query($res); |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//列表页
|
|||
public function category(Request $request) |
|||
{ |
|||
$pagesize = 10; |
|||
$offset = 0; |
|||
|
|||
//文章分类
|
|||
$postdata = array( |
|||
'id' => $cat |
|||
); |
|||
$url = env('APP_API_URL') . "/arctype_detail"; |
|||
$arctype_detail = curl_request($url, $postdata, 'GET'); |
|||
$data['post'] = $arctype_detail['data']; |
|||
dd($data['post']); |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//文章列表
|
|||
$postdata2['limit'] = $limit; |
|||
$postdata2['offset'] = $offset; |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata2['typeid'] = $request->input('typeid'); |
|||
} |
|||
|
|||
$url = env('APP_API_URL') . "/article_list"; |
|||
$res = curl_request($url, $postdata2, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . $v['article_detail_url'] . '">' . $v['title'] . '</a><p>' . $v['pubdate'] . '</p></li>'; |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
return view('home.index.' . $data['post']['templist'], $data); |
|||
} |
|||
|
|||
//文章列表页
|
|||
public function arclist(Request $request) |
|||
{ |
|||
$pagesize = 10; |
|||
$offset = 0; |
|||
|
|||
//文章分类
|
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata = array( |
|||
'id' => $request->input('typeid') |
|||
); |
|||
$url = env('APP_API_URL') . "/arctype_detail"; |
|||
$arctype_detail = curl_request($url, $postdata, 'GET'); |
|||
$data['post'] = $arctype_detail['data']; |
|||
} |
|||
|
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//文章列表
|
|||
$postdata2 = array( |
|||
'limit' => $pagesize, |
|||
'offset' => $offset |
|||
); |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata2['typeid'] = $request->input('typeid'); |
|||
} |
|||
|
|||
$url = env('APP_API_URL') . "/article_list"; |
|||
$res = curl_request($url, $postdata2, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<div class="list">'; |
|||
if (!empty($v['litpic'])) { |
|||
$html .= '<a class="limg" href="' . get_front_url(array("id" => $v['id'], "catid" => $v['typeid'], "type" => 'content')) . '"><img alt="' . $v['title'] . '" src="' . $v['litpic'] . '"></a>'; |
|||
} |
|||
$html .= '<strong class="tit"><a href="' . get_front_url(array("id" => $v['id'], "catid" => $v['typeid'], "type" => 'content')) . '">' . $v['title'] . '</a></strong><p>' . mb_strcut($v['description'], 0, 150, 'UTF-8') . '..</p>'; |
|||
$html .= '<div class="info"><span class="fl">'; |
|||
$taglist = taglist($v['id']); |
|||
if ($taglist) { |
|||
foreach ($taglist as $row) { |
|||
$html .= '<a href="' . get_front_url(array("tagid" => $row['id'], "type" => 'tags')) . '">' . $row['tag'] . '</a>'; |
|||
} |
|||
} |
|||
$html .= '<em>' . date("m-d H:i", $v['pubdate']) . '</em></span><span class="fr"><em>' . $v['click'] . '</em>人阅读</span></div><div class="cl"></div></div>'; |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
return view('home.index.arclist', $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("detailid$id")) { |
|||
$post = cache("detailid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name'); |
|||
cache(["detailid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
return view('home.index.' . $post['temparticle'], $data); |
|||
} |
|||
|
|||
//标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
|
|||
public function tag($tag, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if (empty($tag) || !preg_match('/[0-9]+/', $tag)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('tagindex')->where('id', $tag)->first(), 1); |
|||
$data['post'] = $post; |
|||
|
|||
$counts = DB::table("taglist")->where('tid', $tag)->count('aid'); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$posts = object_to_array(DB::table("taglist")->where('tid', $tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach ($posts as $row) { |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
$aid = isset($aid) ? implode(',', $aid) : ""; |
|||
|
|||
if ($aid != "") { |
|||
if ($post['template'] == 'tag2') { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize", "field" => "title,body")); //获取列表
|
|||
} else { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize")); //获取列表
|
|||
} |
|||
} else { |
|||
$data['posts'] = ''; //获取列表
|
|||
} |
|||
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $tag, "urltype" => "tag")); //获取分页列表
|
|||
|
|||
if ($post['template'] == 'tag2' || $post['template'] == 'tag3') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('home.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//标签页
|
|||
public function tags() |
|||
{ |
|||
return view('home.index.tags'); |
|||
} |
|||
|
|||
//搜索页
|
|||
public function search($keyword) |
|||
{ |
|||
if (empty($keyword)) { |
|||
echo '请输入正确的关键词'; |
|||
exit; |
|||
} |
|||
|
|||
if (strstr($keyword, "&")) exit; |
|||
|
|||
$data['posts'] = object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword'] = $keyword; |
|||
|
|||
return view('home.index.search', $data); |
|||
} |
|||
|
|||
//单页面
|
|||
public function page($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) { |
|||
$map['filename'] = $id; |
|||
if (cache("pageid$id")) { |
|||
$post = cache("pageid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('page')->where($map)->first(), 1); |
|||
cache("pageid$id", $post, 2592000); |
|||
cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
if ($post) { |
|||
$data['post'] = $post; |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('home.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//sitemap页面
|
|||
public function sitemap() |
|||
{ |
|||
return view('home.index.sitemap'); |
|||
} |
|||
|
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
|
|||
//验证消息的确来自微信服务器
|
|||
public function checksignature() |
|||
{ |
|||
$signature = $_GET["signature"]; |
|||
$timestamp = $_GET["timestamp"]; |
|||
$nonce = $_GET["nonce"]; |
|||
$echoStr = $_GET["echostr"]; |
|||
|
|||
$token = 'fanli'; |
|||
$tmpArr = array($token, $timestamp, $nonce); |
|||
sort($tmpArr, SORT_STRING); |
|||
$tmpStr = implode($tmpArr); |
|||
$tmpStr = sha1($tmpStr); |
|||
|
|||
if ($tmpStr == $signature) { |
|||
exit($echoStr); |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//测试页面
|
|||
public function test() |
|||
{ |
|||
return view('home.index.test'); |
|||
//return base_path('resources/org');
|
|||
//$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
|
|||
//return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
|
|||
//return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
|
|||
//set_exception_handler('myException');
|
|||
//return uniqid();
|
|||
//return \App\Common\Helper::formatPrice(1.2346);
|
|||
} |
|||
} |
@ -0,0 +1,526 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class TagController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//首页
|
|||
public function index() |
|||
{ |
|||
//推荐商品列表
|
|||
$postdata = array( |
|||
'tuijian' => 1, |
|||
'status' => 0, |
|||
'limit' => 6, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['tjlist'] = $res['data']['list']; |
|||
|
|||
//商品列表
|
|||
$pagesize = 15; |
|||
$offset = 0; |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
$postdata = array( |
|||
'status' => 0, |
|||
'limit' => $pagesize, |
|||
'offset' => $offset |
|||
); |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . route('home_goods', array('id' => $v['id'])) . '" target="_blank"><img src="' . $v['litpic'] . '" alt="' . $v['title'] . '">'; |
|||
$html .= '<p class="title">' . $v['title'] . '</p>'; |
|||
$html .= '<p class="desc"><span class="price-point"><i></i>库存(' . $v['goods_number'] . ')</span> ' . $v['description'] . '</p>'; |
|||
$html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">' . ceil($v['price']) . '</span></em></div>'; |
|||
$html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥' . $v['market_price'] . '</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>' . $v['sale'] . '</em> 件已付款</div></div></div></div></div></a></li>'; |
|||
|
|||
/* if($v['is_promote_goods']>0) |
|||
{ |
|||
$html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>'; |
|||
} |
|||
|
|||
$html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>'; |
|||
$html .= '</li>'; */ |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
//商品分类列表
|
|||
$postdata = array( |
|||
'pid' => 0, |
|||
'limit' => 15, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goodstype_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['goodstype_list'] = $res['data']['list']; |
|||
|
|||
//banner轮播图
|
|||
$postdata = array( |
|||
'type' => 0, |
|||
'limit' => 5, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/slide_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['slide_list'] = $res['data']['list']; |
|||
|
|||
return view('home.index.index', $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function goodslist(Request $request) |
|||
{ |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata['typeid'] = $request->input('typeid'); |
|||
} |
|||
if ($request->input('orderby', null) != null) { |
|||
$postdata['orderby'] = $request->input('orderby'); |
|||
} |
|||
if ($request->input('tuijian', null) != null) { |
|||
$postdata['tuijian'] = $request->input('tuijian'); |
|||
} |
|||
|
|||
$pagesize = 15; |
|||
$offset = 0; |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//商品列表
|
|||
$postdata['limit'] = $pagesize; |
|||
$postdata['offset'] = $offset; |
|||
$url = env('APP_API_URL') . "/goods_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . route('home_goods', array('id' => $v['id'])) . '" target="_blank"><img src="' . $v['litpic'] . '" alt="' . $v['title'] . '">'; |
|||
$html .= '<p class="title">' . $v['title'] . '</p>'; |
|||
$html .= '<p class="desc"><span class="price-point"><i></i>库存(' . $v['goods_number'] . ')</span> ' . $v['description'] . '</p>'; |
|||
$html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">' . ceil($v['price']) . '</span></em></div>'; |
|||
$html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥' . $v['market_price'] . '</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>' . $v['sale'] . '</em> 件已付款</div></div></div></div></div></a></li>'; |
|||
|
|||
/* if($v['is_promote_goods']>0) |
|||
{ |
|||
$html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>'; |
|||
} |
|||
|
|||
$html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>'; |
|||
$html .= '</li>'; */ |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
//商品分类列表
|
|||
$postdata = array( |
|||
'pid' => 0, |
|||
'limit' => 15, |
|||
'offset' => 0 |
|||
); |
|||
$url = env('APP_API_URL') . "/goodstype_list"; |
|||
$res = curl_request($url, $postdata, 'GET'); |
|||
$data['goodstype_list'] = $res['data']['list']; |
|||
|
|||
return view('home.index.goodslist', $data); |
|||
} |
|||
|
|||
//商品详情页
|
|||
public function goods($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$where['id'] = $id; |
|||
$where['status'] = 0; |
|||
$data['post'] = logic('Goods')->getOne($where); |
|||
if (!$data['post']) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['tj_list'] = DB::table('goods')->where(['tuijian' => 1, 'status' => 0])->orderBy('id', 'desc')->get(); |
|||
|
|||
return view('home.index.goods', $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function brandList(Request $request) |
|||
{ |
|||
$data['brand_list'] = object_to_array(DB::table('goods_brand')->where(['status' => 0])->take(30)->orderBy('listorder', 'asc')->get()); |
|||
|
|||
return view('home.index.brandList', $data); |
|||
} |
|||
|
|||
//网址组装
|
|||
public function listpageurl($http_host, $query_string, $page = 0) |
|||
{ |
|||
$res = ''; |
|||
foreach (explode("&", $query_string) as $row) { |
|||
if ($row) { |
|||
$canshu = explode("=", $row); |
|||
$res[$canshu[0]] = $canshu[1]; |
|||
} |
|||
} |
|||
|
|||
if (isset($res['page'])) { |
|||
unset($res['page']); |
|||
} |
|||
|
|||
if ($page == 1 || $page == 0) { |
|||
} else { |
|||
$res['page'] = $page; |
|||
} |
|||
|
|||
if ($res) { |
|||
$res = $http_host . '?' . http_build_query($res); |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//列表页
|
|||
public function category(Request $request) |
|||
{ |
|||
$pagesize = 10; |
|||
$offset = 0; |
|||
|
|||
//文章分类
|
|||
$postdata = array( |
|||
'id' => $cat |
|||
); |
|||
$url = env('APP_API_URL') . "/arctype_detail"; |
|||
$arctype_detail = curl_request($url, $postdata, 'GET'); |
|||
$data['post'] = $arctype_detail['data']; |
|||
dd($data['post']); |
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//文章列表
|
|||
$postdata2['limit'] = $limit; |
|||
$postdata2['offset'] = $offset; |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata2['typeid'] = $request->input('typeid'); |
|||
} |
|||
|
|||
$url = env('APP_API_URL') . "/article_list"; |
|||
$res = curl_request($url, $postdata2, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<li><a href="' . $v['article_detail_url'] . '">' . $v['title'] . '</a><p>' . $v['pubdate'] . '</p></li>'; |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
return view('home.index.' . $data['post']['templist'], $data); |
|||
} |
|||
|
|||
//文章列表页
|
|||
public function arclist(Request $request) |
|||
{ |
|||
$pagesize = 10; |
|||
$offset = 0; |
|||
|
|||
//文章分类
|
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata = array( |
|||
'id' => $request->input('typeid') |
|||
); |
|||
$url = env('APP_API_URL') . "/arctype_detail"; |
|||
$arctype_detail = curl_request($url, $postdata, 'GET'); |
|||
$data['post'] = $arctype_detail['data']; |
|||
} |
|||
|
|||
if (isset($_REQUEST['page'])) { |
|||
$offset = ($_REQUEST['page'] - 1) * $pagesize; |
|||
} |
|||
|
|||
//文章列表
|
|||
$postdata2 = array( |
|||
'limit' => $pagesize, |
|||
'offset' => $offset |
|||
); |
|||
if ($request->input('typeid', null) != null) { |
|||
$postdata2['typeid'] = $request->input('typeid'); |
|||
} |
|||
|
|||
$url = env('APP_API_URL') . "/article_list"; |
|||
$res = curl_request($url, $postdata2, 'GET'); |
|||
$data['list'] = $res['data']['list']; |
|||
|
|||
$data['totalpage'] = ceil($res['data']['count'] / $pagesize); |
|||
|
|||
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) { |
|||
$html = ''; |
|||
|
|||
if ($res['data']['list']) { |
|||
foreach ($res['data']['list'] as $k => $v) { |
|||
$html .= '<div class="list">'; |
|||
if (!empty($v['litpic'])) { |
|||
$html .= '<a class="limg" href="' . get_front_url(array("id" => $v['id'], "catid" => $v['typeid'], "type" => 'content')) . '"><img alt="' . $v['title'] . '" src="' . $v['litpic'] . '"></a>'; |
|||
} |
|||
$html .= '<strong class="tit"><a href="' . get_front_url(array("id" => $v['id'], "catid" => $v['typeid'], "type" => 'content')) . '">' . $v['title'] . '</a></strong><p>' . mb_strcut($v['description'], 0, 150, 'UTF-8') . '..</p>'; |
|||
$html .= '<div class="info"><span class="fl">'; |
|||
$taglist = taglist($v['id']); |
|||
if ($taglist) { |
|||
foreach ($taglist as $row) { |
|||
$html .= '<a href="' . get_front_url(array("tagid" => $row['id'], "type" => 'tags')) . '">' . $row['tag'] . '</a>'; |
|||
} |
|||
} |
|||
$html .= '<em>' . date("m-d H:i", $v['pubdate']) . '</em></span><span class="fr"><em>' . $v['click'] . '</em>人阅读</span></div><div class="cl"></div></div>'; |
|||
} |
|||
} |
|||
|
|||
exit(json_encode($html)); |
|||
} |
|||
|
|||
return view('home.index.arclist', $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("detailid$id")) { |
|||
$post = cache("detailid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name'); |
|||
cache(["detailid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
return view('home.index.' . $post['temparticle'], $data); |
|||
} |
|||
|
|||
//标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
|
|||
public function tag($tag, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if (empty($tag) || !preg_match('/[0-9]+/', $tag)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('tagindex')->where('id', $tag)->first(), 1); |
|||
$data['post'] = $post; |
|||
|
|||
$counts = DB::table("taglist")->where('tid', $tag)->count('aid'); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$posts = object_to_array(DB::table("taglist")->where('tid', $tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach ($posts as $row) { |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
$aid = isset($aid) ? implode(',', $aid) : ""; |
|||
|
|||
if ($aid != "") { |
|||
if ($post['template'] == 'tag2') { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize", "field" => "title,body")); //获取列表
|
|||
} else { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize")); //获取列表
|
|||
} |
|||
} else { |
|||
$data['posts'] = ''; //获取列表
|
|||
} |
|||
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $tag, "urltype" => "tag")); //获取分页列表
|
|||
|
|||
if ($post['template'] == 'tag2' || $post['template'] == 'tag3') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('home.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//标签页
|
|||
public function tags() |
|||
{ |
|||
return view('home.index.tags'); |
|||
} |
|||
|
|||
//搜索页
|
|||
public function search($keyword) |
|||
{ |
|||
if (empty($keyword)) { |
|||
echo '请输入正确的关键词'; |
|||
exit; |
|||
} |
|||
|
|||
if (strstr($keyword, "&")) exit; |
|||
|
|||
$data['posts'] = object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword'] = $keyword; |
|||
|
|||
return view('home.index.search', $data); |
|||
} |
|||
|
|||
//单页面
|
|||
public function page($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) { |
|||
$map['filename'] = $id; |
|||
if (cache("pageid$id")) { |
|||
$post = cache("pageid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('page')->where($map)->first(), 1); |
|||
cache("pageid$id", $post, 2592000); |
|||
cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
if ($post) { |
|||
$data['post'] = $post; |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('home.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//sitemap页面
|
|||
public function sitemap() |
|||
{ |
|||
return view('home.index.sitemap'); |
|||
} |
|||
|
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
|
|||
//验证消息的确来自微信服务器
|
|||
public function checksignature() |
|||
{ |
|||
$signature = $_GET["signature"]; |
|||
$timestamp = $_GET["timestamp"]; |
|||
$nonce = $_GET["nonce"]; |
|||
$echoStr = $_GET["echostr"]; |
|||
|
|||
$token = 'fanli'; |
|||
$tmpArr = array($token, $timestamp, $nonce); |
|||
sort($tmpArr, SORT_STRING); |
|||
$tmpStr = implode($tmpArr); |
|||
$tmpStr = sha1($tmpStr); |
|||
|
|||
if ($tmpStr == $signature) { |
|||
exit($echoStr); |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//测试页面
|
|||
public function test() |
|||
{ |
|||
return view('home.index.test'); |
|||
//return base_path('resources/org');
|
|||
//$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
|
|||
//return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
|
|||
//return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
|
|||
//set_exception_handler('myException');
|
|||
//return uniqid();
|
|||
//return \App\Common\Helper::formatPrice(1.2346);
|
|||
} |
|||
} |
@ -1,291 +1,62 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class TestController extends CommonController |
|||
class TestController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//首页
|
|||
//首页
|
|||
public function index() |
|||
{ |
|||
//Excel文件导出功能,如果出现文件名中文乱码,iconv('UTF-8', 'GBK', '学生成绩')
|
|||
/* $cellData = [ |
|||
['学号','姓名','成绩'], |
|||
['10001','AAAAA','99'], |
|||
['10002','BBBBB','92'], |
|||
['10003','CCCCC','95'], |
|||
['10004','DDDDD','89'], |
|||
['10005','EEEEE','96'], |
|||
]; |
|||
\Excel::create('学生成绩',function($excel) use ($cellData){ |
|||
//第一个工作簿,score是工作簿的名称
|
|||
$excel->sheet('score', function($sheet) use ($cellData){ |
|||
$sheet->rows($cellData); |
|||
}); |
|||
|
|||
//第二个工作簿
|
|||
$excel->sheet('score', function($sheet) use ($cellData){ |
|||
$sheet->rows($cellData); |
|||
}); |
|||
})->export('xls'); |
|||
|
|||
//Excel文件导入功能
|
|||
$filePath = 'storage/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls'; |
|||
\Excel::load($filePath, function($reader) { |
|||
$reader = $reader->getSheet(0); |
|||
{ |
|||
//Excel文件导出功能,如果出现文件名中文乱码,iconv('UTF-8', 'GBK', '学生成绩')
|
|||
/* $cellData = [ |
|||
['学号','姓名','成绩'], |
|||
['10001','AAAAA','99'], |
|||
['10002','BBBBB','92'], |
|||
['10003','CCCCC','95'], |
|||
['10004','DDDDD','89'], |
|||
['10005','EEEEE','96'], |
|||
]; |
|||
\Excel::create('学生成绩',function($excel) use ($cellData){ |
|||
//第一个工作簿,score是工作簿的名称
|
|||
$excel->sheet('score', function($sheet) use ($cellData){ |
|||
$sheet->rows($cellData); |
|||
}); |
|||
|
|||
//第二个工作簿
|
|||
$excel->sheet('score', function($sheet) use ($cellData){ |
|||
$sheet->rows($cellData); |
|||
}); |
|||
})->export('xls'); |
|||
|
|||
//Excel文件导入功能
|
|||
$filePath = 'storage/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls'; |
|||
\Excel::load($filePath, function($reader) { |
|||
$reader = $reader->getSheet(0); |
|||
$res = $reader->toArray(); |
|||
dd($res); |
|||
}); */ |
|||
} |
|||
|
|||
//列表页
|
|||
public function category($cat, $page=0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} |
|||
|
|||
if(cache("catid$cat")){$post = cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat="";$sql=""; |
|||
$post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); |
|||
if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} |
|||
$subcat=$subcat."typeid=".$cat; |
|||
$sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit;
|
|||
$data['sql'] = $sql; |
|||
|
|||
$counts = DB::table("article")->whereRaw($sql)->count(); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} |
|||
$pagesize = sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page*$pagesize; |
|||
|
|||
$data['posts'] = arclist(array("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表
|
|||
|
|||
if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
|
|||
return view('home.index.'.$post['templist'], $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} |
|||
|
|||
if(cache("detailid$id")){$post = cache("detailid$id");}else{$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name');cache(["detailid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if($post) |
|||
{ |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); |
|||
} |
|||
else |
|||
{ |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("catid$cat")){$post=cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
|
|||
return view('home.index.'.$post['temparticle'], $data); |
|||
} |
|||
|
|||
//标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
|
|||
public function tag($tag, $page=0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');} |
|||
|
|||
$post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1); |
|||
$data['post'] = $post; |
|||
|
|||
$counts=DB::table("taglist")->where('tid',$tag)->count('aid'); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');} |
|||
$pagesize=sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start=$page*$pagesize; |
|||
|
|||
$posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach($posts as $row) |
|||
{ |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
$aid = isset($aid)?implode(',',$aid):""; |
|||
|
|||
if($aid!="") |
|||
{ |
|||
if($post['template']=='tag2') |
|||
{ |
|||
$data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
|
|||
} |
|||
else |
|||
{ |
|||
$data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
|
|||
} |
|||
} |
|||
else |
|||
{ |
|||
$data['posts'] = ''; //获取列表
|
|||
} |
|||
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
|
|||
|
|||
if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
|
|||
return view('home.index.'.$post['template'], $data); |
|||
} |
|||
|
|||
//标签页
|
|||
public function tags() |
|||
{ |
|||
return view('home.index.tags'); |
|||
} |
|||
|
|||
//搜索页
|
|||
public function search($keyword) |
|||
{ |
|||
if(empty($keyword)) |
|||
{ |
|||
echo '请输入正确的关键词';exit; |
|||
} |
|||
|
|||
if(strstr($keyword,"&")) exit; |
|||
|
|||
$data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword']= $keyword; |
|||
|
|||
return view('home.index.search', $data); |
|||
dd($res); |
|||
}); */ |
|||
} |
|||
|
|||
//单页面
|
|||
public function page($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if(!empty($id) && preg_match('/[a-z0-9]+/',$id)) |
|||
{ |
|||
$map['filename']=$id; |
|||
if(cache("pageid$id")){$post=cache("pageid$id");}else{$post = object_to_array(DB::table('page')->where($map)->first(), 1);cache("pageid$id", $post, 2592000);cache(["pageid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
|
|||
if($post) |
|||
{ |
|||
$data['post'] = $post; |
|||
} |
|||
else |
|||
{ |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
} |
|||
else |
|||
{ |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('home.index.'.$post['template'], $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function productcat($cat, $page=0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} |
|||
|
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat=""; |
|||
$post2 = object_to_array(DB::table('product_type')->select('id')->where('pid', $cat)->get()); |
|||
if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} |
|||
$subcat=$subcat."typeid=".$cat; |
|||
$data['sql'] = $subcat; |
|||
|
|||
$counts = DB::table("product")->whereRaw($subcat)->count(); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} |
|||
$pagesize = sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page*$pagesize; |
|||
|
|||
$data['posts'] = arclist(array("table"=>"product","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"product")); //获取分页列表
|
|||
|
|||
if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
|
|||
return view('home.index.'.$post['templist'], $data); |
|||
} |
|||
|
|||
//商品详情页
|
|||
public function product($id) |
|||
{ |
|||
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} |
|||
|
|||
$post = object_to_array(DB::table('product')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('product_type')->where('id', $post['typeid'])->value('name'); |
|||
if($post) |
|||
{ |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); |
|||
} |
|||
else |
|||
{ |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); |
|||
|
|||
return view('home.index.'.$post['temparticle'], $data); |
|||
} |
|||
|
|||
//sitemap页面
|
|||
public function sitemap() |
|||
// 队列测试
|
|||
public function queue() |
|||
{ |
|||
return view('home.index.sitemap'); |
|||
// php artisan queue:work
|
|||
dispatch(new \App\Jobs\Example()); |
|||
} |
|||
|
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
|
|||
//测试页面
|
|||
public function test() |
|||
// 事件测试
|
|||
public function event() |
|||
{ |
|||
return date("Y-m-d H:i:s",strtotime("2017-04")); |
|||
$order = \App\Http\Model\Order::where(['id' => 1])->first(); |
|||
$order_id = 1; |
|||
event(new \App\Events\OrderShipped($order_id)); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,126 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Wap; |
|||
|
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class ArticleController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//列表页
|
|||
public function index($cat, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if (empty($cat) || !preg_match('/[0-9]+/', $cat)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat = ""; |
|||
$sql = ""; |
|||
$post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); |
|||
if (!empty($post2)) { |
|||
foreach ($post2 as $row) { |
|||
$subcat = $subcat . "typeid=" . $row["id"] . " or "; |
|||
} |
|||
} |
|||
$subcat = $subcat . "typeid=" . $cat; |
|||
$sql = $subcat . " or typeid2 in (" . $cat . ")";//echo $subcat2;exit;
|
|||
$data['sql'] = $sql; |
|||
|
|||
$counts = DB::table("article")->whereRaw($sql)->count(); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
dd($counts); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$data['posts'] = arclist(array("sql" => $sql, "limit" => "$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $cat)); //获取分页列表
|
|||
|
|||
if ($post['templist'] == 'category2') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('wap.article.index', $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("detailid$id")) { |
|||
$post = cache("detailid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name'); |
|||
cache(["detailid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
return view('wap.article.detail', $data); |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Wap; |
|||
|
|||
class BaseController extends CommonController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
} |
@ -1,12 +1,45 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Wap; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
|
|||
class CommonController extends Controller |
|||
{ |
|||
/** |
|||
* 初始化 |
|||
* @param void |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
|
|||
// 添加操作记录
|
|||
$this->operation_log_add(); |
|||
} |
|||
|
|||
// 添加操作记录
|
|||
public function operation_log_add($login_info = []) |
|||
{ |
|||
$time = time(); |
|||
// 记录操作
|
|||
if ($login_info) { |
|||
$data['login_id'] = $login_info['id']; |
|||
$data['login_name'] = $login_info['user_name']; |
|||
} |
|||
$data['type'] = 4; |
|||
$data['ip'] = request()->ip(); |
|||
$data['url'] = mb_strcut(request()->url(), 0, 255, 'UTF-8'); |
|||
$data['http_method'] = request()->method(); |
|||
$data['domain_name'] = mb_strcut($_SERVER['SERVER_NAME'], 0, 60, 'UTF-8'); |
|||
if ($data['http_method'] != 'GET') { |
|||
$data['content'] = mb_strcut(json_encode(request()->toArray(), JSON_UNESCAPED_SLASHES), 0, 255, 'UTF-8'); |
|||
} |
|||
if (!empty($_SERVER['HTTP_REFERER'])) { |
|||
$data['http_referer'] = mb_strcut($_SERVER['HTTP_REFERER'], 0, 255, 'UTF-8'); |
|||
} |
|||
$data['add_time'] = $time; |
|||
logic('Log')->add($data); |
|||
} |
|||
} |
@ -0,0 +1,108 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Wap; |
|||
|
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class GoodsController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function index($cat, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if (empty($cat) || !preg_match('/[0-9]+/', $cat)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat = ""; |
|||
$post2 = object_to_array(DB::table('product_type')->select('id')->where('pid', $cat)->get()); |
|||
if (!empty($post2)) { |
|||
foreach ($post2 as $row) { |
|||
$subcat = $subcat . "typeid=" . $row["id"] . " or "; |
|||
} |
|||
} |
|||
$subcat = $subcat . "typeid=" . $cat; |
|||
$data['sql'] = $subcat; |
|||
|
|||
$counts = DB::table("product")->whereRaw($subcat)->count(); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
dd($counts); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$data['posts'] = arclist(array("table" => "product", "sql" => $subcat, "limit" => "$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $cat, "urltype" => "product")); //获取分页列表
|
|||
|
|||
if ($post['templist'] == 'category2') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('wap.goods.index', $data); |
|||
} |
|||
|
|||
//商品详情页
|
|||
public function detail($id) |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('product')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('product_type')->where('id', $post['typeid'])->value('name'); |
|||
if (!$post) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
|
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); |
|||
|
|||
return view('wap.goods.detail', $data); |
|||
} |
|||
} |
@ -1,264 +1,365 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Wap; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class IndexController extends CommonController |
|||
class IndexController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//首页
|
|||
//首页
|
|||
public function index() |
|||
{ |
|||
{ |
|||
return view('wap.index.index'); |
|||
} |
|||
|
|||
//列表页
|
|||
public function category($cat, $page=0) |
|||
{ |
|||
public function category($cat, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} |
|||
if (empty($cat) || !preg_match('/[0-9]+/', $cat)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("catid$cat")){$post = cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat="";$sql=""; |
|||
$post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); |
|||
if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} |
|||
$subcat=$subcat."typeid=".$cat; |
|||
$sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit;
|
|||
$data['sql'] = $sql; |
|||
|
|||
$counts = DB::table("article")->whereRaw($sql)->count(); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} |
|||
$pagesize = sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page*$pagesize; |
|||
|
|||
$data['posts'] = arclist(array("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表
|
|||
|
|||
if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
|
|||
return view('wap.index.'.$post['templist'], $data); |
|||
} |
|||
$subcat = ""; |
|||
$sql = ""; |
|||
$post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); |
|||
if (!empty($post2)) { |
|||
foreach ($post2 as $row) { |
|||
$subcat = $subcat . "typeid=" . $row["id"] . " or "; |
|||
} |
|||
} |
|||
$subcat = $subcat . "typeid=" . $cat; |
|||
$sql = $subcat . " or typeid2 in (" . $cat . ")";//echo $subcat2;exit;
|
|||
$data['sql'] = $sql; |
|||
|
|||
$counts = DB::table("article")->whereRaw($sql)->count(); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
dd($counts); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$data['posts'] = arclist(array("sql" => $sql, "limit" => "$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $cat)); //获取分页列表
|
|||
|
|||
if ($post['templist'] == 'category2') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('wap.index.' . $post['templist'], $data); |
|||
} |
|||
|
|||
//文章详情页
|
|||
public function detail($id) |
|||
{ |
|||
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("detailid$id")){$post = cache("detailid$id");}else{$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name');cache(["detailid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if($post) |
|||
{ |
|||
$cat = $post['typeid']; |
|||
if (cache("detailid$id")) { |
|||
$post = cache("detailid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name'); |
|||
cache(["detailid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); |
|||
} |
|||
else |
|||
{ |
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
if(cache("catid$cat")){$post=cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
if (cache("catid$cat")) { |
|||
$post = cache("catid$cat"); |
|||
} else { |
|||
$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1); |
|||
cache(["catid$cat" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
return view('wap.index.'.$post['temparticle'], $data); |
|||
return view('wap.index.' . $post['temparticle'], $data); |
|||
} |
|||
|
|||
//标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
|
|||
public function tag($tag, $page=0) |
|||
{ |
|||
public function tag($tag, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');} |
|||
if (empty($tag) || !preg_match('/[0-9]+/', $tag)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1); |
|||
$post = object_to_array(DB::table('tagindex')->where('id', $tag)->first(), 1); |
|||
$data['post'] = $post; |
|||
|
|||
$counts=DB::table("taglist")->where('tid',$tag)->count('aid'); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');} |
|||
$pagesize=sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start=$page*$pagesize; |
|||
|
|||
$posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach($posts as $row) |
|||
{ |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
$aid = isset($aid)?implode(',',$aid):""; |
|||
|
|||
if($aid!="") |
|||
{ |
|||
if($post['template']=='tag2') |
|||
{ |
|||
$data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
|
|||
} |
|||
else |
|||
{ |
|||
$data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
|
|||
$counts = DB::table("taglist")->where('tid', $tag)->count('aid'); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$posts = object_to_array(DB::table("taglist")->where('tid', $tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); |
|||
foreach ($posts as $row) { |
|||
$aid[] = $row["aid"]; |
|||
} |
|||
else |
|||
{ |
|||
$aid = isset($aid) ? implode(',', $aid) : ""; |
|||
|
|||
if ($aid != "") { |
|||
if ($post['template'] == 'tag2') { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize", "field" => "title,body")); //获取列表
|
|||
} else { |
|||
$data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize")); //获取列表
|
|||
} |
|||
} else { |
|||
$data['posts'] = ''; //获取列表
|
|||
} |
|||
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $tag, "urltype" => "tag")); //获取分页列表
|
|||
|
|||
if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
if ($post['template'] == 'tag2' || $post['template'] == 'tag3') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('wap.index.'.$post['template'], $data); |
|||
return view('wap.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//标签页
|
|||
//标签页
|
|||
public function tags() |
|||
{ |
|||
return view('wap.index.tags'); |
|||
{ |
|||
return view('wap.index.tags'); |
|||
} |
|||
|
|||
//搜索页
|
|||
public function search($keyword) |
|||
{ |
|||
if(empty($keyword)) |
|||
{ |
|||
echo '请输入正确的关键词';exit; |
|||
} |
|||
public function search($keyword) |
|||
{ |
|||
if (empty($keyword)) { |
|||
echo '请输入正确的关键词'; |
|||
exit; |
|||
} |
|||
|
|||
if(strstr($keyword,"&")) exit; |
|||
if (strstr($keyword, "&")) exit; |
|||
|
|||
$data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword']= $keyword; |
|||
$data['posts'] = object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); |
|||
$data['keyword'] = $keyword; |
|||
|
|||
return view('wap.index.search', $data); |
|||
return view('wap.index.search', $data); |
|||
} |
|||
|
|||
//单页面
|
|||
public function page($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if(!empty($id) && preg_match('/[a-z0-9]+/',$id)) |
|||
{ |
|||
$map['filename']=$id; |
|||
if(cache("pageid$id")){$post=cache("pageid$id");}else{$post = object_to_array(DB::table('page')->where($map)->first(), 1);cache("pageid$id", $post, 2592000);cache(["pageid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} |
|||
{ |
|||
$data = []; |
|||
|
|||
if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) { |
|||
$map['filename'] = $id; |
|||
if (cache("pageid$id")) { |
|||
$post = cache("pageid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('page')->where($map)->first(), 1); |
|||
cache("pageid$id", $post, 2592000); |
|||
cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
if($post) |
|||
{ |
|||
if ($post) { |
|||
$data['post'] = $post; |
|||
} |
|||
else |
|||
{ |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
} |
|||
else |
|||
{ |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('wap.index.'.$post['template'], $data); |
|||
return view('wap.index.' . $post['template'], $data); |
|||
} |
|||
|
|||
//商品列表页
|
|||
public function productcat($cat, $page=0) |
|||
{ |
|||
//商品列表页
|
|||
public function productcat($cat, $page = 0) |
|||
{ |
|||
$pagenow = $page; |
|||
|
|||
if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} |
|||
if (empty($cat) || !preg_match('/[0-9]+/', $cat)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} |
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$data['post'] = $post; |
|||
|
|||
$subcat=""; |
|||
$post2 = object_to_array(DB::table('product_type')->select('id')->where('pid', $cat)->get()); |
|||
if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} |
|||
$subcat=$subcat."typeid=".$cat; |
|||
$data['sql'] = $subcat; |
|||
$subcat = ""; |
|||
$post2 = object_to_array(DB::table('product_type')->select('id')->where('pid', $cat)->get()); |
|||
if (!empty($post2)) { |
|||
foreach ($post2 as $row) { |
|||
$subcat = $subcat . "typeid=" . $row["id"] . " or "; |
|||
} |
|||
} |
|||
$subcat = $subcat . "typeid=" . $cat; |
|||
$data['sql'] = $subcat; |
|||
|
|||
$counts = DB::table("product")->whereRaw($subcat)->count(); |
|||
if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} |
|||
$pagesize = sysconfig('CMS_PAGESIZE');$page=0; |
|||
if($counts % $pagesize){//取总数据量除以每页数的余数
|
|||
$pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
}else{$pages = $counts/$pagesize;} |
|||
if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page*$pagesize; |
|||
$counts = DB::table("product")->whereRaw($subcat)->count(); |
|||
if ($counts > sysconfig('CMS_MAXARC')) { |
|||
$counts = sysconfig('CMS_MAXARC'); |
|||
dd($counts); |
|||
} |
|||
$pagesize = sysconfig('CMS_PAGESIZE'); |
|||
$page = 0; |
|||
if ($counts % $pagesize) {//取总数据量除以每页数的余数
|
|||
$pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
|
|||
} else { |
|||
$pages = $counts / $pagesize; |
|||
} |
|||
if (!empty($pagenow)) { |
|||
if ($pagenow == 1 || $pagenow > $pages) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$page = $pagenow - 1; |
|||
$nextpage = $pagenow + 1; |
|||
$previouspage = $pagenow - 1; |
|||
} else { |
|||
$page = 0; |
|||
$nextpage = 2; |
|||
$previouspage = 0; |
|||
} |
|||
$data['page'] = $page; |
|||
$data['pages'] = $pages; |
|||
$data['counts'] = $counts; |
|||
$start = $page * $pagesize; |
|||
|
|||
$data['posts'] = arclist(array("table"=>"product","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"product")); //获取分页列表
|
|||
$data['posts'] = arclist(array("table" => "product", "sql" => $subcat, "limit" => "$start,$pagesize")); //获取列表
|
|||
$data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $cat, "urltype" => "product")); //获取分页列表
|
|||
|
|||
if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} |
|||
if ($post['templist'] == 'category2') { |
|||
if (!empty($pagenow)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
} |
|||
|
|||
return view('wap.index.'.$post['templist'], $data); |
|||
} |
|||
return view('wap.index.' . $post['templist'], $data); |
|||
} |
|||
|
|||
//商品详情页
|
|||
public function product($id) |
|||
{ |
|||
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} |
|||
{ |
|||
if (empty($id) || !preg_match('/[0-9]+/', $id)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('product')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('product_type')->where('id', $post['typeid'])->value('name'); |
|||
if($post) |
|||
{ |
|||
$cat = $post['typeid']; |
|||
$post = object_to_array(DB::table('product')->where('id', $id)->first(), 1); |
|||
if (empty($post)) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$post['name'] = DB::table('product_type')->where('id', $post['typeid'])->value('name'); |
|||
if ($post) { |
|||
$cat = $post['typeid']; |
|||
$post['body'] = ReplaceKeyword($post['body']); |
|||
if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} |
|||
if (!empty($post['writer'])) { |
|||
$post['writertitle'] = $post['title'] . ' ' . $post['writer']; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); |
|||
} |
|||
else |
|||
{ |
|||
$data['post'] = $post; |
|||
$data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre")); |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); |
|||
$post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); |
|||
|
|||
return view('wap.index.'.$post['temparticle'], $data); |
|||
return view('wap.index.' . $post['temparticle'], $data); |
|||
} |
|||
|
|||
//sitemap页面
|
|||
//sitemap页面
|
|||
public function sitemap() |
|||
{ |
|||
return view('wap.index.sitemap'); |
|||
return view('wap.index.sitemap'); |
|||
} |
|||
|
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
//404页面
|
|||
public function page404() |
|||
{ |
|||
return view('home.404'); |
|||
} |
|||
|
|||
//测试页面
|
|||
public function test() |
|||
public function test() |
|||
{ |
|||
return date("Y-m-d H:i:s",strtotime("2017-04")); |
|||
return date("Y-m-d H:i:s", strtotime("2017-04")); |
|||
} |
|||
} |
@ -0,0 +1,42 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Wap; |
|||
|
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class PageController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
//单页面
|
|||
public function detail($id) |
|||
{ |
|||
$data = []; |
|||
|
|||
if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) { |
|||
$map['filename'] = $id; |
|||
if (cache("pageid$id")) { |
|||
$post = cache("pageid$id"); |
|||
} else { |
|||
$post = object_to_array(DB::table('page')->where($map)->first(), 1); |
|||
cache("pageid$id", $post, 2592000); |
|||
cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000)); |
|||
} |
|||
|
|||
if (!$post) { |
|||
return redirect()->route('page404'); |
|||
} |
|||
$data['post'] = $post; |
|||
} else { |
|||
return redirect()->route('page404'); |
|||
} |
|||
|
|||
$data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); |
|||
|
|||
return view('wap.page.detail', $data); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Weixin; |
|||
|
|||
use App\Common\Helper; |
|||
|
|||
class BaseController extends CommonController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue