123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\admin\controller;
- /**
- * 管理用户
- */
- class Customer extends Admin{
- protected $Customer = null;
- protected function _initialize(){
- parent::_initialize();
- $this->Customer = model('Customer');
- }
- public function index(){
- $this->assign('meta_title','客户列表');
- return $this->fetch();
- }
- public function load(){
- $where = [];
- $page = input('get.page');
- $limit = input('get.limit');
- $list = $this->Customer->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->Customer->cname = $cname;
- $this->Customer->truename = input('post.truename');
- $this->Customer->mobile = input('post.mobile');
- $this->Customer->address = input('post.address');
- $result = $this->Customer->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');
- $customer = $this->Customer->where(['id'=>$id])->find();
- if (!$customer) {
- $this->output(1,'参数错误');
- }
- $cname = input('post.cname');
- if (empty($cname)) {
- $this->output(1,'名称不能为空');
- }
- $customer->cname = $cname;
- $customer->truename = input('post.truename');
- $customer->mobile = input('post.mobile');
- $customer->address = input('post.address');
- $result = $customer->save();
- if (!$result) {
- $this->output(1,'保存失败');
- }
- $this->output(0,'保存成功');
- }else{
- $id = input('get.id');
- $customer = $this->Customer->where(['id'=>$id])->find();
- if (!$customer) {
- $this->error('参数错误');
- }
- $this->assign('customer',$customer);
- $this->assign('meta_title','添加客户');
- return $this->fetch();
- }
- }
- public function delete(){
- if ($this->request->isPost()) {
- $id = input('post.id');
- $customer = $this->Customer->where(['id'=>$id])->find();
- if (!$customer) {
- $this->output(1,'参数错误');
- }
- $result = $customer->delete();
- if (!$result) {
- $this->output(1,'删除失败');
- }
- $this->output(0,'删除成功');
- }
- }
- }
|