作者 liyuhang

更新

... ... @@ -13,5 +13,21 @@ class Image
$this->request = $request;
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function uploads(){
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $this->request->file('image')->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
return false;
}
return $url.$filename;
}
}
... ...
... ... @@ -167,9 +167,13 @@ class BaseController extends Controller
* @method
*/
public function uploads(){
$files = $this->request->file('file');
if(empty($files)){
return $this->response('没有上传文件',Code::USER_ERROR);
}
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $this->request->file('image')->isValid()){
if($this->request->hasFile('image') && $files->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Models\ProductClassify as ProductClassifyModel;
/**
* @name:产品分类
*/
class ProductClassify extends BaseController
{
/**
* @name : 获取当前登录的产品分裂
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
//TODO::获取当前登录用户
$this->map['project_id'] = $this->user['project_id'];
$productClassifyModel = new ProductClassifyModel();
$lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order);
}
}
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\Product as ProductModel;
use App\Models\ProductClassify as ProductClassifyModel;
use Illuminate\Support\Facades\Validator;
/**
* @name:产品分类
*/
class ProductClassifyController extends BaseController
{
/**
* @name : 获取当前登录的产品分裂
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
//TODO::获取当前登录用户
$this->map['project_id'] = $this->user['project_id'];
$productClassifyModel = new ProductClassifyModel();
$lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order);
$this->result($lists);
}
/**
* @name :添加产品分类
* @return void
* @author :liyuhang
* @method
*/
public function add(){
//参数验证
$rules = [
'name'=>'required|max:11',
'image'=>'required',
'keywords'=>'required|max:50',
'describe'=>'required',
];
//验证的提示信息
$message = [
'name.required'=>'名称必须填写',
'name.max' => '名称不大于16字符.',
'image.required'=>'路由必须填写',
'keywords.required'=>'关键字必须填写',
'keywords.max'=>'关键字最大50个字符',
'describe.required'=>'路由必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
//TODO::关联项目
$this->param['project_id'] = $this->user['project_id'];
$productClassifyModel = new ProductClassifyModel();
$this->param['image'] = $this->uploads();
$rs = $productClassifyModel->add($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
/**
* @name :编辑产品分类
* @return void
* @author :liyuhang
* @method
*/
public function edit(){
//参数验证
$rules = [
'id'=>'required',
'name'=>'required|max:11',
'describe'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'name.required'=>'名称必须填写',
'name.max' => '名称不大于16字符.',
'describe.required'=>'路由必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
if(isset($this->param['image'])){
//TODO::删除上一次的图片
$this->param['image'] = $this->uploads();
}
$productClassifyModel = new ProductClassifyModel();
$rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
/**
* @name :编辑当前类
* @return void
* @author :liyuhang
* @method
*/
public function status(){
//参数验证
$rules = [
'id'=>'required',
'status'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'status.required'=>'状态必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$productClassifyModel = new ProductClassifyModel();
$rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
/**
* @name :删除产品分类
* @return void
* @author :liyuhang
* @method
*/
public function del(){
//参数验证
$rules = [
'id'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$productClassifyModel = new ProductClassifyModel();
//TODO::判断当前产品无下级
$info = $productClassifyModel->read(['pid'=>$this->param['id']],['id']);
if(empty($info)){
$this->response('当前分类不允许删除',Code::USER_ERROR);
}
//TODO::判断当前分类是否关联商品
$productModel = new ProductModel();
$classify_info = $productModel->read(['classify_id'=>$this->param['id']]);
if(empty($classify_info)){
$this->response('当前分类不允许删除',Code::USER_ERROR);
}
$rs = $productClassifyModel->del(['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
}
... ...
... ... @@ -2,6 +2,11 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\Product as ProductModel;
use App\Models\ProductClassify as ProductClassifyModel;
use Illuminate\Support\Facades\Validator;
/**
* @name:产品表
*/
... ... @@ -15,6 +20,137 @@ class ProductController extends BaseController
*/
public function lists(){
//获取当前登录用户下的产品列表
$this->map['project_id'] = $this->user['project_id'];
$productModel = new ProductModel();
$lists = $productModel->lists($this->map,$this->p,$this->row,$this->order);
$this->result($lists);
}
/**
* @name :添加产品
* @return void
* @author :liyuhang
* @method
*/
public function add(){
//参数验证
$rules = [
'name'=>'required|max:11',
'image'=>'required',
'describe'=>'required',
'keywords'=>'required|max:50',
];
//验证的提示信息
$message = [
'name.required'=>'名称必须填写',
'name.max' => '名称不大于16字符.',
'image.required'=>'图片必须上传',
'describe.required'=>'描述必须填写',
'keywords.required'=>'关键字必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
//TODO::关联项目
$this->param['project_id'] = $this->user['project_id'];
$productModel = new ProductModel();
$this->param['image'] = $this->uploads();
$rs = $productModel->add($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
public function edit(){
//参数验证
$rules = [
'name'=>'required|max:11',
'image'=>'required',
'describe'=>'required',
'keywords'=>'required|max:50',
];
//验证的提示信息
$message = [
'name.required'=>'名称必须填写',
'name.max' => '名称不大于16字符.',
'image.required'=>'图片必须上传',
'describe.required'=>'描述必须填写',
'keywords.required'=>'关键字必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
if(isset($this->param['image'])){
//TODO::删除上一次的图片
$this->param['image'] = $this->uploads();
}
$productModel = new ProductModel();
$rs = $productModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
/**
* @name :修改产品状态
* @return void
* @author :liyuhang
* @method
*/
public function status(){
//参数验证
$rules = [
'id'=>'required',
'status'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'status.required'=>'状态必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$productModel = new ProductModel();
$rs = $productModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
/**
* @name :删除产品
* @return void
* @author :liyuhang
* @method
*/
public function del(){
//参数验证
$rules = [
'id'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$productModel = new ProductModel();
$info = $productModel->read(['id'=>$this->param['id']],['image']);
//TODO::删除添加的图片
shell_exec('rm -rf '.request()->path().$info['image']);
$rs = $productModel->del(['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
}
... ...
... ... @@ -93,7 +93,7 @@ class UserController extends BaseController
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$userLogic = new UserLogic();
$rs = $userLogic->edit($this->param);
$rs = $userLogic->edits($this->param);
if($rs === false){
$this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
}
... ... @@ -101,6 +101,34 @@ class UserController extends BaseController
}
/**
* @name :修改当前用户状态
* @return void
* @author :liyuhang
* @method
*/
public function status(){
//参数验证
$rules = [
'id'=>'required',
'status'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'status.required'=>'状态必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$userLogic = new UserModel();
$rs = $userLogic->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
}
/**
* @name :删除管理员
* @return void
* @author :liyuhang
... ...
... ... @@ -41,7 +41,7 @@ class UserLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function edit($param){
public function edits($param){
$userModel = new UserModel();
//验证当前用户是否存在
$info = $userModel->read(['mobile'=>$param['mobile']]);
... ...
... ... @@ -67,7 +67,7 @@ class Base extends Model
* @author :liyuhang
* @method
*/
public function del(){
public function del($condition){
return DB::table($this->table)->where($condition)->delete();
}
}
... ...