Consult.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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]];
  26. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  27. if ($zxNo !== "") {
  28. $where['zxNo'] = $zxNo;
  29. }
  30. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  31. if ($salesman !== "") {
  32. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  33. $where[]= ["salesman",'like',"%$salesman%"];
  34. }
  35. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  36. if ($cpName !== "") {
  37. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  38. $where[]= ["cpName",'like',"%$cpName%"];
  39. }
  40. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  41. if ($khNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["khNo",'like',"%$khNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["zxtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["zxtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["status",'=',$status];
  57. }
  58. $count = Db::name('consult')->where($where)->count();
  59. $total = ceil($count / $size);
  60. $page = $page >= $total ? $total : $page;
  61. $list = Db::name('consult')->where($where)->page($page,$size)
  62. ->field('id,zxNo,salesman,khNo,zxtime,zxtype,color,cpname,model,material,num,unit,total_fee,desc,
  63. sale_price,sale_fee,khname,scheme_name,status')->select();
  64. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  65. }
  66. public function info(){
  67. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  68. if($id==""){
  69. return error_show(1002,"咨询单编号不能为空");
  70. }
  71. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  72. if(empty($fo)){
  73. return error_show(1002,"未找到咨询单编号");
  74. }else{
  75. return app_show(0,"获取成功",$fo);
  76. }
  77. }
  78. public function del(){
  79. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  80. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  81. if($de==false){
  82. return error_show(1002,'咨询单编号未找到');
  83. }
  84. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  85. if($dell){
  86. return error_show(0,"删除成功");
  87. }else
  88. return error_show(1002,"删除失败");
  89. }
  90. }