diff --git a/app/api/controller/HomeIndex.php b/app/api/controller/HomeIndex.php index ccf35bf..94a0d73 100644 --- a/app/api/controller/HomeIndex.php +++ b/app/api/controller/HomeIndex.php @@ -39,11 +39,13 @@ class HomeIndex extends ApiController //用户数据汇总 public function data_total() { + $this->uid = JWT_UID; $total = []; - $approveCount = Db::name('Approve')->count(); $noteCount = Db::name('Note')->where('status', '1')->count(); - $expenseCount = Db::name('Expense')->where('delete_time', '0')->count(); - $invoiceCount = Db::name('Invoice')->where('delete_time', '0')->count(); + $approveCount = Db::name('Approve')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")]])->count(); + $expenseCount = Db::name('Expense')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")],['delete_time', '=', 0]])->count(); + $invoiceCount = Db::name('Invoice')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")],['delete_time', '=', 0]])->count(); + $total[] = array( 'name' => '公告', 'type' => 'note', @@ -64,89 +66,20 @@ class HomeIndex extends ApiController 'type' => 'invoice', 'num' => $invoiceCount, ); - $this->uid = JWT_UID; + $module = Db::name('AdminModule')->column('name'); - if (in_array('customer', $module)) { - $whereCustomer = array(); - $whereCustomerOr = array(); - $uid = $this->uid; - $dids = get_department_role($uid); - - $whereCustomer[] = ['delete_time', '=', 0]; - $whereCustomerOr[] =['belong_uid', '=', $uid]; - if(!empty($dids)){ - $whereCustomerOr[] =['belong_did', 'in', $dids]; - } - $whereCustomerOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")]; - - $customerCount = Db::name('Customer')->where($whereCustomer) - ->where(function ($query) use($whereCustomerOr) { - $query->whereOr($whereCustomerOr); - }) - ->count(); - // $total[] = array( - // 'name' => '客户', - // 'type' => 'customer', - // 'num' => $customerCount, - // ); - } - if (in_array('contract', $module)) { - $whereContract = array(); - $whereContractOr = array(); - $uid = $this->uid; - - $whereContract[] = ['delete_time', '=', 0]; - $whereContractOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid]; - $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")]; - $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_admin_ids)")]; - $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',flow_admin_ids)")]; - $dids = get_department_role($uid); - if(!empty($dids)){ - $whereContractOr[] =['sign_did', 'in', $dids]; - } - - $contractCount = Db::name('Contract')->where($whereContract) - ->where(function ($query) use($whereContractOr) { - $query->whereOr($whereContractOr); - }) - ->count(); - // $total[] = array( - // 'name' => '合同', - // 'type' => 'contract', - // 'num' => $contractCount, - // ); - } if (in_array('project', $module)) { $project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id'); $whereProject = []; $whereProject[] = ['delete_time', '=', 0]; $whereProject[] = ['id', 'in', $project_ids]; - $projectCount = Db::name('Project')->where($whereProject)->count(); - - $whereOr = array(); - $map1 = []; - $map2 = []; - $map3 = []; - $map4 = []; - $uid = $this->uid; - $map1[] = ['admin_id', '=', $uid]; - $map2[] = ['director_uid', '=', $uid]; - $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$uid},assist_admin_ids)")]; - $map4[] = ['project_id', 'in', $project_ids]; - - $whereOr =[$map1,$map2,$map3,$map4]; - $taskCount = Db::name('ProjectTask') - ->where(function ($query) use ($whereOr) { - if (!empty($whereOr)) - $query->whereOr($whereOr); - }) - ->where([['delete_time', '=', 0]])->count(); - + $projectCount = Db::name('Project')->where($whereProject)->fetchSql(false)->count(); $total[] = array( 'name' => '项目', 'type' => 'project', 'num' => $projectCount, ); + $taskCount = Db::name('ProjectTask')->where([['director_uid', '=', $this->uid],['flow_status', '<', 3],['delete_time', '=', 0]])->count(); $total[] = array( 'name' => '任务', 'type' => 'task',