OrderAutoSendArea.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\util\ExcelUtil;
  4. use think\App;
  5. use think\Db;
  6. use think\Exception;
  7. class OrderAutoSendArea extends Auth
  8. {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->table='order_auto_send_area';
  12. $this->model= new \app\common\model\OrderAutoSendArea();
  13. }
  14. public function index(){
  15. if(request()->isAjax()){
  16. //分页参数
  17. $length = input('rows',10,'intval'); //每页条数
  18. $page = input('page',1,'intval'); //第几页
  19. $start = ($page - 1) * $length; //分页开始位置
  20. //排序
  21. $sortRow = input('sidx','id','trim'); //排序列
  22. $sort = input('sord','desc','trim'); //排序方式
  23. $order = $sortRow.' '.$sort;
  24. $title = input('title','','trim');
  25. if($title){
  26. $map1[] = ['title','like','%'.$title.'%'];
  27. $ids = Db::name('dep')
  28. ->where($map1)
  29. ->column('id');
  30. if(empty($ids)){
  31. $map[] = ['dep_id','=',-1];
  32. }else{
  33. $map[] = ['dep_id','in',$ids];
  34. }
  35. }
  36. $enable = input('enable','','trim');
  37. if($enable != ''){
  38. $map[] = ['enable','=',$enable];
  39. }
  40. $map[] = ['org_id','=',$this->orgId];
  41. $map= empty($map) ? true: $map;
  42. //数据查询
  43. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  44. foreach ($lists as $k=>$v){
  45. $lists[$k]['dep_name'] = Db::name('dep')
  46. ->where('id',$v['dep_id'])
  47. ->value('title');
  48. $real_name = Db::name('user')
  49. ->where('id','in',explode(',',$v['user_id']))
  50. ->column('real_name');
  51. $lists[$k]['real_name'] =implode(',',$real_name);
  52. $lists[$k]['last_name'] = Db::name('user')
  53. ->where('id',$v['last_user'])
  54. ->value('real_name');
  55. }
  56. //数据返回
  57. $totalCount = db($this->table)->where($map)->count();
  58. $totalPage = ceil($totalCount/$length);
  59. $result['page'] = $page;
  60. $result['total'] = $totalPage;
  61. $result['records'] = $totalCount;
  62. $result['rows'] = $lists;
  63. return json($result);
  64. }else{
  65. return $this->fetch();
  66. }
  67. }
  68. /**
  69. * 新增/编辑
  70. */
  71. public function add($id=0){
  72. if(request()->isPost()){
  73. $res = $this->model->updates();
  74. if($res){
  75. $this->success('操作成功',url('index'));
  76. }else{
  77. $this->error($this->model->getError());
  78. }
  79. }else{
  80. if($id){
  81. $info =db($this->table)->where('id',$id)->find();
  82. $info['user_id'] = $info['user_id']?explode(',',$info['user_id']):[];
  83. $this->assign('info',$info);
  84. }
  85. $user = Db::name('user')
  86. ->where('id','in',get_sort_user($this->orgId))
  87. ->field('id,real_name as title')
  88. ->order(['sorts'=>'desc','id'=>'asc'])
  89. ->select();
  90. $this->assign('user',$user);
  91. $dep = Db::name('dep')
  92. ->where('org_id',$this->orgId)
  93. ->where('del',0)
  94. ->where('enable',1)
  95. ->select();
  96. $this->assign('dep',$dep);
  97. return $this->fetch();
  98. }
  99. }
  100. /**
  101. * 删除记录
  102. * @param int $id
  103. */
  104. public function del($id=0){
  105. if(!$id){
  106. $this->error('参数错误');
  107. }
  108. $res = db($this->table)->where('id',$id)
  109. ->where('org_id',$this->orgId)->delete();
  110. if($res){
  111. $this->success('删除成功');
  112. }else{
  113. $this->error('删除失败');
  114. }
  115. }
  116. }