123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
- <?php
- namespace app\admin\controller\datastat;
- use app\admin\BaseController;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\View;
- use think\App;
- use app\admin\model\Department as DepartmentModel;
- use app\admin\model\CostProject as CostProjectModel;
- use app\admin\validate\datastat\Datastat as DatastatValidate;
- class Datastat extends BaseController
- {
- /**
- * 构造函数
- */
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->DepartmentModel = new DepartmentModel();
- $this->CostProjectModel = new CostProjectModel();
- }
- public function index()
- {
- if (request()->isAjax()) {
- $unit_name = get_login_admin('unit_name');
- $where = array();
- if (get_login_admin('user_type') != -2) {
- $where = [
- 'entrust_unit' => $unit_name,
- ];
- }
- $param = get_params();
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $list = $this->CostProjectModel->where($where)
- ->where('project_status', 8)
- ->order('project_dead_time', 'desc')
- ->paginate($rows, false, ['query' => $param])
- ->each(function ($item, $key) {
- })->toArray();
- $data = $list['data'];
- // dump($data);
- foreach ($data as $key => $value) {
- // 一级审批
- $first = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
- ->where('audit_status', 2)
- ->where('audit_type', 4)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- $judge = $first;
-
- // 二级审批
- $second = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
- ->where('audit_status', 2)
- ->where('audit_type', 5)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- // 三级审批
- $third = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
- ->where('audit_status', 2)
- ->where('audit_type', 6)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- // 四级审批
- $fourth = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
- ->where('audit_status', 2)
- ->where('audit_type', 14)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- // 五级审批
- $fifth = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
- ->where('audit_status', 2)
- ->where('audit_type', 15)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- if($fifth != NULL){
- $examiner = $fifth;
- }else if($fourth != NULL){
- $examiner = $fourth;
- }else if ($third != NULL) {
- $examiner = $third;
- } else if ($second != NULL) {
- $examiner = $second;
- } else {
- $examiner = $first;
- }
- $data[$key]['judge'] = $judge;
- $data[$key]['examiner'] = $examiner;
- }
- $list['data'] = $data;
- // dump($list);
- return table_assign(0, '', $list);
- } else {
- return view();
- }
- }
-
- public function test(){
- $fifth = Db::name('ProjectAudit')->where('project_id', 474)
- ->where('audit_status', 2)
- ->where('audit_type', 5)
- ->order('audit_time', 'desc')
- // ->select()->toArray();
- ->value('approver_name');
-
- dump($fifth);
- }
- public function edit()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $data = [
- 'project_code' => $param['project_code'],
- 'sent_review_time' => $param['sent_review_time'],
- 'division' => $param['division'],
- 'contract_out_sent_review_amount' => $param['contract_out_sent_review_amount'],
- 'contract_out_authorize_amount' => $param['contract_out_authorize_amount'],
- // 'contract_in_sent_review_amount' => $param['contract_in_sent_review_amount'],
- // 'contract_in_authorize_amount' => $param['contract_in_authorize_amount'],
- 'contract_amount' => $param['contract_amount'],
- 'basic_reserve_funds' => $param['basic_reserve_funds'],
- ];
- // 检验完整性
- try {
- validate(DatastatValidate::class)->check($data);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- Db::startTrans();
- try {
- $this->CostProjectModel->where('id', $param['id'])->force(true)->update($data);
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- return to_assign(1, '提交失败:' . $e->getMessage());
- }
- return to_assign(0, "操作成功");
- } else {
- $id = empty(get_params('id')) ? 0 : get_params('id');
- $project = Db::name('CostProject')->where('id', $id)->find();
- // 一级审批
- $first = Db::name('ProjectAudit')->where('project_id', $id)
- ->where('audit_status', 2)
- ->where('audit_type', 4)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- $judge = $first;
-
- // 二级审批
- $second = Db::name('ProjectAudit')->where('project_id', $id)
- ->where('audit_status', 2)
- ->where('audit_type', 5)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- // 三级审批
- $third = Db::name('ProjectAudit')->where('project_id', $id)
- ->where('audit_status', 2)
- ->where('audit_type', 6)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- // 四级审批
- $fourth = Db::name('ProjectAudit')->where('project_id', $id)
- ->where('audit_status', 2)
- ->where('audit_type', 14)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- // 五级审批
- $fifth = Db::name('ProjectAudit')->where('project_id', $id)
- ->where('audit_status', 2)
- ->where('audit_type', 15)
- ->order('audit_time', 'desc')
- ->value('approver_name');
-
- if($fifth != NULL){
- $examiner = $fifth;
- }else if($fourth != NULL){
- $examiner = $fourth;
- }else if ($third != NULL) {
- $examiner = $third;
- } else if ($second != NULL) {
- $examiner = $second;
- } else {
- $examiner = $first;
- }
-
- // dump($project);
- $project['judge'] = $judge;
- $project['examiner'] = $examiner;
- View::assign('project', $project);
- return view();
- }
- }
- public function cost($today = 2024)
- {
-
- $all_sent_review_cost = self::sent_review_cost($today);
- $review_poportion = self::review_poportion();
- $sent_poportion = self::sent_poportion();
- // halt($all_sent_review_cost);
- View::assign('sent', $all_sent_review_cost);
- View::assign('review_poportion', $review_poportion);
- View::assign('sent_poportion', $sent_poportion);
- return view();
- }
- public function cost_company($today = 2024)
- {
- $all_sent_review_cost = self::sent_review_cost_company($today);
- // halt($all_sent_review_cost);
- $review_poportion = self::review_poportion_company();
- $sent_poportion = self::sent_poportion_company();
- // halt($today);
- View::assign('sent', $all_sent_review_cost);
- View::assign('review_poportion', $review_poportion);
- View::assign('sent_poportion', $sent_poportion);
- return view();
- }
- public function cost_chat($today = 2024)
- {
- $unit_id = get_login_admin("unit_name");
- //送审单位项目数量排行
- $sent_number_top = Db::query("select sent_review_unit_name
- ,sum(sent_review_amount) as all_sent_amount
- ,count(sent_review_unit_name) as project_number
- from cp_cost_project where entrust_unit=$unit_id and sent_review_unit_name != ''
- group by sent_review_unit_name order by project_number");
- //评审机审定总额排行
- $authorize_amount_top = Db::query("select review_unit,review_unit_name
- ,sum(authorize_amount) as all_authorize_amount
- from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
- group by review_unit order by all_authorize_amount");
- //评审机构送审总额排行
- $sent_review_amount_top = Db::query("select review_unit,review_unit_name
- ,sum(sent_review_amount) as all_sent_amount
- from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
- group by review_unit order by all_sent_amount");
- $year = (double)$today;
- //2024年送审总额占比分布图
- $sentAndaAuthorize = Db::query("select sum(sent_review_amount) as all_amount,engineering_type1
- from cp_cost_project where entrust_unit = $unit_id
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- group by engineering_type1");
-
- if(!$sentAndaAuthorize){
- $sentAndaAuthorize[0] = 0;
- $sentAndaAuthorize[1] = 0;
- }
-
- $sent_poportion = self::sent_poportion();
- $all_sent_review_cost = self::sent_review_cost($today);
- $review_poportion = self::review_poportion();
-
- // halt($today);
- $data = [
- 'sent_poportion' => $sent_poportion,
- 'sent_number_top' => $sent_number_top,
- 'review_poportion' => $review_poportion,
- 'authorize_amount_top' => $authorize_amount_top,
- 'sent_review_amount_top' => $sent_review_amount_top,
- 'sentAndaAuthorize' => $sentAndaAuthorize,
- 'all_sent_review_cost' => $all_sent_review_cost,
- ];
-
- $this->success($msg = '成功!', $url = null, $data = $data);
- // return json($data);
- }
- //2024年项目送审服务费分布图、项目数量、项目送审、审定总额、表格
- public function sent_review_cost($today)
- {
- $unit_id = get_login_admin("unit_name");
- $year = (double)$today;
- $sent_review_cost = Db::query("select sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,sum(sent_review_cost) as all_sent_review_cost
- ,count(*) as project_number
- ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as project_start_time
- from cp_cost_project where entrust_unit= $unit_id
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
- $summarization = Db::query("select sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,sum(sent_review_cost) as all_sent_review_cost
- ,count(*) as project_number
- from cp_cost_project where entrust_unit = $unit_id
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year");
- $all_sent_review_cost = [];
- for ($i = 1; $i <= 12; $i++) {
- $ayear = $today . '-' . $i;
- if (!in_array($ayear, array_column($sent_review_cost, 'project_start_time'))) {
- $all_sent_review_cost[$i] = [
- 'all_sent_amount' => 0,
- 'all_authorize_amount' => 0,
- 'all_sent_review_cost' => 0,
- 'project_number' => 0,
- 'project_start_time' => $ayear,
- ];
-
- } else {
- $num = array_search($ayear, array_column($sent_review_cost, 'project_start_time'));
- $all_sent_review_cost[$i] = [
- 'all_sent_amount' => $sent_review_cost[$num]['all_sent_amount'],
- 'all_authorize_amount' => $sent_review_cost[$num]['all_authorize_amount'],
- 'all_sent_review_cost' => $sent_review_cost[$num]['all_sent_review_cost'],
- 'project_number' => $sent_review_cost[$num]['project_number'],
- 'project_start_time' => $sent_review_cost[$num]['project_start_time'],
- ];
- }
- }
- $all_sent_review_cost['all'] = $summarization[0];
-
- // halt($year);
- return $all_sent_review_cost;
- }
- //评审机构项目数量、送审总额、审定总额、(预算总额、结算总额、送审服务费)、表格、项目数量排行
- public function review_poportion()
- {
- $unit_id = get_login_admin("unit_name");
- $review_poportion = Db::query("select review_unit,review_unit_name
- ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
- ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
- ,sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,sum(sent_review_cost) as all_sent_review_cost
- ,(sum(authorize_amount)-sum(sent_review_amount))/sum(sent_review_amount) as increaseOrdecrease
- ,count(*) as project_number
- from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
- group by review_unit order by project_number");
- return $review_poportion;
- }
- //送审单位送审总额占比图、送审总额排行、表格
- public function sent_poportion()
- {
- $unit_id = get_login_admin("unit_name");
- $sent_poportion = Db::query("select
- sent_review_unit_name
- ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
- ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
- ,sum(sent_review_amount) as all_sent_amount
- ,count(sent_review_unit_name) as project_number
- from cp_cost_project where entrust_unit=$unit_id and sent_review_unit_name != ''
- group by sent_review_unit_name order by all_sent_amount");
- return $sent_poportion;
- }
- public function cost_chat_company($today = 2024)
- {
-
- $unit_id = get_login_admin("unit_name");
- //送审单位项目数量排行
- $sent_number_top = Db::query("select sent_review_unit_name
- ,sum(sent_review_amount) as all_sent_amount
- ,count(sent_review_unit_name) as project_number
- from cp_cost_project where review_unit=$unit_id and sent_review_unit_name != ''
- group by sent_review_unit_name order by project_number");
- //委托单位定总额排行
- $authorize_amount_top = Db::query("select entrust_unit,entrust_unit_name
- ,sum(authorize_amount) as all_authorize_amount
- from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
- group by entrust_unit order by all_authorize_amount");
- //委托单位送审总额排行
- $sent_review_amount_top = Db::query("select entrust_unit,entrust_unit_name
- ,sum(sent_review_amount) as all_sent_amount
- from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
- group by entrust_unit order by all_sent_amount");
- $year = (double)$today;
- //2024年送审总额占比分布图
- $sentAndaAuthorize = Db::query("select sum(sent_review_amount) as all_amount,engineering_type1
- from cp_cost_project where review_unit = $unit_id
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- group by engineering_type1");
- if(!$sentAndaAuthorize){
- $sentAndaAuthorize[0] = 0;
- $sentAndaAuthorize[1] = 0;
- }
- $sent_poportion = self::sent_poportion_company();
- $all_sent_review_cost = self::sent_review_cost_company($today);
- $review_poportion = self::review_poportion_company();
-
- $data = [
- 'sent_poportion' => $sent_poportion,
- 'sent_number_top' => $sent_number_top,
- 'review_poportion' => $review_poportion,
- 'authorize_amount_top' => $authorize_amount_top,
- 'sent_review_amount_top' => $sent_review_amount_top,
- 'sentAndaAuthorize' => $sentAndaAuthorize,
- 'all_sent_review_cost' => $all_sent_review_cost,
- ];
-
- // halt($data);
- $this->success($msg = '成功!', $url = null, $data = $data);
- }
- //2024年项目送审服务费分布图、项目数量、项目送审、审定总额、表格
- public function sent_review_cost_company($today)
- {
- $unit_id = get_login_admin("unit_name");
- $year = (double)$today;
- $sent_review_cost = Db::query("select sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,sum(sent_review_cost) as all_sent_review_cost
- ,count(*) as project_number
- ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as project_start_time
- from cp_cost_project where review_unit= $unit_id
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
- $summarization = Db::query("select sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,sum(sent_review_cost) as all_sent_review_cost
- ,count(*) as project_number
- from cp_cost_project where review_unit= $unit_id
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year");
- $all_sent_review_cost = [];
- for ($i = 1; $i <= 12; $i++) {
- $ayear = $today . '-' . $i;
- if (!in_array($ayear, array_column($sent_review_cost, 'project_start_time'))) {
- $all_sent_review_cost[$i] = [
- 'all_sent_amount' => 0,
- 'all_authorize_amount' => 0,
- 'all_sent_review_cost' => 0,
- 'project_number' => 0,
- 'project_start_time' => $ayear,
- ];
- } else {
- $num = array_search($ayear, array_column($sent_review_cost, 'project_start_time'));
- $all_sent_review_cost[$i] = [
- 'all_sent_amount' => $sent_review_cost[$num]['all_sent_amount'],
- 'all_authorize_amount' => $sent_review_cost[$num]['all_authorize_amount'],
- 'all_sent_review_cost' => $sent_review_cost[$num]['all_sent_review_cost'],
- 'project_number' => $sent_review_cost[$num]['project_number'],
- 'project_start_time' => $sent_review_cost[$num]['project_start_time'],
- ];
- }
- }
- $all_sent_review_cost['all'] = $summarization[0];
- return $all_sent_review_cost;
- }
- //委托单位项目数量、送审总额、审定总额、(预算总额、结算总额、送审服务费)、表格、项目数量排行
- public function review_poportion_company()
- {
- $unit_id = get_login_admin("unit_name");
- $review_poportion = Db::query("select entrust_unit,entrust_unit_name
- ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
- ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
- ,sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,sum(sent_review_cost) as all_sent_review_cost
- ,(sum(authorize_amount)-sum(sent_review_amount))/sum(sent_review_amount) as increaseOrdecrease
- ,count(*) as project_number
- from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
- group by entrust_unit order by project_number");
- return $review_poportion;
- }
- //送审单位送审总额占比图、送审总额排行、表格
- public function sent_poportion_company()
- {
- $unit_id = get_login_admin("unit_name");
- $sent_poportion = Db::query("select
- sent_review_unit_name
- ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
- ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
- ,sum(sent_review_amount) as all_sent_amount
- ,count(sent_review_unit_name) as project_number
- from cp_cost_project where review_unit=$unit_id and sent_review_unit_name != ''
- group by sent_review_unit_name order by all_sent_amount");
- return $sent_poportion;
- }
- public function cost_member($today = 2024)
- {
- $unit_id = get_login_admin("unit_name");
- $users = Db::name('admin')->where('unit_name', $unit_id)->select();
- $cost_project_member = self::cost_project_member($today);
- $cost_month_member = self::cost_month_member($today);
- //halt($cost_project_member,$cost_month_member);
- View::assign('users', $users);
- View::assign('cost_project_member', $cost_project_member);
- View::assign('cost_month_member', $cost_month_member);
- return View();
- }
- //名字和项目数量
- public function cost_project_member($today = 2024)
- {
- $unit_id = get_login_admin("unit_name");
- $year = (double)$today;
- $users = Db::name('admin')->where('unit_name', $unit_id)->column('id');
- $usersStr = implode(',', $users);
- $data = Db::query("select
- sum(sent_review_amount) as all_sent_amount
- ,sum(authorize_amount) as all_authorize_amount
- ,count(*) as project_number
- ,review_head_name
- ,review_head
- ,COUNT(CASE WHEN project_status = 1 THEN 1 END) AS count_status_1,
- COUNT(CASE WHEN project_status = 2 THEN 1 END) AS count_status_2,
- COUNT(CASE WHEN project_status = 3 THEN 1 END) AS count_status_3,
- COUNT(CASE WHEN project_status = 4 THEN 1 END) AS count_status_4,
- COUNT(CASE WHEN project_status = 5 THEN 1 END) AS count_status_5,
- COUNT(CASE WHEN project_status = 6 THEN 1 END) AS count_status_6,
- COUNT(CASE WHEN project_status = 7 THEN 1 END) AS count_status_7,
- COUNT(CASE WHEN project_status = 8 THEN 1 END) AS count_status_8,
- COUNT(CASE WHEN project_status = 9 THEN 1 END) AS count_status_9
- from cp_cost_project where review_head in ($usersStr)
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- group by review_head");
- //
- // halt($data);
- return $data;
- }
- //名字和月份
- public function cost_month_member($today = 2024)
- {
- $unit_id = get_login_admin("unit_name");
- $year = (double)$today;
- $data = Db::query("SELECT
- review_head,
- review_head_name,
- COUNT(*) AS project_number,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 1 THEN 1 ELSE 0 END) AS month_1,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 2 THEN 1 ELSE 0 END) AS month_2,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 3 THEN 1 ELSE 0 END) AS month_3,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 4 THEN 1 ELSE 0 END) AS month_4,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 5 THEN 1 ELSE 0 END) AS month_5,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 6 THEN 1 ELSE 0 END) AS month_6,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 7 THEN 1 ELSE 0 END) AS month_7,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 8 THEN 1 ELSE 0 END) AS month_8,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 9 THEN 1 ELSE 0 END) AS month_9,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 10 THEN 1 ELSE 0 END) AS month_10,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 11 THEN 1 ELSE 0 END) AS month_11,
- SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 12 THEN 1 ELSE 0 END) AS month_12
- FROM
- cp_cost_project
- WHERE
- review_head IN (SELECT id FROM cp_admin WHERE unit_name = $unit_id)
- AND review_head != ''
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- GROUP BY
- review_head,
- review_head_name
- ORDER BY
- project_number DESC");
- return $data;
- }
- //根据名字作图
- public
- function cost_name_member($today = 2024, $name = '')
- {
- $unit_id = get_login_admin("unit_name");
- if ($name == '') {
- $users = Db::name('admin')->where('unit_name', $unit_id)->column('id');
- $name = $users[0];
- }
- $year = (double)$today;
- $data = Db::query("select
- count(*) as project_number
- ,review_head_name
- ,review_head
- ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as month
- from cp_cost_project where review_head = $name and review_head != ''
- and YEAR(FROM_UNIXTIME(project_start_time)) = $year
- group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
- $all_sent_review_cost = [];
- for ($i = 1; $i <= 12; $i++) {
- $ayear = $today . '-' . $i;
- if ($data != []) {
- if (!in_array($ayear, array_column($data, 'month'))) {
- $all_sent_review_cost[$i] = [
- "project_number" => 0,
- "review_head" => $data[0]['review_head'],
- 'review_head_name' => $data[0]['review_head_name'],
- "month" => $ayear,
- ];
- } else {
- $num = array_search($ayear, array_column($data, 'month'));
- $all_sent_review_cost[$i] = [
- 'project_number' => $data[$num]['project_number'],
- 'review_head_name' => $data[$num]['review_head_name'],
- 'review_head' => $data[$num]['review_head'],
- 'month' => $data[$num]['month'],
- ];
- }
- } else {
- $all_sent_review_cost[$i] = [
- 'project_number' => 0,
- 'review_head' => $name,
- 'month' => $ayear,
- ];
- }
- }
- $this->success($msg = '成功!', $url = null, $data = $all_sent_review_cost);
- }
- }
|