|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\admin\service\member;
|
|
namespace app\admin\service\member;
|
|
|
|
|
|
|
|
+use app\common\Tree;
|
|
use app\model\ClientPoints;
|
|
use app\model\ClientPoints;
|
|
use app\model\CouponDetail;
|
|
use app\model\CouponDetail;
|
|
use app\model\Device;
|
|
use app\model\Device;
|
|
@@ -23,6 +24,7 @@ use app\model\SysUser;
|
|
use support\Db;
|
|
use support\Db;
|
|
use support\exception\BusinessException;
|
|
use support\exception\BusinessException;
|
|
use support\Request;
|
|
use support\Request;
|
|
|
|
+use support\Response;
|
|
|
|
|
|
class MemberService
|
|
class MemberService
|
|
{
|
|
{
|
|
@@ -37,6 +39,7 @@ class MemberService
|
|
$isAuth = $request->get('is_auth', '');
|
|
$isAuth = $request->get('is_auth', '');
|
|
$addtime = $request->get('member_addtimes', []);
|
|
$addtime = $request->get('member_addtimes', []);
|
|
$type = $request->get('type', '');
|
|
$type = $request->get('type', '');
|
|
|
|
+ $status = $request->get('member_status', '');
|
|
|
|
|
|
$rows = Member::with([
|
|
$rows = Member::with([
|
|
'account' => function ($query) {
|
|
'account' => function ($query) {
|
|
@@ -82,11 +85,13 @@ class MemberService
|
|
}
|
|
}
|
|
$query->whereBetween('member.member_addtimes', $addtime);
|
|
$query->whereBetween('member.member_addtimes', $addtime);
|
|
})->when(!empty($nickname), function ($query) use ($nickname) {
|
|
})->when(!empty($nickname), function ($query) use ($nickname) {
|
|
- $query->where(function($query2) use ($nickname){
|
|
|
|
- $query2->where('member_info.member_info_nickname','like','%'.$nickname.'%')->orWhere('member.member_mobile','like','%'.$nickname.'%');
|
|
|
|
|
|
+ $query->where(function ($query2) use ($nickname) {
|
|
|
|
+ $query2->where('member_info.member_info_nickname', 'like', '%' . $nickname . '%')->orWhere('member.member_mobile', 'like', '%' . $nickname . '%');
|
|
});
|
|
});
|
|
|
|
+ })->when(!empty($status), function ($query) use ($status) {
|
|
|
|
+ $query->where('member_status', $status);
|
|
})
|
|
})
|
|
- ->select('member_id', 'member_is_vip', 'member_is_owner', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
|
|
|
|
|
|
+ ->select('member_id', 'member_is_vip', 'member_is_owner','member_is_partner','member_is_referrer', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
|
|
'member_info.member_info_nickname', 'member_info.member_info_headimg', 'member_info.member_info_referee', 'member_info.member_info_business', 'member_info.member_info_service', 'member_info.member_info_city', 'member_info.member_info_address', 'member_info.member_info_gender', 'member_info.member_info_birthday',
|
|
'member_info.member_info_nickname', 'member_info.member_info_headimg', 'member_info.member_info_referee', 'member_info.member_info_business', 'member_info.member_info_service', 'member_info.member_info_city', 'member_info.member_info_address', 'member_info.member_info_gender', 'member_info.member_info_birthday',
|
|
'member_role.member_role_id', 'member_role.member_role_name',
|
|
'member_role.member_role_id', 'member_role.member_role_name',
|
|
'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'
|
|
'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'
|
|
@@ -210,6 +215,16 @@ class MemberService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // 粉丝
|
|
|
|
+ $fans1 = Member::where('join_invite_member_id', $row['member_id'])
|
|
|
|
+ ->select('member_id')
|
|
|
|
+ ->get()
|
|
|
|
+ ->toArray();
|
|
|
|
+ $fans1Ids = array_column($fans1, 'member_id');
|
|
|
|
+ $fans2Count = Member::whereIn('join_invite_member_id', $fans1Ids)
|
|
|
|
+ ->count();
|
|
|
|
+ $row['fans_total'] = count($fans1) + $fans2Count;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
@@ -267,7 +282,7 @@ class MemberService
|
|
$exportData = [];
|
|
$exportData = [];
|
|
foreach ($rows as $row) {
|
|
foreach ($rows as $row) {
|
|
$row['info'] = [
|
|
$row['info'] = [
|
|
- 'member_info_nickname' => !empty($row['member_info_nickname']) ? $row['member_info_nickname'] : substr($row['member_mobile'], -4, 4) . '用户',
|
|
|
|
|
|
+ 'member_info_nickname' => !empty($row['member_info_nickname']) ? $row['member_info_nickname'] : substr($row['member_mobile'], -4, 4) . '会员',
|
|
'member_info_headimg' => !empty($row['member_info_headimg']) ? $row['member_info_headimg'] : '',
|
|
'member_info_headimg' => !empty($row['member_info_headimg']) ? $row['member_info_headimg'] : '',
|
|
'member_info_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
|
|
'member_info_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
|
|
'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
|
|
'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
|
|
@@ -322,7 +337,7 @@ class MemberService
|
|
'cash' => isset($account['cash']) ? $account['cash']['member_account_surplus'] + $account['cash']['member_account_added'] : 0,
|
|
'cash' => isset($account['cash']) ? $account['cash']['member_account_surplus'] + $account['cash']['member_account_added'] : 0,
|
|
'points' => isset($account['points']) ? $account['points']['member_account_surplus'] + $account['points']['member_account_added'] : 0,
|
|
'points' => isset($account['points']) ? $account['points']['member_account_surplus'] + $account['points']['member_account_added'] : 0,
|
|
'is_auth' => $row['is_auth'],
|
|
'is_auth' => $row['is_auth'],
|
|
- 'level' => $row['member_role_name'] ?? '普通用户',
|
|
|
|
|
|
+ 'level' => $row['member_role_name'] ?? '普通会员',
|
|
'member_addtimes' => $row['member_addtimes'],
|
|
'member_addtimes' => $row['member_addtimes'],
|
|
'member_info_referee' => $row['info']['member_info_referee'] ?? '',
|
|
'member_info_referee' => $row['info']['member_info_referee'] ?? '',
|
|
'member_info_business' => $row['info']['member_info_business'] ?? '',
|
|
'member_info_business' => $row['info']['member_info_business'] ?? '',
|
|
@@ -343,7 +358,7 @@ class MemberService
|
|
}
|
|
}
|
|
$member = $member->toArray();
|
|
$member = $member->toArray();
|
|
$member['info'] = [
|
|
$member['info'] = [
|
|
- 'member_info_nickname' => !empty($member['info']) && !empty($member['info']['member_info_nickname']) ? $member['info']['member_info_nickname'] : substr($member['member_mobile'], -4, 4) . '用户',
|
|
|
|
|
|
+ 'member_info_nickname' => !empty($member['info']) && !empty($member['info']['member_info_nickname']) ? $member['info']['member_info_nickname'] : substr($member['member_mobile'], -4, 4) . '会员',
|
|
'member_info_headimg' => !empty($member['info']) && !empty($member['info']['member_info_headimg']) ? $member['info']['member_info_headimg'] : '',
|
|
'member_info_headimg' => !empty($member['info']) && !empty($member['info']['member_info_headimg']) ? $member['info']['member_info_headimg'] : '',
|
|
'member_info_referee' => !empty($member['info']) && !empty($member['info']['member_info_referee']) ? $member['info']['member_info_referee'] : '',
|
|
'member_info_referee' => !empty($member['info']) && !empty($member['info']['member_info_referee']) ? $member['info']['member_info_referee'] : '',
|
|
'member_info_business' => !empty($member['info']) && !empty($member['info']['member_info_business']) ? $member['info']['member_info_business'] : '',
|
|
'member_info_business' => !empty($member['info']) && !empty($member['info']['member_info_business']) ? $member['info']['member_info_business'] : '',
|
|
@@ -659,6 +674,175 @@ class MemberService
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @Desc 我的粉丝列表
|
|
|
|
+ * @Author Gorden
|
|
|
|
+ * @Date 2024/9/20 10:22
|
|
|
|
+ *
|
|
|
|
+ * @param Request $request
|
|
|
|
+ */
|
|
|
|
+ public static function fansList(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $memberId = $request->get('member_id');
|
|
|
|
+ $name = $request->get('name', '');
|
|
|
|
+ $mobile = $request->get('mobile', '');
|
|
|
|
+ $memberIds = [];
|
|
|
|
+ $memberInviteIds = [];
|
|
|
|
+ if (!empty($name)) {
|
|
|
|
+ $memberIds = MemberCert::where('member_cert_name', 'like', '%' . $name . '%')->pluck('join_cert_member_id')->toArray();
|
|
|
|
+ $memberInviteIds = Member::whereIn('member_id', $memberIds)->pluck('join_invite_member_id')->toArray();
|
|
|
|
+ }
|
|
|
|
+ if (!empty($mobile)) {
|
|
|
|
+ $members = Member::where('member_mobile', 'like', '%' . $mobile . '%')
|
|
|
|
+ ->select('member_id', 'join_invite_member_id')
|
|
|
|
+ ->get()
|
|
|
|
+ ->toArray();
|
|
|
|
+ $memberIds2 = array_column($members, 'member_id');
|
|
|
|
+ $memberInviteIds2 = array_column($members, 'join_invite_member_id');
|
|
|
|
+ $memberIds = array_merge($memberIds, $memberIds2);
|
|
|
|
+ $memberInviteIds = array_merge($memberInviteIds, $memberInviteIds2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $fans1 = Member::with([
|
|
|
|
+ 'info' => function ($query) {
|
|
|
|
+ $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
|
|
|
|
+ },
|
|
|
|
+ 'cert' => function ($query) {
|
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
|
+ },
|
|
|
|
+ 'role' => function ($query) {
|
|
|
|
+ $query->select('member_role_id', 'member_role_name');
|
|
|
|
+ }
|
|
|
|
+ ])->where('join_invite_member_id', $memberId)
|
|
|
|
+ ->when(!empty($memberIds), function ($query) use ($memberIds, $memberInviteIds) {
|
|
|
|
+ $allSub = array_merge($memberIds, $memberInviteIds);
|
|
|
|
+ $query->whereIn('member_id', $allSub);
|
|
|
|
+ })
|
|
|
|
+ ->select('member_id', 'join_member_role_id', 'member_id as id', 'join_invite_member_id as pid', 'member_partner_json', 'member_mobile', 'member_addtimes', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer')
|
|
|
|
+ ->get()
|
|
|
|
+ ->toArray();
|
|
|
|
+ $fans1Ids = array_column($fans1, 'id');
|
|
|
|
+ $fans2 = Member::with([
|
|
|
|
+ 'info' => function ($query) {
|
|
|
|
+ $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
|
|
|
|
+ },
|
|
|
|
+ 'cert' => function ($query) {
|
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
|
+ },
|
|
|
|
+ 'role' => function ($query) {
|
|
|
|
+ $query->select('member_role_id', 'member_role_name');
|
|
|
|
+ }
|
|
|
|
+ ])->whereIn('join_invite_member_id', $fans1Ids)
|
|
|
|
+ ->when(!empty($memberIds), function ($query) use ($memberIds) {
|
|
|
|
+ $query->whereIn('member_id', $memberIds);
|
|
|
|
+ })
|
|
|
|
+ ->select('member_id', 'join_member_role_id', 'member_id as id', 'join_invite_member_id as pid', 'member_partner_json', 'member_mobile', 'member_addtimes', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer')
|
|
|
|
+ ->get()
|
|
|
|
+ ->toArray();
|
|
|
|
+
|
|
|
|
+ $fans = array_merge($fans1, $fans2);
|
|
|
|
+ foreach ($fans as &$fan) {
|
|
|
|
+ $memberMobile = $fan['member_mobile'] ?? '';
|
|
|
|
+// $memberNickname = $fan['info'] && $fan['info']['member_info_nickname'] ? $fan['info']['member_info_nickname'] : '';
|
|
|
|
+ $memberCertName = $fan['cert'] && $fan['cert']['member_cert_name'] ? $fan['cert']['member_cert_name'] : '';
|
|
|
|
+ $fan['member_name'] = '';
|
|
|
|
+ if (!empty($memberCertName) && !empty($memberMobile)) {
|
|
|
|
+ $fan['member_name'] = $memberCertName . '-' . $memberMobile;
|
|
|
|
+ } elseif (!empty($memberCertName)) {
|
|
|
|
+ $fan['member_name'] = $memberCertName;
|
|
|
|
+ } elseif (!empty($memberMobile)) {
|
|
|
|
+ $fan['member_name'] = $memberMobile;
|
|
|
|
+ }
|
|
|
|
+ if (!empty($fan['info']) && substr($fan['info']['member_info_headimg'], 0, 4) == 'http') {
|
|
|
|
+ $fan['member_info_headimg'] = $fan['info']['member_info_headimg'];
|
|
|
|
+ } else {
|
|
|
|
+ $fan['member_info_headimg'] = 'https://img.wanyuewellness.com.cn/images/avatar_default.png';
|
|
|
|
+ }
|
|
|
|
+ // 等级名称
|
|
|
|
+ $fan['role_name'] = $fan['role'] && $fan['role']['member_role_name'] ? $fan['role']['member_role_name'] : '';
|
|
|
|
+
|
|
|
|
+ unset($fan['info'], $fan['cert'], $fan['role']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tree = new Tree($fans);
|
|
|
|
+ return json_success('success', $tree->getTree());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 格式化树
|
|
|
|
+ * @param $items
|
|
|
|
+ * @return Response
|
|
|
|
+ */
|
|
|
|
+ protected static function formatTree($items): Response
|
|
|
|
+ {
|
|
|
|
+ $format_items = [];
|
|
|
|
+ foreach ($items as $item) {
|
|
|
|
+ $format_items[] = [
|
|
|
|
+ 'name' => $item->title ?? $item->name ?? $item->id,
|
|
|
|
+ 'value' => (string)$item->id,
|
|
|
|
+ 'id' => $item->id,
|
|
|
|
+ 'pid' => $item->pid,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $tree = new Tree($format_items);
|
|
|
|
+ return json_success('success', $tree->getTree());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static function clearWelfare(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $memberId = $request->post('member_id');
|
|
|
|
+ $payTime = $request->post('pay_paytimes', date('Y-m-d H:i:s'));
|
|
|
|
+ $payTime = date('Y-m-d H:i:s', strtotime($payTime));
|
|
|
|
+ $payRemark = $request->post('pay_remark', '');
|
|
|
|
+ $clearPwd = $request->post('clear_password');
|
|
|
|
+ if (!$clearPwd || $clearPwd != '123456') {
|
|
|
|
+ return json_fail('清零密码错误');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $account = MemberAccount::where('join_account_member_id', $memberId)
|
|
|
|
+ ->where('member_account_classify', 'WELFARE')
|
|
|
|
+ ->where('member_account_status', 'ACTIVED')
|
|
|
|
+ ->first();
|
|
|
|
+ if (!$account) {
|
|
|
|
+ throw new BusinessException("账户异常");
|
|
|
|
+ }
|
|
|
|
+ if ($account->member_account_surplus <= 0) {
|
|
|
|
+ throw new BusinessException("账户余额为0,无需清零");
|
|
|
|
+ }
|
|
|
|
+ // 创建清除记录
|
|
|
|
+ PayDetail::insert([
|
|
|
|
+ 'join_pay_member_id' => $memberId,
|
|
|
|
+ 'pay_status' => 'SUCCESS',
|
|
|
|
+ 'pay_category' => 'CLEAR',
|
|
|
|
+ 'pay_amount' => $account->member_account_surplus,
|
|
|
|
+ 'pay_paytimes' => $payTime,
|
|
|
|
+ 'pay_prepayid' => $memberId . '-WELFARE',
|
|
|
|
+ 'pay_remark' => $payRemark,
|
|
|
|
+ 'pay_addtimes' => time()
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ // 账户归零
|
|
|
|
+ $account->member_account_expend = $account->member_account_expend + $account->member_account_surplus;
|
|
|
|
+ $account->member_account_surplus = 0;
|
|
|
|
+ $account->save();
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+
|
|
|
|
+ return json_success('success');
|
|
|
|
+ } catch (BusinessException $e) {
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return json_fail($e->getMessage());
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ dump($e->getMessage());
|
|
|
|
+ Db::rollBack();
|
|
|
|
+
|
|
|
|
+ return json_fail('清零失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public static function balanceInfo(Request $request)
|
|
public static function balanceInfo(Request $request)
|
|
{
|
|
{
|
|
$memberId = $request->get('member_id', '');
|
|
$memberId = $request->get('member_id', '');
|
|
@@ -711,12 +895,12 @@ class MemberService
|
|
if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
|
|
if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
|
|
$item['goods_category'] = '自定义金额充值';
|
|
$item['goods_category'] = '自定义金额充值';
|
|
}
|
|
}
|
|
- if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE','PARTNER'])) {
|
|
|
|
|
|
+ if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
|
|
$item['balance_type'] = 'add';
|
|
$item['balance_type'] = 'add';
|
|
} else {
|
|
} else {
|
|
$item['balance_type'] = 'cut';
|
|
$item['balance_type'] = 'cut';
|
|
}
|
|
}
|
|
- if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE','PARTNER'])) {
|
|
|
|
|
|
+ if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
|
|
if (!empty($item['pay_extend_json'])) {
|
|
if (!empty($item['pay_extend_json'])) {
|
|
$extendJson = json_decode($item['pay_extend_json'], true);
|
|
$extendJson = json_decode($item['pay_extend_json'], true);
|
|
if (!isset($extendJson['added_amount'])) {
|
|
if (!isset($extendJson['added_amount'])) {
|
|
@@ -741,14 +925,14 @@ class MemberService
|
|
|
|
|
|
$item['balance'] = number_format($balance, 2, '.', '');
|
|
$item['balance'] = number_format($balance, 2, '.', '');
|
|
$balance = $balance - $item['pay_amount'];
|
|
$balance = $balance - $item['pay_amount'];
|
|
- if ($item['pay_category'] != 'GIVE'){
|
|
|
|
|
|
+ if ($item['pay_category'] != 'GIVE') {
|
|
$data[] = $item;
|
|
$data[] = $item;
|
|
}
|
|
}
|
|
|
|
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE','PARTNER'])) {
|
|
|
|
|
|
+ if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
|
|
if (!empty($item['pay_extend_json'])) {
|
|
if (!empty($item['pay_extend_json'])) {
|
|
$extendJson = json_decode($item['pay_extend_json'], true);
|
|
$extendJson = json_decode($item['pay_extend_json'], true);
|
|
if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
|
|
if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
|