FamilyService.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\admin\service\member;
  3. use app\model\Family;
  4. use app\model\FamilyMember;
  5. class FamilyService
  6. {
  7. public static function list($page, $pageSize, $keywords)
  8. {
  9. $rows = Family::when($keywords != '', function ($query) use ($keywords) {
  10. $query->where('family_name', 'like', '%' . $keywords . '%');
  11. });
  12. // 总条数
  13. $total = $rows->count('family_id');
  14. $rows = $rows->with([
  15. 'familyMember' => function ($query) {
  16. $query->select('family_member_id', 'join_family_id', 'family_member_name','family_member_remark','family_member_addtimes');
  17. }
  18. ])->select('family_id', 'join_family_creator_member_id','family_city', 'family_name', 'family_remark', 'family_addtimes')
  19. ->orderBy('family_addtimes', 'DESC')
  20. ->forPage($page, $pageSize)
  21. ->get()
  22. ->toArray();
  23. foreach ($rows as &$row){
  24. $row['family_addtimes'] = date('Y-m-d H:i:s',strtotime($row['family_addtimes']));
  25. }
  26. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  27. }
  28. /**
  29. * @Desc 家庭列表
  30. * @Author Gorden
  31. * @Date 2024/3/6 10:56
  32. *
  33. * @param $memberId
  34. * @return \support\Response
  35. */
  36. public static function selectList($memberId)
  37. {
  38. $list = Family::with('familyMember')
  39. ->where('join_family_creator_member_id', $memberId)
  40. ->get()
  41. ->toArray();
  42. return json_success('', $list);
  43. }
  44. /**
  45. * @Desc 家庭详情
  46. * @Author Gorden
  47. * @Date 2024/3/6 11:23
  48. *
  49. * @param $familyId
  50. * @return \support\Response
  51. */
  52. public static function selectInfo($familyId)
  53. {
  54. $family = Family::with('familyMember')
  55. ->where('family_id', $familyId)
  56. ->first();
  57. $family = $family ? $family->toArray() : [];
  58. return json_success('', $family);
  59. }
  60. }