Company.php 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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']])->each(function (&$item) {
  27. switch ($item['type']) {
  28. case 1:
  29. $item['legaler_type'] = \app\user\model\Business::where('companyNo', $item['code'])->value('legaler_type','');
  30. break;
  31. case 2:
  32. $item['legaler_type'] = '';
  33. break;
  34. case 3:
  35. $item['legaler_type'] = \app\user\model\Supplier::where('code', $item['code'])->value('legaler_type','');
  36. break;
  37. default:
  38. $item['legaler_type'] = '';
  39. break;
  40. }
  41. });
  42. return success('获取成功', ["list"=>$list->items(),"count"=>$list->total()]);
  43. }
  44. /**
  45. * @return \think\Response|\think\response\Json
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function query(){
  51. $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'level' =>1, 'size' => 100, 'type' =>[]], 'post');
  52. $condition = [['is_del', '=', 0]];
  53. if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
  54. if ($post['name'] != '') $condition[] =['name', 'like', "%{$post['name']}%"];
  55. if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
  56. if ($this->level != 1 && $post['level'] != 1) $condition[] = ['code', 'in', function ($query) use ($post) {
  57. return $query->name('account_company')->where(['account_id'=>$this->uid,'is_del'=>0,'status'=>1])
  58. ->column('companyCode');
  59. }];
  60. if (!empty($post['type'])) $condition[] = ['type', 'in', $post['type']];
  61. $list = $this->model->field('id,code,name,type,status,addtime,relation_code,length(name) len_name')->where
  62. ($condition)->order('len_name', 'asc')->select()->each(function (&$item) {
  63. switch ($item['type']) {
  64. case 1:
  65. $item['legaler_type'] = \app\user\model\Business::where('companyNo', $item['code'])->value('legaler_type','');
  66. break;
  67. case 2:
  68. $item['legaler_type'] = '';
  69. break;
  70. case 3:
  71. $item['legaler_type'] = \app\user\model\Supplier::where('code', $item['code'])->value('legaler_type','');
  72. break;
  73. default:
  74. $item['legaler_type'] = '';
  75. break;
  76. }
  77. });
  78. return success('获取成功', $list);
  79. }
  80. public function companyType(){
  81. $param = $this->request->only(['company_type' => '', 'status' => ''], 'post', 'trim');
  82. $where=[["is_del","=",0]];
  83. if ($param['company_type'] != '') $where[] = ['company_type', 'like', "%{$param['company_type']}%"];
  84. if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
  85. $list = \app\user\model\CompanyType::where($where)->order('id', 'desc')->select();
  86. return success('获取成功', $list);
  87. }
  88. }