Express.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\Admin\controller;
  3. use think\Db;
  4. class Express extends Base
  5. {
  6. #public $post="";
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. #$this->post=request()->post();
  11. }
  12. public function list(){
  13. $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
  14. $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
  15. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  16. $where = [];
  17. if ($status !== "") {
  18. $where['status'] = $status;
  19. }
  20. $code = isset($this->post['code']) && $this->post['code'] !== "" ? trim($this->post['code']) : "";
  21. if ($code !== "") {
  22. $where['express_code'] = ["like","%$code%"];
  23. }
  24. $express_name = isset($this->post['express_name']) && $this->post['express_name'] !== "" ? trim($this->post['express_name']) : "";
  25. if ($express_name !== "") {
  26. $where['express_name'] = ["like","%$express_name%"];
  27. }
  28. $count = Db::name("express")->where($where)->count();
  29. $total = ceil($count / $size);
  30. $page = $page >= $total ? $total : $page;
  31. $list= Db::name("express")->where($where)->page($page,$size)->select();
  32. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  33. }
  34. public function qureylist(){
  35. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  36. $where = ["status"=>1];
  37. if ($status !== "") {
  38. $where['status'] = $status;
  39. }
  40. $code = isset($this->post['code']) && $this->post['code'] !== "" ? trim($this->post['code']) : "";
  41. if ($code !== "") {
  42. $where['express_code'] = ["like","%$code%"];
  43. }
  44. $express_name = isset($this->post['express_name']) && $this->post['express_name'] !== "" ? trim($this->post['express_name']) : "";
  45. if ($express_name !== "") {
  46. $where['express_name'] = ["like","%$express_name%"];
  47. }
  48. $list= Db::name("express")->where($where)->select();
  49. return app_show(0, "获取成功", $list);
  50. }
  51. public function status(){
  52. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  53. if($id==""){
  54. return error_show(1004,"参数id不能为空");
  55. }
  56. $info= Db::name("express")->where(["id"=>$id])->find();
  57. if($info==false){
  58. return error_show(1004,"未找到快递数据");
  59. }
  60. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  61. if($status===""){
  62. return error_show(1004,"参数status不能为空");
  63. }
  64. $msg=$status==0?"禁用":"启用";
  65. $info['status']=$status;
  66. $up =Db::name("express")->update($info);
  67. return $up? app_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  68. }
  69. }