MemberService.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  1. <?php
  2. namespace app\admin\service\member;
  3. use app\common\Tree;
  4. use app\model\ClientPoints;
  5. use app\model\CouponDetail;
  6. use app\model\Device;
  7. use app\model\Family;
  8. use app\model\FamilyMember;
  9. use app\model\Goods;
  10. use app\model\Member;
  11. use app\model\MemberAccount;
  12. use app\model\MemberCert;
  13. use app\model\MemberDevice;
  14. use app\model\MemberInfo;
  15. use app\model\Order;
  16. use app\model\OrderSheet;
  17. use app\model\PayDetail;
  18. use app\model\SysCategory;
  19. use app\model\SysDept;
  20. use app\model\SysSerial;
  21. use app\model\SysUser;
  22. use support\Db;
  23. use support\exception\BusinessException;
  24. use support\Request;
  25. use support\Response;
  26. class MemberService
  27. {
  28. public static function list(Request $request)
  29. {
  30. $page = $request->get('page', 1);
  31. $pageSize = $request->get('pageSize', 10);
  32. $name = $request->get('name', '');
  33. $nickname = $request->get('nickname', '');
  34. $mobile = $request->get('mobile', '');
  35. $level = $request->get('level', '');
  36. $isAuth = $request->get('is_auth', '');
  37. $addtime = $request->get('member_addtimes', []);
  38. $type = $request->get('type', '');
  39. $status = $request->get('member_status', '');
  40. $rows = Member::with([
  41. 'account' => function ($query) {
  42. $query->where('member_account_status', 'ACTIVED');
  43. }
  44. ])
  45. ->where('member_is_owner', 'N')
  46. ->where('member_mobile', '<>', '0000')
  47. ->leftJoin('member_info', 'member_info.join_info_member_id', 'member.member_id')
  48. ->leftJoin('member_cert', 'member_cert.join_cert_member_id', 'member.member_id')
  49. // ->leftjoin('member_account', 'member.member_id', '=', 'member_account.join_account_member_id')
  50. ->leftJoin('member_role', 'member_role.member_role_id', 'member.join_member_role_id')
  51. // ->where('member_account.member_account_classify', 'CASH')
  52. ->when($name != '', function ($query) use ($name) {
  53. $query->where('member_cert.member_cert_name', 'like', '%' . $name . '%');
  54. })->when($mobile != '', function ($query) use ($mobile) {
  55. $query->where('member.member_mobile', 'like', '%' . $mobile . '%');
  56. })->when($level != '', function ($query) use ($level) {
  57. if ($level == 'other') {
  58. $query->where('member.join_member_role_id', NULL)->orWhere('member.join_member_role_id', '');
  59. } else if ($level == 'VIP') {
  60. $query->where('member.member_is_vip', 'Y');
  61. } else {
  62. $query->where('member_role.member_role_id', $level);
  63. }
  64. })->when($isAuth != '', function ($query) use ($isAuth) {
  65. if ($isAuth == 'Y') {
  66. $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', '<>', '');
  67. } else {
  68. $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', '');
  69. }
  70. })->when(!empty($addtime), function ($query) use ($addtime) {
  71. $addtime[0] = strtotime($addtime[0]);
  72. $addtime[1] = strtotime($addtime[1]);
  73. $query->whereBetween('member.member_addtimes', $addtime);
  74. })->when(!empty($type), function ($query) use ($type) {
  75. if ($type == 'todayAdd') {
  76. $addtime[0] = strtotime(date('Y-m-d') . ' 00:00:00');
  77. $addtime[1] = strtotime(date('Y-m-d') . ' 23:59:59');
  78. } else if ($type == 'monthAdd') {
  79. $addtime[0] = strtotime(date('Y-m-01') . ' 00:00:00');
  80. $addtime[1] = strtotime(date('Y-m-t') . ' 23:59:59');
  81. }
  82. $query->whereBetween('member.member_addtimes', $addtime);
  83. })->when(!empty($nickname), function ($query) use ($nickname) {
  84. $query->where(function ($query2) use ($nickname) {
  85. $query2->where('member_info.member_info_nickname', 'like', '%' . $nickname . '%')->orWhere('member.member_mobile', 'like', '%' . $nickname . '%');
  86. });
  87. })->when(!empty($status), function ($query) use ($status) {
  88. $query->where('member_status', $status);
  89. })
  90. ->select('member_id', 'member_is_vip', 'member_is_owner','member_is_partner','member_is_referrer', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
  91. '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',
  92. 'member_role.member_role_id', 'member_role.member_role_name',
  93. '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'
  94. // 'member_account.member_account_surplus'
  95. );
  96. // 总条数
  97. $total = $rows->count('member_id');
  98. $rows = $rows->orderBy('member_addtimes', 'DESC')
  99. ->forPage($page, $pageSize)
  100. ->get()
  101. ->toArray();
  102. foreach ($rows as &$row) {
  103. $row['coupon_count'] = CouponDetail::where('join_coupon_detail_member_id', $row['member_id'])->count();
  104. $row['member_mobile'] = substr($row['member_mobile'], 0, 3) . '****' . substr($row['member_mobile'], 7);
  105. $row['info'] = [
  106. 'member_info_nickname' => !empty($row['member_info_nickname']) ? $row['member_info_nickname'] : substr($row['member_mobile'], -4, 4) . '会员',
  107. 'member_info_headimg' => !empty($row['member_info_headimg']) ? $row['member_info_headimg'] : '',
  108. 'member_info_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
  109. 'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
  110. 'member_info_service' => !empty($row['member_info_service']) ? $row['member_info_service'] : '',
  111. 'member_info_city' => !empty($row['member_info_city']) ? explode('-', $row['member_info_city']) : '',
  112. 'member_info_address' => !empty($row['member_info_address']) ? $row['member_info_address'] : '',
  113. 'member_info_birthday' => !empty($row['member_info_birthday']) ? $row['member_info_birthday'] : '',
  114. 'member_info_gender' => !empty($row['member_info_gender']) ? $row['member_info_gender'] : '',
  115. ];
  116. if (substr($row['info']['member_info_headimg'], 0, 2) == '..') {
  117. $row['info']['member_info_headimg'] = '';
  118. }
  119. if (!empty($row['info']['member_info_address']) && in_array($row['info']['member_info_address'], ['请选择', '省-市-区'])) {
  120. $row['info']['member_info_address'] = '';
  121. }
  122. $row['cert'] = [
  123. 'member_cert_birth' => $row['member_cert_birth'],
  124. 'member_cert_gender' => $row['member_cert_gender'],
  125. 'member_cert_name' => $row['member_cert_name'],
  126. 'member_cert_nbr' => $row['member_cert_nbr'],
  127. 'member_cert_province' => !empty($row['member_cert_province']) && is_json($row['member_cert_province']) ? json_decode($row['member_cert_province']) : '',
  128. 'member_cert_addr' => $row['member_cert_addr'],
  129. 'member_cert_face' => !empty($row['member_cert_face']) ? getenv('STORAGE_DOMAIN') . $row['member_cert_face'] : '',
  130. 'member_cert_photo' => !empty($row['member_cert_photo']) ? getenv('STORAGE_DOMAIN') . $row['member_cert_photo'] : '',
  131. 'member_cert_nation' => $row['member_cert_nation'],
  132. ];
  133. $account = [];
  134. if (!empty($row['account'])) {
  135. foreach ($row['account'] as $item) {
  136. if ($item['member_account_classify'] == 'WELFARE') {
  137. $account['welfare'] = [
  138. 'member_account_name' => $item['member_account_name'],
  139. 'member_account_income' => $item['member_account_income'],
  140. 'member_account_expend' => $item['member_account_expend'],
  141. 'member_account_surplus' => $item['member_account_surplus'],
  142. 'member_account_added' => $item['member_account_added'],
  143. ];
  144. } else if ($item['member_account_classify'] == 'POINTS') {
  145. $account['points'] = [
  146. 'member_account_name' => $item['member_account_name'],
  147. 'member_account_income' => $item['member_account_income'],
  148. 'member_account_expend' => $item['member_account_expend'],
  149. 'member_account_surplus' => $item['member_account_surplus'],
  150. 'member_account_added' => $item['member_account_added'],
  151. ];
  152. } else if ($item['member_account_classify'] == 'CASH') {
  153. $account['cash'] = [
  154. 'member_account_name' => $item['member_account_name'],
  155. 'member_account_income' => $item['member_account_income'],
  156. 'member_account_expend' => $item['member_account_expend'],
  157. 'member_account_surplus' => $item['member_account_surplus'],
  158. 'member_account_added' => $item['member_account_added'],
  159. ];
  160. } else if ($item['member_account_classify'] == 'CARD') {
  161. $account['card'] = [
  162. 'member_account_name' => $item['member_account_name'],
  163. 'member_account_income' => $item['member_account_income'],
  164. 'member_account_expend' => $item['member_account_expend'],
  165. 'member_account_surplus' => $item['member_account_surplus'],
  166. 'member_account_added' => $item['member_account_added'],
  167. ];
  168. } else if ($item['member_account_classify'] == 'VIP') {
  169. $account['vip'] = [
  170. 'member_account_name' => $item['member_account_name'],
  171. 'member_account_income' => $item['member_account_income'],
  172. 'member_account_expend' => $item['member_account_expend'],
  173. 'member_account_surplus' => $item['member_account_surplus'],
  174. 'member_account_added' => $item['member_account_added'],
  175. ];
  176. }
  177. }
  178. }
  179. $row['account'] = $account;
  180. $row['is_auth'] = "未认证";
  181. if (!empty($row['member_cert_nbr']) && !empty($row['member_cert_name'])) {
  182. $row['is_auth'] = "已认证";
  183. }
  184. $row['source'] = "APP";
  185. $row['belong'] = [];
  186. $row['referee'] = [];
  187. if (!empty($row['member_extend_json'])) {
  188. $extendJson = json_decode($row['member_extend_json'], true);
  189. if (isset($extendJson['come_from'])) {
  190. $row['source'] = $extendJson['come_from'] ?? '';
  191. }
  192. if (isset($extendJson['belong'])) {
  193. $user = SysUser::where('user_id', $extendJson['belong']['user_id'])->select('user_name', 'user_mobile')->first();
  194. if ($user) {
  195. $row['belong']['user_id'] = $extendJson['belong']['user_id'];
  196. $row['belong']['username'] = $user->user_name;
  197. $row['belong']['user_mobile'] = $user->user_mobile;
  198. }
  199. $row['belong']['deptName'] = SysDept::where('dept_id', $extendJson['belong']['premises'])->value('dept_name');
  200. }
  201. if (isset($extendJson['referee'])) {
  202. foreach ($extendJson['referee'] as $key => $referee) {
  203. $row['referee'][] = [
  204. 'name' => $referee,
  205. 'time' => $key
  206. ];
  207. }
  208. }
  209. }
  210. // 粉丝
  211. $fans1 = Member::where('join_invite_member_id', $row['member_id'])
  212. ->select('member_id')
  213. ->get()
  214. ->toArray();
  215. $fans1Ids = array_column($fans1, 'member_id');
  216. $fans2Count = Member::whereIn('join_invite_member_id', $fans1Ids)
  217. ->count();
  218. $row['fans_total'] = count($fans1) + $fans2Count;
  219. }
  220. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  221. }
  222. public static function exportMember(Request $request)
  223. {
  224. $memberIds = $request->get('member_id', '');
  225. $name = $request->get('name', '');
  226. $mobile = $request->get('mobile', '');
  227. $level = $request->get('level', '');
  228. $isAuth = $request->get('is_auth', '');
  229. $addtime = $request->get('member_addtimes', []);
  230. $rows = Member::with('account')
  231. ->where('member_is_owner', 'N')
  232. ->where('member_mobile', '<>', '0000')
  233. ->leftJoin('member_info', 'member_info.join_info_member_id', 'member.member_id')
  234. ->leftJoin('member_cert', 'member_cert.join_cert_member_id', 'member.member_id')
  235. // ->leftjoin('member_account', 'member.member_id', '=', 'member_account.join_account_member_id')
  236. ->leftJoin('member_role', 'member_role.member_role_id', 'member.join_member_role_id')
  237. // ->where('member_account.member_account_classify', 'CASH')
  238. ->when($memberIds != '', function ($query) use ($memberIds) {
  239. $query->whereIn('member.member_id', $memberIds);
  240. })->when($name != '', function ($query) use ($name) {
  241. $query->where('member_cert.member_cert_name', 'like', '%' . $name . '%');
  242. })->when($mobile != '', function ($query) use ($mobile) {
  243. $query->where('member.member_mobile', 'like', '%' . $mobile . '%');
  244. })->when($level != '', function ($query) use ($level) {
  245. if ($level == 'other') {
  246. $query->where('member.join_member_role_id', NULL)->orWhere('member.join_member_role_id', '');
  247. } else {
  248. $query->where('member_role.member_role_id', $level);
  249. }
  250. })->when($isAuth != '', function ($query) use ($isAuth) {
  251. if ($isAuth == 'Y') {
  252. $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', '<>', '');
  253. } else {
  254. $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', '');
  255. }
  256. })->when(!empty($addtime), function ($query) use ($addtime) {
  257. $addtime[0] = strtotime($addtime[0]);
  258. $addtime[1] = strtotime($addtime[1]);
  259. $query->whereBetween('member.member_addtimes', $addtime);
  260. })->select('member_id', 'member_is_owner', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
  261. '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',
  262. 'member_role.member_role_id', 'member_role.member_role_name',
  263. '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',
  264. // 'member_account.member_account_surplus'
  265. )->orderBy('member_addtimes', 'DESC')
  266. ->get()
  267. ->toArray();
  268. $exportData = [];
  269. foreach ($rows as $row) {
  270. $row['info'] = [
  271. 'member_info_nickname' => !empty($row['member_info_nickname']) ? $row['member_info_nickname'] : substr($row['member_mobile'], -4, 4) . '会员',
  272. 'member_info_headimg' => !empty($row['member_info_headimg']) ? $row['member_info_headimg'] : '',
  273. 'member_info_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
  274. 'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
  275. 'member_info_service' => !empty($row['member_info_service']) ? $row['member_info_service'] : ''
  276. ];
  277. $row['cert'] = [
  278. 'member_cert_name' => $row['member_cert_name'],
  279. ];
  280. $account = [];
  281. if (!empty($row['account'])) {
  282. foreach ($row['account'] as $item) {
  283. if ($item['member_account_classify'] == 'POINTS') {
  284. $account['points'] = [
  285. 'member_account_surplus' => $item['member_account_surplus'],
  286. 'member_account_added' => $item['member_account_added'],
  287. ];
  288. } else if ($item['member_account_classify'] == 'CASH') {
  289. $account['cash'] = [
  290. 'member_account_surplus' => $item['member_account_surplus'],
  291. 'member_account_added' => $item['member_account_added'],
  292. ];
  293. } else if ($item['member_account_classify'] == 'CARD') {
  294. $account['card'] = [
  295. 'member_account_surplus' => $item['member_account_surplus'],
  296. 'member_account_added' => $item['member_account_added'],
  297. ];
  298. }
  299. }
  300. }
  301. // $row['account'] = $account;
  302. $row['is_auth'] = "未认证";
  303. if (!empty($row['member_cert_nbr']) && !empty($row['member_cert_name'])) {
  304. $row['is_auth'] = "已认证";
  305. }
  306. $row['source'] = "APP";
  307. if (!empty($row['member_extend_json'])) {
  308. $extendJson = json_decode($row['member_extend_json'], true);
  309. if (isset($extendJson['come_from'])) {
  310. $row['source'] = $extendJson['come_from'] ?? '';
  311. }
  312. }
  313. $sourceStr = ['APP' => "APP", 'CUSTOMER' => "客户管理", 'SYSTEM' => "后台"];
  314. $exportData[] = [
  315. 'member_id' => $row['member_id'],
  316. 'member_info_nickname' => $row['info']['member_info_nickname'] ?? '',
  317. 'member_mobile' => $row['member_mobile'] ?? '',
  318. 'member_cert_name' => $row['cert']['member_cert_name'] ?? '',
  319. 'source' => in_array($row['source'], $sourceStr) ? $sourceStr[$row['source']] : 'APP',
  320. 'cash' => isset($account['cash']) ? $account['cash']['member_account_surplus'] + $account['cash']['member_account_added'] : 0,
  321. 'points' => isset($account['points']) ? $account['points']['member_account_surplus'] + $account['points']['member_account_added'] : 0,
  322. 'is_auth' => $row['is_auth'],
  323. 'level' => $row['member_role_name'] ?? '普通会员',
  324. 'member_addtimes' => $row['member_addtimes'],
  325. 'member_info_referee' => $row['info']['member_info_referee'] ?? '',
  326. 'member_info_business' => $row['info']['member_info_business'] ?? '',
  327. 'member_info_service' => $row['info']['member_info_service'] ?? '',
  328. ];
  329. }
  330. return json_success('', $exportData);
  331. }
  332. public static function info($memberId)
  333. {
  334. $member = Member::with('cert', 'info')
  335. ->where('member_id', $memberId)
  336. ->first();
  337. if (!$member) {
  338. return json_fail('查询错误');
  339. }
  340. $member = $member->toArray();
  341. $member['info'] = [
  342. 'member_info_nickname' => !empty($member['info']) && !empty($member['info']['member_info_nickname']) ? $member['info']['member_info_nickname'] : substr($member['member_mobile'], -4, 4) . '会员',
  343. 'member_info_headimg' => !empty($member['info']) && !empty($member['info']['member_info_headimg']) ? $member['info']['member_info_headimg'] : '',
  344. 'member_info_referee' => !empty($member['info']) && !empty($member['info']['member_info_referee']) ? $member['info']['member_info_referee'] : '',
  345. 'member_info_business' => !empty($member['info']) && !empty($member['info']['member_info_business']) ? $member['info']['member_info_business'] : '',
  346. 'member_info_service' => !empty($member['info']) && !empty($member['info']['member_info_service']) ? $member['info']['member_info_service'] : '',
  347. 'member_info_city' => !empty($member['info']) && !empty($member['info']['member_info_city']) ? explode('-', $member['info']['member_info_city']) : '',
  348. 'member_info_address' => !empty($member['info']) && !empty($member['info']['member_info_address']) ? $member['info']['member_info_address'] : '',
  349. 'member_info_gender' => !empty($member['info']) && !empty($member['info']['member_info_gender']) ? $member['info']['member_info_gender'] : '',
  350. 'member_info_birthday' => !empty($member['info']) && !empty($member['info']['member_info_birthday']) ? $member['info']['member_info_birthday'] : '',
  351. ];
  352. if (!empty($member['info']['member_info_address']) && in_array($member['info']['member_info_address'], ['请选择', '省-市-区'])) {
  353. $member['info']['member_info_address'] = '';
  354. }
  355. $member['cert'] = [
  356. 'member_cert_birth' => $member['cert']['member_cert_birth'] ?? '',
  357. 'member_cert_gender' => $member['cert']['member_cert_gender'] ?? '',
  358. 'member_cert_name' => $member['cert']['member_cert_name'] ?? '',
  359. 'member_cert_nbr' => $member['cert']['member_cert_nbr'] ?? '',
  360. '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']) : '',
  361. 'member_cert_addr' => $member['cert']['member_cert_addr'] ?? '',
  362. 'member_cert_face' => !empty($member['cert']) && !empty($member['cert']['member_cert_face']) ? getenv('STORAGE_DOMAIN') . $member['cert']['member_cert_face'] : '',
  363. 'member_cert_photo' => !empty($member['cert']) && !empty($member['cert']['member_cert_photo']) ? getenv('STORAGE_DOMAIN') . $member['cert']['member_cert_photo'] : '',
  364. 'member_cert_nation' => $member['cert']['member_cert_nation'] ?? '',
  365. 'member_cert_addtimes' => $member['cert']['member_cert_addtimes'] ?? '',
  366. ];
  367. if (!empty($member['cert']['member_cert_addtimes'])) {
  368. $member['cert']['member_cert_addtimes'] = date('Y-m-d', $member['cert']['member_cert_addtimes']);
  369. } else {
  370. $member['cert']['member_cert_addtimes'] = date('Y-m-d', strtotime($member['member_addtimes']));
  371. }
  372. if (!empty($member['join_invite_member_id'])) {
  373. $inviteMember = Member::with([
  374. 'info' => function ($query) {
  375. $query->select('join_info_member_id', 'member_info_nickname');
  376. },
  377. 'cert' => function ($query) {
  378. $query->select('join_cert_member_id', 'member_cert_name');
  379. }
  380. ])->where('member_id', $member['join_invite_member_id'])
  381. ->first();
  382. $inviteMemberName = '';
  383. if (!empty($inviteMember->cert) && !empty($inviteMember->cert->member_cert_name)) {
  384. $inviteMemberName = $inviteMember->cert->member_cert_name;
  385. } elseif (!empty($inviteMemberName->info) && !empty($inviteMemberName->info->member_info_nickname)) {
  386. $inviteMemberName = $inviteMemberName->info->member_info_nickname;
  387. }
  388. $member['invite_member'] = $inviteMemberName . (!empty($inviteMember->member_invite_code) ? '(' . $inviteMember->member_invite_code . ')' : '');
  389. }
  390. $member['is_auth'] = "未认证";
  391. if (!empty($member['cert']['member_cert_nbr']) && !empty($member['cert']['member_cert_name'])) {
  392. $member['is_auth'] = "已认证";
  393. }
  394. $member['source'] = "APP";
  395. $member['belong'] = [];
  396. $member['referee'] = [];
  397. if (!empty($member['member_extend_json'])) {
  398. $extendJson = json_decode($member['member_extend_json'], true);
  399. if (isset($extendJson['come_from'])) {
  400. $member['source'] = $extendJson['come_from'] ?? '';
  401. }
  402. if (isset($extendJson['belong'])) {
  403. $user = SysUser::where('user_id', $extendJson['belong']['user_id'])->select('user_name', 'user_mobile')->first();
  404. if ($user) {
  405. $member['belong']['user_id'] = $extendJson['belong']['user_id'];
  406. $member['belong']['username'] = $user->user_name;
  407. $member['belong']['user_mobile'] = $user->user_mobile;
  408. }
  409. $member['belong']['deptName'] = SysDept::where('dept_id', $extendJson['belong']['premises'])->value('dept_name');
  410. }
  411. if (isset($extendJson['referee'])) {
  412. foreach ($extendJson['referee'] as $key => $referee) {
  413. $member['referee'][] = [
  414. 'name' => $referee,
  415. 'time' => $key
  416. ];
  417. }
  418. }
  419. }
  420. return json_success('', $member);
  421. }
  422. /**
  423. * VIP账户明细
  424. */
  425. public static function vipInfo(Request $request)
  426. {
  427. $memberId = $request->get('member_id', '');
  428. $page = $request->get('page', 1);
  429. $pageSize = $request->get('pageSize', 20);
  430. $account = MemberAccount::where('join_account_member_id', $memberId)
  431. ->where('member_account_classify', 'VIP')
  432. ->first();
  433. if (!$account) {
  434. return json_fail('暂无数据');
  435. }
  436. $balance = $account->member_account_surplus + $account->member_account_added;
  437. $info = PayDetail::where(function ($query) use ($memberId) {
  438. $query->where('join_pay_member_id', $memberId)
  439. // ->whereIn('pay_prepayid', ['W06', 'A01'])
  440. ->where('pay_category', 'VIP')
  441. ->where('pay_status', 'SUCCESS');
  442. })->orWhere(function ($query) use ($memberId) {
  443. $query->where('join_pay_member_id', $memberId)
  444. ->where('pay_prepayid', 'like', '%VIP%')
  445. ->where('pay_status', 'SUCCESS');
  446. })->orderByDesc('pay_addtimes')
  447. ->get()
  448. ->toArray();
  449. $data = [];
  450. foreach ($info as $key => $item) {
  451. $categoryIds = [];
  452. if (!empty($item['join_pay_order_id'])) {
  453. $orderIds = Order::where('order_groupby', $item['join_pay_order_id'])->pluck('order_id');
  454. $goodsIds = OrderSheet::whereIn('join_sheet_order_id', $orderIds)->pluck('join_sheet_goods_id');
  455. $categoryIds = Goods::whereIn('goods_id', $goodsIds)->pluck('join_goods_category_id');
  456. }
  457. $categoryName = [];
  458. foreach ($categoryIds as $id) {
  459. $category = SysCategory::where('category_id', $id)->first();
  460. if (!empty($category->category_super_path)) {
  461. $path = explode('#', $category->category_super_path);
  462. $ids = array_filter($path);
  463. $categoryName[] = SysCategory::where('category_id', current($ids))->value('category_name');
  464. } else {
  465. $categoryName[] = $category->category_name;
  466. }
  467. }
  468. $item['goods_category'] = implode(',', array_unique($categoryName));
  469. if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
  470. $item['goods_category'] = '自定义金额充值';
  471. }
  472. if (in_array($item['pay_category'], ['VIP', 'REFUND'])) {
  473. $item['balance_type'] = 'add';
  474. } else {
  475. $item['balance_type'] = 'cut';
  476. }
  477. if ($key == 0 && in_array($item['pay_category'], ['VIP', 'REFUND'])) {
  478. if (!empty($item['pay_extend_json'])) {
  479. $extendJson = json_decode($item['pay_extend_json'], true);
  480. if (!isset($extendJson['added_amount'])) {
  481. $extendJson['added_amount'] = 0;
  482. }
  483. if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
  484. $data[] = [
  485. 'join_pay_member_id' => $item['join_pay_member_id'],
  486. 'pay_addtimes' => $item['pay_addtimes'],
  487. 'pay_amount' => $extendJson['added_amount'],
  488. 'pay_category' => 'ADDED',
  489. 'balance' => number_format($balance, 2, '.', ''),
  490. 'balance_type' => 'add',
  491. ];
  492. }
  493. $balance = $balance - $extendJson['added_amount'];
  494. }
  495. $item['balance'] = number_format($balance, 2, '.', '');
  496. $balance = $balance - $item['pay_amount'];
  497. $data[] = $item;
  498. continue;
  499. }
  500. if (in_array($item['pay_category'], ['VIP', 'REFUND'])) {
  501. if (!empty($item['pay_extend_json'])) {
  502. $extendJson = json_decode($item['pay_extend_json'], true);
  503. if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
  504. $data[] = [
  505. 'join_pay_member_id' => $item['join_pay_member_id'],
  506. 'pay_addtimes' => $item['pay_addtimes'],
  507. 'pay_amount' => $extendJson['added_amount'],
  508. 'pay_category' => 'ADDED',
  509. 'balance' => number_format($balance, 2, '.', ''),
  510. 'balance_type' => 'add',
  511. ];
  512. $balance = $balance - $extendJson['added_amount'];
  513. }
  514. }
  515. $item['balance'] = number_format($balance, 2, '.', '');
  516. $balance = $balance - $item['pay_amount'];
  517. } else {
  518. $item['balance'] = number_format($balance, 2, '.', '');
  519. $balance = $balance + $item['pay_amount'];
  520. }
  521. $data[] = $item;
  522. }
  523. $total = count($data);
  524. $start = ($page - 1) * $pageSize;
  525. $rows = array_slice($data, $start, $pageSize);
  526. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  527. }
  528. public static function welfareInfo(Request $request)
  529. {
  530. $memberId = $request->get('member_id', '');
  531. $page = $request->get('page', 1);
  532. $pageSize = $request->get('pageSize', 20);
  533. $account = MemberAccount::where('join_account_member_id', $memberId)
  534. ->where('member_account_classify', 'WELFARE')
  535. ->first();
  536. if (!$account) {
  537. return json_fail('暂无数据');
  538. }
  539. $balance = $account->member_account_surplus + $account->member_account_added;
  540. $info = PayDetail::where(function ($query) use ($memberId) {
  541. $query->where('join_pay_member_id', $memberId)
  542. // ->whereIn('pay_prepayid', ['W06', 'A01'])
  543. ->where('pay_category', 'RECHARGE')
  544. ->where('pay_prepayid', 'WELFARE')
  545. ->where('pay_status', 'SUCCESS');
  546. })->orWhere(function ($query) use ($memberId) {
  547. $query->where('join_pay_member_id', $memberId)
  548. ->where('pay_prepayid', 'like', '%WELFARE%')
  549. ->where('pay_status', 'SUCCESS');
  550. })->orderByDesc('pay_addtimes')
  551. ->get()
  552. ->toArray();
  553. $data = [];
  554. foreach ($info as $key => $item) {
  555. $categoryIds = [];
  556. if (!empty($item['join_pay_order_id'])) {
  557. $orderIds = Order::where('order_groupby', $item['join_pay_order_id'])->pluck('order_id');
  558. $goodsIds = OrderSheet::whereIn('join_sheet_order_id', $orderIds)->pluck('join_sheet_goods_id');
  559. $categoryIds = Goods::whereIn('goods_id', $goodsIds)->pluck('join_goods_category_id');
  560. }
  561. $categoryName = [];
  562. foreach ($categoryIds as $id) {
  563. $category = SysCategory::where('category_id', $id)->first();
  564. if (!empty($category->category_super_path)) {
  565. $path = explode('#', $category->category_super_path);
  566. $ids = array_filter($path);
  567. $categoryName[] = SysCategory::where('category_id', current($ids))->value('category_name');
  568. } else {
  569. $categoryName[] = $category->category_name;
  570. }
  571. }
  572. $item['goods_category'] = implode(',', array_unique($categoryName));
  573. if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
  574. $item['goods_category'] = '自定义金额充值';
  575. }
  576. if (in_array($item['pay_category'], ['RECHARGE', 'REFUND'])) {
  577. $item['balance_type'] = 'add';
  578. } else {
  579. $item['balance_type'] = 'cut';
  580. }
  581. if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND'])) {
  582. if (!empty($item['pay_extend_json'])) {
  583. $extendJson = json_decode($item['pay_extend_json'], true);
  584. if (!isset($extendJson['added_amount'])) {
  585. $extendJson['added_amount'] = 0;
  586. }
  587. if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
  588. $data[] = [
  589. 'join_pay_member_id' => $item['join_pay_member_id'],
  590. 'pay_addtimes' => $item['pay_addtimes'],
  591. 'pay_amount' => $extendJson['added_amount'],
  592. 'pay_category' => 'ADDED',
  593. 'balance' => number_format($balance, 2, '.', ''),
  594. 'balance_type' => 'add',
  595. ];
  596. }
  597. $balance = $balance - $extendJson['added_amount'];
  598. }
  599. $item['balance'] = number_format($balance, 2, '.', '');
  600. $balance = $balance - $item['pay_amount'];
  601. $data[] = $item;
  602. continue;
  603. }
  604. if (in_array($item['pay_category'], ['RECHARGE', 'REFUND'])) {
  605. if (!empty($item['pay_extend_json'])) {
  606. $extendJson = json_decode($item['pay_extend_json'], true);
  607. if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
  608. $data[] = [
  609. 'join_pay_member_id' => $item['join_pay_member_id'],
  610. 'pay_addtimes' => $item['pay_addtimes'],
  611. 'pay_amount' => $extendJson['added_amount'],
  612. 'pay_category' => 'ADDED',
  613. 'balance' => number_format($balance, 2, '.', ''),
  614. 'balance_type' => 'add',
  615. ];
  616. $balance = $balance - $extendJson['added_amount'];
  617. }
  618. }
  619. $item['balance'] = number_format($balance, 2, '.', '');
  620. $balance = $balance - $item['pay_amount'];
  621. } else {
  622. $item['balance'] = number_format($balance, 2, '.', '');
  623. $balance = $balance + $item['pay_amount'];
  624. }
  625. $data[] = $item;
  626. }
  627. $total = count($data);
  628. $start = ($page - 1) * $pageSize;
  629. $rows = array_slice($data, $start, $pageSize);
  630. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  631. }
  632. /**
  633. * @Desc 我的粉丝列表
  634. * @Author Gorden
  635. * @Date 2024/9/20 10:22
  636. *
  637. * @param Request $request
  638. */
  639. public static function fansList(Request $request)
  640. {
  641. $memberId = $request->get('member_id');
  642. $name = $request->get('name', '');
  643. $mobile = $request->get('mobile', '');
  644. $memberIds = [];
  645. $memberInviteIds = [];
  646. if (!empty($name)) {
  647. $memberIds = MemberCert::where('member_cert_name', 'like', '%' . $name . '%')->pluck('join_cert_member_id')->toArray();
  648. $memberInviteIds = Member::whereIn('member_id', $memberIds)->pluck('join_invite_member_id')->toArray();
  649. }
  650. if (!empty($mobile)) {
  651. $members = Member::where('member_mobile', 'like', '%' . $mobile . '%')
  652. ->select('member_id', 'join_invite_member_id')
  653. ->get()
  654. ->toArray();
  655. $memberIds2 = array_column($members, 'member_id');
  656. $memberInviteIds2 = array_column($members, 'join_invite_member_id');
  657. $memberIds = array_merge($memberIds, $memberIds2);
  658. $memberInviteIds = array_merge($memberInviteIds, $memberInviteIds2);
  659. }
  660. $fans1 = Member::with([
  661. 'info' => function ($query) {
  662. $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
  663. },
  664. 'cert' => function ($query) {
  665. $query->select('join_cert_member_id', 'member_cert_name');
  666. },
  667. 'role' => function ($query) {
  668. $query->select('member_role_id', 'member_role_name');
  669. }
  670. ])->where('join_invite_member_id', $memberId)
  671. ->when(!empty($memberIds), function ($query) use ($memberIds, $memberInviteIds) {
  672. $allSub = array_merge($memberIds, $memberInviteIds);
  673. $query->whereIn('member_id', $allSub);
  674. })
  675. ->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')
  676. ->get()
  677. ->toArray();
  678. $fans1Ids = array_column($fans1, 'id');
  679. $fans2 = Member::with([
  680. 'info' => function ($query) {
  681. $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
  682. },
  683. 'cert' => function ($query) {
  684. $query->select('join_cert_member_id', 'member_cert_name');
  685. },
  686. 'role' => function ($query) {
  687. $query->select('member_role_id', 'member_role_name');
  688. }
  689. ])->whereIn('join_invite_member_id', $fans1Ids)
  690. ->when(!empty($memberIds), function ($query) use ($memberIds) {
  691. $query->whereIn('member_id', $memberIds);
  692. })
  693. ->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')
  694. ->get()
  695. ->toArray();
  696. $fans = array_merge($fans1, $fans2);
  697. foreach ($fans as &$fan) {
  698. $memberMobile = $fan['member_mobile'] ?? '';
  699. // $memberNickname = $fan['info'] && $fan['info']['member_info_nickname'] ? $fan['info']['member_info_nickname'] : '';
  700. $memberCertName = $fan['cert'] && $fan['cert']['member_cert_name'] ? $fan['cert']['member_cert_name'] : '';
  701. $fan['member_name'] = '';
  702. if (!empty($memberCertName) && !empty($memberMobile)) {
  703. $fan['member_name'] = $memberCertName . '-' . $memberMobile;
  704. } elseif (!empty($memberCertName)) {
  705. $fan['member_name'] = $memberCertName;
  706. } elseif (!empty($memberMobile)) {
  707. $fan['member_name'] = $memberMobile;
  708. }
  709. if (!empty($fan['info']) && substr($fan['info']['member_info_headimg'], 0, 4) == 'http') {
  710. $fan['member_info_headimg'] = $fan['info']['member_info_headimg'];
  711. } else {
  712. $fan['member_info_headimg'] = 'https://img.wanyuewellness.com.cn/images/avatar_default.png';
  713. }
  714. // 等级名称
  715. $fan['role_name'] = $fan['role'] && $fan['role']['member_role_name'] ? $fan['role']['member_role_name'] : '';
  716. unset($fan['info'], $fan['cert'], $fan['role']);
  717. }
  718. $tree = new Tree($fans);
  719. return json_success('success', $tree->getTree());
  720. }
  721. /**
  722. * 格式化树
  723. * @param $items
  724. * @return Response
  725. */
  726. protected static function formatTree($items): Response
  727. {
  728. $format_items = [];
  729. foreach ($items as $item) {
  730. $format_items[] = [
  731. 'name' => $item->title ?? $item->name ?? $item->id,
  732. 'value' => (string)$item->id,
  733. 'id' => $item->id,
  734. 'pid' => $item->pid,
  735. ];
  736. }
  737. $tree = new Tree($format_items);
  738. return json_success('success', $tree->getTree());
  739. }
  740. public static function clearWelfare(Request $request)
  741. {
  742. $memberId = $request->post('member_id');
  743. $payTime = $request->post('pay_paytimes', date('Y-m-d H:i:s'));
  744. $payTime = date('Y-m-d H:i:s', strtotime($payTime));
  745. $payRemark = $request->post('pay_remark', '');
  746. $clearPwd = $request->post('clear_password');
  747. if (!$clearPwd || $clearPwd != '123456') {
  748. return json_fail('清零密码错误');
  749. }
  750. Db::beginTransaction();
  751. try {
  752. $account = MemberAccount::where('join_account_member_id', $memberId)
  753. ->where('member_account_classify', 'WELFARE')
  754. ->where('member_account_status', 'ACTIVED')
  755. ->first();
  756. if (!$account) {
  757. throw new BusinessException("账户异常");
  758. }
  759. if ($account->member_account_surplus <= 0) {
  760. throw new BusinessException("账户余额为0,无需清零");
  761. }
  762. // 创建清除记录
  763. PayDetail::insert([
  764. 'join_pay_member_id' => $memberId,
  765. 'pay_status' => 'SUCCESS',
  766. 'pay_category' => 'CLEAR',
  767. 'pay_amount' => $account->member_account_surplus,
  768. 'pay_paytimes' => $payTime,
  769. 'pay_prepayid' => $memberId . '-WELFARE',
  770. 'pay_remark' => $payRemark,
  771. 'pay_addtimes' => time()
  772. ]);
  773. // 账户归零
  774. $account->member_account_expend = $account->member_account_expend + $account->member_account_surplus;
  775. $account->member_account_surplus = 0;
  776. $account->save();
  777. Db::commit();
  778. return json_success('success');
  779. } catch (BusinessException $e) {
  780. Db::rollBack();
  781. return json_fail($e->getMessage());
  782. } catch (\Exception $e) {
  783. dump($e->getMessage());
  784. Db::rollBack();
  785. return json_fail('清零失败');
  786. }
  787. }
  788. public static function balanceInfo(Request $request)
  789. {
  790. $memberId = $request->get('member_id', '');
  791. $page = $request->get('page', 1);
  792. $pageSize = $request->get('pageSize', 20);
  793. $account = MemberAccount::where('join_account_member_id', $memberId)
  794. ->where('member_account_classify', 'CASH')
  795. ->first();
  796. if (!$account) {
  797. return json_fail('暂无数据');
  798. }
  799. $balance = $account->member_account_surplus + $account->member_account_added;
  800. $info = PayDetail::where(function ($query) use ($memberId) {
  801. $query->where('join_pay_member_id', $memberId)
  802. // ->whereIn('pay_prepayid', ['W06', 'A01'])
  803. ->where('pay_category', 'RECHARGE')
  804. ->where('pay_prepayid', '<>', $memberId . '-WELFARE')
  805. ->where('pay_status', 'SUCCESS');
  806. })->orWhere(function ($query) use ($memberId) {
  807. $query->where('join_pay_member_id', $memberId)
  808. ->where('pay_prepayid', 'like', '%CASH%')
  809. ->where('pay_status', 'SUCCESS');
  810. })->orderByDesc('pay_addtimes')
  811. ->get()
  812. ->toArray();
  813. $data = [];
  814. foreach ($info as $key => $item) {
  815. $categoryIds = [];
  816. if (!empty($item['join_pay_order_id'])) {
  817. $orderIds = Order::where('order_groupby', $item['join_pay_order_id'])->pluck('order_id');
  818. $goodsIds = OrderSheet::whereIn('join_sheet_order_id', $orderIds)->pluck('join_sheet_goods_id');
  819. $categoryIds = Goods::whereIn('goods_id', $goodsIds)->pluck('join_goods_category_id');
  820. }
  821. $categoryName = [];
  822. foreach ($categoryIds as $id) {
  823. $category = SysCategory::where('category_id', $id)->first();
  824. if (!empty($category->category_super_path)) {
  825. $path = explode('#', $category->category_super_path);
  826. $ids = array_filter($path);
  827. $categoryName[] = SysCategory::where('category_id', current($ids))->value('category_name');
  828. } else {
  829. $categoryName[] = $category->category_name;
  830. }
  831. }
  832. $item['goods_category'] = implode(',', array_unique($categoryName));
  833. if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
  834. $item['goods_category'] = '自定义金额充值';
  835. }
  836. if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
  837. $item['balance_type'] = 'add';
  838. } else {
  839. $item['balance_type'] = 'cut';
  840. }
  841. if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
  842. if (!empty($item['pay_extend_json'])) {
  843. $extendJson = json_decode($item['pay_extend_json'], true);
  844. if (!isset($extendJson['added_amount'])) {
  845. $extendJson['added_amount'] = 0;
  846. }
  847. // 计划任务还没跑
  848. if ($item['pay_category'] == 'RECHARGE' && (!isset($extendJson['notify']) || $extendJson['notify'] != 'success')) {
  849. continue;
  850. }
  851. if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
  852. $data[] = [
  853. 'join_pay_member_id' => $item['join_pay_member_id'],
  854. 'pay_addtimes' => $item['pay_addtimes'],
  855. 'pay_amount' => $extendJson['added_amount'],
  856. 'pay_category' => $item['pay_category'] == 'GIVE' ? 'GIVE' : 'ADDED',
  857. 'balance' => number_format($balance, 2, '.', ''),
  858. 'balance_type' => 'add',
  859. ];
  860. }
  861. $balance = $balance - $extendJson['added_amount'];
  862. }
  863. $item['balance'] = number_format($balance, 2, '.', '');
  864. $balance = $balance - $item['pay_amount'];
  865. if ($item['pay_category'] != 'GIVE') {
  866. $data[] = $item;
  867. }
  868. continue;
  869. }
  870. if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
  871. if (!empty($item['pay_extend_json'])) {
  872. $extendJson = json_decode($item['pay_extend_json'], true);
  873. if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
  874. $data[] = [
  875. 'join_pay_member_id' => $item['join_pay_member_id'],
  876. 'pay_addtimes' => $item['pay_addtimes'],
  877. 'pay_amount' => $extendJson['added_amount'],
  878. 'pay_category' => $item['pay_category'] == 'GIVE' ? 'GIVE' : 'ADDED',
  879. 'balance' => number_format($balance, 2, '.', ''),
  880. 'balance_type' => 'add',
  881. ];
  882. $balance = $balance - $extendJson['added_amount'];
  883. }
  884. }
  885. $item['balance'] = number_format($balance, 2, '.', '');
  886. $balance = $balance - $item['pay_amount'];
  887. } else {
  888. $item['balance'] = number_format($balance, 2, '.', '');
  889. $balance = $balance + $item['pay_amount'];
  890. }
  891. if ($item['pay_category'] != 'GIVE') {
  892. $data[] = $item;
  893. }
  894. }
  895. $total = count($data);
  896. $start = ($page - 1) * $pageSize;
  897. $rows = array_slice($data, $start, $pageSize);
  898. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  899. }
  900. public static function pointInfo($memberId)
  901. {
  902. $account = MemberAccount::where('join_account_member_id', $memberId)
  903. ->where('member_account_classify', 'POINTS')
  904. ->first();
  905. if (!$account) {
  906. return json_fail('暂无数据');
  907. }
  908. $balance = $account->member_account_surplus + $account->member_account_added;
  909. $points = ClientPoints::where('join_client_points_member_id', $memberId)->get()->toArray();
  910. $nowPoint = 0;
  911. foreach ($points as $key => &$point) {
  912. $point['goods_category'] = '其他';
  913. if (!empty($point['join_client_points_goods_id'])) {
  914. $categoryId = Goods::where('goods_id', $point['join_client_points_goods_id'])->pluck('join_goods_category_id');
  915. $category = SysCategory::where('category_id', $categoryId)->first();
  916. if (!empty($category->category_super_path)) {
  917. $path = explode('#', $category->category_super_path);
  918. $ids = array_filter($path);
  919. $point['goods_category'] = SysCategory::where('category_id', current($ids))->value('category_name');
  920. } else {
  921. $point['goods_category'] = $category->category_name;
  922. }
  923. }
  924. if (in_array($point['client_points_category'], ["评价", "消费", "活动", "赠送", '登录活动积分'])) {
  925. $point['balance_type'] = 'add';
  926. } else {
  927. $point['balance_type'] = 'cut';
  928. }
  929. if ($key == 0) {
  930. $point['balance'] = number_format($balance, 2, '.', '');
  931. if (in_array($point['client_points_category'], ["评价", "消费", "活动", "赠送", '登录活动积分'])) {
  932. $balance = $balance - $point['client_points_nbr'];
  933. } else {
  934. $balance = $balance + $point['client_points_nbr'];
  935. }
  936. continue;
  937. }
  938. if (in_array($point['client_points_category'], ["评价", "消费", "活动", "赠送", '登录活动积分'])) {
  939. $point['balance'] = number_format($balance, 2, '.', '');
  940. $balance = $balance - $point['client_points_nbr'];
  941. // $point['balance'] = $balance = $nowPoint = number_format($balance - $point['client_points_nbr'], 2, '.', '');
  942. } else {
  943. $point['balance'] = number_format($balance, 2, '.', '');
  944. $balance = $balance + $point['client_points_nbr'];
  945. // $point['balance'] = $balance = $nowPoint = number_format($balance + $point['client_points_nbr'], 2, '.', '');
  946. }
  947. }
  948. return json_success('', $points);
  949. }
  950. /**
  951. * @Desc 添加会员
  952. * @Author Gorden
  953. * @Date 2024/3/25 13:40
  954. *
  955. * @param $params
  956. * @return \support\Response
  957. */
  958. public static function add($params)
  959. {
  960. Db::beginTransaction();
  961. try {
  962. $memberId = self::generateMemberId();
  963. // 先写主表,要ID
  964. $memberData = [
  965. 'member_id' => $memberId,
  966. 'member_is_owner' => $params['is_owner'] ?? 'N',
  967. 'member_classify' => $params['classify'] ?? '',
  968. 'member_status' => $params['status'] ?? 'PENDING',
  969. 'member_mobile' => $params['mobile'] ?? '',
  970. 'member_category' => $params['member_category'] ?? '后台添加',
  971. 'member_invite_code' => self::generateInviteCode(),
  972. // 'member_from' => $params['source'],
  973. // 'member_extend_json' => json_encode(['come_from' => $params['source']]),
  974. 'member_addtimes' => time(),
  975. ];
  976. $extendJson['come_from'] = $params['source'];
  977. if (!empty($params['user_id'])) {
  978. $deptId = SysUser::where('user_id', $params['user_id'])->value('join_user_dept_id');
  979. if (!$deptId) {
  980. throw new BusinessException('请先关联业务员和门店');
  981. }
  982. $extendJson['belong'] = ['user_id' => $params['user_id'], 'premises' => $deptId];
  983. }
  984. $memberData['member_extend_json'] = json_encode($extendJson);
  985. Member::insert($memberData);
  986. // 账户表
  987. $accountData = [
  988. 'join_account_member_id' => $memberId,
  989. 'member_account_classify' => 'POINTS',
  990. 'member_account_status' => 'ACTIVED',
  991. 'member_account_category' => 'NORMAL',
  992. 'member_account_nbr' => $memberId . '-POINTS',
  993. 'member_account_name' => '积分账户',
  994. 'member_account_addtimes' => time()
  995. ];
  996. // 积分账户
  997. MemberAccount::insert($accountData);
  998. $accountData['member_account_classify'] = 'CASH';
  999. $accountData['member_account_nbr'] = $memberId . '-CASH';
  1000. $accountData['member_account_name'] = '余额账户';
  1001. // 现金/余额账户
  1002. MemberAccount::insert($accountData);
  1003. // 福利账户
  1004. // if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY'){
  1005. // $welfareData = [
  1006. // 'join_account_member_id'=>$memberId,
  1007. // 'member_account_classify'=>'WELFARE',
  1008. // 'member_account_status'=>'ACTIVED',
  1009. // 'member_account_category'=>'NORMAL',
  1010. // 'member_account_nbr'=>$memberId.'-WELFARE',
  1011. // 'member_account_name'=>'福利账户',
  1012. // 'member_account_addtimes'=>time()
  1013. // ];
  1014. // MemberAccount::insert($welfareData);
  1015. // }
  1016. // member cert
  1017. $certData = [
  1018. 'join_cert_member_id' => $memberId,
  1019. 'member_cert_nation' => $params['member_cert_nation'] ?? '',
  1020. 'member_cert_name' => $params['cert_name'] ?? '',
  1021. 'member_cert_nbr' => $params['cert_nbr'] ?? '',
  1022. 'member_cert_birth' => !empty($params['birth']) ? date('Y-m-d', strtotime($params['birth'])) : '',
  1023. 'member_cert_gender' => $params['gender'] ?? '',
  1024. // 'member_cert_province' => !empty($params['province']) ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
  1025. // 'member_cert_city' => $params['city'] ?? '',
  1026. // 'member_cert_addr' => $params['addr'] ?? '',
  1027. // 'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
  1028. // 'member_cert_photo' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_photo']),
  1029. ];
  1030. MemberCert::insert($certData);
  1031. // member info
  1032. $infoData = [
  1033. 'join_info_member_id' => $memberId,
  1034. 'member_info_nickname' => $params['account_name'] ?? '',
  1035. 'member_info_headimg' => !empty($params['avatar']) ? getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']) : '',
  1036. 'member_info_referee' => $params['member_info_referee'] ?? '',
  1037. 'member_info_business' => $params['member_info_business'] ?? '',
  1038. 'member_info_service' => $params['member_info_service'] ?? '',
  1039. 'member_info_city' => !empty($params['province']) ? implode('-', $params['province']) : '',
  1040. 'member_info_address' => $params['member_info_address'] ?? '',
  1041. 'member_info_birthday' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
  1042. 'member_info_gender' => $params['gender'] ?? '',
  1043. ];
  1044. MemberInfo::insert($infoData);
  1045. Db::commit();
  1046. } catch (BusinessException $e) {
  1047. Db::rollBack();
  1048. return json_fail($e->getMessage());
  1049. } catch (\Exception $e) {
  1050. Db::rollBack();
  1051. dump($e->getMessage() . ';line:' . $e->getLine());
  1052. return json_fail("数据添加失败");
  1053. }
  1054. return json_success('数据添加成功', ['member_id' => $memberId]);
  1055. }
  1056. /**
  1057. * @Desc 编辑会员/ 业主
  1058. * @Author Gorden
  1059. * @Date 2024/4/20 15:18
  1060. *
  1061. * @param $params
  1062. * @return \support\Response
  1063. */
  1064. public static function update($params)
  1065. {
  1066. Db::beginTransaction();
  1067. try {
  1068. $memberId = $params['member_id'];
  1069. $member = Member::where('member_id', $params['member_id'])->first();
  1070. if (!$member) {
  1071. throw new BusinessException('数据异常');
  1072. }
  1073. $extendJson = [];
  1074. if (!empty($member->member_extend_json)) {
  1075. $extendJson = json_decode($member->member_extend_json, true);
  1076. }
  1077. $extendJson['come_from'] = $params['source'];
  1078. // 门店、业务员
  1079. if (!empty($params['user_id'])) {
  1080. $deptId = SysUser::where('user_id', $params['user_id'])->value('join_user_dept_id');
  1081. if (!$deptId) {
  1082. throw new BusinessException('您选择的业务员没有关联门店');
  1083. }
  1084. $extendJson['belong'] = ['user_id' => $params['user_id'], 'premises' => $deptId];
  1085. }
  1086. // 先写主表,要ID
  1087. $memberData = [
  1088. 'member_id' => $memberId,
  1089. 'member_is_owner' => $params['is_owner'],
  1090. 'member_classify' => $params['member_classify'],
  1091. 'member_status' => $params['status'],
  1092. // 'member_mobile' => $params['mobile'],
  1093. // 'member_from' => $params['source'],
  1094. 'member_extend_json' => json_encode($extendJson)
  1095. ];
  1096. Member::where('member_id', $params['member_id'])->update($memberData);
  1097. // member cert
  1098. $certData = [
  1099. 'join_cert_member_id' => $memberId,
  1100. 'member_cert_nation' => $params['member_cert_nation'] ?? '',
  1101. 'member_cert_name' => $params['cert_name'] ?? '',
  1102. 'member_cert_nbr' => $params['cert_nbr'] ?? '',
  1103. 'member_cert_birth' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
  1104. 'member_cert_gender' => $params['gender'] ?? '',
  1105. // 'member_cert_province' => $params['province'] ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
  1106. // 'member_cert_city' => $params['city'] ?? '',
  1107. // 'member_cert_addr' => $params['addr'] ?? '',
  1108. 'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
  1109. 'member_cert_photo' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_photo']),
  1110. ];
  1111. if (!MemberCert::where('join_cert_member_id', $memberId)->exists()) {
  1112. MemberCert::insert($certData);
  1113. } else {
  1114. MemberCert::where('join_cert_member_id', $params['member_id'])->update($certData);
  1115. }
  1116. // member info
  1117. $avatar = '';
  1118. if ($params['avatar'] && (strpos($params['avatar'], getenv('APP_IMAGE_DOMAIN')) !== false || strpos($params['avatar'], getenv('SYSTEM_AVATAR_DOMAIN')) !== false)) {
  1119. $avatar = $params['avatar'];
  1120. } else if ($params['avatar']) {
  1121. $avatar = getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']);
  1122. }
  1123. $infoData = [
  1124. 'join_info_member_id' => $memberId,
  1125. 'member_info_nickname' => $params['account_name'],
  1126. 'member_info_headimg' => $avatar,
  1127. 'member_info_referee' => $params['member_info_referee'] ?? '',
  1128. 'member_info_business' => $params['member_info_business'] ?? '',
  1129. 'member_info_service' => $params['member_info_service'] ?? '',
  1130. 'member_info_city' => !empty($params['province']) ? implode('-', $params['province']) : '',
  1131. 'member_info_address' => $params['member_info_address'] ?? '',
  1132. 'member_info_birthday' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
  1133. 'member_info_gender' => $params['gender'] ?? '',
  1134. ];
  1135. if (!MemberInfo::where('join_info_member_id', $params['member_id'])->exists()) {
  1136. MemberInfo::insert($infoData);
  1137. } else {
  1138. MemberInfo::where('join_info_member_id', $params['member_id'])->update($infoData);
  1139. }
  1140. // 福利账户
  1141. if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY' && !MemberAccount::where('member_account_nbr', $memberId . '-WELFARE')->exists()) {
  1142. $welfareData = [
  1143. 'join_account_member_id' => $memberId,
  1144. 'member_account_classify' => 'WELFARE',
  1145. 'member_account_status' => 'ACTIVED',
  1146. 'member_account_category' => 'NORMAL',
  1147. 'member_account_nbr' => $memberId . '-WELFARE',
  1148. 'member_account_name' => '福利账户',
  1149. 'member_account_addtimes' => time()
  1150. ];
  1151. MemberAccount::insert($welfareData);
  1152. }
  1153. Db::commit();
  1154. } catch (BusinessException $e) {
  1155. Db::rollBack();
  1156. dump($e->getMessage() . ';line:' . $e->getLine());
  1157. return json_fail($e->getMessage());
  1158. } catch (\Exception $e) {
  1159. Db::rollBack();
  1160. dump($e->getMessage() . ';line:' . $e->getLine());
  1161. return json_fail("数据更新失败");
  1162. }
  1163. return json_success('数据更新成功');
  1164. }
  1165. /**
  1166. * @Desc 会员关联设备列表
  1167. * @Author Gorden
  1168. * @Date 2024/4/7 9:52
  1169. *
  1170. * @param $id
  1171. * @return \support\Response
  1172. */
  1173. public static function deviceList($id)
  1174. {
  1175. $family = Family::where('join_family_creator_member_id', $id)->get()->toArray();
  1176. $familyMemberIds = '';
  1177. if ($family) {
  1178. $familyIds = array_column($family, 'family_id');
  1179. $familyMember = FamilyMember::whereIn('join_family_id', $familyIds)->get()->toArray();
  1180. $familyMemberIds = array_column($familyMember, 'join_family_member_id');
  1181. }
  1182. $rows = MemberDevice::leftJoin('device', 'device.device_id', '=', 'member_device.join_member_device_id')
  1183. ->leftJoin('member', 'member.member_id', '=', 'member_device.join_device_member_id')
  1184. ->leftJoin('family_member', 'family_member.join_family_member_id', '=', 'member_device.join_device_member_id')
  1185. ->select('device.device_category', 'device.device_name', 'device.device_type', 'member.member_mobile', 'member_device.*', 'family_member.family_member_name')
  1186. ->when(!empty($familyMemberIds), function ($query) use ($familyMemberIds) {
  1187. $query->whereIn('member_device.join_device_master_member_id', $familyMemberIds);
  1188. })
  1189. ->when(empty($familyMemberIds), function ($query) use ($id) {
  1190. $query->where('member_device.join_device_master_member_id', $id);
  1191. })->orderBy('member_device_addtimes', 'desc')
  1192. ->get()
  1193. ->toArray();
  1194. return json_success('', ['rows' => $rows]);
  1195. }
  1196. /**
  1197. * @Desc 绑定设备
  1198. * @Author Gorden
  1199. * @Date 2024/4/7 10:27
  1200. *
  1201. * @param Request $request
  1202. * @return \support\Response
  1203. */
  1204. public static function addDevice(Request $request)
  1205. {
  1206. $params = $request->post();
  1207. Db::beginTransaction();
  1208. try {
  1209. $data = [
  1210. 'join_device_member_id' => $params['join_device_member_id'] ?? '',
  1211. 'join_device_master_member_id' => $params['join_device_master_member_id'],
  1212. 'join_member_device_id' => $params['join_member_device_id'],
  1213. 'member_device_status' => $params['member_device_status'],
  1214. 'member_device_key' => $params['member_device_key'] ?? '',
  1215. 'member_device_config_json' => !empty($params['member_device_config_json']) ? $params['member_device_config_json'] : null,
  1216. 'member_device_remark' => $params['member_device_remark'] ?? null,
  1217. 'member_device_addtimes' => time(),
  1218. ];
  1219. MemberDevice::insert($data);
  1220. $device = Device::where('device_id', $params['join_member_device_id'])->whereIn('device_status', ['PROCESSING', 'PENDING'])->first();
  1221. // 激活设备
  1222. if (!$device) {
  1223. Db::rollBack();
  1224. return json_fail('当前设备不是可激活状态');
  1225. }
  1226. $device->device_status = 'ACTIVED';
  1227. $device->save();
  1228. Device::where('device_id', $params['join_member_device_id'])->update(['device_status' => 'ACTIVED']);
  1229. _syslog("绑定设备", "用户【" . ($params['join_device_member_id'] ?? $params['join_device_master_member_id']) . '】,绑定设备【' . $device->device_name . '】');
  1230. Db::commit();
  1231. } catch (\Exception $e) {
  1232. Db::rollBack();
  1233. dump($e->getMessage());
  1234. return json_fail('绑定失败');
  1235. }
  1236. return json_success('绑定成功');
  1237. }
  1238. public static function updateDevice(Request $request)
  1239. {
  1240. $params = $request->post();
  1241. Db::beginTransaction();
  1242. try {
  1243. $data = [
  1244. 'member_device_status' => $params['member_device_status'],
  1245. 'member_device_key' => $params['member_device_key'],
  1246. 'join_device_member_id' => $params['join_device_member_id'],
  1247. 'member_device_config_json' => !empty($params['member_device_config_json']) ? $params['member_device_config_json'] : null,
  1248. 'member_device_remark' => $params['member_device_remark'] ?? null,
  1249. ];
  1250. MemberDevice::where('member_device_id', $request->post('member_device_id'))->update($data);
  1251. $device = Device::where('device_id', $params['join_member_device_id'])->first();
  1252. if ($device->device_status != $params['member_device_status']) {
  1253. $device->device_status = $params['member_device_status'];
  1254. $device->save();
  1255. }
  1256. // Device::where('device_id', $params['join_member_device_id'])->update(['device_status' => $params['member_device_status']]);
  1257. Db::commit();
  1258. _syslog("更新绑定设备", "用户【" . ($params['join_device_member_id'] == "" ? $params['join_device_member_id'] : $params['join_device_master_member_id']) . '】,绑定设备【' . $device->device_name . '】');
  1259. } catch (\Exception $e) {
  1260. Db::rollBack();
  1261. dump($e->getMessage());
  1262. return json_fail('绑定更新失败');
  1263. }
  1264. return json_success('绑定更新成功');
  1265. }
  1266. public static function deleteDevice(Request $request)
  1267. {
  1268. try {
  1269. Db::beginTransaction();
  1270. $memberDevice = MemberDevice::where('member_device_id', $request->post('member_device_id'))->first();
  1271. if (!$memberDevice) {
  1272. return json_fail('数据不存在');
  1273. }
  1274. $device = Device::where('device_id', $memberDevice->join_member_device_id)->first();
  1275. $device->device_status = "DISABLED";
  1276. $device->save();
  1277. // Device::where('device_id', $memberDevice->join_member_device_id)->update(['device_status' => 'DISABLED']);
  1278. $memberDevice->delete();
  1279. Db::commit();
  1280. _syslog("解除绑定设备", "用户【" . ($memberDevice->join_device_member_id == "" ? $memberDevice->join_device_member_id : $memberDevice->join_device_master_member_id) . '】,解除绑定设备【' . $device->device_name . '】');
  1281. return json_success('解除绑定成功');
  1282. } catch (\Exception $e) {
  1283. Db::rollBack();
  1284. return json_fail('绑定失败');
  1285. }
  1286. }
  1287. /**
  1288. * 手动创建会员
  1289. */
  1290. public static function createMember($params)
  1291. {
  1292. $memberId = $params['member_id'] ?? '';
  1293. if (!$memberId) {
  1294. throw new BusinessException("参数异常");
  1295. }
  1296. // 主表
  1297. $memberData = [
  1298. 'member_id' => $memberId,
  1299. 'member_is_owner' => 'N',
  1300. 'member_classify' => 'MEMBER',
  1301. 'member_status' => 'ACTIVED',
  1302. 'member_mobile' => $params['mobile'],
  1303. 'member_invite_code' => self::generateInviteCode(),
  1304. 'member_extend_json' => json_encode(['come_from' => 'SYSTEM']),
  1305. 'member_addtimes' => time()
  1306. ];
  1307. Member::insert($memberData);
  1308. // 账户表
  1309. $accountData = [
  1310. 'join_account_member_id' => $memberId,
  1311. 'member_account_classify' => 'POINTS',
  1312. 'member_account_status' => 'ACTIVED',
  1313. 'member_account_category' => 'NORMAL',
  1314. 'member_account_nbr' => $memberId . '-POINTS',
  1315. 'member_account_name' => '积分账户',
  1316. 'member_account_addtimes' => time()
  1317. ];
  1318. // 积分账户
  1319. MemberAccount::insert($accountData);
  1320. $accountData['member_account_classify'] = 'CASH';
  1321. $accountData['member_account_nbr'] = $memberId . '-CASH';
  1322. $accountData['member_account_name'] = '余额账户';
  1323. // 现金/余额账户
  1324. MemberAccount::insert($accountData);
  1325. // info
  1326. $infoData = [
  1327. 'join_info_member_id' => $memberId,
  1328. 'member_info_nickname' => $params['username']
  1329. ];
  1330. MemberInfo::insert($infoData);
  1331. }
  1332. private static function generateMemberId()
  1333. {
  1334. $id = SysSerial::getSerial();
  1335. return "MR" . date('ymdHi') . random_string(4, 'up');
  1336. }
  1337. public static function getMemberName($mobile, $certName, $nickname)
  1338. {
  1339. $name = '';
  1340. if (!empty($certName)) {
  1341. $name = $certName;
  1342. } elseif (!empty($nickname)) {
  1343. $name = $nickname;
  1344. }
  1345. if (!empty($name) && !empty($mobile)) {
  1346. $name .= '-' . $mobile;
  1347. } elseif (!empty($mobile)) {
  1348. $name = $mobile;
  1349. }
  1350. return $name;
  1351. }
  1352. public static function getMemberNameByMemberId($memberId)
  1353. {
  1354. $member = Member::with([
  1355. 'cert' => function ($query) {
  1356. $query->select('join_cert_member_id', 'member_cert_name');
  1357. },
  1358. 'info' => function ($query) {
  1359. $query->select('join_info_member_id', 'member_info_nickname');
  1360. },
  1361. ]
  1362. )->where('member_id', $memberId)
  1363. ->first();
  1364. if (empty($member)) {
  1365. return;
  1366. }
  1367. $member = $member->toArray();
  1368. $mobile = $certName = $nickname = '';
  1369. if (!empty($member['member_mobile'])) {
  1370. $mobile = $member['member_mobile'];
  1371. }
  1372. if (!empty($member['cert']) && !empty($member['cert']['member_cert_name'])) {
  1373. $certName = $member['cert']['member_cert_name'];
  1374. }
  1375. if (!empty($member['info']) && !empty($member['info']['member_info_nickname'])) {
  1376. $nickname = $member['info']['member_info_nickname'];
  1377. }
  1378. return self::getMemberName($mobile, $certName, $nickname);
  1379. }
  1380. /**
  1381. * @Desc 生成推荐码
  1382. * @Author Gorden
  1383. * @Date 2024/9/6 9:05
  1384. *
  1385. * @return string
  1386. */
  1387. public static function generateInviteCode()
  1388. {
  1389. $code = random_string(8, 'number');
  1390. if (Member::where('member_invite_code', $code)->exists()) {
  1391. return self::generateInviteCode();
  1392. } else {
  1393. return $code;
  1394. }
  1395. }
  1396. }