返回 小型企业站产品...... 登陆

小型企业站产品模块

1 2019-06-16 10:04:51 229

<?php 

namespace app\admin\controller;

use app\admin\controller\Commn;

use think\facade\Request;

use think\facade\Session;

use app\admin\model\Newsl;

use app\admin\model\Product;


/**

*/

class Productl extends Commn

{

//产品展示

public function index()

{

//查询产品

$data = Product::order('product_id','desc')->paginate(4);

//分页page

$page = $data->render();


$this->assign('page',$page);


$this->assign('data',$data);


return $this->fetch();

}

//图片上传页面

public function uplode()

{

//获取图片信息

$file = Request::file('img');

if ($info = $file->validate(['ext'=>'jpg,png,jpeg,gif'])->move('upload')){

//返回上次成功信息

return json(['errno'=>0,'data'=>["/upload/" .$info->getSaveName()]]);

}else{

echo $info->getError();

}

}


public function add()

{

// //查询产品分类

// $res = Product::all();

// $this->assign('res',$res);


return $this->fetch();

}

public function add_do()

{

$data = Request::param();


$data['username'] = Session::get('username');


$product_name = $data['product_name'];


if ($res = Product::where('product_name',$product_name)->find()) {

return json(['code'=>1,'msg'=>'产品名重复,添加产品失败']);

}

$data['create_time'] = time();

if ($product = Product::insert($data)) {

return json(['code'=>2,'msg'=>'添加产品成功']);

}else{

return json(['code'=>3,'msg'=>'添加产品失败']);

}

}

public function upl()

{

$data = Request::param();



$product_id = $data['product_id'];


$res = Product::where('product_id',$product_id)->find();


$this->assign('res',$res);


return $this->fetch();

}

public function upl_do()

{

$data = Request::param();


$product_id = $data['product_id'];


$data['create_time'] = time();


//查询这条用户数据

$res = Product::where('product_id',$product_id)->find();



// //判断如果传过来的产品名称重复,是根据产品id查询出来的产品一致

if ($res['product_name'] == $data['product_name']) {


if ($Productl = Product::where('product_id',$product_id)->update($data)) {

return json(['code'=>1,'msg'=>'修改产品成功']);

}else{

return json(['code'=>2,'msg'=>'修改产品失败']);

}

}else{

if ($info = Product::where('product_id',$product_id)->all()) {

return json(['code'=>3,'msg'=>'修改产品名已经存在,修改产品失败']);

}

}

}

public function del()

{

//接值

$data = Request::param();


//产品id

$product_id = $data['id'];


//删除操作

if ($Productl = Product::where('product_id',$product_id)->delete()) {

return json(['code'=>1,'msg'=>'删除产品成功']);

}else{

return json(['code'=>2,'msg'=>'删除产品失败']);

}

}


}


















 ?>

1VC[8ME_E}AK6{[LLS0VFYR.png

最新手记推荐

• 用composer安装thinkphp框架的步骤 • 省市区接口说明 • 用thinkphp,后台新增栏目 • 管理员添加编辑删除 • 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消 回复 发送
  • PHP中文网