Browse Source

队列,事件监听,操作日志

master
Fanli2 4 years ago
parent
commit
9fcc3537e0
  1. 2
      .env.example
  2. 27
      .gitignore
  3. 4
      API文档.html
  4. 4
      README.md
  5. 2
      README.txt
  6. 24
      app/Common/function.php
  7. 36
      app/Console/Commands/SendEmail.php
  8. 38
      app/Console/Commands/UnpayOrderSetInvalid.php
  9. 20
      app/Console/Kernel.php
  10. 8
      app/Events/Event.php
  11. 25
      app/Events/OrderShipped.php
  12. 4
      app/Http/Controllers/Admin/AdminController.php
  13. 2
      app/Http/Controllers/Admin/AdminRoleController.php
  14. 366
      app/Http/Controllers/Admin/ArticleController.php
  15. 90
      app/Http/Controllers/Admin/BaseController.php
  16. 2
      app/Http/Controllers/Admin/BonusController.php
  17. 2
      app/Http/Controllers/Admin/CategoryController.php
  18. 110
      app/Http/Controllers/Admin/CommonController.php
  19. 2
      app/Http/Controllers/Admin/FeedbackController.php
  20. 2
      app/Http/Controllers/Admin/FriendlinkController.php
  21. 3
      app/Http/Controllers/Admin/GoodsBrandController.php
  22. 7
      app/Http/Controllers/Admin/GoodsController.php
  23. 3
      app/Http/Controllers/Admin/GoodstypeController.php
  24. 3
      app/Http/Controllers/Admin/GuestbookController.php
  25. 6
      app/Http/Controllers/Admin/IndexController.php
  26. 3
      app/Http/Controllers/Admin/KeywordController.php
  27. 2
      app/Http/Controllers/Admin/KuaidiController.php
  28. 117
      app/Http/Controllers/Admin/LogController.php
  29. 25
      app/Http/Controllers/Admin/LoginController.php
  30. 2
      app/Http/Controllers/Admin/MenuController.php
  31. 2
      app/Http/Controllers/Admin/OrderController.php
  32. 2
      app/Http/Controllers/Admin/PageController.php
  33. 2
      app/Http/Controllers/Admin/SearchController.php
  34. 2
      app/Http/Controllers/Admin/SearchwordController.php
  35. 2
      app/Http/Controllers/Admin/SlideController.php
  36. 2
      app/Http/Controllers/Admin/SysconfigController.php
  37. 2
      app/Http/Controllers/Admin/TagController.php
  38. 2
      app/Http/Controllers/Admin/UserController.php
  39. 2
      app/Http/Controllers/Admin/UserRankController.php
  40. 2
      app/Http/Controllers/Admin/UserWithdrawController.php
  41. 2
      app/Http/Controllers/Admin/WeixinMenuController.php
  42. 2
      app/Http/Controllers/Api/ArctypeController.php
  43. 2
      app/Http/Controllers/Api/ArticleController.php
  44. 10
      app/Http/Controllers/Api/BaseController.php
  45. 2
      app/Http/Controllers/Api/BonusController.php
  46. 2
      app/Http/Controllers/Api/CartController.php
  47. 2
      app/Http/Controllers/Api/CollectGoodsController.php
  48. 2
      app/Http/Controllers/Api/CommentController.php
  49. 32
      app/Http/Controllers/Api/CommonController.php
  50. 2
      app/Http/Controllers/Api/FeedBackController.php
  51. 2
      app/Http/Controllers/Api/GoodsBrandController.php
  52. 2
      app/Http/Controllers/Api/GoodsController.php
  53. 2
      app/Http/Controllers/Api/GoodsSearchwordController.php
  54. 2
      app/Http/Controllers/Api/GoodsTypeController.php
  55. 2
      app/Http/Controllers/Api/ImageController.php
  56. 2
      app/Http/Controllers/Api/IndexController.php
  57. 2
      app/Http/Controllers/Api/NotifyController.php
  58. 2
      app/Http/Controllers/Api/OrderController.php
  59. 2
      app/Http/Controllers/Api/PageController.php
  60. 2
      app/Http/Controllers/Api/PaymentController.php
  61. 2
      app/Http/Controllers/Api/PaymentNotifyController.php
  62. 2
      app/Http/Controllers/Api/QrcodeController.php
  63. 2
      app/Http/Controllers/Api/RegionController.php
  64. 2
      app/Http/Controllers/Api/SlideController.php
  65. 2
      app/Http/Controllers/Api/UserAddressController.php
  66. 2
      app/Http/Controllers/Api/UserBonusController.php
  67. 2
      app/Http/Controllers/Api/UserController.php
  68. 2
      app/Http/Controllers/Api/UserGoodsHistoryController.php
  69. 2
      app/Http/Controllers/Api/UserMessageController.php
  70. 2
      app/Http/Controllers/Api/UserMoneyController.php
  71. 2
      app/Http/Controllers/Api/UserPointController.php
  72. 2
      app/Http/Controllers/Api/UserRechargeController.php
  73. 2
      app/Http/Controllers/Api/UserWithdrawController.php
  74. 2
      app/Http/Controllers/Api/VerifyCodeController.php
  75. 64
      app/Http/Controllers/Controller.php
  76. 114
      app/Http/Controllers/Home/ArticleController.php
  77. 11
      app/Http/Controllers/Home/BaseController.php
  78. 35
      app/Http/Controllers/Home/CommonController.php
  79. 107
      app/Http/Controllers/Home/GoodsController.php
  80. 544
      app/Http/Controllers/Home/IndexController.php
  81. 444
      app/Http/Controllers/Home/IndexController企业.php
  82. 43
      app/Http/Controllers/Home/PageController.php
  83. 526
      app/Http/Controllers/Home/SearchController.php
  84. 526
      app/Http/Controllers/Home/TagController.php
  85. 311
      app/Http/Controllers/Home/TestController.php
  86. 126
      app/Http/Controllers/Wap/ArticleController.php
  87. 11
      app/Http/Controllers/Wap/BaseController.php
  88. 33
      app/Http/Controllers/Wap/CommonController.php
  89. 108
      app/Http/Controllers/Wap/GoodsController.php
  90. 429
      app/Http/Controllers/Wap/IndexController.php
  91. 42
      app/Http/Controllers/Wap/PageController.php
  92. 79
      app/Http/Controllers/Weixin/AddressController.php
  93. 76
      app/Http/Controllers/Weixin/ArticleController.php
  94. 14
      app/Http/Controllers/Weixin/BaseController.php
  95. 2
      app/Http/Controllers/Weixin/BonusController.php
  96. 2
      app/Http/Controllers/Weixin/CartController.php
  97. 2
      app/Http/Controllers/Weixin/CollectGoodsController.php
  98. 66
      app/Http/Controllers/Weixin/CommonController.php
  99. 9
      app/Http/Controllers/Weixin/FeedbackController.php
  100. 27
      app/Http/Controllers/Weixin/GoodsBrandController.php

2
.env.example

@ -6,7 +6,7 @@ APP_LOG_LEVEL=debug
APP_URL=http://www.lqycms.com
APP_DOMAIN=www.lqycms.com
APP_SUBDOMAIN=m.lqycms.com
APP_API_URL=http://www.lqycms.com/dataapi
APP_API_URL=http://www.lqycms.com/api
APP_WEIXIN_URL=http://www.lqycms.com/weixin
DB_CONNECTION=mysql

27
.gitignore

@ -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

4
API文档.html

@ -5382,7 +5382,7 @@
<tbody>
<tr>
<td>api_url</td>
<td>http://www.lqycms.com/dataapi</td>
<td>http://www.lqycms.com/api</td>
</tr> </tbody>
</table><h5><span class="label label-danger">线上环境</span></h5>
<table class="table table-hover" style="margin-top: 7px;">
@ -5399,7 +5399,7 @@
<tbody>
<tr>
<td>api_url</td>
<td>http://www.lqycms.com/dataapi</td>
<td>http://www.lqycms.com/api</td>
</tr> </tbody>
</table>
</div>

4
README.md

@ -28,7 +28,7 @@ WAP端
2、PHP+Mysql
3、后台登录:http://www.lqycms.com/fladmin/login,账号:admin888,密码:admin
3、后台登录:http://www.lqycms.com/fladmin/login,账号:admin888,密码:123456
4、恢复后台默认账号密码:http://www.lqycms.com/fladmin/recoverpwd
@ -95,7 +95,7 @@ php composer.phar install
php artisan key:generate
4、 登录后台:http://www.lqycms.com/fladmin/login,账号:admin888,密码:admin
4、 登录后台:http://www.lqycms.com/fladmin/login,账号:admin888,密码:123456
顶部按钮,更新缓存

2
README.txt

@ -27,7 +27,7 @@ echo hello > .env
php composer.phar install
php artisan key:generate
4、 登录后台->顶部按钮,更新缓存:/fladmin/login.php,账号:admin888,密码:admin
4、 登录后台->顶部按钮,更新缓存:/fladmin/login.php,账号:admin888,密码:123456
注意

24
app/Common/function.php

@ -1044,21 +1044,19 @@ function dir_delete($dir)
//对象转数组
function object_to_array($object, $get=0)
{
$res = '';
if(!empty($object))
{
if($get==0)
{
foreach($object as $key=>$value)
{
$res[$key] = (array)$value;
}
}
elseif($get==1)
{
$res = (array)$object;
$res = [];
if(empty($object)) {
return $res;
}
if ($get==0) {
foreach ($object as $key=>$value) {
$res[$key] = (array)$value;
}
}
elseif ($get==1) {
$res = (array)$object;
}
return $res;
}

36
app/Console/Commands/SendEmail.php

@ -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');
}
}

38
app/Console/Commands/UnpayOrderSetInvalid.php

@ -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小时未支付,设为无效订单:操作成功');
}
}

20
app/Console/Kernel.php

@ -2,30 +2,36 @@
namespace App\Console;
use DB;
use Log;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
/**
* 应用提供的Artisan命令
*
* @var array
*/
protected $commands = [
//
Commands\UnpayOrderSetInvalid::class,
Commands\SendEmail::class,
];
/**
* Define the application's command schedule.
/**
* 定义应用的命令调度
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
Log::info('----Schedule----');
// 使用 command 方法通过命令名或类来调度一个 Artisan 命令
// $schedule->command('unpay_order_set_invalid')->hourly();
// 使用 exec 命令可用于发送命令到操作系统
// $schedule->exec('node /home/forge/script.js')->daily();
}
/**

8
app/Events/Event.php

@ -0,0 +1,8 @@
<?php
namespace App\Events;
abstract class Event
{
//
}

25
app/Events/OrderShipped.php

@ -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----');
}
}

4
app/Http/Controllers/Admin/AdminController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\AdminLogic;
use App\Http\Model\Admin;
class AdminController extends CommonController
class AdminController extends BaseController
{
public function __construct()
{
@ -25,7 +25,7 @@ class AdminController extends CommonController
$where = function ($query) use ($res) {
if(isset($_REQUEST["keyword"]))
{
$query->where('username', 'like', '%'.$_REQUEST['keyword'].'%');
$query->where('name', 'like', '%'.$_REQUEST['keyword'].'%');
}
if(isset($_REQUEST["role_id"]))

2
app/Http/Controllers/Admin/AdminRoleController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\AdminRoleLogic;
use App\Http\Model\AdminRole;
class AdminRoleController extends CommonController
class AdminRoleController extends BaseController
{
public function __construct()
{

366
app/Http/Controllers/Admin/ArticleController.php

@ -1,11 +1,13 @@
<?php
namespace App\Http\Controllers\Admin;
use DB;
use App\Common\ReturnData;
use Illuminate\Http\Request;
use App\Http\Logic\ArticleLogic;
class ArticleController extends CommonController
class ArticleController extends BaseController
{
public function __construct()
{
@ -17,36 +19,32 @@ class ArticleController extends CommonController
return new ArticleLogic();
}
public function index()
public function index()
{
$res = '';
$where = function ($query) use ($res) {
if(isset($_REQUEST["keyword"]))
{
$query->where('title', 'like', '%'.$_REQUEST['keyword'].'%');
}
if(isset($_REQUEST["typeid"]) && $_REQUEST["typeid"]!=0)
{
$query->where('typeid', $_REQUEST["typeid"]);
}
if(isset($_REQUEST["id"]))
{
$query->where('typeid', $_REQUEST["id"]);
}
if(isset($_REQUEST["ischeck"]))
{
$query->where('ischeck', $_REQUEST["ischeck"]); //未审核过的文章
}
$res = '';
$where = function ($query) use ($res) {
if (isset($_REQUEST["keyword"])) {
$query->where('title', 'like', '%' . $_REQUEST['keyword'] . '%');
}
if (isset($_REQUEST["typeid"]) && $_REQUEST["typeid"] != 0) {
$query->where('typeid', $_REQUEST["typeid"]);
}
if (isset($_REQUEST["id"])) {
$query->where('typeid', $_REQUEST["id"]);
}
if (isset($_REQUEST["ischeck"])) {
$query->where('ischeck', $_REQUEST["ischeck"]); //未审核过的文章
}
};
$posts = $this->getLogic()->getPaginate($where, array('id', 'desc'));
$data['posts'] = $posts;
return view('admin.article.index', $data);
return view('admin.article.index', $data);
//if(!empty($_GET["id"])){$id = $_GET["id"];}else {$id="";}if(preg_match('/[0-9]*/',$id)){}else{exit;}
@ -78,192 +76,218 @@ class ArticleController extends CommonController
public function add()
{
$data = '';
if(!empty($_REQUEST["catid"])){$data['catid'] = $_REQUEST["catid"];}else{$data['catid'] = 0;}
$data['catid'] = 0;
if (isset($_REQUEST["catid"]) && $_REQUEST["catid"] > 0) {
$data['catid'] = $_REQUEST["catid"];
}
return view('admin.article.add', $data);
}
public function doadd()
{
$litpic="";if(!empty($_POST["litpic"])){$litpic = $_POST["litpic"];}else{$_POST['litpic']="";} //缩略图
if(empty($_POST["description"])){if(!empty($_POST["body"])){$_POST['description']=cut_str($_POST["body"]);}} //description
$content="";if(!empty($_POST["body"])){$content = $_POST["body"];}
$_POST['user_id'] = $_SESSION['admin_user_info']['id']; // 发布者id
//关键词
if(!empty($_POST["keywords"]))
{
$_POST['keywords']=str_replace("",",",$_POST["keywords"]);
}
else
{
if(!empty($_POST["title"]))
{
$title=$_POST["title"];
$title=str_replace("","",$title);
$title=str_replace(",","",$title);
$_POST['keywords']=get_keywords($title);//标题分词
}
}
if(isset($_POST["dellink"]) && $_POST["dellink"]==1 && !empty($content)){$content=replacelinks($content,array(sysconfig('CMS_BASEHOST')));} //删除非站内链接
$_POST['body']=$content;
//提取第一个图片为缩略图
if(isset($_POST["autolitpic"]) && $_POST["autolitpic"] && empty($litpic))
{
if(getfirstpic($content))
{
//获取文章内容的第一张图片
$imagepath = '.'.getfirstpic($content);
//获取后缀名
preg_match_all ("/\/(.+)\.(gif|jpg|jpeg|bmp|png)$/iU",$imagepath,$out, PREG_PATTERN_ORDER);
$saveimage='./uploads/'.date('Y/m',time()).'/'.basename($imagepath,'.'.$out[2][0]).'-lp.'.$out[2][0];
//生成缩略图,按照原图的比例生成一个最大为240*180的缩略图
\Intervention\Image\Facades\Image::make($imagepath)->resize(sysconfig('CMS_IMGWIDTH'), sysconfig('CMS_IMGHEIGHT'))->save($saveimage);
//缩略图路径
$_POST['litpic']='/uploads/'.date('Y/m',time()).'/'.basename($imagepath,'.'.$out[2][0]).'-lp.'.$out[2][0];
}
}
$res = $this->getLogic()->add($_POST);
if($res['code']==ReturnData::SUCCESS)
{
success_jump($res['msg'], route('admin_article'));
}
else
{
error_jump($res['msg']);
}
$litpic = "";
if (!empty($_POST["litpic"])) {
$litpic = $_POST["litpic"];
} else {
$_POST['litpic'] = "";
} //缩略图
if (empty($_POST["description"])) {
if (!empty($_POST["body"])) {
$_POST['description'] = cut_str($_POST["body"]);
}
} //description
$content = "";
if (!empty($_POST["body"])) {
$content = $_POST["body"];
}
$_POST['user_id'] = $_SESSION['admin_info']['id']; // 发布者id
//关键词
if (!empty($_POST["keywords"])) {
$_POST['keywords'] = str_replace("", ",", $_POST["keywords"]);
} else {
if (!empty($_POST["title"])) {
$title = $_POST["title"];
$title = str_replace("", "", $title);
$title = str_replace(",", "", $title);
$_POST['keywords'] = get_keywords($title);//标题分词
}
}
if (isset($_POST["dellink"]) && $_POST["dellink"] == 1 && !empty($content)) {
$content = replacelinks($content, array(sysconfig('CMS_BASEHOST')));
} //删除非站内链接
$_POST['body'] = $content;
//提取第一个图片为缩略图
if (isset($_POST["autolitpic"]) && $_POST["autolitpic"] && empty($litpic)) {
if (getfirstpic($content)) {
//获取文章内容的第一张图片
$imagepath = '.' . getfirstpic($content);
//获取后缀名
preg_match_all("/\/(.+)\.(gif|jpg|jpeg|bmp|png)$/iU", $imagepath, $out, PREG_PATTERN_ORDER);
$saveimage = './uploads/' . date('Y/m', time()) . '/' . basename($imagepath, '.' . $out[2][0]) . '-lp.' . $out[2][0];
//生成缩略图,按照原图的比例生成一个最大为240*180的缩略图
\Intervention\Image\Facades\Image::make($imagepath)->resize(sysconfig('CMS_IMGWIDTH'), sysconfig('CMS_IMGHEIGHT'))->save($saveimage);
//缩略图路径
$_POST['litpic'] = '/uploads/' . date('Y/m', time()) . '/' . basename($imagepath, '.' . $out[2][0]) . '-lp.' . $out[2][0];
}
}
$res = $this->getLogic()->add($_POST);
if ($res['code'] == ReturnData::SUCCESS) {
success_jump($res['msg'], route('admin_article'));
} else {
error_jump($res['msg']);
}
}
public function edit()
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else {$id="";}if(preg_match('/[0-9]*/',$id)){}else{exit;}
if (!empty($_GET["id"])) {
$id = $_GET["id"];
} else {
$id = "";
}
if (preg_match('/[0-9]*/', $id)) {
} else {
exit;
}
$data['id'] = $id;
$data['post'] = object_to_array($this->getLogic()->getOne(['id'=>$id]), 1);
$data['id'] = $id;
$data['post'] = object_to_array($this->getLogic()->getOne(['id' => $id]), 1);
return view('admin.article.edit', $data);
}
public function doedit()
{
if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else{$id="";exit;}
$litpic="";if(!empty($_POST["litpic"])){$litpic = $_POST["litpic"];}else{$_POST['litpic']="";} //缩略图
if(empty($_POST["description"])){if(!empty($_POST["body"])){$_POST['description']=cut_str($_POST["body"]);}} //description
$content="";if(!empty($_POST["body"])){$content = $_POST["body"];}
if(!empty($_POST["keywords"]))
{
$_POST['keywords']=str_replace("",",",$_POST["keywords"]);
}
else
{
if(!empty($_POST["title"]))
{
$title=$_POST["title"];
$title=str_replace("","",$title);
$title=str_replace(",","",$title);
$_POST['keywords']=get_keywords($title);//标题分词
}
}
if(isset($_POST["dellink"]) && $_POST["dellink"]==1 && !empty($content)){$content=replacelinks($content,array(CMS_BASEHOST));} //删除非站内链接
$_POST['body']=$content;
//提取第一个图片为缩略图
if(isset($_POST["autolitpic"]) && $_POST["autolitpic"] && empty($litpic))
{
if(getfirstpic($content))
{
//获取文章内容的第一张图片
$imagepath = '.'.getfirstpic($content);
//获取后缀名
preg_match_all ("/\/(.+)\.(gif|jpg|jpeg|bmp|png)$/iU",$imagepath,$out, PREG_PATTERN_ORDER);
$saveimage='./uploads/'.date('Y/m',time()).'/'.basename($imagepath,'.'.$out[2][0]).'-lp.'.$out[2][0];
//生成缩略图,按照原图的比例生成一个最大为240*180的缩略图
\Intervention\Image\Facades\Image::make($imagepath)->resize(sysconfig('CMS_IMGWIDTH'), sysconfig('CMS_IMGHEIGHT'))->save($saveimage);
//缩略图路径
$_POST['litpic']='/uploads/'.date('Y/m',time()).'/'.basename($imagepath,'.'.$out[2][0]).'-lp.'.$out[2][0];
}
}
$res = $this->getLogic()->edit($_POST,array('id'=>$id));
if($res['code']==ReturnData::SUCCESS)
{
success_jump($res['msg'], route('admin_article'));
}
else
{
error_jump($res['msg']);
}
if (!empty($_POST["id"])) {
$id = $_POST["id"];
unset($_POST["id"]);
} else {
$id = "";
exit;
}
$litpic = "";
if (!empty($_POST["litpic"])) {
$litpic = $_POST["litpic"];
} else {
$_POST['litpic'] = "";
} //缩略图
if (empty($_POST["description"])) {
if (!empty($_POST["body"])) {
$_POST['description'] = cut_str($_POST["body"]);
}
} //description
$content = "";
if (!empty($_POST["body"])) {
$content = $_POST["body"];
}
if (!empty($_POST["keywords"])) {
$_POST['keywords'] = str_replace("", ",", $_POST["keywords"]);
} else {
if (!empty($_POST["title"])) {
$title = $_POST["title"];
$title = str_replace("", "", $title);
$title = str_replace(",", "", $title);
$_POST['keywords'] = get_keywords($title);//标题分词
}
}
if (isset($_POST["dellink"]) && $_POST["dellink"] == 1 && !empty($content)) {
$content = replacelinks($content, array(CMS_BASEHOST));
} //删除非站内链接
$_POST['body'] = $content;
//提取第一个图片为缩略图
if (isset($_POST["autolitpic"]) && $_POST["autolitpic"] && empty($litpic)) {
if (getfirstpic($content)) {
//获取文章内容的第一张图片
$imagepath = '.' . getfirstpic($content);
//获取后缀名
preg_match_all("/\/(.+)\.(gif|jpg|jpeg|bmp|png)$/iU", $imagepath, $out, PREG_PATTERN_ORDER);
$saveimage = './uploads/' . date('Y/m', time()) . '/' . basename($imagepath, '.' . $out[2][0]) . '-lp.' . $out[2][0];
//生成缩略图,按照原图的比例生成一个最大为240*180的缩略图
\Intervention\Image\Facades\Image::make($imagepath)->resize(sysconfig('CMS_IMGWIDTH'), sysconfig('CMS_IMGHEIGHT'))->save($saveimage);
//缩略图路径
$_POST['litpic'] = '/uploads/' . date('Y/m', time()) . '/' . basename($imagepath, '.' . $out[2][0]) . '-lp.' . $out[2][0];
}
}
$res = $this->getLogic()->edit($_POST, array('id' => $id));
if ($res['code'] == ReturnData::SUCCESS) {
success_jump($res['msg'], route('admin_article'));
} else {
error_jump($res['msg']);
}
}
//删除文章
//删除文章
public function del()
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump("删除失败!请重新提交");}
if (!empty($_GET["id"])) {
$id = $_GET["id"];
} else {
error_jump("删除失败!请重新提交");
}
if(DB::table("article")->whereIn("id", explode(',', $id))->delete())
{
if (DB::table("article")->whereIn("id", explode(',', $id))->delete()) {
success_jump("$id ,删除成功");
} else {
error_jump("$id ,删除失败!请重新提交");
}
else
{
error_jump("$id ,删除失败!请重新提交");
}
}
//重复文章列表
//重复文章列表
public function repetarc()
{
$data['posts'] = object_to_array(DB::table('article')->select(DB::raw('title,count(*) AS count'))->orderBy('count', 'desc')->groupBy('title')->having('count', '>', 1)->get());
$data['posts'] = object_to_array(DB::table('article')->select(DB::raw('title,count(*) AS count'))->orderBy('count', 'desc')->groupBy('title')->having('count', '>', 1)->get());
return view('admin.article.repetarc', $data);
}
//推荐文章
public function recommendarc()
//推荐文章
public function recommendarc()
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump("您访问的页面不存在或已被删除");} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
$data['tuijian'] = 1;
if(DB::table("article")->whereIn("id", explode(',', $id))->update($data))
{
success_jump("$id ,推荐成功");
if (!empty($_GET["id"])) {
$id = $_GET["id"];
} else {
error_jump("您访问的页面不存在或已被删除");
} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
$data['tuijian'] = 1;
if (DB::table("article")->whereIn("id", explode(',', $id))->update($data)) {
success_jump("$id ,推荐成功");
} else {
error_jump("$id ,推荐失败!请重新提交");
}
else
{
error_jump("$id ,推荐失败!请重新提交");
}
}
//检测重复文章数量
//检测重复文章数量
public function articleexists()
{
$res = '';
$where = function ($query) use ($res) {
if(isset($_REQUEST["title"]))
{
$query->where('title', $_REQUEST["title"]);
}
if(isset($_REQUEST["id"]))
{
$query->where('id', '<>', $_REQUEST["id"]);
}
$res = '';
$where = function ($query) use ($res) {
if (isset($_REQUEST["title"])) {
$query->where('title', $_REQUEST["title"]);
}
if (isset($_REQUEST["id"])) {
$query->where('id', '<>', $_REQUEST["id"]);
}
};
return DB::table("article")->where($where)->count();

90
app/Http/Controllers/Admin/BaseController.php

@ -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);
}
}

2
app/Http/Controllers/Admin/BonusController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\BonusLogic;
use App\Http\Model\Bonus;
class BonusController extends CommonController
class BonusController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/CategoryController.php

@ -4,7 +4,7 @@ use DB;
use App\Common\ReturnData;
use Illuminate\Http\Request;
class CategoryController extends CommonController
class CategoryController extends BaseController
{
public function __construct()
{

110
app/Http/Controllers/Admin/CommonController.php

@ -1,4 +1,5 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
@ -6,52 +7,23 @@ use DB;
class CommonController extends Controller
{
public $user_info;
public $admin_info;
public function __construct()
{
parent::__construct();
//判断是否登录
if(isset($_SESSION['admin_user_info']))
{
$this->user_info = $_SESSION['admin_user_info'];
}
else
{
header("Location:".route('page404'));
exit();
}
//判断是否拥有权限
if($_SESSION['admin_user_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_user_info']['role_id'], 'menu_id' => $menu_id])->first();
if(!$check)
{
error_jump('你没有权限访问,请联系管理员', route('admin'));
}
}
}
// 添加管理员操作记录
$this->operation_log_add();
}
/**
* 获取分页数据及分页导航
* @param string $modelname 模块名与数据库表名对应
* @param array $where 查询条件
* @param string $orderby 查询排序
* @param string $field 要返回数据的字段
* @param int $listRows 每页数量,默认30条
* @param array $where 查询条件
* @param string $orderby 查询排序
* @param string $field 要返回数据的字段
* @param int $listRows 每页数量,默认30条
*
* @return 格式化后输出的数据。内容格式为:
* - "code" (string):代码
@ -68,39 +40,53 @@ class CommonController extends Controller
{
$model = \DB::table($modelname);
//查询条件
if(!empty($where)){$model = $model->where($where);}
//查询条件
if (!empty($where)) {
$model = $model->where($where);
}
//排序
if($orderby!='')
{
if($orderby == 'rand()')
{
//排序
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
{
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
{
} else {
$model = $model->orderBy('id', 'desc');
}
//要返回的字段
if($field!='*'){$model = $model->select(\DB::raw($field));}
//要返回的字段
if ($field != '*') {
$model = $model->select(\DB::raw($field));
}
return $model->paginate($listRows);
}
// 添加管理员操作记录
public function operation_log_add()
{
$time = time();
// 记录操作
if ($this->admin_info) {
$data['login_id'] = $this->admin_info['id'];
$data['login_name'] = $this->admin_info['name'];
}
$data['type'] = 1;
$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);
}
}

2
app/Http/Controllers/Admin/FeedbackController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\FeedbackLogic;
use App\Http\Model\Feedback;
class FeedbackController extends CommonController
class FeedbackController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/FriendlinkController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\FriendlinkLogic;
use App\Http\Model\Friendlink;
class FriendlinkController extends CommonController
class FriendlinkController extends BaseController
{
public function __construct()
{

3
app/Http/Controllers/Admin/GoodsBrandController.php

@ -1,10 +1,9 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class GoodsBrandController extends CommonController
class GoodsBrandController extends BaseController
{
public function __construct()
{

7
app/Http/Controllers/Admin/GoodsController.php

@ -1,10 +1,9 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class GoodsController extends CommonController
class GoodsController extends BaseController
{
public function __construct()
{
@ -59,7 +58,7 @@ class GoodsController extends CommonController
$litpic="";if(!empty($_POST["litpic"])){$litpic = $_POST["litpic"];}else{$_POST['litpic']="";} //缩略图
if(empty($_POST["description"])){if(!empty($_POST["body"])){$_POST['description']=cut_str($_POST["body"]);}} //description
$_POST['add_time'] = $_POST['pubdate'] = time(); //添加&更新时间
$_POST['user_id'] = $_SESSION['admin_user_info']['id']; // 发布者id
$_POST['user_id'] = $_SESSION['admin_info']['id']; // 发布者id
//关键词
if(!empty($_POST["keywords"]))
@ -132,7 +131,7 @@ class GoodsController extends CommonController
$litpic="";if(!empty($_POST["litpic"])){$litpic = $_POST["litpic"];}else{$_POST['litpic']="";} //缩略图
if(empty($_POST["description"])){if(!empty($_POST["body"])){$_POST['description']=cut_str($_POST["body"]);}}//description
$_POST['pubdate'] = time();//更新时间
$_POST['user_id'] = $_SESSION['admin_user_info']['id']; // 修改者id
$_POST['user_id'] = $_SESSION['admin_info']['id']; // 修改者id
//关键词
if(!empty($_POST["keywords"]))

3
app/Http/Controllers/Admin/GoodstypeController.php

@ -1,10 +1,9 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class GoodsTypeController extends CommonController
class GoodsTypeController extends BaseController
{
public function __construct()
{

3
app/Http/Controllers/Admin/GuestbookController.php

@ -1,10 +1,9 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class GuestbookController extends CommonController
class GuestbookController extends BaseController
{
public function __construct()
{

6
app/Http/Controllers/Admin/IndexController.php

@ -1,9 +1,7 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
class IndexController extends CommonController
class IndexController extends BaseController
{
public function __construct()
{
@ -13,7 +11,7 @@ class IndexController extends CommonController
public function index()
{
$leftmenu = new \App\Http\Model\Menu();
$data['menus'] = $leftmenu::getPermissionsMenu($_SESSION['admin_user_info']['role_id']);
$data['menus'] = $leftmenu::getPermissionsMenu($_SESSION['admin_info']['role_id']);
return view('admin.index.index', $data);
}

3
app/Http/Controllers/Admin/KeywordController.php

@ -1,10 +1,9 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class KeywordController extends CommonController
class KeywordController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/KuaidiController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\KuaidiLogic;
use App\Http\Model\Kuaidi;
class KuaidiController extends CommonController
class KuaidiController extends BaseController
{
public function __construct()
{

117
app/Http/Controllers/Admin/LogController.php

@ -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']);
}
}

25
app/Http/Controllers/Admin/LoginController.php

@ -1,12 +1,11 @@
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Log;
class LoginController extends BaseController
class LoginController extends CommonController
{
//页面跳转
public function jump()
@ -19,7 +18,7 @@ class LoginController extends BaseController
*/
public function login()
{
if(isset($_SESSION['admin_user_info']))
if(isset($_SESSION['admin_info']))
{
header("Location: ".route('admin'));
exit;
@ -36,18 +35,18 @@ class LoginController extends BaseController
if(!empty($_POST["username"])){$username = $_POST["username"];}else{$username='';exit;}//用户名
if(!empty($_POST["pwd"])){$pwd = md5($_POST["pwd"]);}else{$pwd='';exit;}//密码
$admin_user = DB::table('admin')->where(array('username' => $username, 'pwd' => $pwd))->orWhere(function ($query) use ($username, $pwd) {
$admin_user = DB::table('admin')->where(array('name' => $username, 'pwd' => $pwd))->orWhere(function ($query) use ($username, $pwd) {
$query->where('email', '=', $username)->where('pwd', '=', $pwd);
})->first();
if($admin_user)
{
$admin_user_info = object_to_array($admin_user, 1);
$admin_user_info['rolename'] = DB::table('admin_role')->where(array('id'=>$admin_user->role_id))->value('name');
$admin_info = object_to_array($admin_user, 1);
$admin_info['rolename'] = DB::table('admin_role')->where(array('id'=>$admin_user->role_id))->value('name');
$_SESSION['admin_user_info'] = $admin_user_info;
$_SESSION['admin_info'] = $admin_info;
DB::table('admin')->where(array('id'=>$admin_user->role_id))->update(array('logintime' => time()));
DB::table('admin')->where(array('id'=>$admin_user->id))->update(array('login_time' => time()));
return redirect()->route('admin');
}
@ -66,7 +65,7 @@ class LoginController extends BaseController
//密码恢复
public function recoverpwd()
{
$data["username"] = "admin888";
$data["name"] = "admin888";
$data["pwd"] = "21232f297a57a5a743894a0e4a801fc3";
if(DB::table('admin')->where('id', 1)->update($data))
@ -82,17 +81,17 @@ class LoginController extends BaseController
*/
public function userexists()
{
$map['username'] = "";
if(isset($_POST["username"]) && !empty($_POST["username"]))
$where['name'] = "";
if(isset($_POST["name"]) && !empty($_POST["name"]))
{
$map['username'] = $_POST["username"];
$where['name'] = $_POST["name"];
}
else
{
return 0;
}
return DB::table("admin")->where($map)->count();
return DB::table("admin")->where($where)->count();
}
//测试

2
app/Http/Controllers/Admin/MenuController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class MenuController extends CommonController
class MenuController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/OrderController.php

@ -10,7 +10,7 @@ use DB;
use App\Common\ReturnData;
use Illuminate\Http\Request;
class OrderController extends CommonController
class OrderController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/PageController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class PageController extends CommonController
class PageController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/SearchController.php

@ -1,7 +1,7 @@
<?php
namespace app\fladmin\controller;
class Search extends Base
class Search extends BaseController
{
public function _initialize()
{

2
app/Http/Controllers/Admin/SearchwordController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class SearchwordController extends CommonController
class SearchwordController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/SlideController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\SlideLogic;
use App\Http\Model\Slide;
class SlideController extends CommonController
class SlideController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/SysconfigController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class SysconfigController extends CommonController
class SysconfigController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/TagController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class TagController extends CommonController
class TagController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/UserController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\UserLogic;
use App\Http\Model\User;
class UserController extends CommonController
class UserController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/UserRankController.php

@ -6,7 +6,7 @@ use DB;
use App\Http\Model\UserRank;
use App\Common\Helper;
class UserRankController extends CommonController
class UserRankController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/UserWithdrawController.php

@ -7,7 +7,7 @@ use Illuminate\Http\Request;
use App\Http\Logic\UserWithdrawLogic;
use App\Http\Model\UserWithdraw;
class UserWithdrawController extends CommonController
class UserWithdrawController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Admin/WeixinMenuController.php

@ -8,7 +8,7 @@ use App\Http\Logic\WeixinMenuLogic;
use App\Http\Model\WeixinMenu;
use App\Common\Wechat\WechatMenu;
class WeixinMenuController extends CommonController
class WeixinMenuController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/ArctypeController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Arctype;
use App\Http\Logic\ArctypeLogic;
class ArctypeController extends CommonController
class ArctypeController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/ArticleController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Article;
use App\Http\Logic\ArticleLogic;
class ArticleController extends CommonController
class ArticleController extends BaseController
{
public function __construct()
{

10
app/Http/Controllers/Api/BaseController.php

@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers\Api;
class BaseController extends CommonController
{
public function __construct()
{
parent::__construct();
}
}

2
app/Http/Controllers/Api/BonusController.php

@ -10,7 +10,7 @@ use App\Http\Model\Bonus;
use App\Http\Logic\BonusLogic;
use App\Http\Model\UserBonus;
class BonusController extends CommonController
class BonusController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/CartController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Cart;
use App\Http\Logic\CartLogic;
class CartController extends CommonController
class CartController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/CollectGoodsController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\CollectGoods;
use App\Http\Logic\CollectGoodsLogic;
class CollectGoodsController extends CommonController
class CollectGoodsController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/CommentController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Comment;
use App\Http\Logic\CommentLogic;
class CommentController extends CommonController
class CommentController extends BaseController
{
public function __construct()
{

32
app/Http/Controllers/Api/CommonController.php

@ -5,8 +5,40 @@ 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'] = 3;
$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);
}
}

2
app/Http/Controllers/Api/FeedBackController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\FeedBack;
use App\Http\Logic\FeedBackLogic;
class FeedBackController extends CommonController
class FeedBackController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/GoodsBrandController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\GoodsBrand;
use App\Http\Logic\GoodsBrandLogic;
class GoodsBrandController extends CommonController
class GoodsBrandController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/GoodsController.php

@ -10,7 +10,7 @@ use App\Http\Model\Goods;
use App\Http\Logic\GoodsLogic;
use App\Http\Logic\GoodsSearchwordLogic;
class GoodsController extends CommonController
class GoodsController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/GoodsSearchwordController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\GoodsSearchword;
use App\Http\Logic\GoodsSearchwordLogic;
class GoodsSearchwordController extends CommonController
class GoodsSearchwordController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/GoodsTypeController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\GoodsType;
use App\Http\Logic\GoodsTypeLogic;
class GoodsTypeController extends CommonController
class GoodsTypeController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/ImageController.php

@ -5,7 +5,7 @@ use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Helper;
class ImageController extends CommonController
class ImageController extends BaseController
{
public $path;

2
app/Http/Controllers/Api/IndexController.php

@ -6,7 +6,7 @@ use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Token;
class IndexController extends CommonController
class IndexController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/NotifyController.php

@ -6,7 +6,7 @@ use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Helper;
class NotifyController extends CommonController
class NotifyController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/OrderController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Order;
use App\Http\Logic\OrderLogic;
class OrderController extends CommonController
class OrderController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/PageController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Page;
use App\Http\Logic\PageLogic;
class PageController extends CommonController
class PageController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/PaymentController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Payment;
use App\Http\Logic\PaymentLogic;
class PaymentController extends CommonController
class PaymentController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/PaymentNotifyController.php

@ -7,7 +7,7 @@ use App\Common\ReturnData;
use App\Common\Token;
use App\Http\Model\UserMoney;
class PaymentNotifyController extends CommonController
class PaymentNotifyController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/QrcodeController.php

@ -5,7 +5,7 @@ use App\Common\ReturnData;
use App\Common\Helper;
//二维码,如果输出乱码就转成base64输出
class QrcodeController extends CommonController
class QrcodeController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/RegionController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Region;
use App\Http\Logic\RegionLogic;
class RegionController extends CommonController
class RegionController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/SlideController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\Slide;
use App\Http\Logic\SlideLogic;
class SlideController extends CommonController
class SlideController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserAddressController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\UserAddress;
use App\Http\Logic\UserAddressLogic;
class UserAddressController extends CommonController
class UserAddressController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserBonusController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\UserBonus;
use App\Http\Logic\UserBonusLogic;
class UserBonusController extends CommonController
class UserBonusController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\User;
use App\Http\Logic\UserLogic;
class UserController extends CommonController
class UserController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserGoodsHistoryController.php

@ -10,7 +10,7 @@ use App\Http\Model\UserGoodsHistory;
use App\Http\Logic\UserGoodsHistoryLogic;
//我的足迹
class UserGoodsHistoryController extends CommonController
class UserGoodsHistoryController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserMessageController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\UserMessage;
use App\Http\Logic\UserMessageLogic;
class UserMessageController extends CommonController
class UserMessageController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserMoneyController.php

@ -10,7 +10,7 @@ use App\Http\Model\UserMoney;
use App\Http\Logic\UserMoneyLogic;
//余额明细
class UserMoneyController extends CommonController
class UserMoneyController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserPointController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\UserPoint;
use App\Http\Logic\UserPointLogic;
class UserPointController extends CommonController
class UserPointController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserRechargeController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\UserRecharge;
use App\Http\Logic\UserRechargeLogic;
class UserRechargeController extends CommonController
class UserRechargeController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/UserWithdrawController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\UserWithdraw;
use App\Http\Logic\UserWithdrawLogic;
class UserWithdrawController extends CommonController
class UserWithdrawController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Api/VerifyCodeController.php

@ -9,7 +9,7 @@ use App\Common\Token;
use App\Http\Model\VerifyCode;
use App\Http\Logic\VerifyCodeLogic;
class VerifyCodeController extends CommonController
class VerifyCodeController extends BaseController
{
public function __construct()
{

64
app/Http/Controllers/Controller.php

@ -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];
}
}

114
app/Http/Controllers/Home/ArticleController.php

@ -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);
}
}

11
app/Http/Controllers/Home/BaseController.php

@ -0,0 +1,11 @@
<?php
namespace App\Http\Controllers\Home;
class BaseController extends CommonController
{
public function __construct()
{
parent::__construct();
}
}

35
app/Http/Controllers/Home/CommonController.php

@ -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);
}
}

107
app/Http/Controllers/Home/GoodsController.php

@ -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);
}
}

544
app/Http/Controllers/Home/IndexController.php

@ -1,60 +1,60 @@
<?php
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Home\CommonController;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class IndexController extends CommonController
class IndexController extends BaseController
{
public function __construct()
{
parent::__construct();
}
//首页
//首页
public function index()
{
{
//推荐商品列表
$postdata = array(
'tuijian' => 1,
'status' => 0,
'limit' => 6,
'limit' => 6,
'offset' => 0
);
$url = env('APP_API_URL')."/goods_list";
$res = curl_request($url,$postdata,'GET');
);
$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;}
if (isset($_REQUEST['page'])) {
$offset = ($_REQUEST['page'] - 1) * $pagesize;
}
$postdata = array(
'status' => 0,
'limit' => $pagesize,
'limit' => $pagesize,
'offset' => $offset
);
$url = env('APP_API_URL')."/goods_list";
$res = curl_request($url,$postdata,'GET');
);
$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);
$data['totalpage'] = ceil($res['data']['count'] / $pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
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 ($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)
{
@ -66,65 +66,70 @@ class IndexController extends CommonController
}
}
exit(json_encode($html));
}
exit(json_encode($html));
}
//商品分类列表
$postdata = array(
'pid' => 0,
'limit' => 15,
'pid' => 0,
'limit' => 15,
'offset' => 0
);
$url = env('APP_API_URL')."/goodstype_list";
$res = curl_request($url,$postdata,'GET');
);
$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,
'type' => 0,
'limit' => 5,
'offset' => 0
);
$url = env('APP_API_URL')."/slide_list";
$res = curl_request($url,$postdata,'GET');
);
$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);
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');}
{
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;}
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');
$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);
$data['totalpage'] = ceil($res['data']['count'] / $pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
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 ($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)
{
@ -136,114 +141,121 @@ class IndexController extends CommonController
}
}
exit(json_encode($html));
}
exit(json_encode($html));
}
//商品分类列表
$postdata = array(
'pid' => 0,
'limit' => 15,
'pid' => 0,
'limit' => 15,
'offset' => 0
);
$url = env('APP_API_URL')."/goodstype_list";
$res = curl_request($url,$postdata,'GET');
);
$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);
}
return view('home.index.goodslist', $data);
}
//商品详情页
public function goods($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');
}
$where['id'] = $id;
$where['status'] = 0;
$data['post'] = logic('Goods')->getOne($where);
if(!$data['post']){return redirect()->route('page404');}
if (!$data['post']) {
return redirect()->route('page404');
}
$data['tj_list'] = DB::table('goods')->where(['tuijian'=>1,'status'=>0])->orderBy('id', 'desc')->get();
$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());
{
$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)
{
public function listpageurl($http_host, $query_string, $page = 0)
{
$res = '';
foreach(explode("&",$query_string) as $row)
{
if($row)
{
$canshu = explode("=",$row);
foreach (explode("&", $query_string) as $row) {
if ($row) {
$canshu = explode("=", $row);
$res[$canshu[0]] = $canshu[1];
}
}
if(isset($res['page']))
{
if (isset($res['page'])) {
unset($res['page']);
}
if($page==1 || $page==0){}else{$res['page'] = $page;}
if ($page == 1 || $page == 0) {
} else {
$res['page'] = $page;
}
if($res){$res = $http_host.'?'.http_build_query($res);}
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');
'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;}
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');}
if ($request->input('typeid', null) != null) {
$postdata2['typeid'] = $request->input('typeid');
}
$url = env('APP_API_URL')."/article_list";
$res = curl_request($url,$postdata2,'GET');
$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);
$data['totalpage'] = ceil($res['data']['count'] / $pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
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>';
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));
}
exit(json_encode($html));
}
return view('home.index.'.$data['post']['templist'], $data);
}
return view('home.index.' . $data['post']['templist'], $data);
}
//文章列表页
public function arclist(Request $request)
@ -252,235 +264,263 @@ class IndexController extends CommonController
$offset = 0;
//文章分类
if($request->input('typeid', null) != null)
{
if ($request->input('typeid', null) != null) {
$postdata = array(
'id' => $request->input('typeid')
'id' => $request->input('typeid')
);
$url = env('APP_API_URL')."/arctype_detail";
$arctype_detail = curl_request($url,$postdata,'GET');
$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;}
if (isset($_REQUEST['page'])) {
$offset = ($_REQUEST['page'] - 1) * $pagesize;
}
//文章列表
$postdata2 = array(
'limit' => $pagesize,
'limit' => $pagesize,
'offset' => $offset
);
if($request->input('typeid', null) != null){$postdata2['typeid'] = $request->input('typeid');}
);
if ($request->input('typeid', null) != null) {
$postdata2['typeid'] = $request->input('typeid');
}
$url = env('APP_API_URL')."/article_list";
$res = curl_request($url,$postdata2,'GET');
$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);
$data['totalpage'] = ceil($res['data']['count'] / $pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) {
$html = '';
if($res['data']['list'])
{
foreach($res['data']['list'] as $k => $v)
{
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>';
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 .= '<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>';
$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>';
$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));
}
exit(json_encode($html));
}
return view('home.index.arclist', $data);
}
return view('home.index.arclist', $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);
}
//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 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;
}
}
{
$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');
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);
}
}

444
app/Http/Controllers/Home/IndexController企业.php

@ -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);
}
}

43
app/Http/Controllers/Home/PageController.php

@ -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);
}
}

526
app/Http/Controllers/Home/SearchController.php

@ -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);
}
}

526
app/Http/Controllers/Home/TagController.php

@ -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);
}
}

311
app/Http/Controllers/Home/TestController.php

@ -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));
}
}

126
app/Http/Controllers/Wap/ArticleController.php

@ -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);
}
}

11
app/Http/Controllers/Wap/BaseController.php

@ -0,0 +1,11 @@
<?php
namespace App\Http\Controllers\Wap;
class BaseController extends CommonController
{
public function __construct()
{
parent::__construct();
}
}

33
app/Http/Controllers/Wap/CommonController.php

@ -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);
}
}

108
app/Http/Controllers/Wap/GoodsController.php

@ -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);
}
}

429
app/Http/Controllers/Wap/IndexController.php

@ -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"));
}
}

42
app/Http/Controllers/Wap/PageController.php

@ -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);
}
}

79
app/Http/Controllers/Weixin/AddressController.php

@ -1,11 +1,12 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnCode;
class AddressController extends CommonController
class AddressController extends BaseController
{
public function __construct()
{
@ -14,74 +15,72 @@ class AddressController extends CommonController
//收货地址列表
public function index(Request $request)
{
{
$pagesize = 10;
$offset = 0;
if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
if (isset($_REQUEST['page'])) {
$offset = ($_REQUEST['page'] - 1) * $pagesize;
}
//收货地址列表
$postdata = array(
'limit' => $pagesize,
'limit' => $pagesize,
'offset' => $offset,
'access_token' => $_SESSION['weixin_user_info']['access_token']
);
$url = env('APP_API_URL')."/user_address_list";
$res = curl_request($url,$postdata,'GET');
);
$url = env('APP_API_URL') . "/user_address_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 = '';
$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)
{
if ($res['data']['list']) {
foreach ($res['data']['list'] as $k => $v) {
$html .= '<div class="flow-have-adr">';
if($v['is_default']==1)
{
$html .= '<p class="f-h-adr-title"><label>'.$v['name'].'</label><span class="ect-colory">'.$v['mobile'].'</span><span class="fr">默认</span></p>';
}
else
{
$html .= '<p class="f-h-adr-title"><label>'.$v['name'].'</label><span class="ect-colory">'.$v['mobile'].'</span></p>';
if ($v['is_default'] == 1) {
$html .= '<p class="f-h-adr-title"><label>' . $v['name'] . '</label><span class="ect-colory">' . $v['mobile'] . '</span><span class="fr">默认</span></p>';
} else {
$html .= '<p class="f-h-adr-title"><label>' . $v['name'] . '</label><span class="ect-colory">' . $v['mobile'] . '</span></p>';
}
$html .= '<p class="f-h-adr-con">'.$v['province_name'].$v['city_name'].$v['district_name'].' '.$v['address'].'</p>';
$html .= '<div class="adr-edit-del"><a href="'.route('weixin_user_address_update',array('id'=>$v['id'])).'"><i class="iconfont icon-bianji"></i>编辑</a><a href="javascript:del('.$v['id'].');"><i class="iconfont icon-xiao10"></i>删除</a></div>';
$html .= '<p class="f-h-adr-con">' . $v['province_name'] . $v['city_name'] . $v['district_name'] . ' ' . $v['address'] . '</p>';
$html .= '<div class="adr-edit-del"><a href="' . route('weixin_user_address_update', array('id' => $v['id'])) . '"><i class="iconfont icon-bianji"></i>编辑</a><a href="javascript:del(' . $v['id'] . ');"><i class="iconfont icon-xiao10"></i>删除</a></div>';
$html .= '</div>';
}
}
exit(json_encode($html));
}
exit(json_encode($html));
}
return view('weixin.address.index', $data);
}
return view('weixin.address.index', $data);
}
//收货地址添加
public function userAddressAdd(Request $request)
{
return view('weixin.address.userAddressAdd');
}
{
return view('weixin.address.userAddressAdd');
}
//收货地址修改
public function userAddressUpdate(Request $request)
{
$id = $request->input('id','');
{
$id = $request->input('id', '');
if($id == ''){$this->error_jump(ReturnCode::NO_FOUND,route('weixin'),3);}
if ($id == '') {
$this->error_jump(ReturnCode::NO_FOUND, route('weixin'), 3);
}
$postdata = array(
'id' => $_REQUEST['id'],
'id' => $_REQUEST['id'],
'access_token' => $_SESSION['weixin_user_info']['access_token']
);
$url = env('APP_API_URL')."/user_address_detail";
$res = curl_request($url,$postdata,'GET');
);
$url = env('APP_API_URL') . "/user_address_detail";
$res = curl_request($url, $postdata, 'GET');
$data['post'] = $res['data'];
return view('weixin.address.userAddressUpdate',$data);
}
return view('weixin.address.userAddressUpdate', $data);
}
}

76
app/Http/Controllers/Weixin/ArticleController.php

@ -1,10 +1,11 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
class ArticleController extends CommonController
class ArticleController extends BaseController
{
public function __construct()
{
@ -13,69 +14,68 @@ class ArticleController extends CommonController
//列表页
public function category($cat)
{
{
$pagesize = 10;
$offset = 0;
//文章分类
$postdata = array(
'id' => $cat
);
$url = env('APP_API_URL')."/arctype_detail";
$arctype_detail = curl_request($url,$postdata,'GET');
'id' => $cat
);
$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;}
if (isset($_REQUEST['page'])) {
$offset = ($_REQUEST['page'] - 1) * $pagesize;
}
//文章列表
$postdata2 = array(
'limit' => $pagesize,
'limit' => $pagesize,
'offset' => $offset,
'typeid' => $cat
);
$url = env('APP_API_URL')."/article_list";
$res = curl_request($url,$postdata2,'GET');
if($res['data']['list'])
{
foreach($res['data']['list'] as $k => $v)
{
$res['data']['list'][$k]['pubdate'] = date("Y-m-d H:i",$v['pubdate']);
'typeid' => $cat
);
$url = env('APP_API_URL') . "/article_list";
$res = curl_request($url, $postdata2, 'GET');
if ($res['data']['list']) {
foreach ($res['data']['list'] as $k => $v) {
$res['data']['list'][$k]['pubdate'] = date("Y-m-d H:i", $v['pubdate']);
}
}
$data['list'] = $res['data']['list'];
$data['totalpage'] = ceil($res['data']['count']/$pagesize);
$data['totalpage'] = ceil($res['data']['count'] / $pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
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>';
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));
}
exit(json_encode($html));
}
return view('weixin.article.category', $data);
}
return view('weixin.article.category', $data);
}
//文章详情页
public function detail($id)
{
{
//最新资讯
$postdata = array(
'id' => $id
);
$url = env('APP_API_URL')."/article_detail";
$res = curl_request($url,$postdata,'GET');
if(empty($res['data'])){return redirect()->route('weixin_page404');}
$res['data']['body'] = preg_replace('/src=\"\/uploads\/allimg/',"src=\"".env('APP_URL')."/uploads/allimg",$res['data']['body']);
$res['data']['pubdate'] = date('Y-m-d',$res['data']['pubdate']);
'id' => $id
);
$url = env('APP_API_URL') . "/article_detail";
$res = curl_request($url, $postdata, 'GET');
if (empty($res['data'])) {
return redirect()->route('weixin_page404');
}
$res['data']['body'] = preg_replace('/src=\"\/uploads\/allimg/', "src=\"" . env('APP_URL') . "/uploads/allimg", $res['data']['body']);
$res['data']['pubdate'] = date('Y-m-d', $res['data']['pubdate']);
$data['post'] = $res['data'];
return view('weixin.article.detail', $data);

14
app/Http/Controllers/Weixin/BaseController.php

@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Common\Helper;
class BaseController extends CommonController
{
public function __construct()
{
parent::__construct();
}
}

2
app/Http/Controllers/Weixin/BonusController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
class BonusController extends CommonController
class BonusController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Weixin/CartController.php

@ -6,7 +6,7 @@ use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\ReturnCode;
class CartController extends CommonController
class CartController extends BaseController
{
public function __construct()
{

2
app/Http/Controllers/Weixin/CollectGoodsController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
class CollectGoodsController extends CommonController
class CollectGoodsController extends BaseController
{
public function __construct()
{

66
app/Http/Controllers/Weixin/CommonController.php

@ -1,4 +1,5 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Controller;
@ -7,6 +8,7 @@ use App\Common\Helper;
class CommonController extends Controller
{
protected $isWechatBrowser;
protected $login_info;
public function __construct()
{
@ -14,6 +16,14 @@ class CommonController extends Controller
$this->isWechatBrowser = Helper::isWechatBrowser();
view()->share('isWechatBrowser', $this->isWechatBrowser);
$this->login_info = array();
if (isset($_SESSION['weixin_user_info'])) {
$this->login_info = $_SESSION['weixin_user_info'];
}
// 添加操作记录
$this->operation_log_add();
}
/**
@ -24,21 +34,17 @@ class CommonController extends Controller
* @param mixed $time 当数字时指定跳转时间
* @return void
*/
public function error_jump($msg='', $url='', $time=3)
public function error_jump($msg = '', $url = '', $time = 3)
{
if ($url=='' && isset($_SERVER["HTTP_REFERER"]))
{
if ($url == '' && isset($_SERVER["HTTP_REFERER"])) {
$url = $_SERVER["HTTP_REFERER"];
}
if(!headers_sent())
{
header("Location:".route('weixin_jump')."?error=$msg&url=$url&time=$time");
if (!headers_sent()) {
header("Location:" . route('weixin_jump') . "?error=$msg&url=$url&time=$time");
exit();
}
else
{
$str = "<meta http-equiv='Refresh' content='URL=".route('weixin_jump')."?error=$msg&url=$url&time=$time"."'>";
} else {
$str = "<meta http-equiv='Refresh' content='URL=" . route('weixin_jump') . "?error=$msg&url=$url&time=$time" . "'>";
exit($str);
}
}
@ -51,22 +57,42 @@ class CommonController extends Controller
* @param mixed $time 当数字时指定跳转时间
* @return void
*/
public function success_jump($msg='', $url='', $time=1)
public function success_jump($msg = '', $url = '', $time = 1)
{
if ($url=='' && isset($_SERVER["HTTP_REFERER"]))
{
if ($url == '' && isset($_SERVER["HTTP_REFERER"])) {
$url = $_SERVER["HTTP_REFERER"];
}
if(!headers_sent())
{
header("Location:".route('weixin_jump')."?message=$msg&url=$url&time=$time");
if (!headers_sent()) {
header("Location:" . route('weixin_jump') . "?message=$msg&url=$url&time=$time");
exit();
}
else
{
$str = "<meta http-equiv='Refresh' content='URL=".route('weixin_jump')."?message=$msg&url=$url&time=$time"."'>";
} else {
$str = "<meta http-equiv='Refresh' content='URL=" . route('weixin_jump') . "?message=$msg&url=$url&time=$time" . "'>";
exit($str);
}
}
// 添加操作记录
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'] = 5;
$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);
}
}

9
app/Http/Controllers/Weixin/FeedbackController.php

@ -1,11 +1,12 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnCode;
class FeedbackController extends CommonController
class FeedbackController extends BaseController
{
public function __construct()
{
@ -14,7 +15,7 @@ class FeedbackController extends CommonController
//意见反馈添加
public function userFeedbackAdd(Request $request)
{
return view('weixin.feedback.userFeedbackAdd');
}
{
return view('weixin.feedback.userFeedbackAdd');
}
}

27
app/Http/Controllers/Weixin/GoodsBrandController.php

@ -1,11 +1,12 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnCode;
class GoodsBrandController extends CommonController
class GoodsBrandController extends BaseController
{
public function __construct()
{
@ -14,27 +15,29 @@ class GoodsBrandController extends CommonController
//商品品牌详情
public function brandDetail($id)
{
{
$postdata['id'] = $id;
$url = env('APP_API_URL')."/goodsbrand_detail";
$res = curl_request($url,$postdata,'GET');
$url = env('APP_API_URL') . "/goodsbrand_detail";
$res = curl_request($url, $postdata, 'GET');
$data['post'] = $res['data'];
if(!$data['post']){$this->error_jump(ReturnCode::NO_FOUND,route('weixin'),3);}
if (!$data['post']) {
$this->error_jump(ReturnCode::NO_FOUND, route('weixin'), 3);
}
return view('weixin.goods_brand.brandDetail', $data);
}
return view('weixin.goods_brand.brandDetail', $data);
}
//商品品牌列表
public function brandList(Request $request)
{
{
//商品列表
$postdata['limit'] = 10;
$postdata['offset'] = 0;
$url = env('APP_API_URL')."/goodsbrand_list";
$res = curl_request($url,$postdata,'GET');
$url = env('APP_API_URL') . "/goodsbrand_list";
$res = curl_request($url, $postdata, 'GET');
$data['list'] = $res['data']['list'];
return view('weixin.goods_brand.brandList', $data);
}
return view('weixin.goods_brand.brandList', $data);
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save