1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\user\controller;
- use think\App;use think\facade\Validate;
- class Company extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new \app\user\model\Headquarters();
- }
- /**
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function list(){
- $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' =>
- '', 'account_id' => '', 'type' => ''], 'post');
- $condition = [['is_del', '=', 0]];
- if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
- if ($post['name'] != '') $condition[] = ['name', 'like', "%{$post['name']}%"];
- if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
- if ($post['account_id'] != '') $condition[] = ['code', 'in', function ($query) use ($post) {
- return $query->name('account_company')->where(['account_id'=>$post['account_id'],"is_del"=>0,'status'=>1])
- ->column('companyCode');
- }];
- if ($post['type'] != '') $condition[] = ['type', '=', $post['type']];
- $list = $this->model->field('id,code,name,type,status,addtime,relation_code')->where($condition)->order('id', 'desc')->paginate( ['page' => $post['page'], 'list_rows'
- => $post['size']]);
- return success('获取成功', ["list"=>$list->items(),"count"=>$list->total()]);
- }
- /**
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function query(){
- $post = $this->request->param(['code' => '', 'name' => '', 'status' => '', 'size' => 100, 'account_id' => '',
- 'type' => ''], 'post');
- $condition = [['is_del', '=', 0]];
- if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
- if ($post['name'] != '') $condition[] =['name', 'like', "%{$post['name']}%"];
- if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
- if ($post['account_id'] != '') $condition[] = ['code', 'in', function ($query) use ($post) {
- return $query->name('account_company')->where(['account_id'=>$post['account_id'],"is_del"=>0,'status'=>1])
- ->column('companyCode');
- }];
- if ($post['type'] != '') $condition[] = ['type', '=', $post['type']];
- $list = $this->model->field('id,code,name,type,status,addtime,relation_code,length(name) len_name')->where
- ($condition)->order('len_name', 'asc')->select();
- return success('获取成功', $list);
- }
- }
|