Supplier = model('Supplier'); } public function index(){ $this->assign('meta_title','供应商管理'); return $this->fetch(); } public function load(){ $where = []; $search = input('get.search'); if (!empty($search)) { $where['cname|id'] = ['like','%'.$search.'%']; } $page = input('get.page'); $limit = input('get.limit'); $list = $this->Supplier->where($where)->paginate($limit,false,['page'=>$page]); $data = []; foreach ($list as $key => $value) { $data[$key]['id'] = $value['id']; $data[$key]['cname'] = $value['cname']; $data[$key]['truename'] = $value['truename']; $data[$key]['mobile'] = $value['mobile']; $data[$key]['address'] = $value['address']; $data[$key]['state'] = $value['state']; $data[$key]['create_time'] = $value['create_time']; } $this->output(0,'获取成功',$data,$list->total()); } public function add(){ if ($this->request->isPost()) { $cname = input('post.cname'); if (empty($cname)) { $this->output(1,'名称不能为空'); } $this->Supplier->cname = $cname; $this->Supplier->truename = input('post.truename'); $this->Supplier->mobile = input('post.mobile'); $this->Supplier->address = input('post.address'); $result = $this->Supplier->save(); if (!$result) { $this->output(1,'保存失败'); } $this->output(0,'保存成功'); }else{ $this->assign('meta_title','添加客户'); return $this->fetch(); } } public function edit(){ if ($this->request->isPost()) { $id = input('post.id'); $supplier = $this->Supplier->where(['id'=>$id])->find(); if (!$supplier) { $this->output(1,'参数错误'); } $cname = input('post.cname'); if (empty($cname)) { $this->output(1,'名称不能为空'); } $supplier->cname = $cname; $supplier->truename = input('post.truename'); $supplier->mobile = input('post.mobile'); $supplier->address = input('post.address'); $result = $supplier->save(); if (!$result) { $this->output(1,'保存失败'); } $this->output(0,'保存成功'); }else{ $id = input('get.id'); $supplier = $this->Supplier->where(['id'=>$id])->find(); if (!$supplier) { $this->error('参数错误'); } $this->assign('supplier',$supplier); $this->assign('meta_title','添加客户'); return $this->fetch(); } } public function delete(){ if ($this->request->isPost()) { $id = input('post.id'); $supplier = $this->Supplier->where(['id'=>$id])->find(); if (!$supplier) { $this->output(1,'参数错误'); } $result = $supplier->delete(); if (!$result) { $this->output(1,'删除失败'); } $this->output(0,'删除成功'); } } }