PremisesRevenueController.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\controller\finance;
  3. use app\admin\service\sys_manage\DeptService;
  4. use support\Db;
  5. use support\Request;
  6. class PremisesRevenueController
  7. {
  8. private $accountType = ['CASH', 'POINTS', 'CARD'];
  9. public function list(Request $request)
  10. {
  11. $page = $request->get('page', 1);
  12. $pageSize = $request->get('pageSize', 20);
  13. $premises = $request->get('premises', DeptService::getPremisesList());
  14. $premisesKeyValue = [];
  15. foreach($premises as $item){
  16. $premisesKeyValue[$item['key']] = $item['label'];
  17. }
  18. $month = date('Ym');
  19. $data = [];
  20. $statistics = ['income'=>0,'expend'=>0];
  21. foreach ($premises as $premise) {
  22. $premisesData = [];
  23. $premisesData['premises'] = $premise['label'];
  24. $premiseKey = intval($premise['key']);
  25. $premisesData['expend'] = $premisesData['income'] = [
  26. 'card' => 0,
  27. 'recharge' => 0,
  28. 'goods' => 0,
  29. 'service' => 0,
  30. 'meals' => 0,
  31. 'package' => 0,
  32. 'amount' => 0
  33. ];
  34. $income = Db::table("data_income_{$month}")
  35. ->where('join_data_income_dept_id',$premiseKey)
  36. ->selectRaw("data_income_classify,SUM(data_income_amount) as data_income_amount")
  37. ->groupBy('data_income_classify')
  38. ->get();
  39. foreach($income as $item){
  40. if($item->data_income_classify == 'CARD'){
  41. $premisesData['income']['card']+=$item->data_income_amount;
  42. }else if($item->data_income_classify == 'RECHARGE'){
  43. $premisesData['income']['recharge']+=$item->data_income_amount;
  44. }else if($item->data_income_classify == 'GOODS'){
  45. $premisesData['income']['goods']+=$item->data_income_amount;
  46. }else if(in_array($item->data_income_classify,['CHNMED','CHNNCD','SERVICE'])){
  47. $premisesData['income']['service']+=$item->data_income_amount;
  48. }else if($item->data_income_classify == 'MEALS'){
  49. $premisesData['income']['meals']+=$item->data_income_amount;
  50. }else if($item->data_income_classify == 'PACKAGE'){
  51. $premisesData['income']['package']+=$item->data_income_amount;
  52. }
  53. $premisesData['income']['amount'] += $item->data_income_amount;
  54. $statistics['income'] += $premisesData['income']['amount'];
  55. }
  56. $expend = Db::table("data_expend_{$month}")
  57. ->where('join_data_expend_dept_id',$premiseKey)
  58. ->selectRaw("data_expend_classify,SUM(data_expend_amount) as data_expend_amount")
  59. ->groupBy('data_expend_classify')
  60. ->get();
  61. foreach($expend as $item){
  62. if($item->data_expend_classify == 'CARD'){
  63. $premisesData['expend']['card']+=$item->data_expend_amount;
  64. }else if($item->data_expend_classify == 'RECHARGE'){
  65. $premisesData['expend']['recharge']+=$item->data_expend_amount;
  66. }else if($item->data_expend_classify == 'GOODS'){
  67. $premisesData['expend']['goods']+=$item->data_expend_amount;
  68. }else if(in_array($item->data_expend_classify,['CHNMED','CHNNCD','SERVICE'])){
  69. $premisesData['expend']['service']+=$item->data_expend_amount;
  70. }else if($item->data_expend_classify == 'MEALS'){
  71. $premisesData['expend']['meals']+=$item->data_expend_amount;
  72. }else if($item->data_expend_classify == 'PACKAGE'){
  73. $premisesData['expend']['package']+=$item->data_expend_amount;
  74. }
  75. $premisesData['expend']['amount'] += $item->data_expend_amount;
  76. $statistics['expend'] += $premisesData['expend']['amount'];
  77. }
  78. $data[] = $premisesData;
  79. }
  80. return json_success('', ['rows'=>$data,'statistics'=>$statistics]);
  81. }
  82. }