1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516 |
- <?php
- namespace app\admin\controller\member;
- use app\admin\service\member\MemberService;
- use app\admin\service\notify\RechargeService;
- use app\admin\service\order\OrderService;
- use app\admin\validate\member\MemberValidate;
- use app\model\Coupon;
- use app\model\CouponDetail;
- use app\model\Family;
- use app\model\FamilyMember;
- use app\model\Member;
- use app\model\MemberAccount;
- use app\model\MemberBenefit;
- use app\model\MemberQuota;
- use app\model\MemberRole;
- use app\model\Order;
- use app\model\OrderReturn;
- use app\model\OrderSheet;
- use app\model\PayDetail;
- use app\model\SysUser;
- use support\Db;
- use support\exception\BusinessException;
- use support\Log;
- use support\Request;
- use Tinywan\Jwt\JwtToken;
- use function _PHPStan_cc8d35ffb\RingCentral\Psr7\str;
- class MemberController
- {
- public function selectList(Request $request)
- {
- $keywords = $request->get('keywords');
- $isOwner = $request->get('member_is_owner', 'N');
- if (!$keywords) {
- return json_fail("查询错误");
- }
- $res = Db::table('member')
- ->leftjoin('member_cert', 'member.member_id', '=', 'member_cert.join_cert_member_id')
- ->leftjoin('member_info', 'member.member_id', '=', 'member_info.join_info_member_id')
- ->select('member.member_id', 'member.member_mobile', 'member_cert.member_cert_name', 'member_info.member_info_nickname')
- ->where('member.member_is_owner', $isOwner)
- ->where('member_status', 'ACTIVED')
- // ->where('member_mobile','<>','0000')
- ->where(function ($query) use ($keywords) {
- $query->where('member.member_mobile', 'like', '%' . $keywords . '%')
- ->orWhere("member.member_id", 'like', '%' . $keywords . '%')
- ->orWhere("member_cert.member_cert_name", 'like', '%' . $keywords . '%')
- ->orWhere("member_info.member_info_nickname", 'like', '%' . $keywords . '%');
- })->get();
- $data = [];
- foreach ($res as $item) {
- $certName = $item->member_cert_name ?? '';
- $mobile = $item->member_mobile ?? '';
- $data[] = [
- 'key' => $item->member_id,
- 'value' => MemberService::getMemberCertName($mobile, $certName, ''),
- ];
- }
- return json_success('', $data);
- }
- public function exportMember(Request $request)
- {
- return MemberService::exportMember($request);
- }
- public function selectWriteOffMember()
- {
- $members = Member::with([
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- }
- ])->whereRaw("JSON_EXTRACT(`member_json`, '$.user') IS NOT NULL")
- ->select('member_id', 'member_mobile', 'member_json')
- ->get()
- ->toArray();
- foreach ($members as &$member) {
- // $member['member_mobile'] = substr($member['member_mobile'],0,3).'****'.substr($member['member_mobile'],7);
- $member['member_json'] = json_decode($member['member_json'], true);
- $member['username'] = $member['member_mobile'];
- $member['user_id'] = $member['member_json']['user'] ? $member['member_json']['user']['user_id'] : '';
- if (isset($member['cert']['member_cert_name'])) {
- $member['username'] = $member['cert']['member_cert_name'] . '-' . $member['username'];
- }
- }
- return json_success('', $members);
- }
- public function selectFamilyMemberList(Request $request)
- {
- $keywords = $request->get('keywords');
- if (!$keywords) {
- return json_fail("查询错误");
- }
- // 创建的家庭
- $family = Family::where('join_family_creator_member_id', $request->get('memberId'))->get()->toArray();
- if (!$family) {
- return json_success('暂无数据');
- }
- $familyIds = array_column($family, 'family_id');
- $res = FamilyMember::whereIn('join_family_id', $familyIds)
- ->where("family_member_name", 'like', '%' . $keywords . '%')
- ->get()
- ->toArray();
- $data = [];
- foreach ($res as $item) {
- $data[] = [
- 'key' => $item['join_family_member_id'],
- 'value' => $item['family_member_name']
- ];
- }
- return json_success('', $data);
- }
- public function selectMemberAllQuota(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $orderId = $request->get('order_id', '');
- $goodsId = $request->get('goods_id', '');
- $person = $request->get('person', '');
- $selectType = $request->get('select_type', 'ALL');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $data = [];
- $benefit = MemberBenefit::where('join_benefit_member_id', $memberId)
- ->whereColumn('member_benefit_limit_count', '>', 'member_benefit_used_count')
- ->select('member_benefit_id as id', 'member_benefit_name as name', 'member_benefit_limit_count as total', 'member_benefit_used_count as used')
- ->when($orderId != '', function ($query) use ($orderId) {
- $query->where('join_benefit_order_id', $orderId);
- })->when($goodsId != '', function ($query) use ($goodsId) {
- $query->where('join_benefit_goods_id', $goodsId);
- })
- ->get()
- ->toArray();
- foreach ($benefit as $item) {
- if ($item['total'] - $item['used'] < $person) {
- $item['disabled'] = true;
- }
- $item['cut'] = $item['total'] - $item['used'];
- $data[] = $item;
- }
- if ($selectType == 'BENEFIT') {
- return json_success('', $data);
- }
- $quotas = MemberQuota::where('join_quota_member_id', $memberId)
- ->when($goodsId != '', function ($query) use ($goodsId) {
- $query->whereJsonContains('member_quota_json', ['goods_id' => $goodsId]);
- })
- ->selectRaw('join_quota_member_id,join_member_rule_added_component_id,COUNT(*) as total')
- ->groupBy('join_quota_member_id', 'join_member_rule_added_component_id')
- ->get()
- ->toArray();
- foreach ($quotas as $quota) {
- $usedNum = MemberQuota::where('join_quota_member_id', $quota['join_quota_member_id'])
- ->where('join_member_rule_added_component_id', $quota['join_member_rule_added_component_id'])
- ->where('member_quota_status', 'USED')
- ->count('*');
- if ($quota['total'] <= $usedNum) {
- continue;
- }
- $memberQuota = MemberQuota::where('join_quota_member_id', $quota['join_quota_member_id'])
- ->where('join_member_rule_added_component_id', $quota['join_member_rule_added_component_id'])
- ->select('member_quota_id as id', 'member_quota_name as name')
- ->first()
- ->toArray();
- $memberQuota['total'] = $quota['total'];
- $memberQuota['used'] = $usedNum;
- if ($memberQuota['total'] - $memberQuota['used'] < $person) {
- $memberQuota['disabled'] = true;
- }
- $memberQuota['cut'] = $memberQuota['total'] - $memberQuota['used'];
- $data[] = $memberQuota;
- }
- if ($selectType == 'QUOTA') {
- return json_success('', $data);
- }
- return json_success('', $data);
- }
- /**
- * 预约核销用
- */
- public function selectMemberAllQuotaByAppointment(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $orderId = $request->get('order_id', '');
- $goodsId = $request->get('goods_id', '');
- $person = $request->get('person', '');
- $selectType = $request->get('select_type', 'ALL');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $data = [];
- $benefit = MemberBenefit::where('join_benefit_member_id', $memberId)
- ->whereColumn('member_benefit_limit_count', '>', 'member_benefit_used_count')
- ->select('member_benefit_id as id', 'member_benefit_name as name', 'member_benefit_limit_count as total', 'member_benefit_used_count as used')
- ->when($orderId != '', function ($query) use ($orderId) {
- $query->where('join_benefit_order_id', $orderId);
- })->when($goodsId != '', function ($query) use ($goodsId) {
- $query->where('join_benefit_goods_id', $goodsId);
- })
- ->get()
- ->toArray();
- $data['benefit'] = [];
- foreach ($benefit as $item) {
- $item['benefit']['cut'] = $item['total'] - $item['used'];
- $data['benefit']['name'] = $item['name'];
- $data['benefit']['cut'] += $item['cut'];
- $data['benefit']['id'][] = $item['id'];
- }
- if ($selectType == 'BENEFIT') {
- return json_success('', $data);
- }
- $quotas = MemberQuota::where('join_quota_member_id', $memberId)
- ->when($goodsId != '', function ($query) use ($goodsId) {
- $query->whereJsonContains('member_quota_json', ['goods_id' => $goodsId]);
- })
- ->selectRaw('join_quota_member_id,join_member_rule_added_component_id,COUNT(*) as total')
- ->groupBy('join_quota_member_id', 'join_member_rule_added_component_id')
- ->get()
- ->toArray();
- $data['quota'] = [];
- foreach ($quotas as $quota) {
- $usedNum = MemberQuota::where('join_quota_member_id', $quota['join_quota_member_id'])
- ->where('join_member_rule_added_component_id', $quota['join_member_rule_added_component_id'])
- ->where('member_quota_status', 'USED')
- ->count('*');
- if ($quota['total'] <= $usedNum) {
- continue;
- }
- $memberQuota = MemberQuota::where('join_quota_member_id', $quota['join_quota_member_id'])
- ->where('join_member_rule_added_component_id', $quota['join_member_rule_added_component_id'])
- ->select('member_quota_id as id', 'member_quota_name as name')
- ->first()
- ->toArray();
- $memberQuota['total'] = $quota['total'];
- $memberQuota['used'] = $usedNum;
- if ($memberQuota['total'] - $memberQuota['used'] < $person) {
- $memberQuota['disabled'] = true;
- }
- $memberQuota['cut'] = $memberQuota['total'] - $memberQuota['used'];
- $data['quota']['name'] = $memberQuota['name'];
- $data['quota']['cut'] += $memberQuota['cut'];
- $data['quota']['id'][] = $memberQuota['id'];
- // $data[] = $memberQuota;
- }
- if ($selectType == 'QUOTA') {
- return json_success('', $data);
- }
- return json_success('', $data);
- }
- public function selectMemberAllQuotaByGoods(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $orderId = $request->get('order_id', '');
- $person = $request->get('person', '');
- $selectType = $request->get('select_type', 'ALL');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $data = [];
- $benefit = MemberBenefit::where('join_benefit_member_id', $memberId)
- // ->whereColumn('member_benefit_limit_count','>','member_benefit_used_count')
- ->select('member_benefit_id as id', 'member_benefit_name as name', 'member_benefit_limit_count as total', 'member_benefit_used_count as used')
- ->when($orderId != '', function ($query) use ($orderId) {
- $query->where('join_benefit_order_id', $orderId);
- })
- ->get()
- ->toArray();
- foreach ($benefit as $item) {
- if ($item['total'] - $item['used'] < $person) {
- $item['disabled'] = true;
- }
- $item['cut'] = $item['total'] - $item['used'];
- $data[] = $item;
- }
- if ($selectType == 'BENEFIT') {
- return json_success('', $data);
- }
- $quotas = MemberQuota::where('join_quota_member_id', $memberId)
- ->selectRaw('join_quota_member_id,join_member_rule_added_component_id,COUNT(*) as total')
- ->groupBy('join_quota_member_id', 'join_member_rule_added_component_id')
- ->get()
- ->toArray();
- foreach ($quotas as $quota) {
- $usedNum = MemberQuota::where('join_quota_member_id', $quota['join_quota_member_id'])
- ->where('join_member_rule_added_component_id', $quota['join_member_rule_added_component_id'])
- ->where('member_quota_status', 'USED')
- ->count('*');
- if ($quota['total'] <= $usedNum) {
- continue;
- }
- $memberQuota = MemberQuota::where('join_quota_member_id', $quota['join_quota_member_id'])
- ->where('join_member_rule_added_component_id', $quota['join_member_rule_added_component_id'])
- ->select('member_quota_id as id', 'member_quota_name as name')
- ->first()
- ->toArray();
- $memberQuota['total'] = $quota['total'];
- $memberQuota['used'] = $usedNum;
- if ($memberQuota['total'] - $memberQuota['used'] < $person) {
- $memberQuota['disabled'] = true;
- }
- $memberQuota['cut'] = $memberQuota['total'] - $memberQuota['used'];
- $data[] = $memberQuota;
- }
- if ($selectType == 'QUOTA') {
- return json_success('', $data);
- }
- return json_success('', $data);
- }
- public function list(Request $request)
- {
- return MemberService::list($request);
- }
- public function info(Request $request)
- {
- $memberId = $request->get('member_id', '');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::info($memberId);
- }
- /**
- * @Desc 会员统计
- * @Author Gorden
- * @Date 2024/10/21 16:31
- *
- * @return \support\Response
- */
- public function statistics(Request $request)
- {
- $memberType = $request->get('member_type');
- $todayStart = strtotime(date('Y-m-d'));
- $todayEnd = strtotime(date('Y-m-d 23:59:59'));
- $todayCount = Member::when(empty($memberType), function ($query) use ($todayStart, $todayEnd) {
- $query->where('member_addtimes', '>=', $todayStart)->where('member_addtimes', '<=', $todayEnd);
- })->when(!empty($memberType), function ($query) use ($memberType, $todayStart, $todayEnd) {
- if ($memberType == 'PARTNER') {
- $query->where("member_is_partner", 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) >= {$todayStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) <= {$todayEnd}");
- } elseif ($memberType == 'REFERRER') {
- $query->where('member_is_referrer', 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) >= {$todayStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) <= {$todayEnd}");
- }
- })->count();
- $yesterdayStart = strtotime(date('Y-m-d', strtotime("-1 day")));
- $yesterdayEnd = strtotime(date('Y-m-d 23:59:59', strtotime("-1 day")));
- $yesterdayCount = Member::when(empty($memberType), function ($query) use ($yesterdayStart, $yesterdayEnd) {
- $query->where('member_addtimes', '>=', $yesterdayStart)->where('member_addtimes', '<=', $yesterdayEnd);
- })->when(!empty($memberType), function ($query) use ($memberType, $yesterdayStart, $yesterdayEnd) {
- if ($memberType == 'PARTNER') {
- $query->where("member_is_partner", 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) >= {$yesterdayStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) <= {$yesterdayEnd}");
- } elseif ($memberType == 'REFERRER') {
- $query->where('member_is_referrer', 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) >= {$yesterdayStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) <= {$yesterdayEnd}");
- }
- })->count();
- $monthStart = strtotime(date('Y-m-01'));
- $monthEnd = strtotime(date('Y-m-t 23:59:59'));
- $monthCount = Member::when(empty($memberType), function ($query) use ($monthStart, $monthEnd) {
- $query->where('member_addtimes', '>=', $monthStart)->where('member_addtimes', '<=', $monthEnd);
- })->when(!empty($memberType), function ($query) use ($memberType, $monthStart, $monthEnd) {
- if ($memberType == 'PARTNER') {
- $query->where("member_is_partner", 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) >= {$monthStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) <= {$monthEnd}");
- } elseif ($memberType == 'REFERRER') {
- $query->where('member_is_referrer', 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) >= {$monthStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) <= {$monthEnd}");
- }
- })->count();
- $lastMonthStart = strtotime(date('Y-m-01', strtotime("last day of -1 month")));
- $lastMonthEnd = strtotime(date('Y-m-t 23:59:59', strtotime("last day of -1 month")));
- $lastMonthCount = Member::when(empty($memberType), function ($query) use ($lastMonthStart, $lastMonthEnd) {
- $query->where('member_addtimes', '>=', $lastMonthStart)->where('member_addtimes', '<=', $lastMonthEnd);
- })->when(!empty($memberType), function ($query) use ($memberType, $lastMonthStart, $lastMonthEnd) {
- if ($memberType == 'PARTNER') {
- $query->where("member_is_partner", 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) >= {$lastMonthStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_partner_json,'$.datetime'))) as SIGNED) <= {$lastMonthEnd}");
- } elseif ($memberType == 'REFERRER') {
- $query->where('member_is_referrer', 'Y')
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) >= {$lastMonthStart}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(JSON_UNQUOTE(JSON_EXTRACT(member_referrer_json,'$.datetime'))) as SIGNED) <= {$lastMonthEnd}");
- }
- })->count();
- return json_success('', [
- 'todayCount' => $todayCount,
- 'yesterdayCount' => $yesterdayCount,
- 'monthCount' => $monthCount,
- 'lastMonthCount' => $lastMonthCount
- ]);
- }
- public function vipInfo(Request $request)
- {
- $memberId = $request->get('member_id', '');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::vipInfo($request);
- }
- /**
- * @Desc 储值卡账户明细
- * @Author Gorden
- * @Date 2024/11/19 11:46
- *
- * @param Request $request
- * @return \support\Response
- */
- public function cardInfo(Request $request)
- {
- $memberId = $request->get('member_id', '');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::cardInfo($request);
- }
- public function welfareInfo(Request $request)
- {
- $memberId = $request->get('member_id');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::welfareInfo($request);
- }
- public function commissionList(Request $request)
- {
- $memberId = $request->get('member_id');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::commissionList($request);
- }
- /**
- * @Desc 我的粉丝列表
- * @Author Gorden
- * @Date 2024/9/20 10:22
- *
- * @param Request $request
- * @return \support\Response
- */
- public function fansList(Request $request)
- {
- $memberId = $request->get('member_id');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::fansList($request);
- }
- public function clearWelfare(Request $request)
- {
- $memberId = $request->post('member_id', '');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::clearWelfare($request);
- }
- public function balanceInfo(Request $request)
- {
- $memberId = $request->get('member_id', '');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::balanceInfo($request);
- }
- public function pointInfo(Request $request)
- {
- $memberId = $request->get('member_id', '');
- if (!$memberId) {
- return json_fail("参数错误");
- }
- return MemberService::pointInfo($memberId);
- }
- /**
- * @Desc 添加会员
- * @Author Gorden
- * @Date 2024/3/25 13:40
- *
- * @param Request $request
- * @return \support\Response
- */
- public function add(Request $request)
- {
- $validate = new MemberValidate();
- if (!$validate->scene('add')->check($request->post())) {
- return json_fail($validate->getError());
- }
- _syslog("添加用户", "用户【" . $request->post('member_cert_name') . '】');
- return MemberService::add($request->post());
- }
- public function update(Request $request)
- {
- $validate = new MemberValidate();
- if (!$validate->scene('update')->check($request->post())) {
- return json_fail($validate->getError());
- }
- _syslog("编辑用户", "用户【" . $request->post('member_cert_name') ?? $request->post('member_id') . '】');
- return MemberService::update($request->post());
- }
- /**
- * @Desc 更换手机号
- * @Author Gorden
- * @Date 2024/11/25 15:54
- *
- * @param Request $request
- * @return \support\Response
- */
- public function changeMobile(Request $request)
- {
- $memberId = $request->post('member_id');
- $mobile = $request->post('member_mobile');
- $ticket = $request->post('ticket');
- if (!$memberId || !$mobile || !$ticket) {
- return json_fail("参数异常");
- }
- if (Member::where('member_mobile', $mobile)->exists()) {
- return json_fail("新的手机号已存在账户,无法变更,请联系管理员");
- }
- try {
- $member = Member::where('member_id', $memberId)->first();
- $oldMobile = $member->member_mobile;
- $member->member_mobile = $mobile;
- $memberUpdateJson = [];
- if (!empty($member->member_update_json)) {
- $memberUpdateJson = json_decode($member->member_update_json, true);
- }
- $memberUpdateJson['update'][] = [
- 'time' => date('Y-m-d H:i:s'),
- 'user_id' => JwtToken::getCurrentId(),
- 'data' => [
- [
- 'field' => 'member_mobile',
- 'old' => $oldMobile,
- 'new' => $mobile,
- 'media' => [
- 'url' => str_replace(getenv("STORAGE_DOMAIN"), '', $ticket)
- ]
- ]
- ]
- ];
- $member->member_update_json = json_encode($memberUpdateJson);
- $member->save();
- return json_success("更换手机号成功");
- } catch (\Exception $e) {
- return json_fail("更换手机号失败");
- }
- }
- /**
- * @Desc 会员修改记录
- * @Author Gorden
- * @Date 2024/11/26 8:41
- *
- * @param Request $request
- * @return \support\Response
- */
- public function updateLogList(Request $request)
- {
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 10);
- $memberId = $request->get('member_id');
- $member = Member::where('member_id', $memberId)->first();
- $updateJson = [];
- if (!empty($member->member_update_json)) {
- $memberUpdateJson = json_decode($member->member_update_json, true);
- $updateJson = $memberUpdateJson['update'] ?? [];
- }
- foreach ($updateJson as &$item) {
- if (!empty($item['user_id'])) {
- $item['user_name'] = SysUser::where('user_id', $item['user_id'])->value('user_name');
- } else {
- $item['user_name'] = '会员';
- }
- // 修改内容
- $item['content'] = '';
- $item['images'] = '';
- $item['imagesOrigin'] = '';
- foreach ($item['data'] as $datum) {
- if ($datum['field'] == 'member_mobile') {
- $item['content'] = '手机号由' . $datum['old'] . '更换为' . $datum['new'] . ';';
- if (!empty($datum['media'])) {
- $item['images'] = getenv('STORAGE_DOMAIN') . $datum['media']['url'];
- $item['imagesOrigin'] = str_replace('/thumb', '', $item['images']);
- }
- }
- }
- $item['content'] = rtrim($item['content'], ';');
- }
- $total = count($updateJson);
- $updateJson = array_reverse($updateJson);
- $start = ($page - 1) * $pageSize;
- $rows = array_slice($updateJson, $start, $pageSize);
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 绑定的设备
- * @Author Gorden
- * @Date 2024/4/7 10:20
- *
- * @param $id
- * @return \support\Response
- */
- public function device($id)
- {
- return MemberService::deviceList($id);
- }
- public function addDevice(Request $request)
- {
- return MemberService::addDevice($request);
- }
- public function updateDevice(Request $request)
- {
- return MemberService::updateDevice($request);
- }
- public function deleteDevice(Request $request)
- {
- return MemberService::deleteDevice($request);
- }
- /**
- * @Desc 卡券数量
- * @Author Gorden
- * @Date 2024/8/22 18:51
- *
- * @param Request $request
- * @return \support\Response
- */
- public function couponCount(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $coupons = CouponDetail::leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
- ->where('join_coupon_detail_member_id', $memberId)
- ->select('coupon.coupon_name', 'coupon.coupon_classify', 'coupon.coupon_value')
- ->get()
- ->toArray();
- $data = ['manjian' => 0, 'diyong' => 0, 'zhekou' => 0, 'lijian' => 0, 'zengpin' => 0, 'fuli' => 0, 'nianka' => 0, 'jika' => 0, 'yueka' => 0];
- foreach ($coupons as $item) {
- if ($item['coupon_classify'] == '满减券') {
- $data['manjian'] += 1;
- } elseif ($item['coupon_classify'] == '抵用券') {
- $data['diyong'] += 1;
- } elseif ($item['coupon_classify'] == '折扣券') {
- $data['zhekou'] += 1;
- } elseif ($item['coupon_classify'] == '立减券') {
- $data['lijian'] += 1;
- } elseif ($item['coupon_classify'] == '赠品券') {
- $data['zengpin'] += 1;
- } elseif ($item['coupon_classify'] == '福利券') {
- $data['fuli'] += 1;
- } elseif ($item['coupon_classify'] == '年卡') {
- $data['nianka'] += 1;
- } elseif ($item['coupon_classify'] == '季卡') {
- $data['jika'] += 1;
- } elseif ($item['coupon_classify'] == '月卡') {
- $data['yueka'] += 1;
- }
- }
- $data['total'] = $data['manjian'] + $data['diyong'] + $data['zhekou'] + $data['lijian'] + $data['zengpin'] + $data['fuli'] + $data['nianka'] + $data['jika'] + $data['yueka'];
- return json_success('', $data);
- }
- /**
- * @Desc 我的卡券
- * @Author Gorden
- * @Date 2024/8/22 18:45
- *
- * @param Request $request
- * @return \support\Response
- */
- public function coupon(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $classify = $request->get('classify', '');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $coupons = CouponDetail::with([
- 'member' => function ($query) {
- $query->select('member_id', 'member_mobile');
- },
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- },
- 'info' => function ($query) {
- $query->select('join_info_member_id', 'member_info_nickname');
- }
- ])
- ->leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
- ->where('join_coupon_detail_member_id', $memberId)
- ->where('coupon.coupon_classify', $classify)
- ->groupBy('join_coupon_detail_member_id', 'join_detail_coupon_id');
- // $total = $coupons->count();
- $totalModel = Db::select("select count(a.join_detail_coupon_id) as total from (select join_detail_coupon_id from app_coupon_detail as d left join app_coupon as c ON d.join_detail_coupon_id = c.coupon_id where d.join_coupon_detail_member_id='" . $memberId . "' and c.coupon_classify='" . $classify . "' group by d.join_coupon_detail_member_id,d.join_detail_coupon_id) as a");
- $total = 0;
- if (!empty($totalModel) && !empty($totalModel[0])) {
- $total = $totalModel[0]->total;
- }
- $rows = $coupons->select('coupon_detail.join_coupon_detail_member_id', 'coupon_detail.join_detail_coupon_id'
- , 'coupon.coupon_name', 'coupon.coupon_classify', 'coupon.coupon_value')
- ->selectRaw('COUNT(1) as total,
- COUNT(IF(app_coupon_detail.coupon_detail_status="USED",1,NULL)) as used_total,
- COUNT(IF(app_coupon_detail.coupon_detail_status="ACTIVED" or app_coupon_detail.coupon_detail_status="WAITING",1,NULL)) as unused_total,
- MAX(app_coupon_detail.coupon_detail_deadline_datetime) as deadline_datetime')
- ->orderBy('deadline_datetime', 'DESC')
- ->forPage($page, $pageSize)
- ->get()
- ->toArray();
- foreach ($rows as &$item) {
- $mobile = $certName = $nickname = '';
- if (!empty($item['member']) && !empty($item['member']['member_mobile'])) {
- $mobile = $item['member']['member_mobile'];
- }
- if (!empty($item['cert']) && !empty($item['cert']['member_cert_name'])) {
- $certName = $item['cert']['member_cert_name'];
- }
- if (!empty($item['info']) && !empty($item['info']['member_info_nickname'])) {
- $nickname = $item['info']['member_info_nickname'];
- }
- $item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
- unset($item['member'], $item['cert'], $item['info']);
- $item['invalid_total'] = $item['total'] - $item['used_total'] - $item['unused_total'];
- // 优惠券分类
- $coupon = Coupon::with('category')->where('coupon_id', $item['join_detail_coupon_id'])
- ->select('coupon_id', 'join_coupon_category_id')
- ->first();
- if (!empty($coupon) && !empty($coupon->category)) {
- $item['category_name'] = $coupon->category->category_name;
- }
- }
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 我的卡券
- * @Author Gorden
- * @Date 2024/8/22 18:45
- *
- * @param Request $request
- * @return \support\Response
- */
- public function allCoupon(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $coupons = CouponDetail::with([
- 'member' => function ($query) {
- $query->select('member_id', 'member_mobile');
- },
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- },
- 'info' => function ($query) {
- $query->select('join_info_member_id', 'member_info_nickname');
- }
- ])
- ->leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
- ->where('join_coupon_detail_member_id', $memberId)
- ->groupBy('join_coupon_detail_member_id', 'join_detail_coupon_id');
- // $total = $coupons->count();
- $totalModel = Db::select("select count(a.join_detail_coupon_id) as total from (select join_detail_coupon_id from app_coupon_detail as d left join app_coupon as c ON d.join_detail_coupon_id = c.coupon_id where d.join_coupon_detail_member_id='" . $memberId . "' group by d.join_coupon_detail_member_id,d.join_detail_coupon_id) as a");
- $total = 0;
- if (!empty($totalModel) && !empty($totalModel[0])) {
- $total = $totalModel[0]->total;
- }
- $rows = $coupons->select('coupon_detail.join_coupon_detail_member_id', 'coupon_detail.join_detail_coupon_id'
- , 'coupon.coupon_name', 'coupon.coupon_classify', 'coupon.coupon_value')
- ->selectRaw('COUNT(1) as total,
- COUNT(IF(app_coupon_detail.coupon_detail_status="USED",1,NULL)) as used_total,
- COUNT(IF(app_coupon_detail.coupon_detail_status="ACTIVED" or app_coupon_detail.coupon_detail_status="WAITING",1,NULL)) as unused_total,
- MAX(app_coupon_detail.coupon_detail_deadline_datetime) as deadline_datetime')
- ->orderBy('deadline_datetime', 'DESC')
- ->forPage($page, $pageSize)
- ->get()
- ->toArray();
- foreach ($rows as &$item) {
- $mobile = $certName = $nickname = '';
- if (!empty($item['member']) && !empty($item['member']['member_mobile'])) {
- $mobile = $item['member']['member_mobile'];
- }
- if (!empty($item['cert']) && !empty($item['cert']['member_cert_name'])) {
- $certName = $item['cert']['member_cert_name'];
- }
- if (!empty($item['info']) && !empty($item['info']['member_info_nickname'])) {
- $nickname = $item['info']['member_info_nickname'];
- }
- $item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
- unset($item['member'], $item['cert'], $item['info']);
- $item['invalid_total'] = $item['total'] - $item['used_total'] - $item['unused_total'];
- // 优惠券分类
- $coupon = Coupon::with('category')->where('coupon_id', $item['join_detail_coupon_id'])
- ->select('coupon_id', 'join_coupon_category_id')
- ->first();
- if (!empty($coupon) && !empty($coupon->category)) {
- $item['category_name'] = $coupon->category->category_name;
- }
- }
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 我的卡券 领取记录
- * @Author Gorden
- * @Date 2024/8/22 18:45
- *
- * @param Request $request
- * @return \support\Response
- */
- public function couponDetail(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $couponId = $request->get('coupon_id', '');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $coupons = CouponDetail::with([
- 'member' => function ($query) {
- $query->select('member_id', 'member_mobile');
- },
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- },
- 'info' => function ($query) {
- $query->select('join_info_member_id', 'member_info_nickname');
- }
- ])
- ->leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
- ->where('join_coupon_detail_member_id', $memberId)
- ->where('coupon.coupon_id', $couponId);
- $total = $coupons->count();
- $rows = $coupons->select('coupon_detail.*', 'coupon.coupon_name', 'coupon.coupon_classify', 'coupon.coupon_value')
- ->orderBy('coupon_detail_deadline_datetime', 'desc')
- ->forPage($page, $pageSize)
- ->get()
- ->toArray();
- foreach ($rows as &$item) {
- $mobile = $certName = $nickname = '';
- if (!empty($item['member']) && !empty($item['member']['member_mobile'])) {
- $mobile = $item['member']['member_mobile'];
- }
- if (!empty($item['cert']) && !empty($item['cert']['member_cert_name'])) {
- $certName = $item['cert']['member_cert_name'];
- }
- if (!empty($item['info']) && !empty($item['info']['member_info_nickname'])) {
- $nickname = $item['info']['member_info_nickname'];
- }
- $item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
- unset($item['member'], $item['cert'], $item['info']);
- if (!empty($coupon) && !empty($coupon->category)) {
- $item['category_name'] = $coupon->category->category_name;
- }
- if (!empty($item['coupon_detail_gain_datetime'])) {
- $item['coupon_detail_gain_datetime'] = date('Y/m/d H:i:s', strtotime($item['coupon_detail_gain_datetime']));
- }
- if (!empty($item['coupon_detail_deadline_datetime'])) {
- $item['coupon_detail_deadline_datetime'] = date('Y/m/d H:i:s', strtotime($item['coupon_detail_deadline_datetime']));
- }
- }
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 新会员充值备份记录
- * @Author Gorden
- * @Date 2024/10/15 10:27
- *
- * @param Request $request
- * @return \support\Response
- */
- public function rechargeBackupsList(Request $request)
- {
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $memberId = $request->get('member_id');
- if (!$memberId) {
- return json_fail("参数异常");
- }
- $member = Member::where('member_id', $memberId)
- ->select('member_id', 'member_extend_json')
- ->first();
- $data = [];
- if (!empty($member->member_extend_json)) {
- $extendJson = json_decode($member->member_extend_json, true);
- if (isset($extendJson['snap'])) {
- foreach ($extendJson['snap'] as $key => $item) {
- $data[] = [
- 'recharge_times' => $key,
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- 'pay_amount' => $item['pay_amount'],
- 'added_rate' => floatval($item['added_rate']) * 100,
- 'added_amount' => $item['added_amount']
- ];
- }
- }
- }
- $total = count($data);
- $start = ($page - 1) * $pageSize;
- $rows = array_slice($data, $start, $pageSize);
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 会员权益使用记录
- * @Author Gorden
- * @Date 2024/10/15 11:13
- *
- * @param Request $request
- * @return \support\Response
- */
- public function roleBenefitUsedList(Request $request)
- {
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $memberId = $request->get('member_id');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $data = $this->getRoleBenefitUsedList($memberId);
- $total = count($data);
- $start = ($page - 1) * $pageSize;
- $rows = array_slice($data, $start, $pageSize);
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- public function consumptionList(Request $request)
- {
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $memberId = $request->get('member_id');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $member = Member::where('member_id', $memberId)->first();
- $firstRechargeTime = 0;
- if (!empty($member->member_extend_json)) {
- $memberExtendJson = json_decode($member->member_extend_json, true);
- if (isset($memberExtendJson['snap'])) {
- foreach ($memberExtendJson['snap'] as $key => $value) {
- $firstRechargeTime = strtotime($key);
- break;
- }
- }
- }
- $payDetailIds = PayDetail::where('pay_addtimes', '>', $firstRechargeTime)
- ->where('pay_prepayid', $memberId . '-CASH')
- ->where('pay_status', 'SUCCESS')
- ->pluck('join_pay_order_id')
- ->toArray();
- $orders = Order::with([
- 'payDetail' => function ($query) {
- $query->where('pay_prepayid', 'like', '%CASH%');
- }
- ])->whereIn('order_groupby', $payDetailIds)
- ->where('order_addtimes', '>', $firstRechargeTime)
- ->whereIn('order_classify', ['GOODS', 'SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE', 'DISHES']);
- $total = $orders->count();
- $rows = $orders->orderBy('order_addtimes', 'DESC')
- ->forPage($page, $pageSize)
- ->get()
- ->toArray();
- $data = [];
- foreach ($rows as $row) {
- $sheets = OrderSheet::with([
- 'goods' => function ($query) {
- $query->select('goods_id', 'goods_name');
- }
- ])->where('join_sheet_order_id', $row['order_id'])
- ->get()
- ->toArray();
- $deng = "";
- if (count($sheets) > 1) {
- $deng = '等';
- }
- foreach ($row['pay_detail'] as $item) {
- if (!empty($item['join_pay_object_json'])) {
- $payObjectJson = json_decode($item['join_pay_object_json'], true);
- if ($payObjectJson['order_id'] != $row['order_id']) {
- continue;
- }
- }
- $data[] = [
- 'order_classify' => $row['order_classify'],
- 'order_id' => $row['order_id'],
- 'goods_name' => !empty($sheets[0]) && !empty($sheets[0]['goods']) ? ($sheets[0]['goods']['goods_name'] . $deng) : '',
- 'order_amount_total' => $row['order_amount_total'],
- 'order_amount_pay' => $row['order_amount_pay'],
- 'pay_paytimes' => $item['pay_paytimes'] ?? "",
- 'order_addtimes' => $row['order_addtimes'],
- 'pay_amount' => $item['pay_amount']
- ];
- }
- }
- $rows = $data;
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 消费导出
- * @Author Gorden
- * @Date 2024/10/15 17:36
- *
- * @param Request $request
- * @return \support\Response
- */
- public function exportConsumptionList(Request $request)
- {
- $memberId = $request->post('member_id');
- $orderIds = $request->post('order_id', []);
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $member = Member::where('member_id', $memberId)->first();
- $firstRechargeTime = 0;
- if (!empty($member->member_extend_json)) {
- $memberExtendJson = json_decode($member->member_extend_json, true);
- if (isset($memberExtendJson['snap'])) {
- foreach ($memberExtendJson['snap'] as $key => $value) {
- $firstRechargeTime = strtotime($key);
- break;
- }
- }
- }
- if (empty($orderIds)) {
- $payDetailIds = PayDetail::where('pay_addtimes', '>', $firstRechargeTime)
- ->where('pay_prepayid', $memberId . '-CASH')
- ->where('pay_status', 'SUCCESS')
- ->pluck('join_pay_order_id')
- ->toArray();
- } else {
- $payDetailIds = Order::whereIn('order_id', $orderIds)->pluck('order_groupby')->toArray();
- }
- $rows = Order::with([
- 'payDetail' => function ($query) {
- $query->where('pay_prepayid', 'like', '%CASH%');
- }
- ])->whereIn('order_groupby', $payDetailIds)
- ->where('order_addtimes', '>', $firstRechargeTime)
- ->whereIn('order_classify', ['GOODS', 'SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE', 'DISHES'])
- ->orderBy('order_addtimes', 'DESC')
- ->get()
- ->toArray();
- $data = [];
- $payAmount = 0;
- foreach ($rows as $row) {
- $sheets = OrderSheet::with([
- 'goods' => function ($query) {
- $query->select('goods_id', 'goods_name');
- }
- ])->where('join_sheet_order_id', $row['order_id'])
- ->get()
- ->toArray();
- $deng = "";
- if (count($sheets) > 1) {
- $deng = '等';
- }
- foreach ($row['pay_detail'] as $item) {
- if (!empty($item['join_pay_object_json'])) {
- $payObjectJson = json_decode($item['join_pay_object_json'], true);
- if ($payObjectJson['order_id'] != $row['order_id']) {
- continue;
- }
- }
- $payAmount += $item['pay_amount'];
- $data[] = [
- 'order_classify' => OrderService::$orderClassify[$row['order_classify']],
- 'order_id' => $row['order_id'],
- 'goods_name' => !empty($sheets[0]) && !empty($sheets[0]['goods']) ? ($sheets[0]['goods']['goods_name'] . $deng) : '',
- 'order_amount_total' => $row['order_amount_total'],
- 'order_amount_pay' => $row['order_amount_pay'],
- 'pay_paytimes' => $item['pay_paytimes'] ?? "",
- 'order_addtimes' => $row['order_addtimes'],
- 'pay_amount' => $item['pay_amount']
- ];
- }
- }
- $data[] = ['pay_amount' => "总计:" . sprintf('%.2f', $payAmount)];
- return json_success('success', $data);
- }
- /**
- * @Desc 获取权益使用记录
- * @Author Gorden
- * @Date 2024/10/15 11:35
- *
- * @param $memberId
- * @param $orderIds
- * @return array
- */
- public function getRoleBenefitUsedList($memberId, $orderIds = [])
- {
- $couponDetails = CouponDetail::where('join_coupon_detail_member_id', $memberId)
- ->where('coupon_detail_status', 'USED')
- ->whereJsonContains('coupon_detail_extend_json->gettype', 'ROLE')
- ->get()
- ->toArray();
- $data = [];
- foreach ($couponDetails as $couponDetail) {
- $orders = Order::where('order_discount_json', 'like', '%' . $couponDetail['coupon_detail_id'] . '%')
- ->whereIn('order_is_complete', ['Y', 'N'])
- ->where('order_status_payment', 'SUCCESS')
- ->when(!empty($orderIds), function ($query) use ($orderIds) {
- $query->whereIn('order_id', $orderIds);
- })->get()
- ->toArray();
- foreach ($orders as $order) {
- $sheets = OrderSheet::with([
- 'goods' => function ($query) {
- $query->select('goods_id', 'goods_name');
- }
- ])->where('join_sheet_order_id', $order['order_id'])
- ->get()
- ->toArray();
- $deng = "";
- if (count($sheets) > 1) {
- $deng = '等';
- }
- $discountJson = json_decode($order['order_discount_json'], true);
- $couponName = '';
- $discountAmount = 0;
- foreach ($discountJson as $item) {
- $discountAmount = $item['coupon_value'];
- $couponName = Coupon::where('coupon_id', $item['coupon_id'])->value('coupon_name');
- }
- $payDetailTimes = PayDetail::whereJsonContains('join_pay_object_json->order_id', $order['order_id'])->value('pay_paytimes');
- $data[] = [
- 'order_id' => $order['order_id'],
- 'goods_name' => !empty($sheets[0]) && !empty($sheets[0]['goods']) ? ($sheets[0]['goods']['goods_name'] . $deng) : '',
- 'order_classify' => $order['order_classify'],
- 'order_amount_total' => $order['order_amount_total'],
- 'order_amount_pay' => $order['order_amount_pay'],
- 'coupon_name' => $couponName,
- 'discountAmount' => $discountAmount,
- 'order_status_system' => $order['order_status_system'],
- 'order_addtimes' => $order['order_addtimes'],
- 'pay_paytimes' => $payDetailTimes
- ];
- }
- }
- return $data;
- }
- public function roleBenefitExport(Request $request)
- {
- $orderIds = $request->post('order_id', []);
- $memberId = $request->post('member_id');
- $applyUsername = $request->post('apply_username', '');
- $applyMobile = $request->post('apply_mobile', '');
- $applyAmount = $request->post('apply_amount', '');
- if (!$memberId) {
- return json_fail("参数异常");
- }
- $data = $this->getRoleBenefitUsedList($memberId, $orderIds);
- $dicountAmount = 0;
- foreach ($data as $key => $item) {
- $data[$key]['order_classify'] = OrderService::$orderClassify[$item['order_classify']];
- $dicountAmount += $item['discountAmount'];
- }
- $returnApplayData['data'] = $data;
- $returnApplayData['amount'] = $applyAmount;
- $returnApplayData['apply_username'] = $applyUsername;
- $returnApplayData['apply_mobile'] = $applyMobile;
- $returnApplayData['reason'] = "会员权益退款";
- $data[] = [
- 'discountAmount' => '优惠合计:¥' . sprintf('%.2f', $dicountAmount)
- ];
- // $data[] = [
- // 'order_classify' => '申请人:' . $applyUsername,
- // ];
- // $data[] = [
- // 'order_classify' => '电话:' . $applyMobile,
- // ];
- // $data[] = [
- // 'order_classify' => '退款金额:' . $applyAmount,
- // ];
- // 产生退款记录
- // $this->refundOrder($memberId, $returnApplayData);
- return json_success('success', $data);
- }
- public function refundOrder(Request $request)
- {
- $params = $request->post();
- Db::beginTransaction();
- try {
- // OrderReturn::where('join_return_member_id', $params['member_id'])
- // ->where('order_return_status', '<>', 'DONE')
- // ->where('order_return_category', '会员退款')
- // ->delete();
- // 验证余额
- $memberAccount = MemberAccount::where('join_account_member_id', $params['member_id'])
- ->where('member_account_classify', 'CASH')
- ->first();
- if ($params['surplus'] + $params['bank_amount'] > $memberAccount->member_account_surplus) {
- throw new BusinessException("本金退款金额超出账户本金余额");
- }
- if ($params['added'] > $memberAccount->member_account_added) {
- throw new BusinessException("赠送退款金额超出账户赠送余额");
- }
- $returnApplyJson = [
- 'reason' => '会员退款',
- 'order_id' => 'ROLE_REFUND',
- 'classify' => 'ROLE_REFUND',
- 'username' => $params['username'],
- 'mobile' => $params['mobile'],
- 'surplus' => $params['surplus'],
- 'added' => $params['added'],
- 'amount' => $params['bank_amount'],
- 'bank_amount' => $params['bank_amount'],
- 'bank_name' => $params['bank_name'],
- 'bank_acount' => $params['bank_acount'],
- 'bank_cardno' => $params['bank_cardno']
- ];
- // 退款记录
- OrderReturn::insert([
- 'join_order_return_user_id' => JwtToken::getCurrentId(),
- 'join_return_member_id' => $params['member_id'],
- 'join_return_order_id' => 'ROLE_REFUND',
- 'order_return_status' => 'PENDING',
- 'order_return_category' => '会员退款',
- 'order_return_apply_datetime' => date('Y-m-d H:i:s'),
- 'order_return_apply_json' => json_encode($returnApplyJson),
- 'order_return_remark' => $params['remark'] ?? '',
- 'order_return_addtimes' => time()
- ]);
- Db::commit();
- return json_success("success");
- } catch (BusinessException $e) {
- Db::rollBack();
- Log::error("创建退款记录失败:" . $e->getMessage());
- return json_fail($e->getMessage());
- } catch (\Exception $e) {
- Db::rollBack();
- Log::error("创建退款记录失败:" . $e->getMessage());
- return json_fail("创建退款记录失败");
- }
- }
- public function roleBenefitRefund(Request $request)
- {
- $memberId = $request->post('member_id');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $returnOrder = OrderReturn::where('join_return_member_id', $memberId)
- ->where('order_return_status', 'DOING')
- ->where('order_return_category', '会员权益退款')
- ->first();
- if (!$returnOrder) {
- return json_fail("退款数据异常");
- }
- $memberAccount = MemberAccount::where('join_account_member_id', $memberId)
- ->where('member_account_classify', 'CASH')
- ->where('member_account_status', 'ACTIVED')
- ->first();
- if (!$memberAccount) {
- return json_fail('会员账户异常');
- }
- try {
- Db::beginTransaction();
- $refundApplyJson = json_decode($returnOrder->order_return_apply_json, true);
- $amount = $refundApplyJson['amount'];
- $refundApplyJson['user_id'] = JwtToken::getCurrentId();
- $refundApplyJson['datetime'] = date('Y-m-d H:i:s');
- $returnOrder->order_return_refund_json = json_encode($refundApplyJson);
- $returnOrder->order_return_status = 'DONE';
- $returnOrder->save();
- // 账户剩余
- if ($memberAccount->member_account_surplus + $memberAccount->member_account_added < $amount) {
- throw new BusinessException("账户余额不足");
- }
- // 本金
- if ($memberAccount->member_account_surplus >= $amount) {
- $memberAccount->member_account_surplus = $memberAccount->member_account_surplus - $amount;
- } else {
- $memberAccount->member_account_added = $memberAccount->member_account_added - ($amount - $memberAccount->member_account_surplus);
- $memberAccount->member_account_surplus = 0;
- }
- $memberAccount->member_account_update_user_id = JwtToken::getCurrentId();
- $memberAccount->member_account_updatetimes = time();
- $memberAccount->save();
- // 删除会员身份
- Member::where('member_id', $memberId)
- ->update([
- 'join_member_role_id' => '',
- 'member_role_begintime' => '',
- 'member_role_config_json' => '[]'
- ]);
- // 没用的优惠券失效
- CouponDetail::where('join_coupon_detail_member_id', $memberId)
- ->where('coupon_detail_status', '<>', 'USED')
- ->whereJsonContains('coupon_detail_extend_json->gettype', 'ROLE')
- ->update([
- 'coupon_detail_status' => 'DISABLED'
- ]);
- // 产生一条退款记录 (pay_detail)
- PayDetail::insert([
- 'join_pay_member_id' => $memberId,
- 'join_pay_order_id' => 'ROLE_REFUND',
- 'join_pay_object_json' => '[]',
- 'pay_status' => 'SUCCESS',
- 'pay_category' => 'ROLE_REFUND',
- 'pay_amount' => $amount,
- 'pay_paytimes' => date('Y-m-d H:i:s'),
- 'pay_prepayid' => $memberId . '-CASH',
- 'pay_addtimes' => time()
- ]);
- Db::commit();
- return json_success('success');
- } catch (BusinessException $e) {
- Db::rollBack();
- return json_fail($e->getMessage());
- } catch (\Exception $e) {
- Db::rollBack();
- return json_fail('退款失败');
- }
- }
- public function crownContinue(Request $request)
- {
- $memberId = $request->post('member_id');
- $dataTime = $request->post('datetime', date('Y-m-d'));
- $sendAll = $request->post('send_all', false);
- $orderId = $request->post('order_id');
- if (!$memberId || !$orderId) {
- return json_fail('参数异常');
- }
- $member = Member::where('member_id', $memberId)->first();
- try {
- Db::beginTransaction();
- $roleConfigJson = [];
- if (!empty($member->member_role_config_json)) {
- $roleConfigJson = json_decode($member->member_role_config_json, true);
- if (!empty($roleConfigJson['next'])) {
- unset($roleConfigJson['next']);
- }
- }
- $roleConfigJson['deadline_datetime'] = date('Y-m-d 23:59:59', strtotime($dataTime . ' + 364 days'));
- $member->member_role_config_json = json_encode($roleConfigJson);
- $member->member_role_begintime = date('Y-m-d 00:00:00', strtotime($dataTime));
- $memberRoleId = MemberRole::where('member_role_category', 'COMBINE')
- ->where('member_role_status', 'ACTIVED')
- ->where('member_role_name', 'like', '%皇冠%')
- ->value('member_role_id');
- $member->join_member_role_id = $memberRoleId;
- $member->save();
- if ($sendAll === true) {
- $payDetail = PayDetail::whereJsonContains('join_pay_object_json->order_id', $orderId)
- ->first();
- if (!empty($payDetail->pay_extend_json)) {
- $payExtendJson = json_decode($payDetail->pay_extend_json, true);
- $account = MemberAccount::where('join_account_member_id', $memberId)
- ->where('member_account_classify', 'CASH')
- ->first();
- $account->member_account_added = $account->member_account_added + $payExtendJson['added_amount'];
- $account->save();
- }
- // 产生一条支付记录
- PayDetail::insert([
- 'join_pay_member_id' => $memberId,
- 'join_pay_order_id' => 'CROWN_CONTINUE',
- 'join_pay_object_json' => '[]',
- 'pay_status' => 'SUCCESS',
- 'pay_category' => 'CROWN_CONTINUE',
- 'pay_amount' => 0,
- 'pay_paytimes' => date('Y-m-d H:i:s'),
- 'pay_prepayid' => $memberId . '-CASH',
- 'pay_extend_json' => $payDetail->pay_extend_json,
- 'pay_addtimes' => time()
- ]);
- $goodsAttributeJson = RechargeService::getGoodsAttributeJson($orderId);
- // 发券
- $couponParams['order_id'] = $orderId;
- RechargeService::disposeRoleCoupon($goodsAttributeJson, $couponParams, $memberId);
- }
- Db::commit();
- return json_success('success');
- } catch (\Exception $e) {
- dump($e->getTrace());
- Db::rollBack();
- Log::error("续期失败:" . $e->getMessage());
- return json_fail("续期失败");
- }
- }
- }
|