Express.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Express extends \app\BaseController
  6. {
  7. public $post='';
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->post = request()->post();
  12. }
  13. public function list(){
  14. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  15. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  16. $type = isset($this->post['type']) &&$this->post['type'] !=="" ? intval($this->post['type']):'0';
  17. $where = [["type","=",$type]];
  18. $name = isset($this->post['name']) &&$this->post['name'] !="" ? trim($this->post['name']):'';
  19. if($name!=''){
  20. $where[]=["name|shortName","like","%{$name}%"];
  21. }
  22. $count = Db::name("express")->where($where)->count();
  23. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  24. $list= Db::name("express")->where($where)->field('id,type,comTypeName,name,shortName,shortNameEn,shortNumber,canOrder')
  25. ->page($page,$size)->select();
  26. return app_show(0,'获取成功',['list'=>$list,"count"=>$count]);
  27. }
  28. public function SetUse(){
  29. $id = isset($this->post['id']) &&$this->post['id'] !="" ? intval($this->post['id']):'';
  30. if($id==''){
  31. return error_show(1004,"参数id不能为空");
  32. }
  33. $express = Db::name("express")->where(["id"=>$id])->find();
  34. if(empty($express)){
  35. return error_show(1004,"未找到数据");
  36. }
  37. $express['canOrder'] = $express['canOrder']==0 ?1:0;
  38. $up = Db::name("express")->save($express);
  39. return $up?app_show(0,"更新成功"):error_show(1005,"更新失败");
  40. }
  41. public function GetExpress(){
  42. $type = isset($this->post['type']) &&$this->post['type'] !=="" ? intval($this->post['type']):'0';
  43. $where = [["type","=",$type],['canOrder',"=",1]];
  44. $name = isset($this->post['name']) &&$this->post['name'] !="" ? trim($this->post['name']):'';
  45. if($name!=''){
  46. $where[]=["name|shortName","like","%{$name}%"];
  47. }
  48. $list= Db::name("express")->where($where)->field('id,type,comTypeName,name,shortName,shortNameEn,shortNumber,canOrder')
  49. ->select();
  50. return app_show(0,'获取成功',$list);
  51. }
  52. }