123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\admin\controller;
- /**
- * 供应商
- */
- class Supplier extends Admin{
- protected $Supplier = null;
- public function init(){
- parent::init();
- $this->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,'删除成功');
- }
- }
- }
|