OwnerService.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\admin\service\member;
  3. use app\model\Member;
  4. use app\model\MemberCert;
  5. use app\model\MemberInfo;
  6. use app\model\SysSerial;
  7. use support\Db;
  8. use support\Request;
  9. class OwnerService
  10. {
  11. public static function list(Request $request)
  12. {
  13. $page = $request->get('page', 1);
  14. $pageSize = $request->get('pageSize', 10);
  15. $name = $request->get('name', '');
  16. $mobile = $request->get('mobile', '');
  17. $rows = Member::where('member_is_owner', 'Y')
  18. ->leftJoin('member_info', 'member_info.join_info_member_id', 'member.member_id')
  19. ->leftJoin('member_cert', 'member_cert.join_cert_member_id', 'member.member_id')
  20. ->when($name != '', function ($query) use ($name) {
  21. $query->where('member_cert.member_cert_name', 'like', '%' . $name . '%');
  22. })->when($mobile != '', function ($query) use ($mobile) {
  23. $query->where('member.member_mobile', 'like', '%' . $mobile . '%');
  24. })->select('member_id', 'member_is_owner', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes',
  25. 'member_info.member_info_nickname', 'member_info.member_info_headimg',
  26. 'member_cert.member_cert_birth', 'member_cert.member_cert_gender', 'member_cert.member_cert_name', 'member_cert.member_cert_nbr', 'member_cert.member_cert_province', 'member_cert.member_cert_addr', 'member_cert.member_cert_face', 'member_cert.member_cert_photo', 'member_cert.member_cert_nation'
  27. );
  28. // 总条数
  29. $total = $rows->count('member_id');
  30. $rows = $rows->orderBy('member_addtimes', 'DESC')
  31. ->forPage($page, $pageSize)
  32. ->get()
  33. ->toArray();
  34. foreach ($rows as &$row) {
  35. $row['info'] = [
  36. 'member_info_nickname' => $row['member_info_nickname'] ?? '',
  37. 'member_info_headimg' => !empty($row['member_info_headimg']) ? getenv('STORAGE_DOMAIN') . $row['member_info_headimg'] : ''
  38. ];
  39. $row['cert'] = [
  40. 'member_cert_birth' => $row['member_cert_birth'],
  41. 'member_cert_gender' => $row['member_cert_gender'],
  42. 'member_cert_name' => $row['member_cert_name'],
  43. 'member_cert_nbr' => $row['member_cert_nbr'],
  44. 'member_cert_province' => !empty($row['member_cert_province']) && is_json($row['member_cert_province']) ? json_decode($row['member_cert_province']) : '',
  45. 'member_cert_addr' => $row['member_cert_addr'],
  46. 'member_cert_face' => !empty($row['member_cert_face']) ? getenv('STORAGE_DOMAIN') . $row['member_cert_face'] : '',
  47. 'member_cert_photo' => !empty($row['member_cert_photo']) ? getenv('STORAGE_DOMAIN') . $row['member_cert_photo'] : '',
  48. 'member_cert_nation' => $row['member_cert_nation'],
  49. ];
  50. $row['is_auth'] = "未认证";
  51. if (!empty($row['member_cert_nbr']) && !empty($row['member_cert_face']) && !empty($row['member_cert_photo'])) {
  52. $row['is_auth'] = "已认证";
  53. }
  54. }
  55. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  56. }
  57. /**
  58. * @Desc 添加会员
  59. * @Author Gorden
  60. * @Date 2024/3/25 13:40
  61. *
  62. * @param $params
  63. * @return \support\Response
  64. */
  65. public static function add($params)
  66. {
  67. Db::beginTransaction();
  68. try {
  69. $memberId = self::generateMemberId();
  70. // 先写主表,要ID
  71. $memberData = [
  72. 'member_id' => $memberId,
  73. 'member_is_owner' => $params['is_owner'],
  74. 'member_classify' => $params['classify'],
  75. 'member_status' => $params['status'],
  76. 'member_mobile' => $params['mobile'],
  77. 'member_from' => $params['source'],
  78. 'member_addtimes' => time(),
  79. ];
  80. Member::insert($memberData);
  81. // member cert
  82. $certData = [
  83. 'join_cert_member_id' => $memberId,
  84. 'member_cert_nation' => $params['member_cert_nation'] ?? '',
  85. 'member_cert_name' => $params['cert_name'] ?? '',
  86. 'member_cert_nbr' => $params['cert_nbr'] ?? '',
  87. 'member_cert_birth' => $params['birth'] ?? '',
  88. 'member_cert_gender' => $params['gender'] ?? '',
  89. 'member_cert_province' => $params['province'] ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
  90. 'member_cert_city' => $params['city'] ?? '',
  91. 'member_cert_addr' => $params['addr'] ?? '',
  92. 'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
  93. 'member_cert_photo' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_photo']),
  94. ];
  95. MemberCert::insert($certData);
  96. // member info
  97. $infoData = [
  98. 'join_info_member_id' => $memberId,
  99. 'member_info_nickname' => $params['account_name'],
  100. 'member_info_headimg' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar'])
  101. ];
  102. MemberInfo::insert($infoData);
  103. Db::commit();
  104. } catch (\Exception $e) {
  105. Db::rollBack();
  106. dump($e->getMessage() . ';line:' . $e->getLine());
  107. return json_fail("数据添加失败");
  108. }
  109. return json_success('数据添加成功');
  110. }
  111. private static function generateMemberId()
  112. {
  113. $id = SysSerial::getSerial();
  114. return "ME" . str_pad($id, 16, "0", STR_PAD_LEFT) . random_string(8);
  115. }
  116. }