Browse Source

slide

master
林一峰 7 years ago
parent
commit
14c26e8c05
  1. 3
      .gitignore
  2. 79
      app/Common/Helper.php
  3. 2
      app/Common/ReturnData.php
  4. 3
      app/Common/Token.php
  5. 52
      app/Http/Controllers/Api/RegionController.php
  6. 32
      app/Http/Controllers/Api/SlideController.php
  7. 3
      app/Http/Kernel.php
  8. 31
      app/Http/Middleware/Sign.php
  9. 2
      app/Http/Middleware/TokenAuth.php
  10. 1
      app/Http/Middleware/TrimStrings.php
  11. 13
      app/Http/Model/Region.php
  12. 72
      app/Http/Model/Slide.php
  13. 38
      app/Http/Model/UserAddress.php
  14. 8
      public/other/flueditor/ueditor.config.js
  15. 2
      resources/views/admin/article/add.blade.php
  16. 2
      resources/views/admin/article/edit.blade.php
  17. 2
      resources/views/admin/category/add.blade.php
  18. 2
      resources/views/admin/category/edit.blade.php
  19. 2
      resources/views/admin/goods/add.blade.php
  20. 2
      resources/views/admin/goods/edit.blade.php
  21. 2
      resources/views/admin/goodstype/add.blade.php
  22. 2
      resources/views/admin/goodstype/edit.blade.php
  23. 2
      resources/views/admin/tag/add.blade.php
  24. 2
      resources/views/admin/tag/edit.blade.php
  25. 18
      routes/web.php

3
.gitignore

@ -1,8 +1,9 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/storage
/vendor
/public/uploads
/.idea
/.vagrant
Homestead.json

79
app/Common/Helper.php

@ -165,4 +165,81 @@ class Helper
return $result;
}
}
//获取浏览器信息
public static function getBrowser()
{
$browser = array('name'=>'unknown', 'version'=>'unknown');
if(empty($_SERVER['HTTP_USER_AGENT'])) return $browser;
$agent = $_SERVER["HTTP_USER_AGENT"];
// Chrome should checked before safari
if(strpos($agent, 'Firefox') !== false) $browser['name'] = "firefox";
if(strpos($agent, 'Opera') !== false) $browser['name'] = 'opera';
if(strpos($agent, 'Safari') !== false) $browser['name'] = 'safari';
if(strpos($agent, 'Chrome') !== false) $browser['name'] = "chrome";
// Check the name of browser
if(strpos($agent, 'MSIE') !== false || strpos($agent, 'rv:11.0')) $browser['name'] = 'ie';
if(strpos($agent, 'Edge') !== false) $browser['name'] = 'edge';
// Check the version of browser
if(preg_match('/MSIE\s(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1];
if(preg_match('/FireFox\/(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1];
if(preg_match('/Opera[\s|\/](\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1];
if(preg_match('/Chrome\/(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1];
if((strpos($agent, 'Chrome') == false) && preg_match('/Safari\/(\d+)\..*$/i', $agent, $regs)) $browser['version'] = $regs[1];
if(preg_match('/rv:(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1];
if(preg_match('/Edge\/(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1];
return $browser;
}
/**
* 检查是否是AJAX请求。
* Check is ajax request.
*
* @static
* @access public
* @return bool
*/
public static function isAjaxRequest()
{
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') return true;
if(isset($_GET['HTTP_X_REQUESTED_WITH']) && $_GET['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') return true;
return false;
}
/**
* 301跳转。
* Header 301 Moved Permanently.
*
* @param string $locate
* @access public
* @return void
*/
public static function header301($locate)
{
header('HTTP/1.1 301 Moved Permanently');
die(header('Location:' . $locate));
}
/**
* 获取远程IP。
* Get remote ip.
*
* @access public
* @return string
*/
public static function getRemoteIp()
{
$ip = '';
if(!empty($_SERVER["REMOTE_ADDR"])) $ip = $_SERVER["REMOTE_ADDR"];
if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
if(!empty($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP'];
return $ip;
}
}

2
app/Common/ReturnData.php

@ -10,7 +10,7 @@ class ReturnData
const PARAMS_ERROR = 8003; //参数错误
const NOT_FOUND = 8004; //资源未找到
const TOKEN_ERROR = 8005; //token错误
const SIGN_FAIL = 8006; //签名错误
const SIGN_ERROR = 8006; //签名错误
const RECORD_EXIST = 8007; //记录已存在
const RECORD_NOT_EXIST = 8008; //记录不存在
const NOT_MODIFY = 8009; //没有变动

3
app/Common/Token.php

@ -1,6 +1,7 @@
<?php
namespace App\Common;
use DB;
use Illuminate\Support\Facades\DB;
class Token
{

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

@ -0,0 +1,52 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Http\Model\Region;
class RegionController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function regionList(Request $request)
{
//参数
$id = $request->input('id', null);
if ($id == null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = Region::getList($id);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
public function regionDetail(Request $request)
{
//参数
$id = $request->input('id', null);
if ($id == null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = Region::getOne($id);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

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

@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Http\Model\Slide;
class SlideController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function slideList(Request $request)
{
//参数
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
if($request->input('group_id', null) !== null){$data['group_id'] = $request->input('group_id');};
$res = Slide::getList($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

3
app/Http/Kernel.php

@ -58,5 +58,8 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'check.login' => \App\Http\Middleware\CheckLogin::class,
'token' => \App\Http\Middleware\TokenAuth::class,
'sign' => \App\Http\Middleware\Sign::class,
];
}

31
app/Http/Middleware/Sign.php

@ -0,0 +1,31 @@
<?php
namespace App\Http\Middleware;
use Closure;
use App\Common\ReturnData;
use App\Common\Token;
class Sign
{
/**
* Sign验证
*/
public function handle($request, Closure $next)
{
$app_key = $request->header('app_key') ?: $request->input('app_key');
$app_time = $request->header('app_time') ?: $request->input('app_time');
$sign = $request->header('sign') ?: $request->input('sign');
if (empty($app_key) || empty($app_time) || empty($sign))
{
return ReturnData::create(ReturnData::FORBIDDEN);
}
if (!Token::checkSign($app_key, $app_time, $sign))
{
return ReturnData::create(ReturnData::SIGN_ERROR);
}
return $next($request);
}
}

2
app/Http/Middleware/Token.php → app/Http/Middleware/TokenAuth.php

@ -5,7 +5,7 @@ use Closure;
use App\Common\ReturnData;
use App\Common\Token;
class Token
class TokenAuth
{
/**
* Token验证

1
app/Http/Middleware/TrimStrings.php

@ -1,5 +1,4 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;

13
app/Http/Model/Region.php

@ -3,6 +3,7 @@ namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
use App\Common\Token;
use Cache;
class Region extends BaseModel
{
@ -24,15 +25,7 @@ class Region extends BaseModel
public static function getList($parent_id=86)
{
$key = 'region';
if (!$model = Cache::get($key))
{
$model = self::where('parent_id', $parent_id)->get()->toArray();
Cache::put($key, $model, 10);
}
return $model;
return self::where('parent_id', $parent_id)->get()->toArray();
}
public static function getOne($id)
@ -45,4 +38,4 @@ class Region extends BaseModel
return false;
}
}
}

72
app/Http/Model/Slide.php

@ -2,11 +2,83 @@
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
use App\Common\Token;
use DB;
class Slide extends Model
{
//轮播图
protected $table = 'slide';
public $timestamps = false;
protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
const UN_SHOW = 0; // 不显示
const IS_SHOW = 1; // 显示
public static function getList(array $param)
{
extract($param); //参数:group_id,limit,offset
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$where['is_show'] = self::IS_SHOW;
$model = new Slide;
if(isset($group_id)){$where['group_id'] = $group_id;}
if($where){$model = $model->where($where);}
$res['count'] = $model->count();
$res['list'] = array();
if($res['count']>0)
{
$res['list'] = $model->orderBy('id', 'desc')->skip($offset)->take($limit)->get()->toArray();
}
else
{
return false;
}
return $res;
}
public static function getOne($id)
{
return self::where('id', $id)->first()->toArray();
}
public static function add(array $data)
{
if ($id = DB::table('slide')->insertGetId($data))
{
return $id;
}
return false;
}
public static function modify($where, array $data)
{
$slide = DB::table('slide');
if ($slide->where($where)->update($data))
{
return true;
}
return false;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
}

38
app/Http/Model/UserAddress.php

@ -21,9 +21,28 @@ class UserAddress extends BaseModel
protected $guarded = array();
//获取列表
public static function getList()
public static function getList(array $param)
{
return self::where('user_id', Token::$uid)->get()->toArray();
extract($param); //参数:limit,offset
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = self::where('user_id', Token::$uid);
$res['count'] = $model->count();
$res['list'] = array();
if($res['count']>0)
{
$res['list'] = $model->skip($offset)->take($limit)->get()->toArray();
}
else
{
return false;
}
return $res;
}
//获取一条记录
@ -50,8 +69,7 @@ class UserAddress extends BaseModel
public static function add(array $param)
{
extract($param);
$arr = Region::getParentId($region);
$model = new UserAddress;
$model->user_id = Token::$uid;
$model->name = $name;
@ -84,14 +102,12 @@ class UserAddress extends BaseModel
return false;
}
public static function update(array $param)
public static function modify(array $param)
{
extract($param);
if ($model = UserAddress::where('id', $id)->where('user_id', Token::$uid)->first())
{
$arr = Region::getParentId($region);
$model->user_id = Token::$uid;
$model->name = $name;
$model->email = isset($email) ? $email : '';
@ -117,10 +133,8 @@ class UserAddress extends BaseModel
}
//删除一条记录
public static function delete(array $param)
public static function remove($id)
{
extract($param);
if (UserAddress::where('id', $id)->where('user_id', Token::$uid)->delete())
{
if ($address = UserAddress::where('user_id', Token::$uid)->first())
@ -139,10 +153,8 @@ class UserAddress extends BaseModel
}
//设为默认地址
public static function setDefault(array $param)
public static function setDefault($id)
{
extract($param);
if (UserAddress::where('id', $id)->where('user_id', Token::$uid)->first())
{
if($user = User::where('id', Token::$uid)->first())

8
public/other/flueditor/ueditor.config.js

@ -40,12 +40,12 @@
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'directionalityltr', 'directionalityrtl', 'indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
'simpleupload', 'insertimage', 'scrawl', 'attachment', 'map', 'insertframe', 'insertcode', 'template', '|',
'horizontal', 'spechars', 'wordimage', '|',
'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
'print', 'preview', 'searchreplace', 'help', 'drafts'
'print', 'preview', 'searchreplace', 'drafts'
]]
//当鼠标放在工具栏上时显示的tooltip提示,留空支持自动多语言配置,否则以配置值为准
//,labelMap:{

2
resources/views/admin/article/add.blade.php

@ -104,7 +104,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="body" type="text/plain"></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>

2
resources/views/admin/article/edit.blade.php

@ -105,7 +105,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="body" type="text/plain"><?php echo $post["body"]; ?></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>

2
resources/views/admin/category/add.blade.php

@ -82,7 +82,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="content" type="text/plain"></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script>
</td>
</tr>

2
resources/views/admin/category/edit.blade.php

@ -78,7 +78,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="content" type="text/plain"><?php echo $post["content"]; ?></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script>
</td>
</tr>

2
resources/views/admin/goods/add.blade.php

@ -99,7 +99,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="body" type="text/plain"></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>

2
resources/views/admin/goods/edit.blade.php

@ -100,7 +100,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="body" type="text/plain"><?php echo $post["body"]; ?></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>

2
resources/views/admin/goodstype/add.blade.php

@ -82,7 +82,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="content" type="text/plain"></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script>
</td>
</tr>

2
resources/views/admin/goodstype/edit.blade.php

@ -78,7 +78,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="content" type="text/plain"><?php echo $post["content"]; ?></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script>
</td>
</tr>

2
resources/views/admin/tag/add.blade.php

@ -81,7 +81,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="content" type="text/plain"></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>

2
resources/views/admin/tag/edit.blade.php

@ -81,7 +81,7 @@ function upImage()
<td colspan="2">
<!-- 加载编辑器的容器 --><script id="container" name="content" type="text/plain"><?php echo $post["content"]; ?></script>
<!-- 配置文件 --><script type="text/javascript" src="/other/flueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.js"></script>
<!-- 编辑器源码文件 --><script type="text/javascript" src="/other/flueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>

18
routes/web.php

@ -180,13 +180,25 @@ Route::group(['prefix' => 'fladmin', 'namespace' => 'Admin', 'middleware' => ['w
});
//接口路由,无需token验证
Route::group(['prefix' => 'api', 'namespace' => 'Api', 'middleware' => ['web']], function () {
Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web']], function () {
});
//接口路由,需token验证
Route::group(['prefix' => 'api', 'namespace' => 'Api', 'middleware' => ['web','token']], function () {
Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web','token']], function () {
//轮播图
Route::get('/slide_list', 'SlideController@slideList');
//收货地址
Route::get('/user_address_list', 'UserAddressController@userAddressList');
Route::get('/user_address_detail', 'UserAddressController@userAddressDetail');
Route::post('/user_address_setdefault', 'UserAddressController@userAddressSetDefault');
Route::post('/user_address_add', 'UserAddressController@userAddressAdd');
Route::post('/user_address_update', 'UserAddressController@userAddressUpdate');
Route::post('/user_address_delete', 'UserAddressController@userAddressDelete');
//地区,省市区
Route::get('/region_list', 'RegionController@regionList');
Route::get('/region_detail', 'RegionController@regionDetail');
});
//中间件

Loading…
Cancel
Save