Consult.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Consult extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  14. if($token==""){
  15. return error_show(101,'token不能为空');
  16. }
  17. $effetc = VerifyTokens($token);
  18. if(!empty($effetc) && $effetc['code']!=0) {
  19. return error_show($effetc['code'], $effetc['message']);
  20. }
  21. }
  22. public function list(){
  23. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  24. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  25. $where=[['is_del',"=",0],["cat_id","<>",0]];
  26. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  27. if ($zxNo !== "") {
  28. $where[] = ['zxNo','=',$zxNo];
  29. }
  30. $sequenceNo = isset($this->post['sequenceNo']) && $this->post['sequenceNo'] !== "" ? trim($this->post['sequenceNo']) : "";
  31. if ($sequenceNo !== "") {
  32. $where[] = ['sequenceNo','like',"%$sequenceNo%"];
  33. }
  34. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  35. if ($salesman !== "") {
  36. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  37. $where[]= ["salesman",'like',"%$salesman%"];
  38. }
  39. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  40. if ($cpName !== "") {
  41. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  42. $where[]= ["cpName",'like',"%$cpName%"];
  43. }
  44. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  45. if ($khNo !== "") {
  46. // $where['khNo'] = $khNo;
  47. $where[]= ["khNo",'like',"%$khNo%"];
  48. }
  49. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  50. if ($start !="") {
  51. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  52. $where[]= ["zxtime",'>=',$start];
  53. }
  54. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  55. if($end !=""){
  56. $where[]= ["zxtime",'<=',$end];
  57. }
  58. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  59. if ($status !== "") {
  60. $where[]= ["status",'=',$status];
  61. }
  62. $count = Db::name('consult')->where($where)->count();
  63. $total = ceil($count / $size);
  64. $page = $page >= $total ? $total : $page;
  65. $list = Db::name('consult')->where($where)->page($page,$size)
  66. ->select();
  67. $data=[];
  68. foreach ($list as $value){
  69. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  70. $data[]=$value;
  71. }
  72. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  73. }
  74. public function info(){
  75. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  76. if($id==""){
  77. return error_show(1002,"咨询单编号不能为空");
  78. }
  79. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  80. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  81. $fo['can']=$in;
  82. if(empty($fo)){
  83. return error_show(1002,"未找到咨询单编号");
  84. }else{
  85. return app_show(0,"获取成功",$fo);
  86. }
  87. }
  88. public function del(){
  89. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  90. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  91. if($de==false){
  92. return error_show(1002,'咨询单编号未找到');
  93. }
  94. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  95. if($dell){
  96. return error_show(0,"删除成功");
  97. }else
  98. return error_show(1002,"删除失败");
  99. }
  100. }