MaintController.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class MaintController extends ComController {
  5. public function _initialize() {
  6. parent::_initialize();
  7. $this->dbname ='wb_wuye';
  8. }
  9. public function wuye(){
  10. $Data=I();
  11. if(isset($Data['list'])){
  12. $UserVIew=M('wb_wuye');
  13. $GetPage=$Data['pageCurrent'];//第几页
  14. $GetSize=$Data['pageSize'];//每页条数
  15. $Page=($GetPage-1)*$GetSize;
  16. $Map=array();
  17. if(!empty($Data['name'])){
  18. $Map['yw_name']=array("LIKE",'%'.$Data['name'].'%');
  19. }
  20. if(!empty($Data['phone'])){
  21. $Map['yw_phone']=array("LIKE",'%'.$Data['phone'].'%');
  22. }
  23. $permdata=$this->permdata();
  24. if (!empty($permdata))
  25. {
  26. $Map['yw_edit']=$permdata;
  27. }
  28. $Count= $UserVIew->where($Map)->count();// 查询满足要求的总记录数
  29. $List = $UserVIew->field("id,yw_name,yw_phone,yw_time,yw_edit,yw_type")->where($Map)->order('yw_time desc')
  30. ->limit($Page,$GetSize)->select();
  31. $Info = array(
  32. 'totalRow' => $Count,
  33. //'pageSize' => $count,//分页时不传
  34. 'list' => $List,
  35. );
  36. echo json_encode($Info);
  37. }
  38. else
  39. {
  40. $this->display();
  41. }
  42. }
  43. public function add(){
  44. if (IS_POST) {
  45. $Tab=M('wb_wuye');
  46. $rules = array(
  47. array('phone','','电话号码重复!',0,'unique'),
  48. );
  49. if (!$Tab->validate($rules)->create())
  50. {
  51. // echo json_encode(array('statusCode'=>'300','message'=> $menu->getError()));
  52. $this->mtReturn(300,$Tab->getError());
  53. }
  54. else
  55. {
  56. /*$PhoneRes=M('')->query('SELECT openid FROM ztcrm.sp_customuser where phone='.$Data['phone']);
  57. if (empty($PhoneRes)) {
  58. $this->mtReturn(300,'该号码未关注公众号,请先关注公众号注册信息才能录入');
  59. }*/
  60. $Data=I();
  61. $Data['yw_time']=date('Y-m-d H:i:s');
  62. $Data['yw_edit']=session('zt_username');
  63. $res = $Tab->add($Data);
  64. if($res)
  65. $this->mtReturn(200,'维保公司新增成功');
  66. else
  67. $this->mtReturn(300,'维保公司新增失败');
  68. }
  69. }
  70. else
  71. {
  72. $this->assign('action','/home/Maint/add');
  73. $this->display();
  74. }
  75. }
  76. public function edit(){
  77. $Data=I();
  78. $Tab=M('wb_wuye');
  79. if(IS_POST)
  80. {
  81. $this->logcs(print_r($Data,ture));
  82. $res=$Tab->save($Data);
  83. if($res)
  84. $this->mtReturn(200,'编辑成功');
  85. else
  86. $this->mtReturn(300,'编辑失败');
  87. }
  88. else
  89. {
  90. $ResData = $Tab->field("id,yw_name,yw_phone,yw_time,yw_edit,yw_type")->where(array('id'=>$Data['id']))->select();
  91. $this->assign('ResData',$ResData[0]);
  92. $this->assign('action','/home/Maint/edit');
  93. $this->display();
  94. }
  95. }
  96. }