1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ProductModel;
- use app\admin\model\UserModel;
- use think\Db;
- use think\Session;
- use app\admin\model\Types;
- class Product extends Base
- {
- /**
- * 行业显示
- */
- public function index()
- {
- if (request()->isAjax()) {
- $product = new ProductModel();
- $lists = $product->alias('d')
- ->join('admin a','a.id = d.admin_id')
- ->whereOr('d.admin_id',session('uid'))
- ->whereOr('a.groupid','3')
- ->whereOr('a.groupid','5')
- ->select();
- $count = count($lists);
- return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
- }
- return $this->fetch('index');
- }
- /**
- * 添加
- */
- public function add()
- {
- if (request()->isAjax()) {
- $name = input('name');
- if (!isset($name) || empty($name)) return json(['code' => 100, 'msg' => "请输入行业名"]);
- if (mb_strlen($name) <=1 || mb_strlen($name)>8) return json(['code' => 100, 'msg' => "字符长度最大为8最小为1"]);
- $da_isset = ProductModel::where('product_name', $name)->find();
- if ($da_isset) return json(['code' => 100, 'msg' => "此产品已存在"]);
- $product = new ProductModel();
- $add = $product->save(['product_name' => $name,'admin_id' => session('uid')]);
- if ($add) return json(['code' => 200, 'msg' => "添加成功"]);
- if (!$add) return json(['code' => 100, 'msg' => "添加失败"]);
- }
- return $this->fetch('add');
- }
- /**
- * 修改
- */
- public function edit()
- {
- $product = new ProductModel();
- if (request()->isAjax()) {
- $name = input('name');
- $id = input('id');
- if (!isset($name) || empty($name)) return json(['code' => 100, 'msg' => "请输入行业名"]);
- if (mb_strlen($name) <=1 || mb_strlen($name)>8) return json(['code' => 100, 'msg' => "字符长度最大为8最小为1"]);
- $da_isset = ProductModel::where('product_name', $name)->select();
- if (count($da_isset)>1) return json(['code' => 100, 'msg' => "此行业已存在"]);
- $add = $product->save(['product_name' => $name],['id'=> $id]);
- if ($add) return json(['code' => 200, 'msg' => "编辑成功"]);
- if (!$add) return json(['code' => 100, 'msg' => "编辑失败"]);
- }
- $id = input('id');
- $this->assign(['data' => $product->where('id',$id)->find()]);
- return $this->fetch('edit');
- }
- /**
- * 删除
- */
- public function del()
- {
- $id = input('id');
- // $user = new UserModel();
- // $is_use = Db::name('customer')->where('type',$id)->find(); // 判断是否由用户使用此字段
- // if ($is_use) return json(['code' => 100, 'msg' => "还有用户正在使用此行业呢!"]);
- $del = ProductModel::where('id',$id)->delete();
- if ($del) return json(['code' => 200, 'msg' => "删除成功"]);
- if (!$del) return json(['code' => 100, 'msg' => "删除失败"]);
- }
- }
|