RechargeController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\admin\controller\finance;
  3. use app\admin\service\member\MemberService;
  4. use app\model\Member;
  5. use app\model\Order;
  6. use support\Db;
  7. use support\Request;
  8. class RechargeController
  9. {
  10. public function list(Request $request)
  11. {
  12. $page = $request->get('page', 1);
  13. $pageSize = $request->get('pageSize', 20);
  14. $memberId = $request->get('join_order_member_id', '');
  15. $days = $request->get('order_addtimes', []);
  16. $premisesId = intval($request->get('premises_id', ''));
  17. if (!empty($days)) {
  18. $days[0] = strtotime($days[0]);
  19. $days[1] = strtotime($days[1]);
  20. }
  21. $rows = Order::with([
  22. 'member' => function ($query) {
  23. $query->select('member_id', 'member_mobile');
  24. },
  25. 'cert' => function ($query) {
  26. $query->select('join_cert_member_id', 'member_cert_name');
  27. },
  28. ])->where('order_classify','RECHARGE')
  29. ->when(!empty($days), function ($query) use ($days) {
  30. $query->whereBetween('order_addtimes', $days);
  31. })->when(!empty($memberId), function ($query) use ($memberId) {
  32. $query->where('join_order_member_id', $memberId);
  33. });
  34. $total = $rows->count();
  35. $memberIds = $rows->pluck('join_order_member_id')->toArray();
  36. dump(count(array_unique($memberIds)));
  37. $statistics['member_count'] = count(array_unique($memberIds));
  38. $statistics['amount'] = $rows->sum('order_amount_pay');
  39. $rows = $rows->orderBy('order_addtimes', 'DESC')
  40. ->forPage($page, $pageSize)
  41. ->get()
  42. ->toArray();
  43. foreach ($rows as &$row){
  44. $mobile = $row['member'] && $row['member']['member_mobile'] ? $row['member']['member_mobile'] : '';
  45. $certName = $row['cert'] && $row['cert']['member_cert_name'] ? $row['cert']['member_cert_name'] : '';
  46. $row['member_name'] = MemberService::getMemberCertName($mobile,$certName,'');
  47. }
  48. return json_success('', compact('rows', 'page', 'pageSize', 'total', 'statistics'));
  49. }
  50. }