12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132 |
- <?php
- namespace app\admin\service\member;
- use app\common\Tree;
- use app\model\ClientPoints;
- use app\model\CouponDetail;
- use app\model\Device;
- use app\model\Family;
- use app\model\FamilyMember;
- use app\model\Goods;
- use app\model\Member;
- use app\model\MemberAccount;
- use app\model\MemberAccountList;
- use app\model\MemberCert;
- use app\model\MemberDevice;
- use app\model\MemberInfo;
- use app\model\MemberRole;
- use app\model\Order;
- use app\model\OrderSheet;
- use app\model\PayDetail;
- use app\model\SysCategory;
- use app\model\SysDept;
- use app\model\SysSerial;
- use app\model\SysUser;
- use support\Db;
- use support\exception\BusinessException;
- use support\Log;
- use support\Request;
- use support\Response;
- class MemberService
- {
- public static function list(Request $request)
- {
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 10);
- $name = $request->get('name', '');
- $nickname = $request->get('nickname', '');
- $mobile = $request->get('mobile', '');
- $level = $request->get('level', '');
- $isAuth = $request->get('is_auth', '');
- $addtime = $request->get('member_addtimes', []);
- $type = $request->get('type', '');
- $status = $request->get('member_status', '');
- $memberIsPartner = $request->get('member_is_partner', '');
- $memberIsReferrer = $request->get('member_is_referrer', '');
- // 兼容老等级搜索
- $levelIds = [];
- if (!empty($level)) {
- $levelName = MemberRole::where('member_role_id', $level)->value('member_role_name');
- if (!empty($levelName)) {
- $levelIds = MemberRole::where('member_role_name', $levelName)->pluck('member_role_id')->toArray();
- }
- }
- $rows = Member::with([
- 'account' => function ($query) {
- $query->where('member_account_status', 'ACTIVED');
- }
- ])->where('member_is_owner', 'N')
- ->where('member_mobile', '<>', '0000')
- ->leftJoin('member_info', 'member_info.join_info_member_id', 'member.member_id')
- ->leftJoin('member_cert', 'member_cert.join_cert_member_id', 'member.member_id')
- ->leftJoin('member_role', 'member_role.member_role_id', 'member.join_member_role_id')
- ->when($name != '', function ($query) use ($name) {
- $query->where('member_cert.member_cert_name', 'like', '%' . $name . '%');
- })->when($mobile != '', function ($query) use ($mobile) {
- $query->where('member.member_mobile', 'like', '%' . $mobile . '%');
- })->when($level != '', function ($query) use ($level, $levelIds) {
- if ($level == 'other') {
- $query->where('member.join_member_role_id', NULL)->orWhere('member.join_member_role_id', '');
- } else if ($level == 'VIP') {
- $query->where('member.member_is_vip', 'Y');
- } else if (!empty($levelIds)) {
- $query->whereIn('member_role.member_role_id', $levelIds);
- } else {
- $query->where('member_role.member_role_id', $level);
- }
- })->when($isAuth != '', function ($query) use ($isAuth) {
- if ($isAuth == 'Y') {
- $query->where('member_cert.member_cert_name', '<>', NULL)->where('member_cert.member_cert_nbr', '<>', NULL)->where('member_cert.member_cert_name', '<>', '')->where('member_cert.member_cert_nbr', '<>', '');
- } else {
- $query->where('member_cert.member_cert_name', NULL)->orWhere('member_cert.member_cert_nbr', NULL)->orWhere('member_cert.member_cert_name', '')->orWhere('member_cert.member_cert_nbr', '');
- }
- })->when(!empty($addtime), function ($query) use ($addtime) {
- $addtime[0] = strtotime($addtime[0]);
- $addtime[1] = strtotime($addtime[1]);
- $query->whereBetween('member.member_addtimes', $addtime);
- })->when(!empty($type), function ($query) use ($type) {
- if ($type == 'todayAdd') {
- $addtime[0] = strtotime(date('Y-m-d') . ' 00:00:00');
- $addtime[1] = strtotime(date('Y-m-d') . ' 23:59:59');
- } else if ($type == 'monthAdd') {
- $addtime[0] = strtotime(date('Y-m-01') . ' 00:00:00');
- $addtime[1] = strtotime(date('Y-m-t') . ' 23:59:59');
- }
- $query->whereBetween('member.member_addtimes', $addtime);
- })->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 . '%');
- });
- })->when(!empty($status), function ($query) use ($status) {
- $query->where('member_status', $status);
- })->when(!empty($memberIsPartner), function ($query) use ($memberIsPartner) {
- if ($memberIsPartner == 'Y') {
- $query->where('member_is_partner', 'Y');
- }
- })->when(!empty($memberIsReferrer), function ($query) use ($memberIsReferrer) {
- if ($memberIsReferrer == 'Y') {
- $query->where('member_is_referrer', 'Y');
- }
- })
- ->select('member_id', 'member_is_vip', 'member_is_owner', 'join_invite_member_id', 'member_is_partner', 'member_partner_json', 'member_is_referrer', 'member_referrer_json', 'member_is_franchisee', 'member_franchisee_json', '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_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_account.member_account_surplus'
- );
- // 总条数
- $total = $rows->count('member_id');
- // 已认证条数
- $authModel = clone $rows;
- $authTotal = $authModel->where('member_cert.member_cert_name', '<>', '')
- ->where('member_cert.member_cert_nbr', '<>', '')
- ->count();
- $rows = $rows->orderBy('member_addtimes', 'DESC')
- ->forPage($page, $pageSize)
- ->get()
- ->toArray();
- foreach ($rows as &$row) {
- $row['coupon_count'] = CouponDetail::where('join_coupon_detail_member_id', $row['member_id'])->count();
- $row['member_mobile'] = substr($row['member_mobile'], 0, 3) . '****' . substr($row['member_mobile'], 7);
- // 推荐人
- if (!empty($row['join_invite_member_id'])) {
- $row['referrer_name'] = MemberService::getMemberNameByMemberId($row['join_invite_member_id']);
- }
- $row['info'] = [
- '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_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
- 'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
- 'member_info_service' => !empty($row['member_info_service']) ? $row['member_info_service'] : '',
- 'member_info_city' => !empty($row['member_info_city']) ? explode('-', $row['member_info_city']) : '',
- 'member_info_address' => !empty($row['member_info_address']) ? $row['member_info_address'] : '',
- 'member_info_birthday' => !empty($row['member_info_birthday']) ? $row['member_info_birthday'] : '',
- 'member_info_gender' => !empty($row['member_info_gender']) ? $row['member_info_gender'] : '',
- ];
- if (substr($row['info']['member_info_headimg'], 0, 2) == '..') {
- $row['info']['member_info_headimg'] = '';
- }
- if (!empty($row['info']['member_info_address']) && in_array($row['info']['member_info_address'], ['请选择', '省-市-区'])) {
- $row['info']['member_info_address'] = '';
- }
- $row['cert'] = [
- 'member_cert_birth' => $row['member_cert_birth'],
- 'member_cert_gender' => $row['member_cert_gender'],
- 'member_cert_name' => $row['member_cert_name'],
- 'member_cert_nbr' => $row['member_cert_nbr'],
- 'member_cert_province' => !empty($row['member_cert_province']) && is_json($row['member_cert_province']) ? json_decode($row['member_cert_province']) : '',
- 'member_cert_addr' => $row['member_cert_addr'],
- 'member_cert_face' => !empty($row['member_cert_face']) ? getenv('STORAGE_DOMAIN') . $row['member_cert_face'] : '',
- 'member_cert_photo' => !empty($row['member_cert_photo']) ? getenv('STORAGE_DOMAIN') . $row['member_cert_photo'] : '',
- 'member_cert_nation' => $row['member_cert_nation'],
- ];
- $account = [];
- if (!empty($row['account'])) {
- foreach ($row['account'] as $item) {
- if ($item['member_account_classify'] == 'WELFARE') {
- $account['welfare'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'POINTS') {
- $account['points'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'CASH') {
- $account['cash'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'CARD') {
- $account['card'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'VIP') {
- $account['vip'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- }
- }
- }
- $row['account'] = $account;
- $row['is_auth'] = "未认证";
- if (!empty($row['member_cert_nbr']) && !empty($row['member_cert_name'])) {
- $row['is_auth'] = "已认证";
- }
- $row['source'] = "APP";
- $row['belong'] = [];
- $row['referee'] = [];
- if (!empty($row['member_extend_json'])) {
- $extendJson = json_decode($row['member_extend_json'], true);
- if (isset($extendJson['come_from'])) {
- $row['source'] = $extendJson['come_from'] ?? '';
- }
- if (isset($extendJson['belong'])) {
- $user = SysUser::where('user_id', $extendJson['belong']['user_id'])->select('user_name', 'user_mobile')->first();
- if ($user) {
- $row['belong']['user_id'] = $extendJson['belong']['user_id'];
- $row['belong']['username'] = $user->user_name;
- $row['belong']['user_mobile'] = $user->user_mobile;
- }
- $row['belong']['deptName'] = SysDept::where('dept_id', $extendJson['belong']['premises'])->value('dept_name');
- }
- if (isset($extendJson['referee'])) {
- foreach ($extendJson['referee'] as $key => $referee) {
- if (preg_match('/^1[3-9]\d{9}$/', $referee)) {
- $member = Member::with([
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- }
- ])->where('member_mobile', $referee)->where('member_status', 'ACTIVED')
- ->first();
- if ($member->cert && $member->cert->member_cert_name) {
- $referee = $member->cert->member_cert_name . '-' . $referee;
- }
- }
- $row['referee'][] = [
- 'name' => $referee,
- 'time' => $key
- ];
- }
- }
- }
- // 粉丝
- $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;
- // 合伙人信息
- if ($row['member_is_partner'] == 'Y' && !empty($row['member_partner_json'])) {
- $partnerJson = json_decode($row['member_partner_json'], true);
- $row['partner_add_times'] = $partnerJson['datetime'] ?? '';
- unset($row['member_partner_json']);
- }
- // 推荐信息
- if ($row['member_is_referrer'] == 'Y' && !empty($row['member_referrer_json'])) {
- $referrerJson = json_decode($row['member_referrer_json'], true);
- $row['referrer_add_times'] = $referrerJson['datetime'] ?? '';
- unset($row['member_referrer_json']);
- }
- }
- return json_success('', compact('rows', 'page', 'pageSize', 'total', 'authTotal'));
- }
- public static function exportMember(Request $request)
- {
- $memberIds = $request->get('member_id', '');
- $name = $request->get('name', '');
- $mobile = $request->get('mobile', '');
- $level = $request->get('level', '');
- $isAuth = $request->get('is_auth', '');
- $addtime = $request->get('member_addtimes', []);
- $isPartner = $request->get('member_is_partner', '');
- $isReferrer = $request->get('member_is_referrer', '');
- $rows = Member::with('account')
- ->where('member_is_owner', 'N')
- ->where('member_mobile', '<>', '0000')
- ->leftJoin('member_info', 'member_info.join_info_member_id', 'member.member_id')
- ->leftJoin('member_cert', 'member_cert.join_cert_member_id', 'member.member_id')
- // ->leftjoin('member_account', 'member.member_id', '=', 'member_account.join_account_member_id')
- ->leftJoin('member_role', 'member_role.member_role_id', 'member.join_member_role_id')
- // ->where('member_account.member_account_classify', 'CASH')
- ->when($memberIds != '', function ($query) use ($memberIds) {
- $query->whereIn('member.member_id', $memberIds);
- })->when($name != '', function ($query) use ($name) {
- $query->where('member_cert.member_cert_name', 'like', '%' . $name . '%');
- })->when($mobile != '', function ($query) use ($mobile) {
- $query->where('member.member_mobile', 'like', '%' . $mobile . '%');
- })->when($isPartner != '', function ($query) use ($isPartner) {
- $query->where('member.member_is_partner', $isPartner);
- })->when($isReferrer != '', function ($query) use ($isReferrer) {
- $query->where('member.member_is_referrer', $isReferrer);
- })->when($level != '', function ($query) use ($level) {
- if ($level == 'other') {
- $query->where('member.join_member_role_id', NULL)->orWhere('member.join_member_role_id', '');
- } else {
- $query->where('member_role.member_role_id', $level);
- }
- })->when($isAuth != '', function ($query) use ($isAuth) {
- if ($isAuth == 'Y') {
- $query->where('member_cert.member_cert_name', '<>', NULL)->where('member_cert.member_cert_nbr', '<>', NULL)->where('member_cert.member_cert_name', '<>', '')->where('member_cert.member_cert_nbr', '<>', '');
- } else {
- $query->where('member_cert.member_cert_name', NULL)->where('member_cert.member_cert_nbr', NULL)->where('member_cert.member_cert_name', '')->where('member_cert.member_cert_nbr', '');
- }
- })->when(!empty($addtime), function ($query) use ($addtime) {
- $addtime[0] = strtotime($addtime[0]);
- $addtime[1] = strtotime($addtime[1]);
- $query->whereBetween('member.member_addtimes', $addtime);
- })->select('member_id', 'join_invite_member_id', 'member_is_owner', '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_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_account.member_account_surplus'
- )->orderBy('member_addtimes', 'DESC')
- ->get()
- ->toArray();
- $exportData = [];
- foreach ($rows as $row) {// 推荐人
- if (!empty($row['join_invite_member_id'])) {
- $row['referrer_name'] = MemberService::getMemberNameByMemberId($row['join_invite_member_id']);
- }
- $row['info'] = [
- '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_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
- 'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
- 'member_info_service' => !empty($row['member_info_service']) ? $row['member_info_service'] : ''
- ];
- $row['cert'] = [
- 'member_cert_name' => $row['member_cert_name'],
- ];
- $account = [];
- if (!empty($row['account'])) {
- foreach ($row['account'] as $item) {
- if ($item['member_account_classify'] == 'POINTS') {
- $account['points'] = [
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'CASH') {
- $account['cash'] = [
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'CARD') {
- $account['card'] = [
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- }
- }
- }
- // $row['account'] = $account;
- $row['is_auth'] = "未认证";
- if (!empty($row['member_cert_nbr']) && !empty($row['member_cert_name'])) {
- $row['is_auth'] = "已认证";
- }
- $row['source'] = "APP";
- if (!empty($row['member_extend_json'])) {
- $extendJson = json_decode($row['member_extend_json'], true);
- if (isset($extendJson['come_from'])) {
- $row['source'] = $extendJson['come_from'] ?? '';
- }
- }
- $sourceStr = ['APP' => "APP", 'CUSTOMER' => "客户管理", 'SYSTEM' => "后台"];
- $exportData[] = [
- 'member_id' => $row['member_id'],
- 'member_info_nickname' => $row['info']['member_info_nickname'] ?? '',
- 'member_mobile' => $row['member_mobile'] ?? '',
- 'member_cert_name' => $row['cert']['member_cert_name'] ?? '',
- 'source' => in_array($row['source'], $sourceStr) ? $sourceStr[$row['source']] : 'APP',
- '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,
- 'is_auth' => $row['is_auth'],
- 'level' => $row['member_role_name'] ?? '普通会员',
- 'member_addtimes' => $row['member_addtimes'],
- 'referrer_name' => $row['referrer_name'] ?? '',
- 'member_info_business' => $row['info']['member_info_business'] ?? '',
- 'member_info_service' => $row['info']['member_info_service'] ?? '',
- ];
- }
- return json_success('', $exportData);
- }
- public static function info($memberId)
- {
- $member = Member::with([
- 'cert',
- 'info',
- 'role' => function ($query) {
- $query->select('member_role_id', 'member_role_name');
- },
- 'account'
- ])
- ->where('member_id', $memberId)
- ->first();
- if (!$member) {
- return json_fail('查询错误');
- }
- $member = $member->toArray();
- unset($member['member_password']);
- $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_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_business' => !empty($member['info']) && !empty($member['info']['member_info_business']) ? $member['info']['member_info_business'] : '',
- 'member_info_service' => !empty($member['info']) && !empty($member['info']['member_info_service']) ? $member['info']['member_info_service'] : '',
- 'member_info_city' => !empty($member['info']) && !empty($member['info']['member_info_city']) ? explode('-', $member['info']['member_info_city']) : '',
- 'member_info_address' => !empty($member['info']) && !empty($member['info']['member_info_address']) ? $member['info']['member_info_address'] : '',
- 'member_info_gender' => !empty($member['info']) && !empty($member['info']['member_info_gender']) ? $member['info']['member_info_gender'] : '',
- 'member_info_birthday' => !empty($member['info']) && !empty($member['info']['member_info_birthday']) ? $member['info']['member_info_birthday'] : '',
- ];
- if (!empty($member['info']['member_info_address']) && in_array($member['info']['member_info_address'], ['请选择', '省-市-区'])) {
- $member['info']['member_info_address'] = '';
- }
- $member['cert'] = [
- 'member_cert_birth' => $member['cert']['member_cert_birth'] ?? '',
- 'member_cert_gender' => $member['cert']['member_cert_gender'] ?? '',
- 'member_cert_name' => $member['cert']['member_cert_name'] ?? '',
- 'member_cert_nbr' => $member['cert']['member_cert_nbr'] ?? '',
- 'member_cert_province' => !empty($member['cert']) && !empty($member['cert']['member_cert_province']) && is_json($member['cert']['member_cert_province']) ? json_decode($member['cert']['member_cert_province']) : '',
- 'member_cert_addr' => $member['cert']['member_cert_addr'] ?? '',
- 'member_cert_face' => !empty($member['cert']) && !empty($member['cert']['member_cert_face']) ? getenv('STORAGE_DOMAIN') . $member['cert']['member_cert_face'] : '',
- 'member_cert_photo' => !empty($member['cert']) && !empty($member['cert']['member_cert_photo']) ? getenv('STORAGE_DOMAIN') . $member['cert']['member_cert_photo'] : '',
- 'member_cert_nation' => $member['cert']['member_cert_nation'] ?? '',
- 'member_cert_addtimes' => $member['cert']['member_cert_addtimes'] ?? '',
- ];
- if (!empty($member['cert']['member_cert_addtimes'])) {
- $member['cert']['member_cert_addtimes'] = date('Y-m-d', $member['cert']['member_cert_addtimes']);
- } else {
- $member['cert']['member_cert_addtimes'] = date('Y-m-d', strtotime($member['member_addtimes']));
- }
- if (!empty($member['join_invite_member_id'])) {
- $inviteMember = Member::with([
- 'info' => function ($query) {
- $query->select('join_info_member_id', 'member_info_nickname');
- },
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- }
- ])->where('member_id', $member['join_invite_member_id'])
- ->first();
- $inviteMemberName = '';
- if (!empty($inviteMember->cert) && !empty($inviteMember->cert->member_cert_name)) {
- $inviteMemberName = $inviteMember->cert->member_cert_name;
- } elseif (!empty($inviteMemberName->info) && !empty($inviteMemberName->info->member_info_nickname)) {
- $inviteMemberName = $inviteMemberName->info->member_info_nickname;
- }
- $member['invite_member'] = $inviteMemberName . (!empty($inviteMember->member_invite_code) ? '(' . $inviteMember->member_invite_code . ')' : '');
- }
- $member['is_auth'] = "未认证";
- if (!empty($member['cert']['member_cert_nbr']) && !empty($member['cert']['member_cert_name'])) {
- $member['is_auth'] = "已认证";
- }
- $member['source'] = "APP";
- $member['belong'] = [];
- $member['referee'] = [];
- if (!empty($member['member_extend_json'])) {
- $extendJson = json_decode($member['member_extend_json'], true);
- if (isset($extendJson['come_from'])) {
- $member['source'] = $extendJson['come_from'] ?? '';
- }
- if (isset($extendJson['belong'])) {
- $user = SysUser::where('user_id', $extendJson['belong']['user_id'])->select('user_name', 'user_mobile')->first();
- if ($user) {
- $member['belong']['user_id'] = $extendJson['belong']['user_id'];
- $member['belong']['username'] = $user->user_name;
- $member['belong']['user_mobile'] = $user->user_mobile;
- }
- $member['belong']['deptName'] = SysDept::where('dept_id', $extendJson['belong']['premises'])->value('dept_name');
- }
- if (isset($extendJson['referee'])) {
- foreach ($extendJson['referee'] as $key => $referee) {
- if (preg_match('/^1[3-9]\d{9}$/', $referee)) {
- $refereeMember = Member::with([
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- }
- ])->where('member_mobile', $referee)->where('member_status', 'ACTIVED')
- ->first();
- if ($refereeMember->cert && $refereeMember->cert->member_cert_name) {
- $referee = $refereeMember->cert->member_cert_name . '-' . $referee;
- }
- }
- $member['referee'][] = [
- 'name' => $referee,
- 'time' => $key
- ];
- }
- }
- }
- if (!empty($member['join_invite_member_id'])) {
- $inviteMember = Member::with('cert', 'info')
- ->where('member_id', $member['join_invite_member_id'])
- ->select('member_id', 'member_mobile', 'member_invite_code')
- ->first();
- if (!empty($inviteMember)) {
- $inviteMember = $inviteMember->toArray();
- $mobile = '';
- if (!empty($inviteMember['member_mobile'])) {
- $mobile = $inviteMember['member_mobile'];
- }
- $nickname = '';
- if (!empty($inviteMember['info']) && !empty($inviteMember['info']['member_info_nickname'])) {
- $nickname = $inviteMember['info']['member_info_nickname'];
- }
- $certname = '';
- if (!empty($inviteMember['cert']) && !empty($inviteMember['cert']['member_cert_name'])) {
- $certname = $inviteMember['cert']['member_cert_name'];
- }
- $member['invite_name'] = MemberService::getMemberName($mobile, $certname, $nickname);
- $member['invite_code'] = $inviteMember['member_invite_code'] ?? '';
- }
- }
- if (!empty($member['member_partner_json'])) {
- $partnerJson = json_decode($member['member_partner_json'], true);
- if (isset($partnerJson['duedate'])) {
- $member['partner_info'] = [
- 'add_times' => $partnerJson['datetime'],
- 'surplus' => ceil((strtotime($partnerJson['duedate'] . ' 23:59:59') - time()) / (3600 * 24)),
- 'dates' => date('Y/m/d 00:00:00', strtotime($partnerJson['datetime'])) . '-' . date('Y/m/d 23:59:59', strtotime($partnerJson['duedate']))
- ];
- }
- }
- if (!empty($member['member_referrer_json'])) {
- $referrerJson = json_decode($member['member_referrer_json'], true);
- if (isset($referrerJson['duedate'])) {
- $member['referrer_info'] = [
- 'add_times' => $referrerJson['datetime'],
- 'surplus' => ceil((strtotime($referrerJson['duedate'] . ' 23:59:59') - time()) / (3600 * 24)),
- 'dates' => date('Y/m/d 00:00:00', strtotime($referrerJson['datetime'])) . '-' . date('Y/m/d 23:59:59', strtotime($referrerJson['duedate']))
- ];
- }
- }
- if (!empty($member['member_franchisee_json'])) {
- $franchiseeJson = json_decode($member['member_franchisee_json'], true);
- if (isset($franchiseeJson['duedate'])) {
- $member['franchisee_info'] = [
- 'add_times' => $franchiseeJson['datetime'],
- 'surplus' => ceil((strtotime($franchiseeJson['duedate'] . ' 23:59:59') - time()) / (3600 * 24)),
- 'dates' => date('Y/m/d 00:00:00', strtotime($franchiseeJson['datetime'])) . '-' . date('Y/m/d 23:59:59', strtotime($franchiseeJson['duedate']))
- ];
- }
- }
- $account = [];
- if (!empty($member['account'])) {
- foreach ($member['account'] as $item) {
- if ($item['member_account_classify'] == 'WELFARE') {
- $account['welfare'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'POINTS') {
- $account['points'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'CASH') {
- $account['cash'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'CARD') {
- $account['card'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- } else if ($item['member_account_classify'] == 'VIP') {
- $account['vip'] = [
- 'member_account_name' => $item['member_account_name'],
- 'member_account_income' => $item['member_account_income'],
- 'member_account_expend' => $item['member_account_expend'],
- 'member_account_surplus' => $item['member_account_surplus'],
- 'member_account_added' => $item['member_account_added'],
- ];
- }
- }
- }
- $member['account'] = $account;
- return json_success('', $member);
- }
- /**
- * VIP账户明细
- */
- public static function vipInfo(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $account = MemberAccount::where('join_account_member_id', $memberId)
- ->where('member_account_classify', 'VIP')
- ->first();
- if (!$account) {
- return json_fail('暂无数据');
- }
- $balance = $account->member_account_surplus + $account->member_account_added;
- $info = PayDetail::where(function ($query) use ($memberId) {
- $query->where('join_pay_member_id', $memberId)
- // ->whereIn('pay_prepayid', ['W06', 'A01'])
- ->where('pay_category', 'VIP')
- ->where('pay_status', 'SUCCESS');
- })->orWhere(function ($query) use ($memberId) {
- $query->where('join_pay_member_id', $memberId)
- ->where('pay_prepayid', 'like', '%VIP%')
- ->where('pay_status', 'SUCCESS');
- })->orderByDesc('pay_addtimes')
- ->get()
- ->toArray();
- $data = [];
- foreach ($info as $key => $item) {
- $categoryIds = [];
- if (!empty($item['join_pay_order_id'])) {
- $orderIds = Order::where('order_groupby', $item['join_pay_order_id'])->pluck('order_id');
- $goodsIds = OrderSheet::whereIn('join_sheet_order_id', $orderIds)->pluck('join_sheet_goods_id');
- $categoryIds = Goods::whereIn('goods_id', $goodsIds)->pluck('join_goods_category_id');
- }
- $categoryName = [];
- foreach ($categoryIds as $id) {
- $category = SysCategory::where('category_id', $id)->first();
- if (!empty($category->category_super_path)) {
- $path = explode('#', $category->category_super_path);
- $ids = array_filter($path);
- $categoryName[] = SysCategory::where('category_id', current($ids))->value('category_name');
- } else {
- $categoryName[] = $category->category_name;
- }
- }
- $item['goods_category'] = implode(',', array_unique($categoryName));
- if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
- $item['goods_category'] = '自定义金额充值';
- }
- if (in_array($item['pay_category'], ['VIP', 'REFUND'])) {
- $item['balance_type'] = 'add';
- } else {
- $item['balance_type'] = 'cut';
- }
- if ($key == 0 && in_array($item['pay_category'], ['VIP', 'REFUND'])) {
- if (!empty($item['pay_extend_json'])) {
- $extendJson = json_decode($item['pay_extend_json'], true);
- if (!isset($extendJson['added_amount'])) {
- $extendJson['added_amount'] = 0;
- }
- if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => 'ADDED',
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- ];
- }
- $balance = $balance - $extendJson['added_amount'];
- }
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $item['pay_amount'];
- $data[] = $item;
- continue;
- }
- if (in_array($item['pay_category'], ['VIP', 'REFUND'])) {
- if (!empty($item['pay_extend_json'])) {
- $extendJson = json_decode($item['pay_extend_json'], true);
- if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => 'ADDED',
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- ];
- $balance = $balance - $extendJson['added_amount'];
- }
- }
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $item['pay_amount'];
- } else {
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance + $item['pay_amount'];
- }
- $data[] = $item;
- }
- $total = count($data);
- $start = ($page - 1) * $pageSize;
- $rows = array_slice($data, $start, $pageSize);
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- public static function welfareInfo(Request $request)
- {
- $memberId = $request->get('member_id', '');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $account = MemberAccount::where('join_account_member_id', $memberId)
- ->where('member_account_classify', 'WELFARE')
- ->first();
- if (!$account) {
- return json_fail('暂无数据');
- }
- $balance = $account->member_account_surplus + $account->member_account_added;
- $info = PayDetail::where(function ($query) use ($memberId) {
- $query->where('join_pay_member_id', $memberId)
- // ->whereIn('pay_prepayid', ['W06', 'A01'])
- ->where('pay_category', 'RECHARGE')
- ->where('pay_prepayid', 'WELFARE')
- ->where('pay_status', 'SUCCESS');
- })->orWhere(function ($query) use ($memberId) {
- $query->where('join_pay_member_id', $memberId)
- ->where('pay_prepayid', 'like', '%WELFARE%')
- ->where('pay_status', 'SUCCESS');
- })->orderByDesc('pay_addtimes')
- ->get()
- ->toArray();
- $data = [];
- foreach ($info as $key => $item) {
- $categoryIds = [];
- if (!empty($item['join_pay_order_id'])) {
- $orderIds = Order::where('order_groupby', $item['join_pay_order_id'])->pluck('order_id');
- $goodsIds = OrderSheet::whereIn('join_sheet_order_id', $orderIds)->pluck('join_sheet_goods_id');
- $categoryIds = Goods::whereIn('goods_id', $goodsIds)->pluck('join_goods_category_id');
- }
- $categoryName = [];
- foreach ($categoryIds as $id) {
- $category = SysCategory::where('category_id', $id)->first();
- if (!empty($category->category_super_path)) {
- $path = explode('#', $category->category_super_path);
- $ids = array_filter($path);
- $categoryName[] = SysCategory::where('category_id', current($ids))->value('category_name');
- } else {
- $categoryName[] = $category->category_name;
- }
- }
- $item['goods_category'] = implode(',', array_unique($categoryName));
- if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
- $item['goods_category'] = '自定义金额充值';
- }
- if (in_array($item['pay_category'], ['RECHARGE', 'REFUND'])) {
- $item['balance_type'] = 'add';
- } else {
- $item['balance_type'] = 'cut';
- }
- if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND'])) {
- if (!empty($item['pay_extend_json'])) {
- $extendJson = json_decode($item['pay_extend_json'], true);
- if (!isset($extendJson['added_amount'])) {
- $extendJson['added_amount'] = 0;
- }
- if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => 'ADDED',
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- ];
- }
- $balance = $balance - $extendJson['added_amount'];
- }
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $item['pay_amount'];
- $data[] = $item;
- continue;
- }
- if (in_array($item['pay_category'], ['RECHARGE', 'REFUND'])) {
- if (!empty($item['pay_extend_json'])) {
- $extendJson = json_decode($item['pay_extend_json'], true);
- if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => 'ADDED',
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- ];
- $balance = $balance - $extendJson['added_amount'];
- }
- }
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $item['pay_amount'];
- } else {
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance + $item['pay_amount'];
- }
- $data[] = $item;
- }
- $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/9/30 14:52
- *
- * @param Request $request
- * @return Response
- */
- public static function commissionList(Request $request)
- {
- $memberId = $request->get('member_id');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $rows = MemberAccountList::where('join_member_account_list_member_id', $memberId)
- ->where('member_account_list_attr', 'IN');
- $total = $rows->count();
- $rows = $rows->forPage($page, $pageSize)
- ->get()
- ->toArray();
- foreach ($rows as &$row) {
- if (!empty($row['member_account_list_json'])) {
- $memberAccountListJson = json_decode($row['member_account_list_json'], true);
- if ($memberAccountListJson['master_member_id']) {
- $row['master_member_name'] = MemberService::getMemberNameByMemberId($memberAccountListJson['master_member_id']);
- }
- }
- }
- 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)
- {
- $memberId = $request->get('member_id', '');
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 20);
- $account = MemberAccount::where('join_account_member_id', $memberId)
- ->where('member_account_classify', 'CASH')
- ->first();
- if (!$account) {
- return json_fail('暂无数据');
- }
- $balance = $account->member_account_surplus + $account->member_account_added;
- $info = PayDetail::where(function ($query) use ($memberId) {
- $query->where('join_pay_member_id', $memberId)
- ->whereIn('pay_category', ['RECHARGE'])
- ->where('pay_prepayid', '<>', $memberId . '-WELFARE')
- ->where('pay_status', 'SUCCESS');
- })->orWhere(function ($query) use ($memberId) {
- $query->where('join_pay_member_id', $memberId)
- ->where('pay_prepayid', 'like', '%CASH%')
- ->where('pay_status', 'SUCCESS');
- })->select('join_pay_object_json', 'join_pay_member_id', 'pay_category', 'join_pay_order_id', 'pay_extend_json', 'pay_addtimes', 'pay_amount');
- // ->orderByDesc('pay_addtimes')
- // ->get()
- // ->toArray();
- $memberAccountList = MemberAccountList::where('join_member_account_list_member_id', $memberId)
- ->where('member_account_list_status', 'ACTIVED')
- ->selectRaw('
- member_account_list_extend_json as join_pay_object_json,
- join_member_account_list_member_id as join_pay_member_id,
- member_account_list_attr as pay_category,
- join_list_member_account_nbr as pay_prepayid,
- member_account_list_extend_json as pay_extend_json,
- member_account_list_addtimes as pay_addtimes,
- member_account_list_amount as pay_amount');
- $info = $info->union($memberAccountList)
- ->orderByDesc('pay_addtimes')
- ->get()
- ->toArray();
- $data = [];
- foreach ($info as $key => $item) {
- $payObjectJson = [];
- if (!empty($item['join_pay_object_json'])) {
- $payObjectJson = json_decode($item['join_pay_object_json'], true);
- }
- $categoryIds = [];
- if (!empty($item['join_pay_order_id'])) {
- $goodsIds = [];
- if (in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE', 'REFERRER', 'FRANCHISEE'])) {
- if (isset($payObjectJson['recharge_goods_id'])) {
- $goodsIds = [$payObjectJson['recharge_goods_id']];
- }
- } else {
- $orderIds = Order::where('order_groupby', $item['join_pay_order_id'])->pluck('order_id');
- $goodsIds = OrderSheet::whereIn('join_sheet_order_id', $orderIds)->pluck('join_sheet_goods_id');
- }
- $categoryIds = Goods::whereIn('goods_id', $goodsIds)->pluck('join_goods_category_id');
- }
- $categoryName = [];
- foreach ($categoryIds as $id) {
- $category = SysCategory::where('category_id', $id)->first();
- if (!empty($category->category_super_path)) {
- $path = explode('#', $category->category_super_path);
- $ids = array_filter($path);
- $categoryName[] = SysCategory::where('category_id', current($ids))->value('category_name');
- } else {
- $categoryName[] = $category->category_name;
- }
- }
- $item['goods_category'] = implode(',', array_unique($categoryName));
- if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
- $item['goods_category'] = '自定义金额充值';
- } else if (mb_substr($item['goods_category'], 0, 7) == '会员合伙人产品') {
- $item['goods_category'] = '会员合伙人充值';
- }
- $goodsCategory = '';
- if ($item['join_pay_order_id'] == 'FRANCHISEE') {
- $goodsCategory = '加盟合伙人充值';
- }
- if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'CROWN_CONTINUE', 'PARTNER', 'FRANCHISEE', 'IN'])) {
- $item['balance_type'] = 'add';
- } else {
- $item['balance_type'] = 'cut';
- }
- if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'FRANCHISEE', 'CROWN_CONTINUE'])) {
- if (!empty($item['pay_extend_json']) && !in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE', 'FRANCHISEE'])) {
- $extendJson = json_decode($item['pay_extend_json'], true);
- if (!isset($extendJson['added_amount'])) {
- $extendJson['added_amount'] = 0;
- }
- if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
- $payCategory = 'ADDED';
- if ($item['pay_category'] == 'GIVE') {
- $payCategory = 'GIVE';
- } elseif ($item['pay_category'] == 'CROWN_CONTINUE') {
- $payCategory = 'CROWN_CONTINUE';
- }
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => $payCategory,
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- 'goods_category' => $goodsCategory
- ];
- } elseif (!empty($payObjectJson['recharge_config']) && $payObjectJson['recharge_config']['nbr'] > 0) {
- $payCategory = 'ADDED';
- if ($item['pay_category'] == 'GIVE') {
- $payCategory = 'GIVE';
- } elseif ($item['pay_category'] == 'CROWN_CONTINUE') {
- $payCategory = 'CROWN_CONTINUE';
- }
- $extendJson['added_amount'] = $item['pay_amount'] * $payObjectJson['recharge_config']['nbr'];
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => $payCategory,
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- ];
- }
- $balance = $balance - $extendJson['added_amount'];
- }
- if (in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE', 'FRANCHISEE'])) {
- $addedAmount = 0;
- if (!isset($payObjectJson['recharge_config'])) {
- $addedAmount = 0;
- }
- if (isset($payObjectJson['recharge_config']) && !empty($payObjectJson['recharge_config']['nbr']) && floatval($payObjectJson['recharge_config']['nbr'] > 0)) {
- $addedAmount = $payObjectJson['recharge_config']['nbr'];
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $addedAmount,
- 'pay_category' => 'ADDED',
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- 'goods_category' => $goodsCategory
- ];
- }
- $balance = $balance - $addedAmount;
- }
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $item['pay_amount'];
- if (!in_array($item['pay_category'], ['GIVE', 'CROWN_CONTINUE']) && !in_array($item['join_pay_order_id'], ['FRANCHISEE'])) {
- $data[] = $item;
- }
- continue;
- }
- if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'CROWN_CONTINUE', 'PARTNER', 'COMBINE', 'FRANCHISEE', 'IN'])) {
- if (!empty($item['pay_extend_json']) && !in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE', 'FRANCHISEE'])) {
- $extendJson = json_decode($item['pay_extend_json'], true);
- if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
- $payCategory = 'ADDED';
- if ($item['pay_category'] == 'GIVE') {
- $payCategory = 'GIVE';
- } elseif ($item['pay_category'] == 'CROWN_CONTINUE') {
- $payCategory = 'CROWN_CONTINUE';
- }
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => $payCategory,
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- 'goods_category' => $goodsCategory
- ];
- $balance = $balance - $extendJson['added_amount'];
- } elseif (!empty($payObjectJson['recharge_config']) && $payObjectJson['recharge_config']['nbr'] > 0) {
- $payCategory = 'ADDED';
- if ($item['pay_category'] == 'GIVE') {
- $payCategory = 'GIVE';
- } elseif ($item['pay_category'] == 'CROWN_CONTINUE') {
- $payCategory = 'CROWN_CONTINUE';
- }
- $extendJson['added_amount'] = $item['pay_amount'] * $payObjectJson['recharge_config']['nbr'];
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $extendJson['added_amount'],
- 'pay_category' => $payCategory,
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- 'goods_category' => $goodsCategory
- ];
- $balance = $balance - $extendJson['added_amount'];
- }
- }
- if (in_array($item['join_pay_order_id'], ['PARTNER', 'COMBINE', 'FRANCHISEE'])) {
- $addedAmount = 0;
- if (!isset($payObjectJson['recharge_config'])) {
- $addedAmount = 0;
- }
- if (isset($payObjectJson['recharge_config']) && !empty($payObjectJson['recharge_config']['nbr']) && floatval($payObjectJson['recharge_config']['nbr'] > 0)) {
- $addedAmount = $payObjectJson['recharge_config']['nbr'];
- $data[] = [
- 'join_pay_member_id' => $item['join_pay_member_id'],
- 'pay_addtimes' => $item['pay_addtimes'],
- 'pay_amount' => $addedAmount,
- 'pay_category' => 'ADDED',
- 'balance' => number_format($balance, 2, '.', ''),
- 'balance_type' => 'add',
- 'goods_category' => $goodsCategory
- ];
- }
- $balance = $balance - $addedAmount;
- }
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $item['pay_amount'];
- } else {
- $item['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance + $item['pay_amount'];
- }
- if (!in_array($item['pay_category'], ['GIVE', 'CROWN_CONTINUE']) && !in_array($item['join_pay_order_id'], ['FRANCHISEE'])) {
- $data[] = $item;
- }
- }
- $total = count($data);
- $start = ($page - 1) * $pageSize;
- $rows = array_slice($data, $start, $pageSize);
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- public static function pointInfo($memberId)
- {
- $account = MemberAccount::where('join_account_member_id', $memberId)
- ->where('member_account_classify', 'POINTS')
- ->first();
- if (!$account) {
- return json_fail('暂无数据');
- }
- $balance = $account->member_account_surplus + $account->member_account_added;
- $points = ClientPoints::where('join_client_points_member_id', $memberId)->orderBy('client_points_addtimes', 'DESC')->get()->toArray();
- $nowPoint = 0;
- foreach ($points as $key => &$point) {
- $point['goods_category'] = '其他';
- if (!empty($point['join_client_points_goods_id'])) {
- $categoryId = Goods::where('goods_id', $point['join_client_points_goods_id'])->pluck('join_goods_category_id');
- $category = SysCategory::where('category_id', $categoryId)->first();
- if (!empty($category->category_super_path)) {
- $path = explode('#', $category->category_super_path);
- $ids = array_filter($path);
- $point['goods_category'] = SysCategory::where('category_id', current($ids))->value('category_name');
- } else {
- $point['goods_category'] = $category->category_name;
- }
- }
- if (in_array($point['client_points_category'], ["评价", "消费", "活动", "赠送", '登录活动积分'])) {
- $point['balance_type'] = 'add';
- } else {
- $point['balance_type'] = 'cut';
- }
- if ($key == 0) {
- $point['balance'] = number_format($balance, 2, '.', '');
- if (in_array($point['client_points_category'], ["评价", "消费", "活动", "赠送", '登录活动积分'])) {
- $balance = $balance - $point['client_points_nbr'];
- } else {
- $balance = $balance + $point['client_points_nbr'];
- }
- continue;
- }
- if (in_array($point['client_points_category'], ["评价", "消费", "活动", "赠送", '登录活动积分'])) {
- $point['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance - $point['client_points_nbr'];
- // $point['balance'] = $balance = $nowPoint = number_format($balance - $point['client_points_nbr'], 2, '.', '');
- } else {
- $point['balance'] = number_format($balance, 2, '.', '');
- $balance = $balance + $point['client_points_nbr'];
- // $point['balance'] = $balance = $nowPoint = number_format($balance + $point['client_points_nbr'], 2, '.', '');
- }
- }
- return json_success('', $points);
- }
- /**
- * @Desc 添加会员
- * @Author Gorden
- * @Date 2024/3/25 13:40
- *
- * @param $params
- * @return \support\Response
- */
- public static function add($params)
- {
- Db::beginTransaction();
- try {
- // 排重
- if (Member::where('member_mobile', $params['mobile'])->where('member_status', 'ACTIVED')->exists()) {
- throw new BusinessException("会员已存在");
- }
- $memberId = self::generateMemberId();
- // 先写主表,要ID
- $memberData = [
- 'member_id' => $memberId,
- 'member_is_owner' => $params['is_owner'] ?? 'N',
- 'member_classify' => $params['classify'] ?? '',
- 'member_status' => $params['status'] ?? 'PENDING',
- 'member_mobile' => $params['mobile'] ?? '',
- 'member_category' => $params['member_category'] ?? '后台添加',
- 'member_invite_code' => self::generateInviteCode(),
- // 'member_from' => $params['source'],
- // 'member_extend_json' => json_encode(['come_from' => $params['source']]),
- 'member_addtimes' => time(),
- ];
- $extendJson['come_from'] = $params['source'];
- if (!empty($params['user_id'])) {
- $deptId = SysUser::where('user_id', $params['user_id'])->value('join_user_dept_id');
- if (!$deptId) {
- throw new BusinessException('请先关联业务员和门店');
- }
- $extendJson['belong'] = ['user_id' => $params['user_id'], 'premises' => $deptId];
- }
- $memberData['member_extend_json'] = json_encode($extendJson);
- Member::insert($memberData);
- // 账户表
- $accountData = [
- 'join_account_member_id' => $memberId,
- 'member_account_classify' => 'POINTS',
- 'member_account_status' => 'ACTIVED',
- 'member_account_category' => 'NORMAL',
- 'member_account_nbr' => $memberId . '-POINTS',
- 'member_account_name' => '积分账户',
- 'member_account_addtimes' => time()
- ];
- // 积分账户
- MemberAccount::insert($accountData);
- $accountData['member_account_classify'] = 'CASH';
- $accountData['member_account_nbr'] = $memberId . '-CASH';
- $accountData['member_account_name'] = '余额账户';
- // 现金/余额账户
- MemberAccount::insert($accountData);
- // 福利账户
- // if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY'){
- // $welfareData = [
- // 'join_account_member_id'=>$memberId,
- // 'member_account_classify'=>'WELFARE',
- // 'member_account_status'=>'ACTIVED',
- // 'member_account_category'=>'NORMAL',
- // 'member_account_nbr'=>$memberId.'-WELFARE',
- // 'member_account_name'=>'福利账户',
- // 'member_account_addtimes'=>time()
- // ];
- // MemberAccount::insert($welfareData);
- // }
- // member cert
- $certData = [
- 'join_cert_member_id' => $memberId,
- 'member_cert_nation' => $params['member_cert_nation'] ?? '',
- 'member_cert_name' => $params['cert_name'] ?? '',
- 'member_cert_nbr' => $params['cert_nbr'] ?? '',
- 'member_cert_birth' => !empty($params['birth']) ? date('Y-m-d', strtotime($params['birth'])) : '',
- 'member_cert_gender' => $params['gender'] ?? '',
- // 'member_cert_province' => !empty($params['province']) ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
- // 'member_cert_city' => $params['city'] ?? '',
- // 'member_cert_addr' => $params['addr'] ?? '',
- // 'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
- // 'member_cert_photo' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_photo']),
- ];
- MemberCert::insert($certData);
- // member info
- $infoData = [
- 'join_info_member_id' => $memberId,
- 'member_info_nickname' => $params['account_name'] ?? '',
- 'member_info_headimg' => !empty($params['avatar']) ? getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']) : '',
- 'member_info_referee' => $params['member_info_referee'] ?? '',
- 'member_info_business' => $params['member_info_business'] ?? '',
- 'member_info_service' => $params['member_info_service'] ?? '',
- 'member_info_city' => !empty($params['province']) ? implode('-', $params['province']) : '',
- 'member_info_address' => $params['member_info_address'] ?? '',
- 'member_info_birthday' => !empty($params['birth']) ? date('Y-m-d', strtotime($params['birth'])) : '',
- 'member_info_gender' => $params['gender'] ?? '',
- ];
- MemberInfo::insert($infoData);
- Db::commit();
- } catch (BusinessException $e) {
- Db::rollBack();
- return json_fail($e->getMessage());
- } catch (\Exception $e) {
- Db::rollBack();
- dump($e->getMessage() . ';line:' . $e->getLine());
- return json_fail("数据添加失败");
- }
- return json_success('数据添加成功', ['member_id' => $memberId]);
- }
- /**
- * @Desc 编辑会员/ 业主
- * @Author Gorden
- * @Date 2024/4/20 15:18
- *
- * @param $params
- * @return \support\Response
- */
- public static function update($params)
- {
- Db::beginTransaction();
- try {
- $memberId = $params['member_id'];
- $member = Member::where('member_id', $params['member_id'])->first();
- if (!$member) {
- throw new BusinessException('数据异常');
- }
- $extendJson = [];
- if (!empty($member->member_extend_json)) {
- $extendJson = json_decode($member->member_extend_json, true);
- }
- $extendJson['come_from'] = $params['source'];
- // 门店、业务员
- if (!empty($params['user_id'])) {
- $deptId = SysUser::where('user_id', $params['user_id'])->value('join_user_dept_id');
- if (!$deptId) {
- throw new BusinessException('您选择的业务员没有关联门店');
- }
- $extendJson['belong'] = ['user_id' => $params['user_id'], 'premises' => $deptId];
- }
- // 先写主表,要ID
- $memberData = [
- 'member_id' => $memberId,
- 'member_is_owner' => $params['is_owner'],
- 'member_classify' => $params['member_classify'],
- 'member_status' => $params['status'],
- // 'member_mobile' => $params['mobile'],
- // 'member_from' => $params['source'],
- 'member_extend_json' => json_encode($extendJson)
- ];
- Member::where('member_id', $params['member_id'])->update($memberData);
- // member cert
- $certData = [
- 'join_cert_member_id' => $memberId,
- 'member_cert_nation' => $params['member_cert_nation'] ?? '',
- 'member_cert_name' => $params['cert_name'] ?? '',
- 'member_cert_nbr' => $params['cert_nbr'] ?? '',
- 'member_cert_birth' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
- 'member_cert_gender' => $params['gender'] ?? '',
- // 'member_cert_province' => $params['province'] ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
- // 'member_cert_city' => $params['city'] ?? '',
- // 'member_cert_addr' => $params['addr'] ?? '',
- 'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
- 'member_cert_photo' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_photo']),
- ];
- if (!MemberCert::where('join_cert_member_id', $memberId)->exists()) {
- MemberCert::insert($certData);
- } else {
- MemberCert::where('join_cert_member_id', $params['member_id'])->update($certData);
- }
- // member info
- $avatar = '';
- if ($params['avatar'] && (strpos($params['avatar'], getenv('APP_IMAGE_DOMAIN')) !== false || strpos($params['avatar'], getenv('SYSTEM_AVATAR_DOMAIN')) !== false)) {
- $avatar = $params['avatar'];
- } else if ($params['avatar']) {
- $avatar = getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']);
- }
- $infoData = [
- 'join_info_member_id' => $memberId,
- 'member_info_nickname' => $params['account_name'],
- 'member_info_headimg' => $avatar,
- 'member_info_referee' => $params['member_info_referee'] ?? '',
- 'member_info_business' => $params['member_info_business'] ?? '',
- 'member_info_service' => $params['member_info_service'] ?? '',
- 'member_info_city' => !empty($params['province']) ? implode('-', $params['province']) : '',
- 'member_info_address' => $params['member_info_address'] ?? '',
- 'member_info_birthday' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
- 'member_info_gender' => $params['gender'] ?? '',
- ];
- if (!MemberInfo::where('join_info_member_id', $params['member_id'])->exists()) {
- MemberInfo::insert($infoData);
- } else {
- MemberInfo::where('join_info_member_id', $params['member_id'])->update($infoData);
- }
- // 福利账户
- if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY' && !MemberAccount::where('member_account_nbr', $memberId . '-WELFARE')->exists()) {
- $welfareData = [
- 'join_account_member_id' => $memberId,
- 'member_account_classify' => 'WELFARE',
- 'member_account_status' => 'ACTIVED',
- 'member_account_category' => 'NORMAL',
- 'member_account_nbr' => $memberId . '-WELFARE',
- 'member_account_name' => '福利账户',
- 'member_account_addtimes' => time()
- ];
- MemberAccount::insert($welfareData);
- }
- Db::commit();
- } catch (BusinessException $e) {
- Db::rollBack();
- dump($e->getMessage() . ';line:' . $e->getLine());
- return json_fail($e->getMessage());
- } catch (\Exception $e) {
- Db::rollBack();
- dump($e->getMessage() . ';line:' . $e->getLine());
- return json_fail("数据更新失败");
- }
- return json_success('数据更新成功');
- }
- /**
- * @Desc 会员关联设备列表
- * @Author Gorden
- * @Date 2024/4/7 9:52
- *
- * @param $id
- * @return \support\Response
- */
- public static function deviceList($id)
- {
- $family = Family::where('join_family_creator_member_id', $id)->get()->toArray();
- $familyMemberIds = '';
- if ($family) {
- $familyIds = array_column($family, 'family_id');
- $familyMember = FamilyMember::whereIn('join_family_id', $familyIds)->get()->toArray();
- $familyMemberIds = array_column($familyMember, 'join_family_member_id');
- }
- $rows = MemberDevice::leftJoin('device', 'device.device_id', '=', 'member_device.join_member_device_id')
- ->leftJoin('member', 'member.member_id', '=', 'member_device.join_device_member_id')
- ->leftJoin('family_member', 'family_member.join_family_member_id', '=', 'member_device.join_device_member_id')
- ->select('device.device_category', 'device.device_name', 'device.device_type', 'member.member_mobile', 'member_device.*', 'family_member.family_member_name')
- ->when(!empty($familyMemberIds), function ($query) use ($familyMemberIds) {
- $query->whereIn('member_device.join_device_master_member_id', $familyMemberIds);
- })
- ->when(empty($familyMemberIds), function ($query) use ($id) {
- $query->where('member_device.join_device_master_member_id', $id);
- })->orderBy('member_device_addtimes', 'desc')
- ->get()
- ->toArray();
- return json_success('', ['rows' => $rows]);
- }
- /**
- * @Desc 绑定设备
- * @Author Gorden
- * @Date 2024/4/7 10:27
- *
- * @param Request $request
- * @return \support\Response
- */
- public static function addDevice(Request $request)
- {
- $params = $request->post();
- Db::beginTransaction();
- try {
- $data = [
- 'join_device_member_id' => $params['join_device_member_id'] ?? '',
- 'join_device_master_member_id' => $params['join_device_master_member_id'],
- 'join_member_device_id' => $params['join_member_device_id'],
- 'member_device_status' => $params['member_device_status'],
- 'member_device_key' => $params['member_device_key'] ?? '',
- 'member_device_config_json' => !empty($params['member_device_config_json']) ? $params['member_device_config_json'] : null,
- 'member_device_remark' => $params['member_device_remark'] ?? null,
- 'member_device_addtimes' => time(),
- ];
- MemberDevice::insert($data);
- $device = Device::where('device_id', $params['join_member_device_id'])->whereIn('device_status', ['PROCESSING', 'PENDING'])->first();
- // 激活设备
- if (!$device) {
- Db::rollBack();
- return json_fail('当前设备不是可激活状态');
- }
- $device->device_status = 'ACTIVED';
- $device->save();
- Device::where('device_id', $params['join_member_device_id'])->update(['device_status' => 'ACTIVED']);
- _syslog("绑定设备", "用户【" . ($params['join_device_member_id'] ?? $params['join_device_master_member_id']) . '】,绑定设备【' . $device->device_name . '】');
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- dump($e->getMessage());
- return json_fail('绑定失败');
- }
- return json_success('绑定成功');
- }
- public static function updateDevice(Request $request)
- {
- $params = $request->post();
- Db::beginTransaction();
- try {
- $data = [
- 'member_device_status' => $params['member_device_status'],
- 'member_device_key' => $params['member_device_key'],
- 'join_device_member_id' => $params['join_device_member_id'],
- 'member_device_config_json' => !empty($params['member_device_config_json']) ? $params['member_device_config_json'] : null,
- 'member_device_remark' => $params['member_device_remark'] ?? null,
- ];
- MemberDevice::where('member_device_id', $request->post('member_device_id'))->update($data);
- $device = Device::where('device_id', $params['join_member_device_id'])->first();
- if ($device->device_status != $params['member_device_status']) {
- $device->device_status = $params['member_device_status'];
- $device->save();
- }
- // Device::where('device_id', $params['join_member_device_id'])->update(['device_status' => $params['member_device_status']]);
- Db::commit();
- _syslog("更新绑定设备", "用户【" . ($params['join_device_member_id'] == "" ? $params['join_device_member_id'] : $params['join_device_master_member_id']) . '】,绑定设备【' . $device->device_name . '】');
- } catch (\Exception $e) {
- Db::rollBack();
- dump($e->getMessage());
- return json_fail('绑定更新失败');
- }
- return json_success('绑定更新成功');
- }
- public static function deleteDevice(Request $request)
- {
- try {
- Db::beginTransaction();
- $memberDevice = MemberDevice::where('member_device_id', $request->post('member_device_id'))->first();
- if (!$memberDevice) {
- return json_fail('数据不存在');
- }
- $device = Device::where('device_id', $memberDevice->join_member_device_id)->first();
- $device->device_status = "DISABLED";
- $device->save();
- // Device::where('device_id', $memberDevice->join_member_device_id)->update(['device_status' => 'DISABLED']);
- $memberDevice->delete();
- Db::commit();
- _syslog("解除绑定设备", "用户【" . ($memberDevice->join_device_member_id == "" ? $memberDevice->join_device_member_id : $memberDevice->join_device_master_member_id) . '】,解除绑定设备【' . $device->device_name . '】');
- return json_success('解除绑定成功');
- } catch (\Exception $e) {
- Db::rollBack();
- return json_fail('绑定失败');
- }
- }
- /**
- * 手动创建会员
- */
- public static function createMember($params)
- {
- $memberId = $params['member_id'] ?? '';
- if (!$memberId) {
- throw new BusinessException("参数异常");
- }
- // 主表
- $memberData = [
- 'member_id' => $memberId,
- 'member_is_owner' => 'N',
- 'member_classify' => 'MEMBER',
- 'member_status' => 'ACTIVED',
- 'member_mobile' => $params['mobile'],
- 'member_invite_code' => self::generateInviteCode(),
- 'member_extend_json' => json_encode(['come_from' => 'SYSTEM']),
- 'member_addtimes' => time()
- ];
- Member::insert($memberData);
- // 账户表
- $accountData = [
- 'join_account_member_id' => $memberId,
- 'member_account_classify' => 'POINTS',
- 'member_account_status' => 'ACTIVED',
- 'member_account_category' => 'NORMAL',
- 'member_account_nbr' => $memberId . '-POINTS',
- 'member_account_name' => '积分账户',
- 'member_account_addtimes' => time()
- ];
- // 积分账户
- MemberAccount::insert($accountData);
- $accountData['member_account_classify'] = 'CASH';
- $accountData['member_account_nbr'] = $memberId . '-CASH';
- $accountData['member_account_name'] = '余额账户';
- // 现金/余额账户
- MemberAccount::insert($accountData);
- // info
- $infoData = [
- 'join_info_member_id' => $memberId,
- 'member_info_nickname' => $params['username']
- ];
- MemberInfo::insert($infoData);
- }
- private static function generateMemberId()
- {
- $id = SysSerial::getSerial();
- return "MR" . date('ymdHi') . random_string(4, 'up');
- }
- public static function getMemberName($mobile, $certName, $nickname)
- {
- $name = '';
- if (!empty($certName)) {
- $name = $certName;
- } elseif (!empty($nickname)) {
- $name = $nickname;
- }
- if (!empty($name) && !empty($mobile)) {
- $name .= '-' . $mobile;
- } elseif (!empty($mobile)) {
- $name = $mobile;
- }
- return $name;
- }
- public static function getMemberCertName($mobile, $certName, $nickname)
- {
- $name = '';
- if (!empty($certName)) {
- $name = $certName;
- }
- if (!empty($name) && !empty($mobile)) {
- $name .= '-' . $mobile;
- } elseif (!empty($mobile)) {
- $name = $mobile;
- }
- return $name;
- }
- public static function getMemberNickname($mobile)
- {
- if (empty($mobile)) {
- return '';
- }
- return substr($mobile, -4, 4) . '会员';
- }
- public static function getMemberNameByMemberId($memberId)
- {
- $member = Member::with([
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- },
- 'info' => function ($query) {
- $query->select('join_info_member_id', 'member_info_nickname');
- },
- ]
- )->where('member_id', $memberId)
- ->first();
- if (empty($member)) {
- return;
- }
- $member = $member->toArray();
- $mobile = $certName = $nickname = '';
- if (!empty($member['member_mobile'])) {
- $mobile = $member['member_mobile'];
- }
- if (!empty($member['cert']) && !empty($member['cert']['member_cert_name'])) {
- $certName = $member['cert']['member_cert_name'];
- }
- if (!empty($member['info']) && !empty($member['info']['member_info_nickname'])) {
- $nickname = $member['info']['member_info_nickname'];
- }
- return self::getMemberName($mobile, $certName, $nickname);
- }
- /**
- * @Desc 生成推荐码
- * @Author Gorden
- * @Date 2024/9/6 9:05
- *
- * @return string
- */
- public static function generateInviteCode()
- {
- $code = random_string(8, 'number');
- if (Member::where('member_invite_code', $code)->exists()) {
- return self::generateInviteCode();
- } else {
- return $code;
- }
- }
- public static function getAvatarUrl($url)
- {
- if (substr($url, 0, 1) == '.' || substr($url, 0, 1) == '/' || empty($url)) {
- $url = "https://img.wanyuewellness.com.cn/images/avatar_default.png";
- }
- return $url;
- }
- /**
- * @Desc 获取昵称
- * @Author Gorden
- * @Date 2024/10/23 11:50
- *
- * @param $nickname
- * @param $mobile
- * @return mixed|string
- */
- public static function getNickname($nickname, $mobile)
- {
- if (!empty($nickname)) {
- return $nickname;
- } else if (!empty($mobile)) {
- return substr($mobile, -4, 4) . '会员';
- } else {
- return '';
- }
- }
- public static function getRoleName($roleId)
- {
- if (empty($roleId)) {
- return '';
- }
- return MemberRole::where('member_role_id', $roleId)->value('member_role_name');
- }
- /**
- * @Desc 获取身份-合伙人,推荐官
- * @Author Gorden
- * @Date 2024/9/28 13:41
- *
- * @param $isPartner
- * @param $isReferrer
- * @return string
- */
- public static function getIdentity($isPartner, $isReferrer, $isFranchisee)
- {
- if ($isPartner == 'Y') {
- return "PARTNER";
- } elseif ($isReferrer == 'Y') {
- return "REFERRER";
- } elseif ($isFranchisee == 'Y') {
- return "FRANCHISEE";
- } else {
- return 'NON';
- }
- }
- /**
- * @Desc 会员合伙人过期
- * @Author Gorden
- * @Date 2024/10/10 9:50
- *
- * @return void
- */
- public static function partnerExpired()
- {
- $members = Member::where('member_is_partner', 'Y')->get()->toArray();
- foreach ($members as $member) {
- $partnerJson = ['member_id' => $member['member_id']];
- if (!empty($member['member_partner_json'])) {
- $partnerJson = json_decode($member['member_partner_json'], true);
- }
- if (isset($partnerJson['duedate'])) {
- $duedateUnix = strtotime($partnerJson['duedate'] . ' 23:59:59');
- if ($duedateUnix > time()) {
- continue;
- }
- }
- Member::where('member_id', $member['member_id'])->update(['member_is_partner' => 'N', 'member_partner_json' => '[]']);
- _syslog("会员合伙人过期", "取消身份", false, $partnerJson, 1001);
- Log::info("会员【" . $member['member_id'] . '】会员合伙人身份已过期', $partnerJson);
- }
- }
- /**
- * @Desc 康养推荐官过期
- * @Author Gorden
- * @Date 2024/10/10 10:14
- *
- * @return void
- */
- public static function referrerExpired()
- {
- $members = Member::where('member_is_referrer', 'Y')->get()->toArray();
- foreach ($members as $member) {
- $referrerJson = ['member_id' => $member['member_id']];
- if (!empty($member['member_referrer_json'])) {
- $referrerJson = json_decode($member['member_referrer_json'], true);
- }
- if (isset($referrerJson['duedate'])) {
- $duedateUnix = strtotime($referrerJson['duedate'] . ' 23:59:59');
- if ($duedateUnix > time()) {
- continue;
- }
- }
- Member::where('member_id', $member['member_id'])->update(['member_is_referrer' => 'N', 'member_referrer_json' => '[]']);
- _syslog("康养推荐官过期", "取消身份", false, $referrerJson, 1001);
- Log::info("会员【" . $member['member_id'] . '】康养推荐官身份已过期', $referrerJson);
- }
- }
- /**
- * @Desc 会员等级变更计划任务
- * @Author Gorden
- * @Date 2024/10/16 14:46
- *
- * @return void
- */
- public static function roleExpired()
- {
- $members = Member::where('join_member_role_id', '<>', '')->get()->toArray();
- foreach ($members as $member) {
- if (empty($member['member_role_begintime'])) {
- continue;
- }
- $endDateTime = date('Y-m-d 23:59:59', strtotime($member['member_role_begintime'] . ' +364 days'));
- if (strtotime($endDateTime) > time()) {
- continue;
- }
- $memberUpdate = [
- 'join_member_role_id' => '',
- 'member_role_begintime' => '',
- 'member_role_config_json' => '[]'
- ];
- if (!empty($member['member_role_config_json'])) {
- $roleConfigJson = json_decode($member['member_role_config_json'], true);
- if (!empty($roleConfigJson['next'])) {
- $memberUpdate['join_member_role_id'] = $roleConfigJson['next'][0]['member_role_id'];
- $memberUpdate['member_role_begintime'] = $roleConfigJson['next'][0]['member_role_begintime'];
- unset($roleConfigJson['next'][0]);
- $memberUpdate['member_role_config_json'] = json_encode($roleConfigJson);
- }
- }
- Member::where('member_id', $member['member_id'])->update($memberUpdate);
- Log::info("会员过期", ['member_id' => $member['member_id'], 'role_id' => $member['join_member_role_id']]);
- }
- }
- /**
- * @Desc 加盟合伙人过期
- * @Author Gorden
- * @Date 2024/11/13 8:48
- *
- * @return void
- */
- public static function franchiseeExpired()
- {
- $members = Member::where('member_is_franchisee', 'Y')->get()->toArray();
- foreach ($members as $member) {
- $franchiseeJson = ['member_id' => $member['member_id']];
- if (!empty($member['member_franchisee_json'])) {
- $franchiseeJson = json_decode($member['member_franchisee_json'], true);
- }
- if (isset($franchiseeJson['duedate'])) {
- $duedateUnix = strtotime($franchiseeJson['duedate'] . ' 23:59:59');
- if ($duedateUnix > time()) {
- continue;
- }
- }
- Member::where('member_id', $member['member_id'])->update(['member_is_franchisee' => 'N', 'member_franchisee_json' => '[]']);
- _syslog("加盟合伙人过期", "取消身份", false, $franchiseeJson, 1001);
- Log::info("会员【" . $member['member_id'] . '】加盟合伙人身份已过期', $franchiseeJson);
- }
- }
- /**
- * @Desc 加盟合伙人每年发20%
- * @Author Gorden
- * @Date 2024/11/13 9:16
- *
- * @return void
- */
- public static function franchiseeAdded()
- {
- try {
- $members = Member::where('member_is_franchisee', 'Y')->get()->toArray();
- foreach ($members as $member) {
- $franchiseeJson = [];
- if (!empty($member['member_franchisee_json'])) {
- $franchiseeJson = json_decode($member['member_franchisee_json'], true);
- }
- if (isset($franchiseeJson['datetime'])) {
- if (date('Ymd', strtotime($franchiseeJson['datetime'])) == date('Ymd')) {
- continue;
- }
- }
- if (isset($franchiseeJson['duedate'])) {
- $duedateUnix = strtotime($franchiseeJson['duedate']);
- $todayUnix = strtotime(date('Y-m-d'));
- if (in_array(($duedateUnix - $todayUnix) / (3600 * 24 * 365), [1, 2, 3, 4])) {
- $payDetail = PayDetail::where('join_pay_member_id', $member['member_id'])
- ->where('join_pay_order_id', 'FRANCHISEE')
- ->orderBy('pay_addtimes', 'DESC')
- ->first();
- if (date('Ymd') == date('Ymd', strtotime($payDetail->pay_addtimes))) {
- continue;
- }
- $payObjectJson = [];
- if (!empty($payDetail->join_pay_object_json)) {
- $payObjectJson = json_decode($payDetail->join_pay_object_json, true);
- }
- // 创建赠送记录
- PayDetail::insert([
- 'join_pay_member_id' => $payDetail->join_pay_member_id,
- 'join_pay_order_id' => $payDetail->join_pay_order_id,
- 'join_pay_object_json' => $payDetail->join_pay_object_json,
- 'pay_status' => $payDetail->pay_status,
- 'pay_category' => $payDetail->pay_category,
- 'pay_amount' => $payDetail->pay_amount,
- 'pay_paytimes' => date('Y-m-d H:i:s'),
- 'pay_prepayid' => $payDetail->pay_prepayid,
- 'pay_addtimes' => time()
- ]);
- // 赠送加入账户余额
- $account = MemberAccount::where('join_account_member_id', $member['member_id'])
- ->where('member_account_classify', 'CASH')
- ->first();
- $account->member_account_income = $account->member_account_income + $payObjectJson['recharge_config']['nbr'];
- $account->member_account_surplus = $account->member_account_surplus + $payObjectJson['recharge_config']['nbr'];
- $account->save();
- Log::info("加盟合伙人赠送成功");
- _syslog("加盟合伙人", "赠送20%成功", false, ['member_id' => $member['member_id']], 1001);
- }
- }
- }
- } catch (\Exception $e) {
- Log::error("加盟合伙人赠送失败", ['member_id' => $member['member_id'], 'msg' => $e->getMessage()]);
- _syslog("加盟合伙人", "赠送20%失败", false, ['member_id' => $member['member_id'], 'msg' => $e->getMessage()], 1001);
- }
- }
- }
|