MemberAccountController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\controller\finance;
  3. use app\model\Member;
  4. use support\Db;
  5. use support\Request;
  6. class MemberAccountController
  7. {
  8. public function list(Request $request)
  9. {
  10. $page = $request->get('page', 1);
  11. $pageSize = $request->get('pageSize', 20);
  12. // $classify = $request->get('classify', 'CASH');
  13. $days = $request->get('member_addtimes', []);
  14. $level = $request->get('level', '');
  15. $accountType = $request->get('account_type', 'CASH');
  16. $premisesId = intval($request->get('premises_id', ''));
  17. if (!empty($days)) {
  18. $days[0] = strtotime($days[0]);
  19. $days[1] = strtotime($days[1]);
  20. $month = date('Ym', $days[0]);
  21. $days[1] = strtotime(date('Y-m-d', $days[1]) . " 23:59:59");
  22. } else {
  23. $month = date('Ym');
  24. }
  25. // $rows = Db::table("data_account_{$month} as da")
  26. // ->leftJoin('member as m', 'm.member_id', '=', 'da.join_data_account_member_id')
  27. // ->leftJoin('member_cert as mc', 'mc.join_cert_member_id', '=', 'da.join_data_account_member_id')
  28. // ->leftJoin('member_info as mi', 'mi.join_info_member_id', '=', 'da.join_data_account_member_id')
  29. // ->when(!empty($classify), function ($query) use ($classify) {
  30. // $query->where('da.data_account_classify', $classify);
  31. // })
  32. // ->selectRaw("app_m.member_mobile,app_mc.member_cert_name,app_mi.member_info_nickname,app_m.member_addtimes as member_addtimes,
  33. // GROUP_CONCAT(app_da.data_account_income) as data_account_income,GROUP_CONCAT(app_da.data_account_expend) as data_account_expend,
  34. // GROUP_CONCAT(app_da.data_account_surplus) as data_account_surplus,GROUP_CONCAT(app_da.data_account_added) as data_account_added
  35. // ")
  36. // ->groupBy('da.join_data_account_member_id');
  37. // $total = $rows->count('*');
  38. // $rows = $rows->orderBy('m.member_addtimes','DESC')
  39. // ->forPage($page, $pageSize)
  40. // ->get()
  41. // ->toArray();
  42. // $statistics = [];
  43. // foreach ($rows as &$row){
  44. // $row->data_account_income = last(explode(',',$row->data_account_income));
  45. // $row->data_account_expend = last(explode(',',$row->data_account_expend));
  46. // $row->data_account_surplus = last(explode(',',$row->data_account_surplus));
  47. // $row->data_account_added = last(explode(',',$row->data_account_added));
  48. // $row->member_addtimes = date('Y-m-d H:i:s',$row->member_addtimes);
  49. // }
  50. // return json_success('', compact('rows', 'page', 'pageSize', 'total','statistics'));
  51. $rows = Member::with([
  52. 'cert' => function ($query) {
  53. $query->select('join_cert_member_id', 'member_cert_name');
  54. },
  55. 'info' => function ($query) {
  56. $query->select('join_info_member_id', 'member_info_nickname');
  57. },
  58. 'role' => function ($query) {
  59. $query->select('member_role_id', 'member_role_name');
  60. }
  61. ])->join('member_account as ma', function ($join) use ($accountType) {
  62. $join->on('member.member_id', '=', 'ma.join_account_member_id')->where('ma.member_account_classify', '=', $accountType);
  63. })->when(!empty($level), function ($query) use ($level) {
  64. if ($level == '00'){
  65. $query->where('join_member_role_id','')->orWhere('join_member_role_id',NULL);
  66. }else{
  67. $query->where('join_member_role_id', $level);
  68. }
  69. })->when(!empty($days), function ($query) use ($days) {
  70. $query->whereBetween('member.member_addtimes', $days);
  71. })->when(!empty($premisesId), function ($query) use ($premisesId) {
  72. $query->whereJsonContains('member.member_extend_json->belong->premises', $premisesId);
  73. });
  74. $total = $rows->count('member_id');
  75. $statistics['surplus'] = $rows->sum('ma.member_account_surplus');
  76. $statistics['income'] = $rows->sum('ma.member_account_income');
  77. $statistics['expend'] = $rows->sum('member_account_expend');
  78. $statistics['added'] = $rows->sum('member_account_added');
  79. $rows = $rows->select('member.member_id', 'member.member_mobile', 'member.member_addtimes', 'member.join_member_role_id',
  80. 'ma.member_account_income as member_account_income', 'ma.member_account_expend as member_account_expend', 'ma.member_account_surplus as member_account_surplus', 'ma.member_account_added as member_account_added'
  81. )
  82. ->orderBy('member.member_addtimes', 'DESC')
  83. ->forPage($page, $pageSize)
  84. ->get()
  85. ->toArray();
  86. return json_success('', compact('rows', 'page', 'pageSize', 'total', 'statistics'));
  87. }
  88. }