MemberAccountController.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 = ['2024-06-01', '2024-06-30'];
  14. if (!empty($days)) {
  15. $days[0] = strtotime($days[0]);
  16. $days[1] = strtotime($days[1]);
  17. if (date('m', $days[0]) != date('m', $days[1])) {
  18. return json_fail('暂不支持跨月查询');
  19. }
  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 ($classify){
  62. $join->on('member.member_id','=','ma.join_account_member_id')->where('ma.member_account_classify','=',$classify);
  63. });
  64. $total = $rows->count('member_id');
  65. $statistics['surplus'] = $rows->sum('ma.member_account_surplus');
  66. $statistics['income'] = $rows->sum('ma.member_account_income');
  67. $statistics['expend'] = $rows->sum('member_account_expend');
  68. $statistics['added'] = $rows->sum('member_account_added');
  69. $rows = $rows->select('member.member_id','member.member_mobile','member.member_addtimes',
  70. 'ma.member_account_income as member_account_income','ma.member_account_expend as member_account_expend'
  71. )
  72. ->orderBy('member.member_addtimes', 'DESC')
  73. ->forPage($page, $pageSize)
  74. ->get()
  75. ->toArray();
  76. return json_success('', compact('rows', 'page', 'pageSize', 'total','statistics'));
  77. }
  78. }