Company.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\user\controller;
  3. use think\App;
  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. '1', '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 ($this->level != 1 && $post['level'] != 1) $condition[] = ['code', 'in', function ($query) use ($post) {
  21. return $query->name('account_company')->where(['account_id'=>$this->uid,"is_del"=>0,'status'=>1])
  22. ->column('companyCode');
  23. }];
  24. if (!empty($post['type'])) $condition[] = ['type', 'in', $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' => '', 'level' =>1, 'size' => 100, 'type' =>[]], 'post');
  37. $condition = [['is_del', '=', 0]];
  38. if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
  39. if ($post['name'] != '') $condition[] =['name', 'like', "%{$post['name']}%"];
  40. if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
  41. if ($this->level != 1 && $post['level'] != 1) $condition[] = ['code', 'in', function ($query) use ($post) {
  42. return $query->name('account_company')->where(['account_id'=>$this->uid,'is_del'=>0,'status'=>1])
  43. ->column('companyCode');
  44. }];
  45. if (!empty($post['type'])) $condition[] = ['type', 'in', $post['type']];
  46. $list = $this->model->field('id,code,name,type,status,addtime,relation_code,length(name) len_name')->where
  47. ($condition)->order('len_name', 'asc')->select();
  48. return success('获取成功', $list);
  49. }
  50. public function companyType(){
  51. $param = $this->request->only(['company_type' => '', 'status' => ''], 'post', 'trim');
  52. $where=[["is_del","=",0]];
  53. if ($param['company_type'] != '') $where[] = ['company_type', 'like', "%{$param['company_type']}%"];
  54. if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
  55. $list = \app\user\model\CompanyType::where($where)->order('id', 'desc')->select();
  56. return success('获取成功', $list);
  57. }
  58. }