Datastat.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. namespace app\admin\controller\datastat;
  3. use app\admin\BaseController;
  4. use think\exception\ValidateException;
  5. use think\facade\Db;
  6. use think\facade\View;
  7. use think\App;
  8. use app\admin\model\Department as DepartmentModel;
  9. use app\admin\model\CostProject as CostProjectModel;
  10. use app\admin\validate\datastat\Datastat as DatastatValidate;
  11. class Datastat extends BaseController
  12. {
  13. /**
  14. * 构造函数
  15. */
  16. public function __construct(App $app)
  17. {
  18. parent::__construct($app);
  19. $this->DepartmentModel = new DepartmentModel();
  20. $this->CostProjectModel = new CostProjectModel();
  21. }
  22. public function index()
  23. {
  24. if (request()->isAjax()) {
  25. $unit_name = get_login_admin('unit_name');
  26. $where = array();
  27. if (get_login_admin('user_type') != -2) {
  28. $where = [
  29. 'entrust_unit' => $unit_name,
  30. ];
  31. }
  32. $param = get_params();
  33. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  34. $list = $this->CostProjectModel->where($where)
  35. ->where('project_status', 8)
  36. ->order('project_dead_time', 'desc')
  37. ->paginate($rows, false, ['query' => $param])
  38. ->each(function ($item, $key) {
  39. })->toArray();
  40. $data = $list['data'];
  41. // dump($data);
  42. foreach ($data as $key => $value) {
  43. // 一级审批
  44. $first = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
  45. ->where('audit_status', 2)
  46. ->where('audit_type', 4)
  47. ->order('audit_time', 'desc')
  48. ->value('approver_name');
  49. $judge = $first;
  50. // 二级审批
  51. $second = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
  52. ->where('audit_status', 2)
  53. ->where('audit_type', 5)
  54. ->order('audit_time', 'desc')
  55. ->value('approver_name');
  56. // 三级审批
  57. $third = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
  58. ->where('audit_status', 2)
  59. ->where('audit_type', 6)
  60. ->order('audit_time', 'desc')
  61. ->value('approver_name');
  62. // 四级审批
  63. $fourth = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
  64. ->where('audit_status', 2)
  65. ->where('audit_type', 14)
  66. ->order('audit_time', 'desc')
  67. ->value('approver_name');
  68. // 五级审批
  69. $fifth = Db::name('ProjectAudit')->where('project_id', $data[$key]['id'])
  70. ->where('audit_status', 2)
  71. ->where('audit_type', 15)
  72. ->order('audit_time', 'desc')
  73. ->value('approver_name');
  74. if($fifth != NULL){
  75. $examiner = $fifth;
  76. }else if($fourth != NULL){
  77. $examiner = $fourth;
  78. }else if ($third != NULL) {
  79. $examiner = $third;
  80. } else if ($second != NULL) {
  81. $examiner = $second;
  82. } else {
  83. $examiner = $first;
  84. }
  85. $data[$key]['judge'] = $judge;
  86. $data[$key]['examiner'] = $examiner;
  87. }
  88. $list['data'] = $data;
  89. // dump($list);
  90. return table_assign(0, '', $list);
  91. } else {
  92. return view();
  93. }
  94. }
  95. public function test(){
  96. $fifth = Db::name('ProjectAudit')->where('project_id', 474)
  97. ->where('audit_status', 2)
  98. ->where('audit_type', 5)
  99. ->order('audit_time', 'desc')
  100. // ->select()->toArray();
  101. ->value('approver_name');
  102. dump($fifth);
  103. }
  104. public function edit()
  105. {
  106. if (request()->isAjax()) {
  107. $param = get_params();
  108. $data = [
  109. 'project_code' => $param['project_code'],
  110. 'sent_review_time' => $param['sent_review_time'],
  111. 'division' => $param['division'],
  112. 'contract_out_sent_review_amount' => $param['contract_out_sent_review_amount'],
  113. 'contract_out_authorize_amount' => $param['contract_out_authorize_amount'],
  114. // 'contract_in_sent_review_amount' => $param['contract_in_sent_review_amount'],
  115. // 'contract_in_authorize_amount' => $param['contract_in_authorize_amount'],
  116. 'contract_amount' => $param['contract_amount'],
  117. 'basic_reserve_funds' => $param['basic_reserve_funds'],
  118. ];
  119. // 检验完整性
  120. try {
  121. validate(DatastatValidate::class)->check($data);
  122. } catch (ValidateException $e) {
  123. // 验证失败 输出错误信息
  124. return to_assign(1, $e->getError());
  125. }
  126. Db::startTrans();
  127. try {
  128. $this->CostProjectModel->where('id', $param['id'])->force(true)->update($data);
  129. // 提交事务
  130. Db::commit();
  131. } catch (\Exception $e) {
  132. // 回滚事务
  133. Db::rollback();
  134. return to_assign(1, '提交失败:' . $e->getMessage());
  135. }
  136. return to_assign(0, "操作成功");
  137. } else {
  138. $id = empty(get_params('id')) ? 0 : get_params('id');
  139. $project = Db::name('CostProject')->where('id', $id)->find();
  140. // 一级审批
  141. $first = Db::name('ProjectAudit')->where('project_id', $id)
  142. ->where('audit_status', 2)
  143. ->where('audit_type', 4)
  144. ->order('audit_time', 'desc')
  145. ->value('approver_name');
  146. $judge = $first;
  147. // 二级审批
  148. $second = Db::name('ProjectAudit')->where('project_id', $id)
  149. ->where('audit_status', 2)
  150. ->where('audit_type', 5)
  151. ->order('audit_time', 'desc')
  152. ->value('approver_name');
  153. // 三级审批
  154. $third = Db::name('ProjectAudit')->where('project_id', $id)
  155. ->where('audit_status', 2)
  156. ->where('audit_type', 6)
  157. ->order('audit_time', 'desc')
  158. ->value('approver_name');
  159. // 四级审批
  160. $fourth = Db::name('ProjectAudit')->where('project_id', $id)
  161. ->where('audit_status', 2)
  162. ->where('audit_type', 14)
  163. ->order('audit_time', 'desc')
  164. ->value('approver_name');
  165. // 五级审批
  166. $fifth = Db::name('ProjectAudit')->where('project_id', $id)
  167. ->where('audit_status', 2)
  168. ->where('audit_type', 15)
  169. ->order('audit_time', 'desc')
  170. ->value('approver_name');
  171. if($fifth != NULL){
  172. $examiner = $fifth;
  173. }else if($fourth != NULL){
  174. $examiner = $fourth;
  175. }else if ($third != NULL) {
  176. $examiner = $third;
  177. } else if ($second != NULL) {
  178. $examiner = $second;
  179. } else {
  180. $examiner = $first;
  181. }
  182. // dump($project);
  183. $project['judge'] = $judge;
  184. $project['examiner'] = $examiner;
  185. View::assign('project', $project);
  186. return view();
  187. }
  188. }
  189. public function cost($today = 2024)
  190. {
  191. $all_sent_review_cost = self::sent_review_cost($today);
  192. $review_poportion = self::review_poportion();
  193. $sent_poportion = self::sent_poportion();
  194. // halt($all_sent_review_cost);
  195. View::assign('sent', $all_sent_review_cost);
  196. View::assign('review_poportion', $review_poportion);
  197. View::assign('sent_poportion', $sent_poportion);
  198. return view();
  199. }
  200. public function cost_company($today = 2024)
  201. {
  202. //self:;调用静态方法
  203. $all_sent_review_cost = self::sent_review_cost_company($today);
  204. // halt($all_sent_review_cost);
  205. $review_poportion = self::review_poportion_company();
  206. $sent_poportion = self::sent_poportion_company();
  207. // halt($today);
  208. View::assign('sent', $all_sent_review_cost);
  209. View::assign('review_poportion', $review_poportion);
  210. View::assign('sent_poportion', $sent_poportion);
  211. return view();
  212. }
  213. public function cost_chat($today = 2024)
  214. {
  215. $unit_id = get_login_admin("unit_name");
  216. //送审单位项目数量排行
  217. $sent_number_top = Db::query("select sent_review_unit_name
  218. ,sum(sent_review_amount) as all_sent_amount
  219. ,count(sent_review_unit_name) as project_number
  220. from cp_cost_project where entrust_unit=$unit_id and sent_review_unit_name != ''
  221. group by sent_review_unit_name order by project_number");
  222. //评审机审定总额排行
  223. $authorize_amount_top = Db::query("select review_unit,review_unit_name
  224. ,sum(authorize_amount) as all_authorize_amount
  225. from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
  226. group by review_unit,review_unit_name order by all_authorize_amount");
  227. //评审机构送审总额排行
  228. $sent_review_amount_top = Db::query("select review_unit,review_unit_name
  229. ,sum(sent_review_amount) as all_sent_amount
  230. from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
  231. group by review_unit,review_unit_name order by all_sent_amount");
  232. $year = (double)$today;
  233. //2024年送审总额占比分布图
  234. $sentAndaAuthorize = Db::query("select sum(sent_review_amount) as all_amount,engineering_type1
  235. from cp_cost_project where entrust_unit = $unit_id
  236. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  237. group by engineering_type1");
  238. if(!$sentAndaAuthorize){
  239. $sentAndaAuthorize[0] = 0;
  240. $sentAndaAuthorize[1] = 0;
  241. }
  242. $sent_poportion = self::sent_poportion();
  243. $all_sent_review_cost = self::sent_review_cost($today);
  244. $review_poportion = self::review_poportion();
  245. // halt($today);
  246. $data = [
  247. 'sent_poportion' => $sent_poportion,
  248. 'sent_number_top' => $sent_number_top,
  249. 'review_poportion' => $review_poportion,
  250. 'authorize_amount_top' => $authorize_amount_top,
  251. 'sent_review_amount_top' => $sent_review_amount_top,
  252. 'sentAndaAuthorize' => $sentAndaAuthorize,
  253. 'all_sent_review_cost' => $all_sent_review_cost,
  254. ];
  255. $this->success($msg = '成功!', $url = null, $data = $data);
  256. // return json($data);
  257. }
  258. //2024年项目送审服务费分布图、项目数量、项目送审、审定总额、表格
  259. public function sent_review_cost($today)
  260. {
  261. $unit_id = get_login_admin("unit_name");
  262. $year = (double)$today;
  263. $sent_review_cost = Db::query("select sum(sent_review_amount) as all_sent_amount
  264. ,sum(authorize_amount) as all_authorize_amount
  265. ,sum(sent_review_cost) as all_sent_review_cost
  266. ,count(*) as project_number
  267. ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as project_start_time
  268. from cp_cost_project where entrust_unit= $unit_id
  269. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  270. group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
  271. $summarization = Db::query("select sum(sent_review_amount) as all_sent_amount
  272. ,sum(authorize_amount) as all_authorize_amount
  273. ,sum(sent_review_cost) as all_sent_review_cost
  274. ,count(*) as project_number
  275. from cp_cost_project where entrust_unit = $unit_id
  276. and YEAR(FROM_UNIXTIME(project_start_time)) = $year");
  277. $all_sent_review_cost = [];
  278. for ($i = 1; $i <= 12; $i++) {
  279. $ayear = $today . '-' . $i;
  280. if (!in_array($ayear, array_column($sent_review_cost, 'project_start_time'))) {
  281. $all_sent_review_cost[$i] = [
  282. 'all_sent_amount' => 0,
  283. 'all_authorize_amount' => 0,
  284. 'all_sent_review_cost' => 0,
  285. 'project_number' => 0,
  286. 'project_start_time' => $ayear,
  287. ];
  288. } else {
  289. $num = array_search($ayear, array_column($sent_review_cost, 'project_start_time'));
  290. $all_sent_review_cost[$i] = [
  291. 'all_sent_amount' => $sent_review_cost[$num]['all_sent_amount'],
  292. 'all_authorize_amount' => $sent_review_cost[$num]['all_authorize_amount'],
  293. 'all_sent_review_cost' => $sent_review_cost[$num]['all_sent_review_cost'],
  294. 'project_number' => $sent_review_cost[$num]['project_number'],
  295. 'project_start_time' => $sent_review_cost[$num]['project_start_time'],
  296. ];
  297. }
  298. }
  299. $all_sent_review_cost['all'] = $summarization[0];
  300. // halt($year);
  301. return $all_sent_review_cost;
  302. }
  303. //评审机构项目数量、送审总额、审定总额、(预算总额、结算总额、送审服务费)、表格、项目数量排行
  304. public function review_poportion()
  305. {
  306. $unit_id = get_login_admin("unit_name");
  307. $review_poportion = Db::query("select review_unit,review_unit_name
  308. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  309. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  310. ,sum(sent_review_amount) as all_sent_amount
  311. ,sum(authorize_amount) as all_authorize_amount
  312. ,sum(sent_review_cost) as all_sent_review_cost
  313. ,(sum(authorize_amount)-sum(sent_review_amount))/sum(sent_review_amount) as increaseOrdecrease
  314. ,count(*) as project_number
  315. from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
  316. group by review_unit,review_unit_name order by project_number");
  317. return $review_poportion;
  318. }
  319. //送审单位送审总额占比图、送审总额排行、表格
  320. public function sent_poportion()
  321. {
  322. $unit_id = get_login_admin("unit_name");
  323. $sent_poportion = Db::query("select
  324. sent_review_unit_name
  325. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  326. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  327. ,sum(sent_review_amount) as all_sent_amount
  328. ,count(sent_review_unit_name) as project_number
  329. from cp_cost_project where entrust_unit=$unit_id and sent_review_unit_name != ''
  330. group by sent_review_unit_name order by all_sent_amount");
  331. return $sent_poportion;
  332. }
  333. public function cost_chat_company($today = 2024)
  334. {
  335. $unit_id = get_login_admin("unit_name");
  336. //送审单位项目数量排行
  337. $sent_number_top = Db::query("select sent_review_unit_name
  338. ,sum(sent_review_amount) as all_sent_amount
  339. ,count(sent_review_unit_name) as project_number
  340. from cp_cost_project where review_unit=$unit_id and sent_review_unit_name != ''
  341. group by sent_review_unit_name order by project_number");
  342. //委托单位定总额排行
  343. $authorize_amount_top = Db::query("select entrust_unit,entrust_unit_name
  344. ,sum(authorize_amount) as all_authorize_amount
  345. from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
  346. group by entrust_unit,entrust_unit_name order by all_authorize_amount");
  347. //委托单位送审总额排行
  348. $sent_review_amount_top = Db::query("select entrust_unit,entrust_unit_name
  349. ,sum(sent_review_amount) as all_sent_amount
  350. from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
  351. group by entrust_unit,entrust_unit_name order by all_sent_amount");
  352. $year = (double)$today;
  353. //2024年送审总额占比分布图
  354. $sentAndaAuthorize = Db::query("select sum(sent_review_amount) as all_amount,engineering_type1
  355. from cp_cost_project where review_unit = $unit_id
  356. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  357. group by engineering_type1");
  358. if(!$sentAndaAuthorize){
  359. $sentAndaAuthorize[0] = 0;
  360. $sentAndaAuthorize[1] = 0;
  361. }
  362. $sent_poportion = self::sent_poportion_company();
  363. $all_sent_review_cost = self::sent_review_cost_company($today);
  364. $review_poportion = self::review_poportion_company();
  365. $data = [
  366. 'sent_poportion' => $sent_poportion,
  367. 'sent_number_top' => $sent_number_top,
  368. 'review_poportion' => $review_poportion,
  369. 'authorize_amount_top' => $authorize_amount_top,
  370. 'sent_review_amount_top' => $sent_review_amount_top,
  371. 'sentAndaAuthorize' => $sentAndaAuthorize,
  372. 'all_sent_review_cost' => $all_sent_review_cost,
  373. ];
  374. // halt($data);
  375. $this->success($msg = '成功!', $url = null, $data = $data);
  376. }
  377. //2024年项目送审服务费分布图、项目数量、项目送审、审定总额、表格
  378. public function sent_review_cost_company($today)
  379. {
  380. $unit_id = get_login_admin("unit_name");
  381. $year = (double)$today;
  382. $sent_review_cost = Db::query("select sum(sent_review_amount) as all_sent_amount
  383. ,sum(authorize_amount) as all_authorize_amount
  384. ,sum(sent_review_cost) as all_sent_review_cost
  385. ,count(*) as project_number
  386. ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as project_start_time
  387. from cp_cost_project where review_unit= $unit_id
  388. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  389. group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
  390. $summarization = Db::query("select sum(sent_review_amount) as all_sent_amount
  391. ,sum(authorize_amount) as all_authorize_amount
  392. ,sum(sent_review_cost) as all_sent_review_cost
  393. ,count(*) as project_number
  394. from cp_cost_project where review_unit= $unit_id
  395. and YEAR(FROM_UNIXTIME(project_start_time)) = $year");
  396. $all_sent_review_cost = [];
  397. for ($i = 1; $i <= 12; $i++) {
  398. $ayear = $today . '-' . $i;
  399. if (!in_array($ayear, array_column($sent_review_cost, 'project_start_time'))) {
  400. $all_sent_review_cost[$i] = [
  401. 'all_sent_amount' => 0,
  402. 'all_authorize_amount' => 0,
  403. 'all_sent_review_cost' => 0,
  404. 'project_number' => 0,
  405. 'project_start_time' => $ayear,
  406. ];
  407. } else {
  408. $num = array_search($ayear, array_column($sent_review_cost, 'project_start_time'));
  409. $all_sent_review_cost[$i] = [
  410. 'all_sent_amount' => $sent_review_cost[$num]['all_sent_amount'],
  411. 'all_authorize_amount' => $sent_review_cost[$num]['all_authorize_amount'],
  412. 'all_sent_review_cost' => $sent_review_cost[$num]['all_sent_review_cost'],
  413. 'project_number' => $sent_review_cost[$num]['project_number'],
  414. 'project_start_time' => $sent_review_cost[$num]['project_start_time'],
  415. ];
  416. }
  417. }
  418. $all_sent_review_cost['all'] = $summarization[0];
  419. return $all_sent_review_cost;
  420. }
  421. //委托单位项目数量、送审总额、审定总额、(预算总额、结算总额、送审服务费)、表格、项目数量排行
  422. public function review_poportion_company()
  423. {
  424. $unit_id = get_login_admin("unit_name");
  425. $review_poportion = Db::query("select entrust_unit,entrust_unit_name
  426. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  427. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  428. ,sum(sent_review_amount) as all_sent_amount
  429. ,sum(authorize_amount) as all_authorize_amount
  430. ,sum(sent_review_cost) as all_sent_review_cost
  431. ,(sum(authorize_amount)-sum(sent_review_amount))/sum(sent_review_amount) as increaseOrdecrease
  432. ,count(*) as project_number
  433. from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
  434. group by entrust_unit,entrust_unit_name order by project_number");
  435. return $review_poportion;
  436. }
  437. //送审单位送审总额占比图、送审总额排行、表格
  438. public function sent_poportion_company()
  439. {
  440. $unit_id = get_login_admin("unit_name");
  441. $sent_poportion = Db::query("select
  442. sent_review_unit_name
  443. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  444. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  445. ,sum(sent_review_amount) as all_sent_amount
  446. ,count(sent_review_unit_name) as project_number
  447. from cp_cost_project where review_unit=$unit_id and sent_review_unit_name != ''
  448. group by sent_review_unit_name order by all_sent_amount");
  449. return $sent_poportion;
  450. }
  451. public function cost_member($today = 2024)
  452. {
  453. $unit_id = get_login_admin("unit_name");
  454. $users = Db::name('admin')->where('unit_name', $unit_id)->select();
  455. $cost_project_member = self::cost_project_member($today);
  456. $cost_month_member = self::cost_month_member($today);
  457. //halt($cost_project_member,$cost_month_member);
  458. View::assign('users', $users);
  459. View::assign('cost_project_member', $cost_project_member);
  460. View::assign('cost_month_member', $cost_month_member);
  461. return View();
  462. }
  463. //名字和项目数量
  464. public function cost_project_member($today = 2024)
  465. {
  466. $unit_id = get_login_admin("unit_name");
  467. $year = (double)$today;
  468. $users = Db::name('admin')->where('unit_name', $unit_id)->column('id');
  469. $usersStr = implode(',', $users);
  470. $data = Db::query("select
  471. sum(sent_review_amount) as all_sent_amount
  472. ,sum(authorize_amount) as all_authorize_amount
  473. ,count(*) as project_number
  474. ,review_head_name
  475. ,review_head
  476. ,COUNT(CASE WHEN project_status = 1 THEN 1 END) AS count_status_1,
  477. COUNT(CASE WHEN project_status = 2 THEN 1 END) AS count_status_2,
  478. COUNT(CASE WHEN project_status = 3 THEN 1 END) AS count_status_3,
  479. COUNT(CASE WHEN project_status = 4 THEN 1 END) AS count_status_4,
  480. COUNT(CASE WHEN project_status = 5 THEN 1 END) AS count_status_5,
  481. COUNT(CASE WHEN project_status = 6 THEN 1 END) AS count_status_6,
  482. COUNT(CASE WHEN project_status = 7 THEN 1 END) AS count_status_7,
  483. COUNT(CASE WHEN project_status = 8 THEN 1 END) AS count_status_8,
  484. COUNT(CASE WHEN project_status = 9 THEN 1 END) AS count_status_9
  485. from cp_cost_project where review_head in ($usersStr)
  486. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  487. group by review_head");
  488. //
  489. // halt($data);
  490. return $data;
  491. }
  492. //名字和月份
  493. public function cost_month_member($today = 2024)
  494. {
  495. $unit_id = get_login_admin("unit_name");
  496. $year = (double)$today;
  497. $data = Db::query("SELECT
  498. review_head,
  499. review_head_name,
  500. COUNT(*) AS project_number,
  501. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 1 THEN 1 ELSE 0 END) AS month_1,
  502. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 2 THEN 1 ELSE 0 END) AS month_2,
  503. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 3 THEN 1 ELSE 0 END) AS month_3,
  504. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 4 THEN 1 ELSE 0 END) AS month_4,
  505. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 5 THEN 1 ELSE 0 END) AS month_5,
  506. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 6 THEN 1 ELSE 0 END) AS month_6,
  507. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 7 THEN 1 ELSE 0 END) AS month_7,
  508. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 8 THEN 1 ELSE 0 END) AS month_8,
  509. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 9 THEN 1 ELSE 0 END) AS month_9,
  510. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 10 THEN 1 ELSE 0 END) AS month_10,
  511. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 11 THEN 1 ELSE 0 END) AS month_11,
  512. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 12 THEN 1 ELSE 0 END) AS month_12
  513. FROM
  514. cp_cost_project
  515. WHERE
  516. review_head IN (SELECT id FROM cp_admin WHERE unit_name = $unit_id)
  517. AND review_head != ''
  518. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  519. GROUP BY
  520. review_head,
  521. review_head_name
  522. ORDER BY
  523. project_number DESC");
  524. return $data;
  525. }
  526. //根据名字作图
  527. public
  528. function cost_name_member($today = 2024, $name = '')
  529. {
  530. $unit_id = get_login_admin("unit_name");
  531. if ($name == '') {
  532. $users = Db::name('admin')->where('unit_name', $unit_id)->column('id');
  533. $name = $users[0];
  534. }
  535. $year = (double)$today;
  536. $data = Db::query("select
  537. count(*) as project_number
  538. ,review_head_name
  539. ,review_head
  540. ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as month
  541. from cp_cost_project where review_head = $name and review_head != ''
  542. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  543. group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
  544. $all_sent_review_cost = [];
  545. for ($i = 1; $i <= 12; $i++) {
  546. $ayear = $today . '-' . $i;
  547. if ($data != []) {
  548. if (!in_array($ayear, array_column($data, 'month'))) {
  549. $all_sent_review_cost[$i] = [
  550. "project_number" => 0,
  551. "review_head" => $data[0]['review_head'],
  552. 'review_head_name' => $data[0]['review_head_name'],
  553. "month" => $ayear,
  554. ];
  555. } else {
  556. $num = array_search($ayear, array_column($data, 'month'));
  557. $all_sent_review_cost[$i] = [
  558. 'project_number' => $data[$num]['project_number'],
  559. 'review_head_name' => $data[$num]['review_head_name'],
  560. 'review_head' => $data[$num]['review_head'],
  561. 'month' => $data[$num]['month'],
  562. ];
  563. }
  564. } else {
  565. $all_sent_review_cost[$i] = [
  566. 'project_number' => 0,
  567. 'review_head' => $name,
  568. 'month' => $ayear,
  569. ];
  570. }
  571. }
  572. $this->success($msg = '成功!', $url = null, $data = $all_sent_review_cost);
  573. }
  574. }