Browse Source

商品表修改

master
林一峰 7 years ago
parent
commit
aa61380d7f
  1. 42
      app/Common/JPush.php
  2. 133
      app/Common/ReturnData.php
  3. 105
      app/Common/Token.php
  4. 57
      app/Common/function.php
  5. 30
      app/Http/Controllers/Admin/GoodsController.php
  6. 34
      app/Http/Controllers/Admin/GoodstypeController.php
  7. 16
      app/Http/Controllers/Admin/LoginController.php
  8. 14
      app/Http/Controllers/Admin/UserController.php
  9. 10
      app/Http/Controllers/Admin/UserRoleController.php
  10. 30
      app/Http/Middleware/Token.php
  11. 3
      composer.json
  12. 6
      resources/views/admin/goods/add.blade.php
  13. 6
      resources/views/admin/goods/edit.blade.php
  14. 14
      resources/views/admin/goods/index.blade.php
  15. 8
      resources/views/admin/goodstype/add.blade.php
  16. 4
      resources/views/admin/goodstype/edit.blade.php
  17. 8
      resources/views/admin/goodstype/index.blade.php
  18. 51
      routes/web.php

42
app/Common/JPush.php

@ -0,0 +1,42 @@
<?php
namespace App\Common;
use JPush\Client as JPushMsg;
use Illuminate\Support\Facades\Log;
//极光推送,"jpush/jpush": "v3.5.*"
class JPush
{
const APP_KEY = 'b82cd9fcd0cbb92866d6d726';
const APP_SECRET = 'ac92d336f90842051dc12f49';
//$registration_id = getenv('registration_id');
public static function send($msg, $param='')
{
$client = new JPushMsg(self::APP_KEY, self::APP_SECRET, null);
$push_payload = $client->push();
$push_payload = $push_payload->setPlatform('all');
if(isset($param['mobile'])){$push_payload = $push_payload->addAlias(md5($param['mobile']));}
$push_payload = $push_payload->addAllAudience();
$push_payload = $push_payload->setNotificationAlert($msg);
try
{
$push_payload->send();
}
catch (JPushMsg\Exceptions\APIConnectionException $e)
{
Log::info($e);
return false;
}
catch (JPushMsg\Exceptions\APIRequestException $e)
{
Log::info($e);
return false;
}
return true;
}
}

133
app/Common/ReturnData.php

@ -0,0 +1,133 @@
<?php
namespace App\Common;
class ReturnData
{
//通用
const SUCCESS = 0; //成功
const FORBIDDEN = 8001; //权限不足
const SYSTEM_FAIL = 8002; //系统错误,如数据写入失败之类的
const PARAMS_ERROR = 8003; //参数错误
const NOT_FOUND = 8004; //资源未找到
const TOKEN_ERROR = 8005; //token错误
const SIGN_FAIL = 8006; //签名错误
const RECORD_EXIST = 8007; //记录已存在
const RECORD_NOT_EXIST = 8008; //记录不存在
const NOT_MODIFY = 8009; //没有变动
const IMG_TYPE_FALSE = 8010; //图片格式不正确
//参数相关
const EMAIL_EXIST = 8201; //邮箱已存在
const EMAIL_FORMAT_FAIL = 8202; //邮箱格式不对正确
const MOBILE_NOT_FIND = 8204; //手机号码不存在
const MOBILE_HAS_MORE = 8205; //存在多个手机号码
const NAME_EXIST = 8206; //名称已被使用
const MOBILE_EXIST = 8207; //手机号已存在
const NOT_UP_GRADE = 8208; //不符合升级条件
const NOT_DOWN_GRADE = 8209; //不符合降级条件
//登录、账号相关
const USERNAME_REQUIRED = 8401; //登录账号为必填
const PASSWORD_REQUIRED = 8402; //登录密码为必填
const USERNAME_EXIST = 8403; //登录账号已被使用
const ADMINNAME_REQUIRED = 8404; //管理员姓名不能为空
const PASSWORD_NOT_MATCH = 8405; //密码错误
const OLD_PASSWORD_NOT_MATCH = 8406; //旧密码不匹配
const PASSWORD_CONFIRM_FAIL = 8407; //两次输入的密码不匹配
const PASSWORD_FORMAT_FAIL = 8408; //密码格式不对
const APPLY_SIGN_FAIL = 8510; //注册邀请码错误
//验证码
const CODE_NOT_EXIST = 8801; //当前状态不能操作
//app
const AUTH_FAIL = 9001; //鉴权失败
const TOKEN_EXP = 9002; //Token失效
const MOBILE_FORMAT_FAIL = 9003; //手机格式不正确
const VERIFY_TYPE_FAIL = 9004; //验证码业务类型无效
const BANK_TYPE_FAIL = 9005; //该银行不支持
const INVALID_IDCARD = 9006;//身份证无效
const REQUEST_AMOUNT_MIN_LESS = 9007;//小于最小提现金额
const SERVICE_AMOUNT_NOT_ENOUGH = 9008;//可提现余额不足
//中文错误详情
public static $codeTexts = array(
0 => '操作成功',
8001 => '权限不足',
8002 => '系统错误,请联系管理员',
8003 => '参数错误',
8004 => '资源未找到',
8005 => 'token错误',
8006 => '签名错误',
8007 => '记录已存在',
8008 => '记录不存在',
8009 => '没有变动',
8010 => '图片格式不正确',
//参数错误
8201 => '邮箱已存在',
8202 => '邮箱格式不对正确',
8204 => '手机号码不存在',
8205 => '存在多个手机号码',
8206 => '名称已被使用',
8207 => '手机号已存在',
8208 => '不符合升级条件',
8209 => '不符合降级条件',
//登录、账号相关
8401 => '登录账号为必填',
8402 => '登录密码为必填',
8403 => '登录账号已被使用',
8404 => '管理员姓名不能为空',
8405 => '登录失败',
8406 => '原密码不匹配',
8407 => '两次输入的密码不匹配',
8408 => '密码格式错误,请输入%s到%s位字符',
8510 => '注册邀请码不存在或已被使用',
//app
9001 => '鉴权失败',
9002 => 'Token失效',
9003 => '手机格式不正确',
9004 => '验证码业务类型无效',
9005 => '该银行不支持',
9006 => '身份证无效',
9007 => '小于最小提现金额',
9008 => '可提现余额不足',
//验证码
8801 =>'验证码无效',
);
public static function create($code, $msg = '', $data = null)
{
if (empty($msg) && isset(self::$codeTexts[$code]))
{
$msg = self::$codeTexts[$code];
}
return array('code' => $code, 'msg' => $msg, 'data' => $data);
}
public static function success($msg = '', $data = null)
{
if (empty($msg) && isset(self::$codeTexts[self::SUCCESS]))
{
$msg = self::$codeTexts[self::SUCCESS];
}
return array('code' => self::SUCCESS, 'msg' => $msg, 'data' => $data);
}
public static function error($code, $msg = '', $data = null)
{
if (empty($msg) && isset(self::$codeTexts[$code]))
{
$msg = self::$codeTexts[$code];
}
if ($code == ReturnCode::SUCCESS)
{
$code = ReturnCode::SYSTEM_FAIL;
$msg = '系统错误';
}
return array('code' => $code, 'msg' => $msg, 'data' => $data);
}
}

105
app/Common/Token.php

@ -0,0 +1,105 @@
<?php
namespace App\Common;
use DB;
class Token
{
const TYPE_APP = 0;
const TYPE_ADMIN = 1;
const TYPE_WEIXIN = 2;
const TYPE_WAP = 3;
const TYPE_PC = 4;
// 已验证的type
public static $type;
// 验证为token时的uid
public static $uid;
// 验证为sign时的app.id
public static $app;
// 已验证的data
public static $data = [];
/**
* 验证token
*
* @param $token
*
* @return bool
*/
public static function checkToken($token)
{
$token = DB::table('token')->where('token', $token)->first();
if ($token)
{
self::$type = $token->type;
self::$uid = $token->uid;
self::$data = $token->data ? json_decode($token->data, true) : [];
}
return $token ? true : false;
}
/**
* 验证sign,
* sign生成方式:md5(app_key + app_secret + time)
* 必传参数:app_key, sign, sign_time
*
* @param $appKey
* @param $signTime
* @param $sign
*
* @return bool
*/
public static function checkSign($appKey, $signTime, $sign)
{
if (!$appRes = DB::table('appsign')->where('app_key', $appKey)->first())
{
return false;
}
//验证sign
$newSign = md5($appKey . $appRes->app_secret . $signTime);
if ($sign == $newSign)
{
self::$type = self::TYPE_ADMIN;
self::$app = $appRes;
return true;
}
return false;
}
/**
* 生成token
*
* @param $type
* @param $uid
* @param $data
*
* @return string
*/
public static function getToken($type, $uid, $data = [])
{
//支持多账号登录
if ($token = DB::table('token')->where(['type' => $type, 'uid' => $uid])->orderBy('id', 'desc')->first())
{
if($data == $token->data && strtotime($token->expired_at)>time())
{
return $token->token;
}
}
//生成新token
$token = md5($type . '-' . $uid . '-' . microtime() . rand(0, 9999));
DB::table('token')->insert([
'token' => $token,
'type' => $type,
'uid' => $uid,
'data' => $data ? json_encode($data) : '',
'expired_at' => date('Y-m-d H:i:s')
]);
return $token;
}
}

57
app/Common/function.php

@ -1,5 +1,62 @@
<?php
// 公共函数文件
if (! function_exists('curl_request'))
{
function curl_request($api, $method = 'GET', $params = array(), $headers = array())
{
$curl = curl_init();
switch (strtoupper($method))
{
case 'GET' :
if (!empty($params))
{
$api .= (strpos($api, '?') ? '&' : '?') . http_build_query($params);
}
curl_setopt($curl, CURLOPT_HTTPGET, TRUE);
break;
case 'POST' :
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
break;
case 'PUT' :
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
break;
case 'DELETE' :
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
break;
}
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
if ($response === FALSE)
{
$error = curl_error($curl);
curl_close($curl);
return FALSE;
}
else
{
// 解决windows 服务器 BOM 问题
$response = trim($response,chr(239).chr(187).chr(191));
$response = json_decode($response, true);
}
curl_close($curl);
return $response;
}
}
//获取数据
function dataList($modelname, $where = [], $size = 15, $page = 1)

30
app/Http/Controllers/Admin/ProductController.php → app/Http/Controllers/Admin/GoodsController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class ProductController extends CommonController
class GoodsController extends CommonController
{
public function __construct()
{
@ -31,17 +31,17 @@ class ProductController extends CommonController
}
};
$posts = parent::pageList('product', $where);
$posts = parent::pageList('goods', $where);
foreach($posts as $key=>$value)
{
$info = DB::table('product_type')->select('name')->where("id", $value->typeid)->first();
$info = DB::table('goods_type')->select('name')->where("id", $value->typeid)->first();
$posts[$key]->name = $info->name;
$posts[$key]->body = '';
}
$data['posts'] = $posts;
return view('admin.product.index', $data);
return view('admin.goods.index', $data);
}
public function add()
@ -49,7 +49,7 @@ class ProductController extends CommonController
$data = [];
if(!empty($_GET["catid"])){$data['catid'] = $_GET["catid"];}else{$data['catid'] = 0;}
return view('admin.product.add', $data);
return view('admin.goods.add', $data);
}
public function doadd()
@ -78,9 +78,9 @@ class ProductController extends CommonController
unset($_POST["_token"]);
if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
if(DB::table('product')->insert(array_filter($_POST)))
if(DB::table('goods')->insert(array_filter($_POST)))
{
success_jump('添加成功!', route('admin_product'));
success_jump('添加成功!', route('admin_goods'));
}
else
{
@ -93,9 +93,9 @@ class ProductController extends CommonController
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(DB::table('product')->where('id', $id)->first(), 1);
$data['post'] = object_to_array(DB::table('goods')->where('id', $id)->first(), 1);
return view('admin.product.edit', $data);
return view('admin.goods.edit', $data);
}
public function doedit()
@ -126,9 +126,9 @@ class ProductController extends CommonController
unset($_POST["_token"]);
if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
if(DB::table('product')->where('id', $id)->update($_POST))
if(DB::table('goods')->where('id', $id)->update($_POST))
{
success_jump('修改成功!', route('admin_product'));
success_jump('修改成功!', route('admin_goods'));
}
else
{
@ -140,7 +140,7 @@ class ProductController extends CommonController
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
if(DB::table('product')->whereIn("id", explode(',', $id))->delete())
if(DB::table('goods')->whereIn("id", explode(',', $id))->delete())
{
success_jump("$id ,删除成功");
}
@ -156,7 +156,7 @@ class ProductController extends CommonController
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
$data['tuijian'] = 1;
if(DB::table('product')->whereIn("id", explode(',', $id))->update($data))
if(DB::table('goods')->whereIn("id", explode(',', $id))->update($data))
{
success_jump("$id ,推荐成功");
}
@ -167,7 +167,7 @@ class ProductController extends CommonController
}
//商品是否存在
public function productexists()
public function goodsexists()
{
$res = '';
$where = function ($query) use ($res) {
@ -182,6 +182,6 @@ class ProductController extends CommonController
}
};
return DB::table("product")->where($where)->count();
return DB::table("goods")->where($where)->count();
}
}

34
app/Http/Controllers/Admin/ProducttypeController.php → app/Http/Controllers/Admin/GoodstypeController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
class ProductTypeController extends CommonController
class GoodsTypeController extends CommonController
{
public function __construct()
{
@ -13,20 +13,20 @@ class ProductTypeController extends CommonController
public function index()
{
$catlist = category_tree(get_category('product_type',0));
$catlist = category_tree(get_category('goods_type',0));
if($catlist)
{
foreach($catlist as $k=>$v)
{
$arctype = DB::table("arctype")->where('id', $v['id'])->first();
$arctype = DB::table("goods_type")->where('id', $v['id'])->first();
$catlist[$k]['typedir'] = $arctype->typedir;
$catlist[$k]['addtime'] = $arctype->addtime;
}
}
$data['catlist'] = $catlist;
return view('admin.producttype.index', $data);
return view('admin.goodstype.index', $data);
}
public function add()
@ -38,7 +38,7 @@ class ProductTypeController extends CommonController
if($id!=0)
{
$data['postone'] = object_to_array(DB::table("product_type")->where('id', $id)->first(), 1);
$data['postone'] = object_to_array(DB::table("goods_type")->where('id', $id)->first(), 1);
}
$data['id'] = $id;
@ -48,7 +48,7 @@ class ProductTypeController extends CommonController
$data['id'] = 0;
}
return view('admin.producttype.add', $data);
return view('admin.goodstype.add', $data);
}
public function doadd()
@ -59,9 +59,9 @@ class ProductTypeController extends CommonController
unset($_POST["_token"]);
if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
if(DB::table("product_type")->insert($_POST))
if(DB::table("goods_type")->insert($_POST))
{
success_jump('添加成功!', route('admin_producttype'));
success_jump('添加成功!', route('admin_goodstype'));
}
else
{
@ -74,12 +74,12 @@ class ProductTypeController extends CommonController
$id = $_GET["id"];if(preg_match('/[0-9]*/',$id)){}else{exit;}
$data['id'] = $id;
$post = object_to_array(DB::table("product_type")->where('id', $id)->first(), 1);
$post = object_to_array(DB::table("goods_type")->where('id', $id)->first(), 1);
$reid = $post['pid'];
if($reid!=0){$data['postone'] = object_to_array(DB::table("product_type")->where('id', $reid)->first(), 1);}
if($reid!=0){$data['postone'] = object_to_array(DB::table("goods_type")->where('id', $reid)->first(), 1);}
$data['post'] = $post;
return view('admin.producttype.edit', $data);
return view('admin.goodstype.edit', $data);
}
public function doedit()
@ -90,9 +90,9 @@ class ProductTypeController extends CommonController
unset($_POST["_token"]);
if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
if(DB::table("product_type")->where('id', $id)->update($_POST))
if(DB::table("goods_type")->where('id', $id)->update($_POST))
{
success_jump('修改成功!', route('admin_producttype'));
success_jump('修改成功!', route('admin_goodstype'));
}
else
{
@ -104,17 +104,17 @@ class ProductTypeController extends CommonController
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
if(DB::table("product_type")->where('pid', $id)->first())
if(DB::table("goods_type")->where('pid', $id)->first())
{
error_jump('删除失败!请先删除子分类');
}
else
{
if(DB::table("product_type")->where('id', $id)->delete())
if(DB::table("goods_type")->where('id', $id)->delete())
{
if(DB::table("product")->where('typeid', $id)->count()>0) //判断该分类下是否有商品,如果有把该分类下的商品也一起删除
if(DB::table("goods")->where('typeid', $id)->count()>0) //判断该分类下是否有商品,如果有把该分类下的商品也一起删除
{
if(DB::table("product")->where('typeid', $id)->delete())
if(DB::table("goods")->where('typeid', $id)->delete())
{
success_jump('删除成功');
}

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

@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Model\User;
use Log;
class LoginController extends BaseController
@ -37,17 +36,16 @@ 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;}//密码
$User = User::where(['username' => $username, 'pwd' => $pwd])->orWhere(['email' => $username, 'pwd' => $pwd])->first();
$admin_user = DB::table('admin_user')->where(array('username' => $username, 'pwd' => $pwd))->orWhere(array('email' => $username, 'pwd' => $pwd))->first();
if($User)
if($admin_user)
{
$admin_user_info = $User->toArray();
$admin_user_info['rolename'] = $User->userrole->name;
$admin_user_info = object_to_array($admin_user, 1);
$admin_user_info['rolename'] = DB::table('admin_user_role')->where(array('id'=>$admin_user->role_id))->value('name');
$_SESSION['admin_user_info'] = $admin_user_info;
$User->logintime = time();
$User->save();
DB::table('admin_user')->where(array('id'=>$admin_user->role_id))->update(array('logintime' => time()));
return redirect()->route('admin');
}
@ -71,7 +69,7 @@ class LoginController extends BaseController
$data["username"] = "admin888";
$data["pwd"] = "21232f297a57a5a743894a0e4a801fc3";
if(DB::table('user')->where('id', 1)->update($data))
if(DB::table('admin_user')->where('id', 1)->update($data))
{
success_jump('密码恢复成功!', route('admin_login'));
}
@ -96,7 +94,7 @@ class LoginController extends BaseController
return 0;
}
return DB::table("user")->where($map)->count();
return DB::table("admin_user")->where($map)->count();
}
//测试

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

@ -13,7 +13,7 @@ class UserController extends CommonController
public function index()
{
$posts = parent::pageList('user');
$posts = parent::pageList('admin_user');
$data['posts'] = $posts;
@ -22,7 +22,7 @@ class UserController extends CommonController
public function add()
{
$data['rolelist'] = object_to_array(DB::table('user_role')->orderBy('listorder','desc')->get());
$data['rolelist'] = object_to_array(DB::table('admin_user_role')->orderBy('listorder','desc')->get());
return view('admin.user.add', $data);
}
@ -31,7 +31,7 @@ class UserController extends CommonController
{
unset($_POST["_token"]);
$_POST['pwd'] = md5($_POST['pwd']);
if(DB::table('user')->insert($_POST))
if(DB::table('admin_user')->insert($_POST))
{
success_jump('添加成功!', route('admin_user'));
}
@ -47,8 +47,8 @@ class UserController extends CommonController
if(preg_match('/[0-9]*/',$id)){}else{exit;}
$data['id'] = $id;
$data['post'] = object_to_array(DB::table('user')->where('id', $id)->first(), 1);
$data['rolelist'] = object_to_array(DB::table('user_role')->orderBy('listorder','desc')->get());
$data['post'] = object_to_array(DB::table('admin_user')->where('id', $id)->first(), 1);
$data['rolelist'] = object_to_array(DB::table('admin_user_role')->orderBy('listorder','desc')->get());
return view('admin.user.edit', $data);
}
@ -59,7 +59,7 @@ class UserController extends CommonController
unset($_POST["_token"]);
$_POST['pwd'] = md5($_POST['pwd']);
if(DB::table('user')->where('id', $id)->update($_POST))
if(DB::table('admin_user')->where('id', $id)->update($_POST))
{
success_jump('修改成功!', route('admin_user'));
}
@ -101,7 +101,7 @@ class UserController extends CommonController
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
if(DB::table('user')->whereIn("id", explode(',', $id))->delete())
if(DB::table('admin_user')->whereIn("id", explode(',', $id))->delete())
{
success_jump('删除成功');
}

10
app/Http/Controllers/Admin/UserRoleController.php

@ -13,7 +13,7 @@ class UserRoleController extends CommonController
public function index()
{
$posts = parent::pageList('user_role', '', ['listorder','desc']);
$posts = parent::pageList('admin_user_role', '', ['listorder','desc']);
$data['posts'] = $posts;
@ -28,7 +28,7 @@ class UserRoleController extends CommonController
public function doadd()
{
unset($_POST["_token"]);
if(DB::table('user_role')->insert($_POST))
if(DB::table('admin_user_role')->insert($_POST))
{
success_jump('添加成功!', route('admin_userrole'));
}
@ -44,7 +44,7 @@ class UserRoleController extends CommonController
if(preg_match('/[0-9]*/',$id)){}else{exit;}
$data['id'] = $id;
$data['post'] = object_to_array(DB::table('user_role')->where('id', $id)->first(), 1);
$data['post'] = object_to_array(DB::table('admin_user_role')->where('id', $id)->first(), 1);
return view('admin.userrole.edit', $data);
}
@ -54,7 +54,7 @@ class UserRoleController extends CommonController
if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
unset($_POST["_token"]);
if(DB::table('user_role')->where('id', $id)->update($_POST))
if(DB::table('admin_user_role')->where('id', $id)->update($_POST))
{
success_jump('修改成功!', route('admin_userrole'));
}
@ -68,7 +68,7 @@ class UserRoleController extends CommonController
{
if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
if(DB::table('user_role')->whereIn("id", explode(',', $id))->delete())
if(DB::table('admin_user_role')->whereIn("id", explode(',', $id))->delete())
{
success_jump('删除成功');
}

30
app/Http/Middleware/Token.php

@ -0,0 +1,30 @@
<?php
namespace App\Http\Middleware;
use Closure;
use App\Common\ReturnData;
use App\Common\Token;
class Token
{
/**
* Token验证
* token可以在header里面传递【Token】,也可以在参数里面传【token】,注意区分大小写
*/
public function handle($request, Closure $next)
{
$token = $request->header('Token') ?: $request->input('token');
if (!$token)
{
return ReturnData::create(ReturnData::FORBIDDEN);
}
if (!Token::checkToken($token))
{
return ReturnData::create(ReturnData::TOKEN_ERROR);
}
return $next($request);
}
}

3
composer.json

@ -10,7 +10,8 @@
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"maatwebsite/excel": "~2.1.0",
"overtrue/laravel-wechat": "~3.1"
"overtrue/laravel-wechat": "~3.1",
"jpush/jpush": "v3.5.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",

6
resources/views/admin/product/add.blade.php → resources/views/admin/goods/add.blade.php

@ -2,9 +2,9 @@
@section('title', '商品添加')
@section('content')
<h5 class="sub-header"><a href="/fladmin/product">商品列表</a> > 添加商品</h5>
<h5 class="sub-header"><a href="/fladmin/goods">商品列表</a> > 添加商品</h5>
<form id="addarc" method="post" action="/fladmin/product/doadd" role="form" enctype="multipart/form-data" class="table-responsive">{{ csrf_field() }}
<form id="addarc" method="post" action="/fladmin/goods/doadd" role="form" enctype="multipart/form-data" class="table-responsive">{{ csrf_field() }}
<table class="table table-striped table-bordered">
<tbody>
<tr>
@ -75,7 +75,7 @@ function upImage()
<td align="right">商品类目:</td>
<td>
<select name="typeid" id="typeid">
<?php $catlist = category_tree(get_category('product_type',0));if($catlist){foreach($catlist as $row){
<?php $catlist = category_tree(get_category('goods_type',0));if($catlist){foreach($catlist as $row){
if($row["id"]==$catid){ ?>
<option selected="selected" value="<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "";}echo $row["name"]; ?></option>
<?php }else{ ?>

6
resources/views/admin/product/edit.blade.php → resources/views/admin/goods/edit.blade.php

@ -2,9 +2,9 @@
@section('title', '商品信息修改')
@section('content')
<h5 class="sub-header"><a href="/fladmin/product">商品列表</a> > 修改商品</h5>
<h5 class="sub-header"><a href="/fladmin/goods">商品列表</a> > 修改商品</h5>
<form id="addarc" method="post" action="/fladmin/product/doedit" role="form" enctype="multipart/form-data" class="table-responsive">{{ csrf_field() }}
<form id="addarc" method="post" action="/fladmin/goods/doedit" role="form" enctype="multipart/form-data" class="table-responsive">{{ csrf_field() }}
<table class="table table-striped table-bordered">
<tbody>
<tr>
@ -76,7 +76,7 @@ function upImage()
<td align="right">商品类目:</td>
<td>
<select name="typeid" id="typeid">
<?php $catlist = category_tree(get_category('product_type',0));foreach($catlist as $row){
<?php $catlist = category_tree(get_category('goods_type',0));foreach($catlist as $row){
if($row["id"]==$post["typeid"]){ ?>
<option selected="selected" value="<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "";}echo $row["name"]; ?></option>
<?php }else{ ?>

14
resources/views/admin/product/index.blade.php → resources/views/admin/goods/index.blade.php

@ -2,7 +2,7 @@
@section('title', '商品列表')
@section('content')
<h5 class="sub-header"><a href="/fladmin/producttype">商品分类</a> > <a href="/fladmin/product">商品列表</a> [ <a href="/fladmin/product/add<?php if(!empty($_GET["id"])){echo '?catid='.$_GET["id"];}?>">发布商品</a> ]</h5>
<h5 class="sub-header"><a href="/fladmin/goodstype">商品分类</a> > <a href="/fladmin/goods">商品列表</a> [ <a href="/fladmin/goods/add<?php if(!empty($_GET["id"])){echo '?catid='.$_GET["id"];}?>">发布商品</a> ]</h5>
<div class="table-responsive">
<table class="table table-striped table-hover">
@ -20,9 +20,9 @@
<tr>
<td><?php echo $row->id; ?></td>
<td><input name="arcID" type="checkbox" value="<?php echo $row->id; ?>" class="np"></td>
<td><a href="/fladmin/product/edit?id=<?php echo $row->id; ?>"><?php echo $row->title; ?></a> <?php if(!empty($row->litpic)){echo "<small style='color:red'>[图]</small>";}if($row->tuijian==1){echo "<small style='color:#22ac38'>[荐]</small>";} ?> </td>
<td><a href="/fladmin/goods/edit?id=<?php echo $row->id; ?>"><?php echo $row->title; ?></a> <?php if(!empty($row->litpic)){echo "<small style='color:red'>[图]</small>";}if($row->tuijian==1){echo "<small style='color:#22ac38'>[荐]</small>";} ?> </td>
<td><?php echo date('Y-m-d',$row->pubdate); ?></td>
<td><a href="/fladmin/product?id=<?php echo $row->typeid; ?>"><?php echo $row->name; ?></a></td><td><?php echo $row->click; ?></td><td><a target="_blank" href="<?php echo route('home_product',['id'=>$row->id]); ?>">预览</a>&nbsp;<a href="/fladmin/product/edit?id=<?php echo $row->id; ?>">修改</a>&nbsp;<a onclick="delconfirm('/fladmin/product/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
<td><a href="/fladmin/goods?id=<?php echo $row->typeid; ?>"><?php echo $row->name; ?></a></td><td><?php echo $row->click; ?></td><td><a target="_blank" href="<?php echo route('home_goods',['id'=>$row->id]); ?>">预览</a>&nbsp;<a href="/fladmin/goods/edit?id=<?php echo $row->id; ?>">修改</a>&nbsp;<a onclick="delconfirm('/fladmin/goods/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
</tr>
<?php }} ?>
<tr>
@ -36,10 +36,10 @@
</table>
</div><!-- 表格结束 -->
<div>
<form id="searcharc" class="navbar-form" action="/fladmin/product" method="get">
<form id="searcharc" class="navbar-form" action="/fladmin/goods" method="get">
<select name="typeid" id="typeid" style="padding:6px 5px;vertical-align:middle;border:1px solid #DBDBDB;border-radius:4px;">
<option value="0">选择栏目...</option>
<?php $catlist = category_tree(get_category('product_type',0));if($catlist){foreach($catlist as $row){ ?><option value="<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "—";}echo $row["name"]; ?></option><?php }} ?>
<?php $catlist = category_tree(get_category('goods_type',0));if($catlist){foreach($catlist as $row){ ?><option value="<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "—";}echo $row["name"]; ?></option><?php }} ?>
</select>
<div class="form-group"><input type="text" name="keyword" id="keyword" class="form-control required" placeholder="搜索关键词..."></div>
<button type="submit" class="btn btn-info" value="Submit">搜索一下</button></form>
@ -60,7 +60,7 @@ function delArc(aid)
if(confirm("确定删除吗"))
{
location="<?php echo route('admin_product_del'); ?>?id="+checkvalue;
location="<?php echo route('admin_goods_del'); ?>?id="+checkvalue;
}
else
{
@ -81,7 +81,7 @@ function tjArc(aid)
if(confirm("确定要推荐吗"))
{
location="<?php echo route('admin_product_recommendarc'); ?>?id="+checkvalue;
location="<?php echo route('admin_goods_recommendarc'); ?>?id="+checkvalue;
}
else
{

8
resources/views/admin/producttype/add.blade.php → resources/views/admin/goodstype/add.blade.php

@ -2,9 +2,9 @@
@section('title', '商品分类添加')
@section('content')
<h5 class="sub-header"><a href="/fladmin/producttype">商品分类管理</a> > 添加分类</h5>
<h5 class="sub-header"><a href="/fladmin/goodstype">商品分类管理</a> > 添加分类</h5>
<form method="post" action="/fladmin/producttype/doadd" role="form" id="addcat" class="table-responsive">{{ csrf_field() }}
<form method="post" action="/fladmin/goodstype/doadd" role="form" id="addcat" class="table-responsive">{{ csrf_field() }}
<table class="table table-striped table-bordered">
<tbody>
<tr>
@ -21,11 +21,11 @@
</tr>
<tr>
<td align="right">列表模板:</td>
<td><input name="templist" id="templist" type="text" value="productcat" class="required" size="20"></td>
<td><input name="templist" id="templist" type="text" value="goodscat" class="required" size="20"></td>
</tr>
<tr>
<td align="right">文章模板:</td>
<td><input name="temparticle" id="temparticle" type="text" value="product" class="required" size="20"></td>
<td><input name="temparticle" id="temparticle" type="text" value="goods" class="required" size="20"></td>
</tr>
<tr>
<td align="right" style="vertical-align:middle;">缩略图:</td>

4
resources/views/admin/producttype/edit.blade.php → resources/views/admin/goodstype/edit.blade.php

@ -2,9 +2,9 @@
@section('title', '商品分类修改')
@section('content')
<h5 class="sub-header"><a href="/fladmin/producttype">商品分类管理</a> > 修改分类</h5>
<h5 class="sub-header"><a href="/fladmin/goodstype">商品分类管理</a> > 修改分类</h5>
<form method="post" action="/fladmin/producttype/doedit" role="form" id="addcat" class="table-responsive">{{ csrf_field() }}
<form method="post" action="/fladmin/goodstype/doedit" role="form" id="addcat" class="table-responsive">{{ csrf_field() }}
<table class="table table-striped table-bordered">
<tbody>
<tr>

8
resources/views/admin/producttype/index.blade.php → resources/views/admin/goodstype/index.blade.php

@ -2,7 +2,7 @@
@section('title', '商品分类')
@section('content')
<h2 class="sub-header">商品分类管理</h2>[ <a href="/fladmin/producttype/add">增加顶级分类</a> ] [ <a href="/fladmin/product/add">发布商品</a> ]<br><br>
<h2 class="sub-header">商品分类管理</h2>[ <a href="/fladmin/goodstype/add">增加顶级分类</a> ] [ <a href="/fladmin/goods/add">发布商品</a> ]<br><br>
<form name="listarc"><div class="table-responsive">
<table class="table table-striped table-hover">
@ -11,11 +11,11 @@
<?php if($catlist){foreach($catlist as $row){ ?>
<tr id="cat-<?php echo $row["id"]; ?>">
<td><?php echo $row["id"]; ?></td>
<td><a href="/fladmin/product?id=<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "";}echo $row["name"]; ?></a></td>
<td><?php echo catarcnum($row["id"].'product'); ?></td>
<td><a href="/fladmin/goods?id=<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "";}echo $row["name"]; ?></a></td>
<td><?php echo catarcnum($row["id"].'goods'); ?></td>
<td><?php echo $row["typedir"]; ?></td>
<td><?php echo date('Y-m-d',$row["addtime"]); ?></td>
<td><a href="<?php echo get_front_url(array("type"=>"list","catid"=>$row["id"])); ?>" target="_blank">预览</a> | <a href="/fladmin/product/add?catid=<?php echo $row["id"]; ?>">发布商品</a> | <a href="/fladmin/producttype/add?reid=<?php echo $row["id"]; ?>">增加子类</a> | <a href="/fladmin/producttype/edit?id=<?php echo $row["id"]; ?>">更改</a> | <a onclick="delconfirm('/fladmin/producttype/del?id=<?php echo $row["id"]; ?>')" href="javascript:;">删除</a></td>
<td><a href="<?php echo get_front_url(array("type"=>"list","catid"=>$row["id"])); ?>" target="_blank">预览</a> | <a href="/fladmin/goods/add?catid=<?php echo $row["id"]; ?>">发布商品</a> | <a href="/fladmin/goodstype/add?reid=<?php echo $row["id"]; ?>">增加子类</a> | <a href="/fladmin/goodstype/edit?id=<?php echo $row["id"]; ?>">更改</a> | <a onclick="delconfirm('/fladmin/goodstype/del?id=<?php echo $row["id"]; ?>')" href="javascript:;">删除</a></td>
</tr><?php }} ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->
@endsection

51
routes/web.php

@ -23,9 +23,9 @@ Route::group(['domain' => env('APP_SUBDOMAIN'), 'namespace' => 'Wap'], function
Route::get('/tag{tag}/{page}', 'IndexController@tag'); //标签页,分页
Route::get('/tag{tag}', 'IndexController@tag')->name('wap_tag'); //标签页
Route::get('/page/{id}', 'IndexController@page')->name('wap_singlepage'); //单页
Route::get('/goods/{id}', 'IndexController@product')->name('wap_product'); //商品详情页
Route::get('/product{cat}/{page}', 'IndexController@productcat'); //产品分类页,分页
Route::get('/product{cat}', 'IndexController@productcat')->name('wap_productcat'); //产品分类页
Route::get('/goods/{id}', 'IndexController@goods')->name('wap_goods'); //商品详情页
Route::get('/goodstype{cat}/{page}', 'IndexController@goodstype'); //产品分类页,分页
Route::get('/goodstype{cat}', 'IndexController@goodstype')->name('wap_goodstype'); //产品分类页
Route::get('/sitemap.xml', 'IndexController@sitemap')->name('wap_sitemap');//sitemap
});
@ -42,9 +42,9 @@ Route::group(['namespace' => 'Home'], function () {
Route::get('/tag{tag}/{page}', 'IndexController@tag'); //标签页,分页
Route::get('/tag{tag}', 'IndexController@tag')->name('home_tag'); //标签页
Route::get('/page/{id}', 'IndexController@page')->name('home_singlepage'); //单页
Route::get('/goods/{id}', 'IndexController@product')->name('home_product'); //商品详情页
Route::get('/product{cat}/{page}', 'IndexController@productcat'); //产品分类页,分页
Route::get('/product{cat}', 'IndexController@productcat')->name('home_productcat'); //产品分类页
Route::get('/goods/{id}', 'IndexController@goods')->name('home_goods'); //商品详情页
Route::get('/goodstype{cat}/{page}', 'IndexController@goodstype'); //产品分类页,分页
Route::get('/goodstype{cat}', 'IndexController@goodstype')->name('home_goodstype'); //产品分类页
Route::get('/sitemap.xml', 'IndexController@sitemap')->name('home_sitemap');//sitemap
Route::get('/aaa', function () {
@ -91,21 +91,21 @@ Route::group(['prefix' => 'fladmin', 'namespace' => 'Admin', 'middleware' => ['w
Route::post('/page/doedit', 'PageController@doedit')->name('admin_page_doedit');
Route::get('/page/del', 'PageController@del')->name('admin_page_del');
//产品
Route::get('/product', 'ProductController@index')->name('admin_product');
Route::get('/product/add', 'ProductController@add')->name('admin_product_add');
Route::post('/product/doadd', 'ProductController@doadd')->name('admin_product_doadd');
Route::get('/product/edit', 'ProductController@edit')->name('admin_product_edit');
Route::post('/product/doedit', 'ProductController@doedit')->name('admin_product_doedit');
Route::get('/product/del', 'ProductController@del')->name('admin_product_del');
Route::get('/product/recommendarc', 'ProductController@recommendarc')->name('admin_product_recommendarc');
Route::get('/product/articleexists', 'ProductController@productexists')->name('admin_product_productexists');
Route::get('/goods', 'GoodsController@index')->name('admin_goods');
Route::get('/goods/add', 'GoodsController@add')->name('admin_goods_add');
Route::post('/goods/doadd', 'GoodsController@doadd')->name('admin_goods_doadd');
Route::get('/goods/edit', 'GoodsController@edit')->name('admin_goods_edit');
Route::post('/goods/doedit', 'GoodsController@doedit')->name('admin_goods_doedit');
Route::get('/goods/del', 'GoodsController@del')->name('admin_goods_del');
Route::get('/goods/recommendarc', 'GoodsController@recommendarc')->name('admin_goods_recommendarc');
Route::get('/goods/articleexists', 'GoodsController@goodsexists')->name('admin_goods_goodsexists');
//产品分类
Route::get('/producttype', 'ProductTypeController@index')->name('admin_producttype');
Route::get('/producttype/add', 'ProductTypeController@add')->name('admin_producttype_add');
Route::post('/producttype/doadd', 'ProductTypeController@doadd')->name('admin_producttype_doadd');
Route::get('/producttype/edit', 'ProductTypeController@edit')->name('admin_producttype_edit');
Route::post('/producttype/doedit', 'ProductTypeController@doedit')->name('admin_producttype_doedit');
Route::get('/producttype/del', 'ProductTypeController@del')->name('admin_producttype_del');
Route::get('/goodstype', 'GoodsTypeController@index')->name('admin_goodstype');
Route::get('/goodstype/add', 'GoodsTypeController@add')->name('admin_goodstype_add');
Route::post('/goodstype/doadd', 'GoodsTypeController@doadd')->name('admin_goodstype_doadd');
Route::get('/goodstype/edit', 'GoodsTypeController@edit')->name('admin_goodstype_edit');
Route::post('/goodstype/doedit', 'GoodsTypeController@doedit')->name('admin_goodstype_doedit');
Route::get('/goodstype/del', 'GoodsTypeController@del')->name('admin_goodstype_del');
//友情链接
Route::get('/friendlink', 'FriendlinkController@index')->name('admin_friendlink');
Route::get('/friendlink/add', 'FriendlinkController@add')->name('admin_friendlink_add');
@ -178,14 +178,15 @@ Route::group(['prefix' => 'fladmin', 'namespace' => 'Admin', 'middleware' => ['w
Route::get('/test', 'LoginController@test')->name('admin_test');
});
//接口路由
//接口路由,无需token验证
Route::group(['prefix' => 'api', 'namespace' => 'Api', 'middleware' => ['web']], function () {
Route::post('/listarc', 'IndexController@listarc')->name('api_listarc');
Route::get('/ccc', function () {
// 匹配 "/api/users" URL
});
});
//接口路由,需token验证
Route::group(['prefix' => 'api', 'namespace' => 'Api', 'middleware' => ['web','token']], function () {
});
//中间件
Route::group(['middleware' => 'auth'], function () {

Loading…
Cancel
Save