1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace app\user\controller;
- use think\App;
- 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' =>
- '1', '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 ($this->level != 1 && $post['level'] != 1) $condition[] = ['code', 'in', function ($query) use ($post) {
- return $query->name('account_company')->where(['account_id'=>$this->uid,"is_del"=>0,'status'=>1])
- ->column('companyCode');
- }];
- if (!empty($post['type'])) $condition[] = ['type', 'in', $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']])->each(function (&$item) {
- switch ($item['type']) {
- case 1:
- $item['legaler_type'] = \app\user\model\Business::where('companyNo', $item['code'])->value('legaler_type','');
- break;
- case 2:
- $item['legaler_type'] = '';
- break;
- case 3:
- $item['legaler_type'] = \app\user\model\Supplier::where('code', $item['code'])->value('legaler_type','');
- break;
- default:
- $item['legaler_type'] = '';
- break;
- }
- });
- 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' => '', 'level' =>1, 'size' => 100, '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 ($this->level != 1 && $post['level'] != 1) $condition[] = ['code', 'in', function ($query) use ($post) {
- return $query->name('account_company')->where(['account_id'=>$this->uid,'is_del'=>0,'status'=>1])
- ->column('companyCode');
- }];
- if (!empty($post['type'])) $condition[] = ['type', 'in', $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()->each(function (&$item) {
- switch ($item['type']) {
- case 1:
- $item['legaler_type'] = \app\user\model\Business::where('companyNo', $item['code'])->value('legaler_type','');
- break;
- case 2:
- $item['legaler_type'] = '';
- break;
- case 3:
- $item['legaler_type'] = \app\user\model\Supplier::where('code', $item['code'])->value('legaler_type','');
- break;
- default:
- $item['legaler_type'] = '';
- break;
- }
- });
- return success('获取成功', $list);
- }
- public function companyType(){
- $param = $this->request->only(['company_type' => '', 'status' => ''], 'post', 'trim');
- $where=[["is_del","=",0]];
- if ($param['company_type'] != '') $where[] = ['company_type', 'like', "%{$param['company_type']}%"];
- if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
- $list = \app\user\model\CompanyType::where($where)->order('id', 'desc')->select();
- return success('获取成功', $list);
- }
- }
|