作者 root

Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev

  1 +<?php
  2 +
  3 +namespace App\Files;
  4 +
  5 +use Illuminate\Http\Request;
  6 +
  7 +class Image
  8 +{
  9 + protected $request = [];
  10 +
  11 + public function __construct(Request $request)
  12 + {
  13 + $this->request = $request;
  14 + }
  15 +
  16 + /**
  17 + * @name :上传图片
  18 + * @return void
  19 + * @author :liyuhang
  20 + * @method
  21 + */
  22 + public function uploads(){
  23 + $url = './uploads/images/';
  24 + $param = $this->request->post();
  25 + if($this->request->hasFile('image') && $this->request->file('image')->isValid()){
  26 + $filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
  27 + $this->request->file('image')->move('./uploads/images/',$filename);
  28 + }else{
  29 + return false;
  30 + }
  31 + return $url.$filename;
  32 + }
  33 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +use App\Models\Project as ProjectModel;
  8 +
  9 +/**
  10 + * @name:项目信息
  11 + */
  12 +class ProjectController extends BaseController
  13 +{
  14 + /**
  15 + * @name :项目列表
  16 + * @return void
  17 + * @author :liyuhang
  18 + * @method
  19 + */
  20 + public function lists(){
  21 + $projectModel = new ProjectModel();
  22 + $lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order);
  23 + $this->result($lists);
  24 + }
  25 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Product as ProductModel;
  7 +use App\Models\ProductClassify as ProductClassifyModel;
  8 +use Illuminate\Support\Facades\Validator;
  9 +
  10 +/**
  11 + * @name:产品分类
  12 + */
  13 +class ProductClassifyController extends BaseController
  14 +{
  15 + /**
  16 + * @name : 获取当前登录的产品分裂
  17 + * @return void
  18 + * @author :liyuhang
  19 + * @method
  20 + */
  21 + public function lists(){
  22 + //TODO::获取当前登录用户
  23 + $this->map['project_id'] = $this->user['project_id'];
  24 + $productClassifyModel = new ProductClassifyModel();
  25 + $lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order);
  26 + $this->result($lists);
  27 + }
  28 +
  29 + /**
  30 + * @name :添加产品分类
  31 + * @return void
  32 + * @author :liyuhang
  33 + * @method
  34 + */
  35 + public function add(){
  36 + //参数验证
  37 + $rules = [
  38 + 'name'=>'required|max:11',
  39 + 'image'=>'required',
  40 + 'keywords'=>'required|max:50',
  41 + 'describe'=>'required',
  42 + ];
  43 + //验证的提示信息
  44 + $message = [
  45 + 'name.required'=>'名称必须填写',
  46 + 'name.max' => '名称不大于16字符.',
  47 + 'image.required'=>'路由必须填写',
  48 + 'keywords.required'=>'关键字必须填写',
  49 + 'keywords.max'=>'关键字最大50个字符',
  50 + 'describe.required'=>'路由必须填写',
  51 + ];
  52 + $validate = Validator::make($this->param, $rules, $message);
  53 + if($validate->fails()){
  54 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  55 + }
  56 + //TODO::关联项目
  57 + $this->param['project_id'] = $this->user['project_id'];
  58 + $productClassifyModel = new ProductClassifyModel();
  59 + $this->param['image'] = $this->uploads();
  60 + $rs = $productClassifyModel->add($this->param);
  61 + if($rs === false){
  62 + $this->response('error',Code::USER_ERROR);
  63 + }
  64 + $this->response('success',Code::SUCCESS);
  65 + }
  66 +
  67 + /**
  68 + * @name :编辑产品分类
  69 + * @return void
  70 + * @author :liyuhang
  71 + * @method
  72 + */
  73 + public function edit(){
  74 + //参数验证
  75 + $rules = [
  76 + 'id'=>'required',
  77 + 'name'=>'required|max:11',
  78 + 'describe'=>'required',
  79 + ];
  80 + //验证的提示信息
  81 + $message = [
  82 + 'id.required'=>'主键必须填写',
  83 + 'name.required'=>'名称必须填写',
  84 + 'name.max' => '名称不大于16字符.',
  85 + 'describe.required'=>'路由必须填写',
  86 + ];
  87 + $validate = Validator::make($this->param, $rules, $message);
  88 + if($validate->fails()){
  89 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  90 + }
  91 + if(isset($this->param['image'])){
  92 + //TODO::删除上一次的图片
  93 + $this->param['image'] = $this->uploads();
  94 + }
  95 + $productClassifyModel = new ProductClassifyModel();
  96 + $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);
  97 + if($rs === false){
  98 + $this->response('error',Code::USER_ERROR);
  99 + }
  100 + $this->response('success',Code::SUCCESS);
  101 + }
  102 +
  103 + /**
  104 + * @name :编辑当前类
  105 + * @return void
  106 + * @author :liyuhang
  107 + * @method
  108 + */
  109 + public function status(){
  110 + //参数验证
  111 + $rules = [
  112 + 'id'=>'required',
  113 + 'status'=>'required',
  114 + ];
  115 + //验证的提示信息
  116 + $message = [
  117 + 'id.required'=>'主键必须填写',
  118 + 'status.required'=>'状态必须填写',
  119 + ];
  120 + $validate = Validator::make($this->param, $rules, $message);
  121 + if($validate->fails()){
  122 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  123 + }
  124 + $productClassifyModel = new ProductClassifyModel();
  125 + $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);
  126 + if($rs === false){
  127 + $this->response('error',Code::USER_ERROR);
  128 + }
  129 + $this->response('success',Code::SUCCESS);
  130 + }
  131 + /**
  132 + * @name :删除产品分类
  133 + * @return void
  134 + * @author :liyuhang
  135 + * @method
  136 + */
  137 + public function del(){
  138 + //参数验证
  139 + $rules = [
  140 + 'id'=>'required',
  141 + ];
  142 + //验证的提示信息
  143 + $message = [
  144 + 'id.required'=>'主键必须填写',
  145 + ];
  146 + $validate = Validator::make($this->param, $rules, $message);
  147 + if($validate->fails()){
  148 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  149 + }
  150 + $productClassifyModel = new ProductClassifyModel();
  151 + //TODO::判断当前产品无下级
  152 + $info = $productClassifyModel->read(['pid'=>$this->param['id']],['id']);
  153 + if(empty($info)){
  154 + $this->response('当前分类不允许删除',Code::USER_ERROR);
  155 + }
  156 + //TODO::判断当前分类是否关联商品
  157 + $productModel = new ProductModel();
  158 + $classify_info = $productModel->read(['classify_id'=>$this->param['id']]);
  159 + if(empty($classify_info)){
  160 + $this->response('当前分类不允许删除',Code::USER_ERROR);
  161 + }
  162 + $rs = $productClassifyModel->del(['id'=>$this->param['id']]);
  163 + if($rs === false){
  164 + $this->response('error',Code::USER_ERROR);
  165 + }
  166 + $this->response('success',Code::SUCCESS);
  167 + }
  168 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Product as ProductModel;
  7 +use App\Models\ProductClassify as ProductClassifyModel;
  8 +use Illuminate\Support\Facades\Validator;
  9 +
  10 +/**
  11 + * @name:产品表
  12 + */
  13 +class ProductController extends BaseController
  14 +{
  15 + /**
  16 + * @name : 产品列表
  17 + * @return void
  18 + * @author :liyuhang
  19 + * @method
  20 + */
  21 + public function lists(){
  22 + //获取当前登录用户下的产品列表
  23 + $this->map['project_id'] = $this->user['project_id'];
  24 + $productModel = new ProductModel();
  25 + $lists = $productModel->lists($this->map,$this->p,$this->row,$this->order);
  26 + $this->result($lists);
  27 + }
  28 +
  29 + /**
  30 + * @name :添加产品
  31 + * @return void
  32 + * @author :liyuhang
  33 + * @method
  34 + */
  35 + public function add(){
  36 + //参数验证
  37 + $rules = [
  38 + 'name'=>'required|max:11',
  39 + 'image'=>'required',
  40 + 'describe'=>'required',
  41 + 'keywords'=>'required|max:50',
  42 + ];
  43 + //验证的提示信息
  44 + $message = [
  45 + 'name.required'=>'名称必须填写',
  46 + 'name.max' => '名称不大于16字符.',
  47 + 'image.required'=>'图片必须上传',
  48 + 'describe.required'=>'描述必须填写',
  49 + 'keywords.required'=>'关键字必须填写',
  50 + ];
  51 + $validate = Validator::make($this->param, $rules, $message);
  52 + if($validate->fails()){
  53 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  54 + }
  55 + //TODO::关联项目
  56 + $this->param['project_id'] = $this->user['project_id'];
  57 + $productModel = new ProductModel();
  58 + $this->param['image'] = $this->uploads();
  59 + $rs = $productModel->add($this->param);
  60 + if($rs === false){
  61 + $this->response('error',Code::USER_ERROR);
  62 + }
  63 + $this->response('success',Code::SUCCESS);
  64 + }
  65 +
  66 + public function edit(){
  67 + //参数验证
  68 + $rules = [
  69 + 'name'=>'required|max:11',
  70 + 'image'=>'required',
  71 + 'describe'=>'required',
  72 + 'keywords'=>'required|max:50',
  73 + ];
  74 + //验证的提示信息
  75 + $message = [
  76 + 'name.required'=>'名称必须填写',
  77 + 'name.max' => '名称不大于16字符.',
  78 + 'image.required'=>'图片必须上传',
  79 + 'describe.required'=>'描述必须填写',
  80 + 'keywords.required'=>'关键字必须填写',
  81 + ];
  82 + $validate = Validator::make($this->param, $rules, $message);
  83 + if($validate->fails()){
  84 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  85 + }
  86 + if(isset($this->param['image'])){
  87 + //TODO::删除上一次的图片
  88 + $this->param['image'] = $this->uploads();
  89 + }
  90 + $productModel = new ProductModel();
  91 + $rs = $productModel->edit($this->param,['id'=>$this->param['id']]);
  92 + if($rs === false){
  93 + $this->response('error',Code::USER_ERROR);
  94 + }
  95 + $this->response('success',Code::SUCCESS);
  96 + }
  97 +
  98 + /**
  99 + * @name :修改产品状态
  100 + * @return void
  101 + * @author :liyuhang
  102 + * @method
  103 + */
  104 + public function status(){
  105 + //参数验证
  106 + $rules = [
  107 + 'id'=>'required',
  108 + 'status'=>'required',
  109 + ];
  110 + //验证的提示信息
  111 + $message = [
  112 + 'id.required'=>'主键必须填写',
  113 + 'status.required'=>'状态必须填写',
  114 + ];
  115 + $validate = Validator::make($this->param, $rules, $message);
  116 + if($validate->fails()){
  117 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  118 + }
  119 + $productModel = new ProductModel();
  120 + $rs = $productModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
  121 + if($rs === false){
  122 + $this->response('error',Code::USER_ERROR);
  123 + }
  124 + $this->response('success',Code::SUCCESS);
  125 + }
  126 +
  127 + /**
  128 + * @name :删除产品
  129 + * @return void
  130 + * @author :liyuhang
  131 + * @method
  132 + */
  133 + public function del(){
  134 + //参数验证
  135 + $rules = [
  136 + 'id'=>'required',
  137 + ];
  138 + //验证的提示信息
  139 + $message = [
  140 + 'id.required'=>'主键必须填写',
  141 + ];
  142 + $validate = Validator::make($this->param, $rules, $message);
  143 + if($validate->fails()){
  144 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  145 + }
  146 + $productModel = new ProductModel();
  147 + $info = $productModel->read(['id'=>$this->param['id']],['image']);
  148 + //TODO::删除添加的图片
  149 + shell_exec('rm -rf '.request()->path().'../../'.$info['image']);
  150 + $rs = $productModel->del(['id'=>$this->param['id']]);
  151 + if($rs === false){
  152 + $this->response('error',Code::USER_ERROR);
  153 + }
  154 + $this->response('success',Code::SUCCESS);
  155 + }
  156 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Models\Project as ProjectModel;
  6 +use Illuminate\Support\Facades\DB;
  7 +
  8 +/**
  9 + * @name:user用户获取相关项目
  10 + */
  11 +class ProjectController extends BaseController
  12 +{
  13 + /**
  14 + * @name :根据登录用户获取所有项目
  15 + * @return void
  16 + * @author :liyuhang
  17 + * @method
  18 + */
  19 + public function page_lists(){
  20 +
  21 + $projectModel = new ProjectModel();
  22 + $lists = DB::table($projectModel->table)->select(['*'])->where($this->map)->forPage($this->p,$this->row)->orderBy($this->order)->get();
  23 +
  24 + }
  25 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class Product extends Base
  6 +{
  7 + //设置关联表名
  8 + protected $table = 'gl_product';
  9 + //自动维护create_at创建时间 updated_at修改时间
  10 + public $timestamps = true;
  11 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class ProductClassify extends Base
  6 +{
  7 + //设置关联表名
  8 + protected $table = 'gl_product_classify';
  9 + //自动维护create_at创建时间 updated_at修改时间
  10 + public $timestamps = true;
  11 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +use Illuminate\Support\Facades\DB;
  6 +
  7 +class Project extends Base
  8 +{
  9 + //设置关联表名
  10 + protected $table = 'gl_project';
  11 + //自动维护create_at创建时间 updated_at修改时间
  12 + public $timestamps = true;
  13 +
  14 + /**
  15 + * @name:获取当前对象不分页列表
  16 + */
  17 + public function page_lists(){
  18 + $lists = DB::table($this->table)->select(['*'])->where($this->map)->orderBy($this->order)->get();
  19 + return $lists;
  20 + }
  21 +}