Datastat.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. $all_sent_review_cost = self::sent_review_cost_company($today);
  203. // halt($all_sent_review_cost);
  204. $review_poportion = self::review_poportion_company();
  205. $sent_poportion = self::sent_poportion_company();
  206. // halt($today);
  207. View::assign('sent', $all_sent_review_cost);
  208. View::assign('review_poportion', $review_poportion);
  209. View::assign('sent_poportion', $sent_poportion);
  210. return view();
  211. }
  212. public function cost_chat($today = 2024)
  213. {
  214. $unit_id = get_login_admin("unit_name");
  215. //送审单位项目数量排行
  216. $sent_number_top = Db::query("select sent_review_unit_name
  217. ,sum(sent_review_amount) as all_sent_amount
  218. ,count(sent_review_unit_name) as project_number
  219. from cp_cost_project where entrust_unit=$unit_id and sent_review_unit_name != ''
  220. group by sent_review_unit_name order by project_number");
  221. //评审机审定总额排行
  222. $authorize_amount_top = Db::query("select review_unit,review_unit_name
  223. ,sum(authorize_amount) as all_authorize_amount
  224. from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
  225. group by review_unit order by all_authorize_amount");
  226. //评审机构送审总额排行
  227. $sent_review_amount_top = Db::query("select review_unit,review_unit_name
  228. ,sum(sent_review_amount) as all_sent_amount
  229. from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
  230. group by review_unit order by all_sent_amount");
  231. $year = (double)$today;
  232. //2024年送审总额占比分布图
  233. $sentAndaAuthorize = Db::query("select sum(sent_review_amount) as all_amount,engineering_type1
  234. from cp_cost_project where entrust_unit = $unit_id
  235. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  236. group by engineering_type1");
  237. if(!$sentAndaAuthorize){
  238. $sentAndaAuthorize[0] = 0;
  239. $sentAndaAuthorize[1] = 0;
  240. }
  241. $sent_poportion = self::sent_poportion();
  242. $all_sent_review_cost = self::sent_review_cost($today);
  243. $review_poportion = self::review_poportion();
  244. // halt($today);
  245. $data = [
  246. 'sent_poportion' => $sent_poportion,
  247. 'sent_number_top' => $sent_number_top,
  248. 'review_poportion' => $review_poportion,
  249. 'authorize_amount_top' => $authorize_amount_top,
  250. 'sent_review_amount_top' => $sent_review_amount_top,
  251. 'sentAndaAuthorize' => $sentAndaAuthorize,
  252. 'all_sent_review_cost' => $all_sent_review_cost,
  253. ];
  254. $this->success($msg = '成功!', $url = null, $data = $data);
  255. // return json($data);
  256. }
  257. //2024年项目送审服务费分布图、项目数量、项目送审、审定总额、表格
  258. public function sent_review_cost($today)
  259. {
  260. $unit_id = get_login_admin("unit_name");
  261. $year = (double)$today;
  262. $sent_review_cost = Db::query("select sum(sent_review_amount) as all_sent_amount
  263. ,sum(authorize_amount) as all_authorize_amount
  264. ,sum(sent_review_cost) as all_sent_review_cost
  265. ,count(*) as project_number
  266. ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as project_start_time
  267. from cp_cost_project where entrust_unit= $unit_id
  268. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  269. group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
  270. $summarization = Db::query("select sum(sent_review_amount) as all_sent_amount
  271. ,sum(authorize_amount) as all_authorize_amount
  272. ,sum(sent_review_cost) as all_sent_review_cost
  273. ,count(*) as project_number
  274. from cp_cost_project where entrust_unit = $unit_id
  275. and YEAR(FROM_UNIXTIME(project_start_time)) = $year");
  276. $all_sent_review_cost = [];
  277. for ($i = 1; $i <= 12; $i++) {
  278. $ayear = $today . '-' . $i;
  279. if (!in_array($ayear, array_column($sent_review_cost, 'project_start_time'))) {
  280. $all_sent_review_cost[$i] = [
  281. 'all_sent_amount' => 0,
  282. 'all_authorize_amount' => 0,
  283. 'all_sent_review_cost' => 0,
  284. 'project_number' => 0,
  285. 'project_start_time' => $ayear,
  286. ];
  287. } else {
  288. $num = array_search($ayear, array_column($sent_review_cost, 'project_start_time'));
  289. $all_sent_review_cost[$i] = [
  290. 'all_sent_amount' => $sent_review_cost[$num]['all_sent_amount'],
  291. 'all_authorize_amount' => $sent_review_cost[$num]['all_authorize_amount'],
  292. 'all_sent_review_cost' => $sent_review_cost[$num]['all_sent_review_cost'],
  293. 'project_number' => $sent_review_cost[$num]['project_number'],
  294. 'project_start_time' => $sent_review_cost[$num]['project_start_time'],
  295. ];
  296. }
  297. }
  298. $all_sent_review_cost['all'] = $summarization[0];
  299. // halt($year);
  300. return $all_sent_review_cost;
  301. }
  302. //评审机构项目数量、送审总额、审定总额、(预算总额、结算总额、送审服务费)、表格、项目数量排行
  303. public function review_poportion()
  304. {
  305. $unit_id = get_login_admin("unit_name");
  306. $review_poportion = Db::query("select review_unit,review_unit_name
  307. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  308. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  309. ,sum(sent_review_amount) as all_sent_amount
  310. ,sum(authorize_amount) as all_authorize_amount
  311. ,sum(sent_review_cost) as all_sent_review_cost
  312. ,(sum(authorize_amount)-sum(sent_review_amount))/sum(sent_review_amount) as increaseOrdecrease
  313. ,count(*) as project_number
  314. from cp_cost_project where entrust_unit=$unit_id and review_unit_name != ''
  315. group by review_unit order by project_number");
  316. return $review_poportion;
  317. }
  318. //送审单位送审总额占比图、送审总额排行、表格
  319. public function sent_poportion()
  320. {
  321. $unit_id = get_login_admin("unit_name");
  322. $sent_poportion = Db::query("select
  323. sent_review_unit_name
  324. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  325. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  326. ,sum(sent_review_amount) as all_sent_amount
  327. ,count(sent_review_unit_name) as project_number
  328. from cp_cost_project where entrust_unit=$unit_id and sent_review_unit_name != ''
  329. group by sent_review_unit_name order by all_sent_amount");
  330. return $sent_poportion;
  331. }
  332. public function cost_chat_company($today = 2024)
  333. {
  334. $unit_id = get_login_admin("unit_name");
  335. //送审单位项目数量排行
  336. $sent_number_top = Db::query("select sent_review_unit_name
  337. ,sum(sent_review_amount) as all_sent_amount
  338. ,count(sent_review_unit_name) as project_number
  339. from cp_cost_project where review_unit=$unit_id and sent_review_unit_name != ''
  340. group by sent_review_unit_name order by project_number");
  341. //委托单位定总额排行
  342. $authorize_amount_top = Db::query("select entrust_unit,entrust_unit_name
  343. ,sum(authorize_amount) as all_authorize_amount
  344. from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
  345. group by entrust_unit order by all_authorize_amount");
  346. //委托单位送审总额排行
  347. $sent_review_amount_top = Db::query("select entrust_unit,entrust_unit_name
  348. ,sum(sent_review_amount) as all_sent_amount
  349. from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
  350. group by entrust_unit order by all_sent_amount");
  351. $year = (double)$today;
  352. //2024年送审总额占比分布图
  353. $sentAndaAuthorize = Db::query("select sum(sent_review_amount) as all_amount,engineering_type1
  354. from cp_cost_project where review_unit = $unit_id
  355. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  356. group by engineering_type1");
  357. if(!$sentAndaAuthorize){
  358. $sentAndaAuthorize[0] = 0;
  359. $sentAndaAuthorize[1] = 0;
  360. }
  361. $sent_poportion = self::sent_poportion_company();
  362. $all_sent_review_cost = self::sent_review_cost_company($today);
  363. $review_poportion = self::review_poportion_company();
  364. $data = [
  365. 'sent_poportion' => $sent_poportion,
  366. 'sent_number_top' => $sent_number_top,
  367. 'review_poportion' => $review_poportion,
  368. 'authorize_amount_top' => $authorize_amount_top,
  369. 'sent_review_amount_top' => $sent_review_amount_top,
  370. 'sentAndaAuthorize' => $sentAndaAuthorize,
  371. 'all_sent_review_cost' => $all_sent_review_cost,
  372. ];
  373. // halt($data);
  374. $this->success($msg = '成功!', $url = null, $data = $data);
  375. }
  376. //2024年项目送审服务费分布图、项目数量、项目送审、审定总额、表格
  377. public function sent_review_cost_company($today)
  378. {
  379. $unit_id = get_login_admin("unit_name");
  380. $year = (double)$today;
  381. $sent_review_cost = Db::query("select sum(sent_review_amount) as all_sent_amount
  382. ,sum(authorize_amount) as all_authorize_amount
  383. ,sum(sent_review_cost) as all_sent_review_cost
  384. ,count(*) as project_number
  385. ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as project_start_time
  386. from cp_cost_project where review_unit= $unit_id
  387. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  388. group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
  389. $summarization = Db::query("select sum(sent_review_amount) as all_sent_amount
  390. ,sum(authorize_amount) as all_authorize_amount
  391. ,sum(sent_review_cost) as all_sent_review_cost
  392. ,count(*) as project_number
  393. from cp_cost_project where review_unit= $unit_id
  394. and YEAR(FROM_UNIXTIME(project_start_time)) = $year");
  395. $all_sent_review_cost = [];
  396. for ($i = 1; $i <= 12; $i++) {
  397. $ayear = $today . '-' . $i;
  398. if (!in_array($ayear, array_column($sent_review_cost, 'project_start_time'))) {
  399. $all_sent_review_cost[$i] = [
  400. 'all_sent_amount' => 0,
  401. 'all_authorize_amount' => 0,
  402. 'all_sent_review_cost' => 0,
  403. 'project_number' => 0,
  404. 'project_start_time' => $ayear,
  405. ];
  406. } else {
  407. $num = array_search($ayear, array_column($sent_review_cost, 'project_start_time'));
  408. $all_sent_review_cost[$i] = [
  409. 'all_sent_amount' => $sent_review_cost[$num]['all_sent_amount'],
  410. 'all_authorize_amount' => $sent_review_cost[$num]['all_authorize_amount'],
  411. 'all_sent_review_cost' => $sent_review_cost[$num]['all_sent_review_cost'],
  412. 'project_number' => $sent_review_cost[$num]['project_number'],
  413. 'project_start_time' => $sent_review_cost[$num]['project_start_time'],
  414. ];
  415. }
  416. }
  417. $all_sent_review_cost['all'] = $summarization[0];
  418. return $all_sent_review_cost;
  419. }
  420. //委托单位项目数量、送审总额、审定总额、(预算总额、结算总额、送审服务费)、表格、项目数量排行
  421. public function review_poportion_company()
  422. {
  423. $unit_id = get_login_admin("unit_name");
  424. $review_poportion = Db::query("select entrust_unit,entrust_unit_name
  425. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  426. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  427. ,sum(sent_review_amount) as all_sent_amount
  428. ,sum(authorize_amount) as all_authorize_amount
  429. ,sum(sent_review_cost) as all_sent_review_cost
  430. ,(sum(authorize_amount)-sum(sent_review_amount))/sum(sent_review_amount) as increaseOrdecrease
  431. ,count(*) as project_number
  432. from cp_cost_project where review_unit=$unit_id and entrust_unit_name != ''
  433. group by entrust_unit order by project_number");
  434. return $review_poportion;
  435. }
  436. //送审单位送审总额占比图、送审总额排行、表格
  437. public function sent_poportion_company()
  438. {
  439. $unit_id = get_login_admin("unit_name");
  440. $sent_poportion = Db::query("select
  441. sent_review_unit_name
  442. ,SUM(CASE WHEN engineering_type1 = 1 THEN sent_review_amount ELSE 0 END) AS budget_amount
  443. ,SUM(CASE WHEN engineering_type1 = 2 THEN sent_review_amount ELSE 0 END) AS settlement_amount
  444. ,sum(sent_review_amount) as all_sent_amount
  445. ,count(sent_review_unit_name) as project_number
  446. from cp_cost_project where review_unit=$unit_id and sent_review_unit_name != ''
  447. group by sent_review_unit_name order by all_sent_amount");
  448. return $sent_poportion;
  449. }
  450. public function cost_member($today = 2024)
  451. {
  452. $unit_id = get_login_admin("unit_name");
  453. $users = Db::name('admin')->where('unit_name', $unit_id)->select();
  454. $cost_project_member = self::cost_project_member($today);
  455. $cost_month_member = self::cost_month_member($today);
  456. //halt($cost_project_member,$cost_month_member);
  457. View::assign('users', $users);
  458. View::assign('cost_project_member', $cost_project_member);
  459. View::assign('cost_month_member', $cost_month_member);
  460. return View();
  461. }
  462. //名字和项目数量
  463. public function cost_project_member($today = 2024)
  464. {
  465. $unit_id = get_login_admin("unit_name");
  466. $year = (double)$today;
  467. $users = Db::name('admin')->where('unit_name', $unit_id)->column('id');
  468. $usersStr = implode(',', $users);
  469. $data = Db::query("select
  470. sum(sent_review_amount) as all_sent_amount
  471. ,sum(authorize_amount) as all_authorize_amount
  472. ,count(*) as project_number
  473. ,review_head_name
  474. ,review_head
  475. ,COUNT(CASE WHEN project_status = 1 THEN 1 END) AS count_status_1,
  476. COUNT(CASE WHEN project_status = 2 THEN 1 END) AS count_status_2,
  477. COUNT(CASE WHEN project_status = 3 THEN 1 END) AS count_status_3,
  478. COUNT(CASE WHEN project_status = 4 THEN 1 END) AS count_status_4,
  479. COUNT(CASE WHEN project_status = 5 THEN 1 END) AS count_status_5,
  480. COUNT(CASE WHEN project_status = 6 THEN 1 END) AS count_status_6,
  481. COUNT(CASE WHEN project_status = 7 THEN 1 END) AS count_status_7,
  482. COUNT(CASE WHEN project_status = 8 THEN 1 END) AS count_status_8,
  483. COUNT(CASE WHEN project_status = 9 THEN 1 END) AS count_status_9
  484. from cp_cost_project where review_head in ($usersStr)
  485. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  486. group by review_head");
  487. //
  488. // halt($data);
  489. return $data;
  490. }
  491. //名字和月份
  492. public function cost_month_member($today = 2024)
  493. {
  494. $unit_id = get_login_admin("unit_name");
  495. $year = (double)$today;
  496. $data = Db::query("SELECT
  497. review_head,
  498. review_head_name,
  499. COUNT(*) AS project_number,
  500. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 1 THEN 1 ELSE 0 END) AS month_1,
  501. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 2 THEN 1 ELSE 0 END) AS month_2,
  502. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 3 THEN 1 ELSE 0 END) AS month_3,
  503. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 4 THEN 1 ELSE 0 END) AS month_4,
  504. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 5 THEN 1 ELSE 0 END) AS month_5,
  505. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 6 THEN 1 ELSE 0 END) AS month_6,
  506. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 7 THEN 1 ELSE 0 END) AS month_7,
  507. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 8 THEN 1 ELSE 0 END) AS month_8,
  508. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 9 THEN 1 ELSE 0 END) AS month_9,
  509. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 10 THEN 1 ELSE 0 END) AS month_10,
  510. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 11 THEN 1 ELSE 0 END) AS month_11,
  511. SUM(CASE WHEN MONTH(FROM_UNIXTIME(project_start_time)) = 12 THEN 1 ELSE 0 END) AS month_12
  512. FROM
  513. cp_cost_project
  514. WHERE
  515. review_head IN (SELECT id FROM cp_admin WHERE unit_name = $unit_id)
  516. AND review_head != ''
  517. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  518. GROUP BY
  519. review_head,
  520. review_head_name
  521. ORDER BY
  522. project_number DESC");
  523. return $data;
  524. }
  525. //根据名字作图
  526. public
  527. function cost_name_member($today = 2024, $name = '')
  528. {
  529. $unit_id = get_login_admin("unit_name");
  530. if ($name == '') {
  531. $users = Db::name('admin')->where('unit_name', $unit_id)->column('id');
  532. $name = $users[0];
  533. }
  534. $year = (double)$today;
  535. $data = Db::query("select
  536. count(*) as project_number
  537. ,review_head_name
  538. ,review_head
  539. ,DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') as month
  540. from cp_cost_project where review_head = $name and review_head != ''
  541. and YEAR(FROM_UNIXTIME(project_start_time)) = $year
  542. group by DATE_FORMAT(FROM_UNIXTIME(project_start_time), '%Y-%c') ");
  543. $all_sent_review_cost = [];
  544. for ($i = 1; $i <= 12; $i++) {
  545. $ayear = $today . '-' . $i;
  546. if ($data != []) {
  547. if (!in_array($ayear, array_column($data, 'month'))) {
  548. $all_sent_review_cost[$i] = [
  549. "project_number" => 0,
  550. "review_head" => $data[0]['review_head'],
  551. 'review_head_name' => $data[0]['review_head_name'],
  552. "month" => $ayear,
  553. ];
  554. } else {
  555. $num = array_search($ayear, array_column($data, 'month'));
  556. $all_sent_review_cost[$i] = [
  557. 'project_number' => $data[$num]['project_number'],
  558. 'review_head_name' => $data[$num]['review_head_name'],
  559. 'review_head' => $data[$num]['review_head'],
  560. 'month' => $data[$num]['month'],
  561. ];
  562. }
  563. } else {
  564. $all_sent_review_cost[$i] = [
  565. 'project_number' => 0,
  566. 'review_head' => $name,
  567. 'month' => $ayear,
  568. ];
  569. }
  570. }
  571. $this->success($msg = '成功!', $url = null, $data = $all_sent_review_cost);
  572. }
  573. }