From 14c26e8c05f3cc22b7d9e310514cfe548ae4147c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Thu, 3 Aug 2017 18:44:33 +0800 Subject: [PATCH] slide --- .gitignore | 3 +- app/Common/Helper.php | 79 ++++++++++++++++++- app/Common/ReturnData.php | 2 +- app/Common/Token.php | 3 +- app/Http/Controllers/Api/RegionController.php | 52 ++++++++++++ app/Http/Controllers/Api/SlideController.php | 32 ++++++++ app/Http/Kernel.php | 3 + app/Http/Middleware/Sign.php | 31 ++++++++ .../Middleware/{Token.php => TokenAuth.php} | 2 +- app/Http/Middleware/TrimStrings.php | 1 - app/Http/Model/Region.php | 13 +-- app/Http/Model/Slide.php | 72 +++++++++++++++++ app/Http/Model/UserAddress.php | 38 ++++++--- public/other/flueditor/ueditor.config.js | 8 +- resources/views/admin/article/add.blade.php | 2 +- resources/views/admin/article/edit.blade.php | 2 +- resources/views/admin/category/add.blade.php | 2 +- resources/views/admin/category/edit.blade.php | 2 +- resources/views/admin/goods/add.blade.php | 2 +- resources/views/admin/goods/edit.blade.php | 2 +- resources/views/admin/goodstype/add.blade.php | 2 +- .../views/admin/goodstype/edit.blade.php | 2 +- resources/views/admin/tag/add.blade.php | 2 +- resources/views/admin/tag/edit.blade.php | 2 +- routes/web.php | 18 ++++- 25 files changed, 331 insertions(+), 46 deletions(-) create mode 100644 app/Http/Controllers/Api/RegionController.php create mode 100644 app/Http/Controllers/Api/SlideController.php create mode 100644 app/Http/Middleware/Sign.php rename app/Http/Middleware/{Token.php => TokenAuth.php} (97%) diff --git a/.gitignore b/.gitignore index 2a41229..379c3a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ /node_modules /public/hot /public/storage -/storage/*.key +/storage /vendor +/public/uploads /.idea /.vagrant Homestead.json diff --git a/app/Common/Helper.php b/app/Common/Helper.php index c4d1d59..8f2e21c 100644 --- a/app/Common/Helper.php +++ b/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; + } +} \ No newline at end of file diff --git a/app/Common/ReturnData.php b/app/Common/ReturnData.php index daf9ac1..a0b6099 100644 --- a/app/Common/ReturnData.php +++ b/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; //没有变动 diff --git a/app/Common/Token.php b/app/Common/Token.php index 0502d38..79914c5 100644 --- a/app/Common/Token.php +++ b/app/Common/Token.php @@ -1,6 +1,7 @@ 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); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/SlideController.php b/app/Http/Controllers/Api/SlideController.php new file mode 100644 index 0000000..8e8a29a --- /dev/null +++ b/app/Http/Controllers/Api/SlideController.php @@ -0,0 +1,32 @@ +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); + } +} \ No newline at end of file diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index ab5b0d1..b0a1f0a 100644 --- a/app/Http/Kernel.php +++ b/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, ]; } diff --git a/app/Http/Middleware/Sign.php b/app/Http/Middleware/Sign.php new file mode 100644 index 0000000..3bb8686 --- /dev/null +++ b/app/Http/Middleware/Sign.php @@ -0,0 +1,31 @@ +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); + } +} \ No newline at end of file diff --git a/app/Http/Middleware/Token.php b/app/Http/Middleware/TokenAuth.php similarity index 97% rename from app/Http/Middleware/Token.php rename to app/Http/Middleware/TokenAuth.php index b55caf4..6b753f9 100644 --- a/app/Http/Middleware/Token.php +++ b/app/Http/Middleware/TokenAuth.php @@ -5,7 +5,7 @@ use Closure; use App\Common\ReturnData; use App\Common\Token; -class Token +class TokenAuth { /** * Token验证 diff --git a/app/Http/Middleware/TrimStrings.php b/app/Http/Middleware/TrimStrings.php index 943e9a4..6900e20 100644 --- a/app/Http/Middleware/TrimStrings.php +++ b/app/Http/Middleware/TrimStrings.php @@ -1,5 +1,4 @@ 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; } -} +} \ No newline at end of file diff --git a/app/Http/Model/Slide.php b/app/Http/Model/Slide.php index 9fc3fdd..2891e21 100644 --- a/app/Http/Model/Slide.php +++ b/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; + } } \ No newline at end of file diff --git a/app/Http/Model/UserAddress.php b/app/Http/Model/UserAddress.php index 2ebf42a..c1c2143 100644 --- a/app/Http/Model/UserAddress.php +++ b/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()) diff --git a/public/other/flueditor/ueditor.config.js b/public/other/flueditor/ueditor.config.js index be19931..7d4e288 100644 --- a/public/other/flueditor/ueditor.config.js +++ b/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:{ diff --git a/resources/views/admin/article/add.blade.php b/resources/views/admin/article/add.blade.php index bebeb3b..ad23e40 100644 --- a/resources/views/admin/article/add.blade.php +++ b/resources/views/admin/article/add.blade.php @@ -104,7 +104,7 @@ function upImage() - + diff --git a/resources/views/admin/article/edit.blade.php b/resources/views/admin/article/edit.blade.php index 9086707..5af5e40 100644 --- a/resources/views/admin/article/edit.blade.php +++ b/resources/views/admin/article/edit.blade.php @@ -105,7 +105,7 @@ function upImage() - + diff --git a/resources/views/admin/category/add.blade.php b/resources/views/admin/category/add.blade.php index 47272e7..7500901 100644 --- a/resources/views/admin/category/add.blade.php +++ b/resources/views/admin/category/add.blade.php @@ -82,7 +82,7 @@ function upImage() - + diff --git a/resources/views/admin/category/edit.blade.php b/resources/views/admin/category/edit.blade.php index 25d83de..290dda1 100644 --- a/resources/views/admin/category/edit.blade.php +++ b/resources/views/admin/category/edit.blade.php @@ -78,7 +78,7 @@ function upImage() - + diff --git a/resources/views/admin/goods/add.blade.php b/resources/views/admin/goods/add.blade.php index 50529bc..8f34332 100644 --- a/resources/views/admin/goods/add.blade.php +++ b/resources/views/admin/goods/add.blade.php @@ -99,7 +99,7 @@ function upImage() - + diff --git a/resources/views/admin/goods/edit.blade.php b/resources/views/admin/goods/edit.blade.php index d705780..44408d9 100644 --- a/resources/views/admin/goods/edit.blade.php +++ b/resources/views/admin/goods/edit.blade.php @@ -100,7 +100,7 @@ function upImage() - + diff --git a/resources/views/admin/goodstype/add.blade.php b/resources/views/admin/goodstype/add.blade.php index 13a184c..9cfd2b5 100644 --- a/resources/views/admin/goodstype/add.blade.php +++ b/resources/views/admin/goodstype/add.blade.php @@ -82,7 +82,7 @@ function upImage() - + diff --git a/resources/views/admin/goodstype/edit.blade.php b/resources/views/admin/goodstype/edit.blade.php index 92921a0..e061ac3 100644 --- a/resources/views/admin/goodstype/edit.blade.php +++ b/resources/views/admin/goodstype/edit.blade.php @@ -78,7 +78,7 @@ function upImage() - + diff --git a/resources/views/admin/tag/add.blade.php b/resources/views/admin/tag/add.blade.php index 51675b4..a3bf0ab 100644 --- a/resources/views/admin/tag/add.blade.php +++ b/resources/views/admin/tag/add.blade.php @@ -81,7 +81,7 @@ function upImage() - + diff --git a/resources/views/admin/tag/edit.blade.php b/resources/views/admin/tag/edit.blade.php index 554f050..7988ab7 100644 --- a/resources/views/admin/tag/edit.blade.php +++ b/resources/views/admin/tag/edit.blade.php @@ -81,7 +81,7 @@ function upImage() - + diff --git a/routes/web.php b/routes/web.php index e1ff133..7dc3c39 100644 --- a/routes/web.php +++ b/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'); }); //中间件