YunShu.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Stats\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. use think\Request;
  7. class YunShu extends BaseController
  8. {
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function index()
  15. {
  16. // $post=\think\facade\Request::instance();
  17. // $endtime = isset($post['endtime']) ? $post['endtime'] : "";
  18. // $starttime = isset($post['starttime']) ? $post['starttime'] : "";
  19. // $condition=[];
  20. // if($starttime!=""){
  21. // $condition[]=["Date1617672422547",">=",$starttime];
  22. // }
  23. // if($endtime!=""){
  24. // $condition[]=["Date1617672422547","<=",$endtime];
  25. // }
  26. $db =Db::connect("mysql2");
  27. // if($endtime==""&& $starttime==""){
  28. $list = $db->name("stats_tj")->field("p,total,wtotal,dtotal")->select()->toArray();
  29. // }else{
  30. // $list = $db->name("il150_querendan")->field("ShortText1619541934512 as p,sum(`Number1617648665166` ) AS `total`,0 wtotal,0 dtotal")->where
  31. // ($condition)->group("p")->select()
  32. // ->toArray();
  33. // }
  34. $tips = Db::name("depart_tips")->field("department,total_tips")->where('year=CONCAT(YEAR(NOW()),"年") and month=CONCAT(month(NOW()),"月")')->select();
  35. $data=[];
  36. $temp=["p"=>"总计","total"=>0,"wtotal"=>0,"dtotal"=>0,"tips"=>0,"rate"=>0];
  37. foreach ($list as $key=>$value){
  38. $value['tips']=0;
  39. foreach ($tips as $val){
  40. if($value["p"]==$val['department']){
  41. $value['tips']=$val['total_tips'];
  42. }
  43. }
  44. $temp['total']+=$value['total'];
  45. $temp['wtotal']+=$value['wtotal'];
  46. $temp['dtotal']+=$value['dtotal'];
  47. $temp['tips']+=$value['tips'];
  48. $data[]=$value;
  49. }
  50. if($temp['tips']==0){
  51. $temp['rate']="-";
  52. $temp['tips']="-";
  53. }else{
  54. $temp['rate'] =number_format( $temp['total']/$temp['tips']*100,2);
  55. $temp['tips'] =round( $temp['tips'],2);
  56. }
  57. $temp['total'] = sprintf( "%.2f",$temp['total']);
  58. $temp['wtotal'] = sprintf( "%.2f",$temp['wtotal']);
  59. $temp['dtotal'] = sprintf( "%.2f",$temp['dtotal']);
  60. array_walk($data,function (&$value){
  61. if(is_null($value['tips']) || $value['tips']==0){
  62. $value['tips']="-";
  63. $value["rate"]="-";
  64. }else{
  65. $value["rate"]=number_format( $value['total']/$value['tips']*100,2);
  66. $value['tips'] = sprintf( "%.2f",$value['tips']);
  67. }
  68. $value['total'] = sprintf( "%.2f",$value['total']);
  69. $value['wtotal'] = sprintf( "%.2f",$value['wtotal']);
  70. $value['dtotal'] = sprintf( "%.2f",$value['dtotal']);
  71. });
  72. $sort = array_column($data,"rate");
  73. array_multisort($sort,SORT_ASC,$data);
  74. array_push($data,$temp);
  75. $data = array_reverse($data);
  76. return app_show(0,"获取成功",$data);
  77. }
  78. /**
  79. * 显示创建资源表单页.
  80. *
  81. * @return \think\Response
  82. */
  83. public function create()
  84. {
  85. // $post=\think\facade\Request::instance();
  86. // $endtime = isset($post['endtime']) ? $post['endtime'] : "";
  87. // $starttime = isset($post['starttime']) ? $post['starttime'] : "";
  88. // $condition=[];
  89. // if($starttime!=""){
  90. // $condition[]=["createdTime",">=",$starttime];
  91. // }
  92. // if($endtime!=""){
  93. // $condition[]=["createdTime","<=",$endtime];
  94. // }
  95. $db =Db::connect("mysql2");
  96. $list = $db->name("stats_th")->select()->toArray();
  97. $temp=["p"=>"总计","thfee"=>0,"wthfee"=>0,"mthfee"=>0,"m"=>0];
  98. foreach ($list as $key=>$value){
  99. $temp['thfee'] += $value['thfee'];
  100. $temp['wthfee'] += $value['wthfee'];
  101. $temp['mthfee'] += $value['mthfee'];
  102. $temp['m'] = $value['m'];
  103. }
  104. $temp['thfee'] = sprintf( "%.2f",$temp['thfee']);
  105. $temp['wthfee'] = sprintf( "%.2f",$temp['wthfee']);
  106. $temp['mthfee'] = sprintf( "%.2f",$temp['mthfee']);
  107. array_unshift($list,$temp);
  108. return app_show(0,"获取成功",$list);
  109. }
  110. /**
  111. * 保存新建的资源
  112. *
  113. * @param \think\Request $request
  114. * @return \think\Response
  115. */
  116. public function save()
  117. {
  118. $db =Db::connect("mysql2");
  119. // if($endtime==""&& $starttime==""){
  120. $list = $db->name("stats_thj")->field("p,total,wtotal,dtotal,thfee,wthfee,mthfee")->select()->toArray();
  121. // $list2 = $db->name("stats_th")->field("p,thfee,wthfee,mthfee")->select()->toArray();
  122. // }else{
  123. // $list = $db->name("il150_querendan")->field("ShortText1619541934512 as p,sum(`Number1617648665166` ) AS `total`,0 wtotal,0 dtotal")->where
  124. // ($condition)->group("p")->select()
  125. // ->toArray();
  126. // }
  127. $tips = Db::name("depart_tips")->field("department,total_tips")->where('year=CONCAT(YEAR(NOW()),"年") and month=CONCAT(month(NOW()),"月")')->select();
  128. $data=[];
  129. $temp=["p"=>"总计","thtotal"=>0,"total"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,"tips"=>0,
  130. "rate"=>0,"thrate"=>0];
  131. foreach ($list as $key=>$value){
  132. $value['tips']=0;
  133. foreach ($tips as $val){
  134. if($value["p"]==$val['department']){
  135. $value['tips']=$val['total_tips'];
  136. }
  137. }
  138. $value['thtotal'] = $value['total']-$value['mthfee'];
  139. $temp['total']+=$value['total'];
  140. $temp['mthfee']+=$value['mthfee'];
  141. $temp['wtotal']+=$value['wtotal'];
  142. $temp['wthfee']+=$value['wthfee'];
  143. $temp['thfee']+=$value['thfee'];
  144. $temp['dtotal']+=$value['dtotal'];
  145. $temp['tips']+=$value['tips'];
  146. $temp['thtotal']+=$value['thtotal'];
  147. $data[]=$value;
  148. }
  149. if($temp['tips']==0){
  150. $temp['rate']="-";
  151. $temp['thrate']="-";
  152. $temp['tips']="-";
  153. }else{
  154. $temp['rate'] =number_format( $temp['total']/$temp['tips']*100,2);
  155. $temp['thrate']=number_format( ($temp['total']- $temp['mthfee'])/$temp['tips']*100,2);;
  156. $temp['tips'] =round( $temp['tips'],2);
  157. }
  158. $temp['total'] = sprintf( "%.2f",$temp['total']);
  159. $temp['mthfee'] = sprintf( "%.2f",$temp['mthfee']);
  160. $temp['wtotal'] = sprintf( "%.2f",$temp['wtotal']);
  161. $temp['wthfee'] = sprintf( "%.2f",$temp['wthfee']);
  162. $temp['dtotal'] = sprintf( "%.2f",$temp['dtotal']);
  163. $temp['thfee'] = sprintf( "%.2f",$temp['thfee']);
  164. $temp['thtotal'] = sprintf( "%.2f",$temp['thtotal']);
  165. array_walk($data,function (&$value){
  166. if(is_null($value['tips']) || $value['tips']==0){
  167. $value['tips']="-";
  168. $value["rate"]="-";
  169. $value["thrate"]="-";
  170. }else{
  171. $value["rate"]=number_format( $value['total']/$value['tips']*100,2);
  172. $value["thrate"]=number_format( ($value['total']- $value['mthfee'])/$value['tips']*100,2);
  173. $value['tips'] = sprintf( "%.2f",$value['tips']);
  174. }
  175. $value['total'] = sprintf( "%.2f",$value['total']);
  176. $value['mthfee'] = sprintf( "%.2f",$value['mthfee']);
  177. $value['wtotal'] = sprintf( "%.2f",$value['wtotal']);
  178. $value['wthfee'] = sprintf( "%.2f",$value['wthfee']);
  179. $value['dtotal'] = sprintf( "%.2f",$value['dtotal']);
  180. $value['thfee'] = sprintf( "%.2f",$value['thfee']);
  181. $value['thtotal'] = sprintf( "%.2f",$value['thtotal']);
  182. });
  183. $sort = array_column($data,"thrate");
  184. array_multisort($sort,SORT_ASC,$data);
  185. array_push($data,$temp);
  186. $data = array_reverse($data);
  187. return app_show(0,"获取成功",$data);
  188. }
  189. /**
  190. * 显示指定的资源
  191. *
  192. * @param int $id
  193. * @return \think\Response
  194. */
  195. public function read()
  196. {
  197. $post=request()->post();
  198. $endtime = isset($post['date']) ? $post['date'] : date("Y-m-d");
  199. $list = DB::query(" SELECT
  200. a.suppitem as p,
  201. m,
  202. a.sale_total AS total,
  203. `a`.`th_total` AS `mthfee`,
  204. IFNULL(w,WEEK('{$endtime}',1)) as w,
  205. IFNULL(b.sale_total,0) AS wtotal,
  206. ifnull( `b`.`th_total`, 0 ) AS `wthfee`,
  207. IFNULL(c.d,date_format('{$endtime}', '%Y-%m-%d' )) as d,
  208. IFNULL(c.sale_total,0) AS dtotal,
  209. ifnull( `c`.`th_total`, 0 ) AS `thfee`
  210. FROM
  211. (
  212. SELECT MONTH
  213. ( ordertime ) AS m,
  214. sum( sale_total ) AS sale_total,
  215. suppitem,
  216. (
  217. SELECT
  218. ifnull( sum( t.th_qrd_fee ), 0 )
  219. FROM
  220. cfp_th_source t
  221. LEFT JOIN source_all l ON ( l.productNo = t.th_qrdcpNo AND t.th_qrdcpNo <> '' )
  222. WHERE
  223. l.suppitem = k.suppitem
  224. AND MONTH ( t.createtime ) = MONTH ( '{$endtime}' )
  225. ) AS th_total
  226. FROM
  227. source_all k
  228. WHERE
  229. MONTH ( ordertime ) = MONTH (
  230. '{$endtime}')
  231. GROUP BY
  232. suppitem,
  233. m
  234. ) AS a
  235. LEFT JOIN (
  236. SELECT WEEK
  237. ( ordertime, 1 ) AS w,
  238. sum( sale_total ) AS sale_total,
  239. suppitem,
  240. (
  241. SELECT
  242. ifnull( sum( t.th_qrd_fee ), 0 )
  243. FROM
  244. cfp_th_source t
  245. LEFT JOIN source_all l ON ( l.productNo = t.th_qrdcpNo AND t.th_qrdcpNo <> '' )
  246. WHERE
  247. l.suppitem = k.suppitem
  248. AND week ( t.createtime,1 ) = WEEK ( '{$endtime}', 1 )
  249. ) AS th_total
  250. FROM
  251. source_all k
  252. WHERE
  253. WEEK ( ordertime, 1 ) = WEEK ( '{$endtime}', 1 )
  254. GROUP BY
  255. suppitem,
  256. w
  257. ) AS b ON a.suppitem = b.suppitem
  258. LEFT JOIN (
  259. SELECT
  260. date_format( ordertime, '%Y-%m-%d' ) AS d,
  261. sum( sale_total ) AS sale_total,
  262. suppitem,
  263. (
  264. SELECT
  265. ifnull( sum( t.th_qrd_fee ), 0 )
  266. FROM
  267. cfp_th_source t
  268. LEFT JOIN source_all l ON ( l.productNo = t.th_qrdcpNo AND t.th_qrdcpNo <> '' )
  269. WHERE
  270. l.suppitem = k.suppitem
  271. AND date_format ( t.createtime,'%Y-%m-%d') = date_format ( '{$endtime}', '%Y-%m-%d' )
  272. ) AS th_total FROM
  273. source_all k
  274. WHERE
  275. date_format( ordertime, '%Y-%m-%d' ) = date_format( '{$endtime}', '%Y-%m-%d' )
  276. GROUP BY
  277. suppitem,
  278. d
  279. ) AS c ON a.suppitem = c.suppitem
  280. ");
  281. $tips = Db::name("depart_tips")->field("department,total_tips")->where('year=CONCAT(YEAR(NOW()),"年") and month=CONCAT(month(NOW()),"月")')->select();
  282. $data=[];
  283. $temp=["p"=>"总计","thtotal"=>0,"total"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,"tips"=>0,
  284. "rate"=>0,"thrate"=>0];
  285. foreach ($list as $key=>$value){
  286. $value['tips']=0;
  287. foreach ($tips as $val){
  288. if($value["p"]==$val['department']){
  289. $value['tips']=$val['total_tips'];
  290. }
  291. }
  292. $value['thtotal'] = $value['total']-$value['mthfee'];
  293. $temp['total']+=$value['total'];
  294. $temp['mthfee']+=$value['mthfee'];
  295. $temp['wtotal']+=$value['wtotal'];
  296. $temp['wthfee']+=$value['wthfee'];
  297. $temp['thfee']+=$value['thfee'];
  298. $temp['dtotal']+=$value['dtotal'];
  299. $temp['tips']+=$value['tips'];
  300. $temp['thtotal']+=$value['thtotal'];
  301. $data[]=$value;
  302. }
  303. if($temp['tips']==0){
  304. $temp['rate']="-";
  305. $temp['thrate']="-";
  306. $temp['tips']="-";
  307. }else{
  308. $temp['rate'] =number_format( $temp['total']/$temp['tips']*100,2);
  309. $temp['thrate']=number_format( ($temp['total']- $temp['mthfee'])/$temp['tips']*100,2);;
  310. $temp['tips'] =round( $temp['tips'],2);
  311. }
  312. $temp['total'] = sprintf( "%.2f",$temp['total']);
  313. $temp['mthfee'] = sprintf( "%.2f",$temp['mthfee']);
  314. $temp['wtotal'] = sprintf( "%.2f",$temp['wtotal']);
  315. $temp['wthfee'] = sprintf( "%.2f",$temp['wthfee']);
  316. $temp['dtotal'] = sprintf( "%.2f",$temp['dtotal']);
  317. $temp['thfee'] = sprintf( "%.2f",$temp['thfee']);
  318. $temp['thtotal'] = sprintf( "%.2f",$temp['thtotal']);
  319. array_walk($data,function (&$value){
  320. if(is_null($value['tips']) || $value['tips']==0){
  321. $value['tips']="-";
  322. $value["rate"]="-";
  323. $value["thrate"]="-";
  324. }else{
  325. $value["rate"]=number_format( $value['total']/$value['tips']*100,2);
  326. $value["thrate"]=number_format( ($value['total']- $value['mthfee'])/$value['tips']*100,2);
  327. $value['tips'] = sprintf( "%.2f",$value['tips']);
  328. }
  329. $value['total'] = sprintf( "%.2f",$value['total']);
  330. $value['mthfee'] = sprintf( "%.2f",$value['mthfee']);
  331. $value['wtotal'] = sprintf( "%.2f",$value['wtotal']);
  332. $value['wthfee'] = sprintf( "%.2f",$value['wthfee']);
  333. $value['dtotal'] = sprintf( "%.2f",$value['dtotal']);
  334. $value['thfee'] = sprintf( "%.2f",$value['thfee']);
  335. $value['thtotal'] = sprintf( "%.2f",$value['thtotal']);
  336. });
  337. $sort = array_column($data,"thrate");
  338. array_multisort($sort,SORT_ASC,$data);
  339. array_push($data,$temp);
  340. $data = array_reverse($data);
  341. return app_show(0,"获取成功",$data);
  342. }
  343. /**
  344. * 显示编辑资源表单页.
  345. *
  346. * @param int $id
  347. * @return \think\Response
  348. */
  349. public function list()
  350. {
  351. $post=request()->post();
  352. $endtime = isset($post['date']) ? $post['date'] : date("Y-m-d");
  353. $list = DB::query(" SELECT
  354. a.suppitem as p,
  355. a.depart,
  356. m,
  357. a.sale_total AS total,
  358. `a`.`th_total` AS `mthfee`,
  359. IFNULL(w,WEEK('{$endtime}',1)) as w,
  360. IFNULL(b.sale_total,0) AS wtotal,
  361. ifnull( `b`.`th_total`, 0 ) AS `wthfee`,
  362. IFNULL(c.d,date_format('{$endtime}', '%Y-%m-%d' )) as d,
  363. IFNULL(c.sale_total,0) AS dtotal,
  364. ifnull( `c`.`th_total`, 0 ) AS `thfee`
  365. FROM
  366. (
  367. SELECT MONTH
  368. ( ordertime ) AS m,
  369. sum( sale_total ) AS sale_total,
  370. suppitem,
  371. depart,
  372. (
  373. SELECT
  374. ifnull( sum( t.th_qrd_fee ), 0 )
  375. FROM
  376. cfp_th_source t LEFT JOIN source_all l on l.productNo = t.th_qrdcpNo
  377. WHERE
  378. t.th_qrdcpNo <> '' and l.depart=k.depart and l.suppitem=k.suppitem and t.th_status<>3
  379. AND DATE_FORMAT ( t.createtime,'%Y-%m' ) = DATE_FORMAT ( '{$endtime}' ,'%Y-%m')
  380. ) AS th_total
  381. FROM
  382. source_all k
  383. WHERE
  384. DATE_FORMAT(ordertime,'%Y-%m') = DATE_FORMAT('{$endtime}','%Y-%m')
  385. GROUP BY
  386. suppitem,depart,
  387. m
  388. ) AS a
  389. LEFT JOIN (
  390. SELECT WEEK
  391. ( ordertime, 1 ) AS w,
  392. sum( sale_total ) AS sale_total,
  393. suppitem,
  394. depart,
  395. (
  396. SELECT
  397. ifnull( sum( t.th_qrd_fee ), 0 )
  398. FROM
  399. cfp_th_source t LEFT JOIN source_all l on l.productNo = t.th_qrdcpNo
  400. WHERE
  401. t.th_qrdcpNo <> '' and l.depart=k.depart and l.suppitem=k.suppitem and t.th_status<>3
  402. AND week ( t.createtime,1 ) = WEEK ( '{$endtime}', 1 ) and DATE_FORMAT ( t.createtime,'%Y' ) = DATE_FORMAT ( '{$endtime}' ,'%Y')
  403. ) AS th_total
  404. FROM
  405. source_all k
  406. WHERE
  407. WEEK ( ordertime, 1 ) = WEEK ( '{$endtime}', 1 ) and DATE_FORMAT ( ordertime,'%Y' ) = DATE_FORMAT ( '{$endtime}' ,'%Y')
  408. GROUP BY
  409. suppitem,depart,
  410. w
  411. ) AS b ON a.suppitem = b.suppitem and a.depart=b.depart
  412. LEFT JOIN (
  413. SELECT
  414. date_format( ordertime, '%Y-%m-%d' ) AS d,
  415. sum( sale_total ) AS sale_total,
  416. suppitem,depart,
  417. (
  418. SELECT
  419. ifnull( sum( t.th_qrd_fee ), 0 )
  420. FROM
  421. cfp_th_source t LEFT JOIN source_all l on l.productNo = t.th_qrdcpNo
  422. WHERE
  423. t.th_qrdcpNo <> '' and l.depart=k.depart and l.suppitem=k.suppitem and t.th_status<>3
  424. AND date_format ( t.createtime,'%Y-%m-%d') = date_format ( '{$endtime}', '%Y-%m-%d' )
  425. ) AS th_total FROM
  426. source_all k
  427. WHERE
  428. date_format( ordertime, '%Y-%m-%d' ) = date_format( '{$endtime}', '%Y-%m-%d' )
  429. GROUP BY
  430. suppitem,depart,
  431. d
  432. ) AS c ON a.suppitem = c.suppitem and a.depart=c.depart
  433. ");
  434. $dtae = isset($endtime) &&$endtime!="" ? $endtime." 00:00:00" : date("Y-m-d H:i:s");
  435. $tips = Db::name("depart_tips")->field("department,total_tips")->where("year=CONCAT(YEAR('{$dtae}'),'年') and month=CONCAT(month('{$dtae}'),'月')")->column("department,total_tips");
  436. $data=[];
  437. $temp=["p"=>"总计",'item'=>"-","thtotal"=>0,"total"=>0,"mthfee"=>0,"wtotal"=>0,"wthfee"=>0,"dtotal"=>0,"thfee"=>0,
  438. "tips"=>0,"rate"=>0,"thrate"=>0];
  439. foreach ($list as $key=>$value){
  440. $value['tips']=0;
  441. // foreach ($tips as $val){
  442. // if($value["depart"]==$val['department']){
  443. // $value['tips']=$val['total_tips'];
  444. // }
  445. // }
  446. $value['thtotal'] = $value['total']-$value['mthfee'];
  447. $data[]=$value;
  448. }
  449. $list = $this->check($data,$temp,$tips);
  450. array_walk($list,function (&$value){
  451. if(is_null($value['tips']) || $value['tips']==0){
  452. $value['tips']="-";
  453. $value["rate"]="-";
  454. $value["thrate"]="-";
  455. }else{
  456. $value["rate"]=number_format( $value['total']/$value['tips']*100,2);
  457. $value["thrate"]=number_format( ($value['total']- $value['mthfee'])/$value['tips']*100,2);
  458. $value['tips'] = sprintf( "%.2f",$value['tips']);
  459. }
  460. $value['total'] = sprintf( "%.2f",$value['total']);
  461. $value['mthfee'] = sprintf( "%.2f",$value['mthfee']);
  462. $value['wtotal'] = sprintf( "%.2f",$value['wtotal']);
  463. $value['wthfee'] = sprintf( "%.2f",$value['wthfee']);
  464. $value['dtotal'] = sprintf( "%.2f",$value['dtotal']);
  465. $value['thfee'] = sprintf( "%.2f",$value['thfee']);
  466. $value['thtotal'] = sprintf( "%.2f",$value['thtotal']);
  467. });
  468. if($temp['tips']==0){
  469. $temp['rate']="-";
  470. $temp['thrate']="-";
  471. $temp['tips']="-";
  472. }else{
  473. $temp['rate'] =number_format( $temp['total']/$temp['tips']*100,2);
  474. $temp['thrate']=number_format( ($temp['total']- $temp['mthfee'])/$temp['tips']*100,2);;
  475. $temp['tips'] =round( $temp['tips'],2);
  476. }
  477. $temp['total'] = sprintf( "%.2f",$temp['total']);
  478. $temp['mthfee'] = sprintf( "%.2f",$temp['mthfee']);
  479. $temp['wtotal'] = sprintf( "%.2f",$temp['wtotal']);
  480. $temp['wthfee'] = sprintf( "%.2f",$temp['wthfee']);
  481. $temp['dtotal'] = sprintf( "%.2f",$temp['dtotal']);
  482. $temp['thfee'] = sprintf( "%.2f",$temp['thfee']);
  483. $temp['thtotal'] = sprintf( "%.2f",$temp['thtotal']);
  484. $sort = array_column($list,"thrate");
  485. array_multisort($sort,SORT_ASC,$list);
  486. array_push($list,$temp);
  487. $list = array_reverse($list);
  488. return app_show(0,"获取成功",$list);
  489. }
  490. public function check($data,&$temp,$tipsArr)
  491. {
  492. $list =[];
  493. // $item = [['客服部','积分商城'],['项目部','印刷系统','泰康小卖部'],['网络部'],['特殊订单']];
  494. $suppitem = [['客服部'],['项目部','印刷系统'],['网络部'],['特殊订单'],['积分商城','泰康小卖部',"优选商城"]];
  495. $item = ['客服部','项目部','网络部','财务部',"平台部"];
  496. $checkitem = ['客服部','积分商城','项目部','印刷系统','泰康小卖部','网络部','特殊订单',"优选商城"];
  497. $tips=array_column($tipsArr,'total_tips');
  498. $tips_depart=array_column($tipsArr,'department');
  499. foreach ($data as $key=>$value){
  500. if(!in_array($value['p'],$checkitem)){
  501. continue;
  502. }
  503. if(in_array($value['depart'],$item)){
  504. $t= array_search( $value['depart'],$tips_depart);
  505. $k= array_search( $value['depart'],$item);
  506. $tip = $t!==false?$tips[$t]:0;
  507. }else{
  508. continue;
  509. }
  510. isset($list[$k])? "" : $list[$k]=['total'=>0,'mthfee'=>0,'tips'=>0,'wtotal'=>0,'wthfee'=>0,'dtotal'=>0,
  511. 'child'=>[],'depart'=>'','thfee'=>0,'thtotal'=>0];
  512. $list[$k]['total'] += $value['total'];
  513. $list[$k]['mthfee'] += $value['mthfee'];
  514. $list[$k]['wtotal'] += $value['wtotal'];
  515. $list[$k]['wthfee'] += $value['wthfee'];
  516. $list[$k]['dtotal'] += $value['dtotal'];
  517. $list[$k]['thfee'] += $value['thfee'];
  518. $list[$k]['thtotal'] += $value['thtotal'];
  519. $list[$k]['tips'] = $tip;
  520. $temp['total']+=$value['total'];
  521. $temp['mthfee']+=$value['mthfee'];
  522. $temp['wtotal']+=$value['wtotal'];
  523. $temp['wthfee']+=$value['wthfee'];
  524. $temp['thfee']+=$value['thfee'];
  525. $temp['dtotal']+=$value['dtotal'];
  526. $temp['thtotal']+=$value['thtotal'];
  527. if (is_null($value['tips']) || $value['tips'] == 0) {
  528. $value['tips'] = "-";
  529. } else {
  530. $value['tips'] = sprintf("%.2f", $value['tips']);
  531. }
  532. $value['total'] = sprintf("%.2f", $value['total']);
  533. $value['mthfee'] = sprintf("%.2f", $value['mthfee']);
  534. $value['wtotal'] = sprintf("%.2f", $value['wtotal']);
  535. $value['wthfee'] = sprintf("%.2f", $value['wthfee']);
  536. $value['dtotal'] = sprintf("%.2f", $value['dtotal']);
  537. $value['thfee'] = sprintf("%.2f", $value['thfee']);
  538. $value['thtotal'] = sprintf("%.2f", $value['thtotal']);
  539. $list[$k]['child'][] = $value;
  540. $list[$k]['depart'] = $value['depart'];
  541. }
  542. $temp['tips'] = array_sum(array_column($list,'tips'));
  543. return $list;
  544. }
  545. /**
  546. * 保存更新的资源
  547. *
  548. * @param \think\Request $request
  549. * @param int $id
  550. * @return \think\Response
  551. */
  552. public function update(Request $request, $id)
  553. {
  554. //
  555. }
  556. /**
  557. * 删除指定资源
  558. *
  559. * @param int $id
  560. * @return \think\Response
  561. */
  562. public function delete($id)
  563. {
  564. //
  565. }
  566. }