Company.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\user\controller;
  3. use think\App;use think\facade\Validate;
  4. class Company extends Base{
  5. public function __construct(App $app) {
  6. parent::__construct($app);
  7. $this->model=new \app\user\model\Headquarters();
  8. }
  9. /**
  10. * @return \think\Response|\think\response\Json
  11. * @throws \think\db\exception\DbException
  12. */
  13. public function list(){
  14. $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' =>
  15. '', 'account_id' => '', 'type' => ''], 'post');
  16. $condition = [['is_del', '=', 0]];
  17. if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
  18. if ($post['name'] != '') $condition[] = ['name', 'like', "%{$post['name']}%"];
  19. if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
  20. if ($post['account_id'] != '') $condition[] = ['code', 'in', function ($query) use ($post) {
  21. return $query->name('account_company')->where(['account_id'=>$post['account_id'],"is_del"=>0,'status'=>1])
  22. ->column('companyCode');
  23. }];
  24. if ($post['type'] != '') $condition[] = ['type', '=', $post['type']];
  25. $list = $this->model->field('id,code,name,type,status,addtime,relation_code')->where($condition)->order('id', 'desc')->paginate( ['page' => $post['page'], 'list_rows'
  26. => $post['size']]);
  27. return success('获取成功', ["list"=>$list->items(),"count"=>$list->total()]);
  28. }
  29. /**
  30. * @return \think\Response|\think\response\Json
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public function query(){
  36. $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'size' => 100, 'account_id' => '',
  37. 'type' => ''], 'post');
  38. $condition = [['is_del', '=', 0]];
  39. if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
  40. if ($post['name'] != '') $condition[] =['name', 'like', "%{$post['name']}%"];
  41. if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
  42. if ($post['account_id'] != '') $condition[] = ['code', 'in', function ($query) use ($post) {
  43. return $query->name('account_company')->where(['account_id'=>$post['account_id'],"is_del"=>0,'status'=>1])
  44. ->column('companyCode');
  45. }];
  46. if ($post['type'] != '') $condition[] = ['type', '=', $post['type']];
  47. $list = $this->model->field('id,code,name,type,status,addtime,relation_code,length(name) len_name')->where
  48. ($condition)->order('len_name', 'asc')->select();
  49. return success('获取成功', $list);
  50. }
  51. }