User.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\AliPay;
  4. use app\common\library\WxMerchPay;
  5. use app\common\library\WxPay;
  6. use app\common\model\Sms;
  7. use app\common\library\Email;
  8. use EasyWeChat\Factory;
  9. use phpDocumentor\Reflection\Type;
  10. use app\common\model\UserIntegralLog;
  11. use think\Model;
  12. use app\common\library\Common;
  13. use think\facade\Validate;
  14. use think\Request;
  15. use think\Db;
  16. use function foo\func;
  17. use app\common\library\WxService;
  18. header('Access-Control-Allow-Origin: *');
  19. /**
  20. * 会员模型
  21. */
  22. class User Extends Model
  23. {
  24. // 开启自动写入时间戳字段
  25. protected $autoWriteTimestamp = 'TIMESTAMP';
  26. // 定义时间戳字段名
  27. protected $createTime = 'create_at';
  28. protected $updateTime = 'update_at';
  29. // 追加属性
  30. protected $append = [
  31. 'url',
  32. ];
  33. /**
  34. * 微信授权登录、注册
  35. */
  36. public static function wechatLogin($code,$rawData){
  37. $appid = Config::get_values('wechat_appid');
  38. $secret = Config::get_values('wechat_appsecret');
  39. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
  40. $session_key = Common::curlRequest($url);
  41. //数据库是否已注册
  42. // $user = Db::name('User')->where('openid','oo7E85LrD0ovt7hbz4sZGrf-_flA')->find();
  43. // $user = Db::name('User')->where('id',53)->find();
  44. // if ($user){
  45. // $user['UserIformationPerfect'] = self::checkUserIformationPerfect($user['id']) ? true : false;
  46. // app()->session->set('us', $user);
  47. // //注册环信
  48. // // Common::huanxin_zhuce('huxuanmao-'.$user['id'],$user['nickname']);
  49. // return Common::return_success('授权成功',$user);
  50. // }
  51. if (!empty($session_key['session_key'])) {
  52. $openid = $session_key['openid'];
  53. //数据库是否已注册
  54. $user = Db::name('User')->where('openid',$openid)
  55. ->where('is_cancellation_account',1)
  56. ->where('is_del',1)
  57. ->find();
  58. if ($user){
  59. $user['UserIformationPerfect'] = self::checkUserIformationPerfect($user['id']) ? true : false;
  60. app()->session->set('us', $user);
  61. $users = self::getUserInfo($user['id']);
  62. User::where('id',$user['id'])->update(['huanxinID'=>'huxuanmao-'.$user['id']]);
  63. //注册环信
  64. Common::huanxin_zhuce('huxuanmao-'.$users['id'],$users['nickname']);
  65. return Common::return_success('授权成功',$users);
  66. }else{
  67. $data['sex'] = 0;
  68. if ($rawData){
  69. $rawData = json_decode($rawData,true);
  70. $data['nickname'] = $rawData['nickName'];
  71. $data['openid'] = $openid;
  72. $data['sex'] = $rawData['gender'];
  73. $data['headimgurl'] = $rawData['avatarUrl'];
  74. }
  75. // $data['province'] = $rawData['province'];
  76. // $data['city'] = $rawData['city'];
  77. Db::startTrans();
  78. try {
  79. $user = self::create($data);
  80. Db::commit();
  81. $userId =$user->id;
  82. $us =Db::name('User')->where('id',$userId)->find();
  83. $us['UserIformationPerfect'] = false;
  84. app()->session->set('us', $us);
  85. //系统赠送注册积分数量
  86. $register_give_integral = Config::get_values('register_give_integral');
  87. if ($register_give_integral>0){
  88. //加积分
  89. self::integral($register_give_integral,$userId, '注册赠送积分',1);
  90. }
  91. User::where('id',$userId)->update(['huanxinID'=>'huxuanmao-'.$userId]);
  92. $users = self::getUserInfo($userId);
  93. //注册环信
  94. Common::huanxin_zhuce('huxuanmao-'.$userId,$users['nickname']);
  95. return Common::return_success('授权成功',$users);
  96. }catch (Exception $e) {
  97. Db::rollback();
  98. return Common::return_error('授权失败');
  99. }
  100. }
  101. }else{
  102. return Common::return_error('获取session_key失败!');
  103. }
  104. }
  105. /**
  106. * 获取用户信息
  107. */
  108. public static function getUserInfo($id=''){
  109. $user = app()->session->get('us');
  110. if ($id){
  111. $userid = $id;
  112. }else{
  113. $userid = $user['id'];
  114. }
  115. $userinfo = Db::name('user')->where('id',$userid)->find();
  116. if ($userinfo['sex']==0){
  117. $userinfo['sex'] = null;
  118. }
  119. if (!$userinfo['hope_age']){
  120. $userinfo['hope_age'] = [];
  121. }else{
  122. $userinfo['hope_age'] = explode(',',$userinfo['hope_age']);
  123. }
  124. if (!$userinfo['hope_height']){
  125. $userinfo['hope_height'] = [];
  126. }else{
  127. $userinfo['hope_height'] = explode(',',$userinfo['hope_height']);
  128. }
  129. if (!$userinfo['imgs']){
  130. $userinfo['imgs'] = [];
  131. }else{
  132. $userinfo['imgs'] = explode(',',$userinfo['imgs']);
  133. }
  134. if (!$userinfo['label']){
  135. $userinfo['label'] = [];
  136. }else{
  137. $userinfo['label'] = explode(',',$userinfo['label']);
  138. }
  139. if (!$userinfo['introduce_myself_imgs']) {
  140. $userinfo['introduce_myself_imgs'] = [];
  141. }else{
  142. $userinfo['introduce_myself_imgs'] = explode(',',$userinfo['introduce_myself_imgs']);
  143. }
  144. if (!$userinfo['family_background_imgs']) {
  145. $userinfo['family_background_imgs'] = [];
  146. }else{
  147. $userinfo['family_background_imgs'] = explode(',',$userinfo['family_background_imgs']);
  148. }
  149. if (!$userinfo['interests_hobbies_imgs']) {
  150. $userinfo['interests_hobbies_imgs'] = [];
  151. }else{
  152. $userinfo['interests_hobbies_imgs'] = explode(',',$userinfo['interests_hobbies_imgs']);
  153. }
  154. if (!$userinfo['love_imgs']){
  155. $userinfo['love_imgs'] = [];
  156. }else{
  157. $userinfo['love_imgs'] = explode(',',$userinfo['love_imgs']);
  158. }
  159. if (!$userinfo['other_half_imgs']){
  160. $userinfo['other_half_imgs'] = [];
  161. }else{
  162. $userinfo['other_half_imgs'] = explode(',',$userinfo['other_half_imgs']);
  163. }
  164. if (!$userinfo['why_single_imgs']){
  165. $userinfo['why_single_imgs'] = [];
  166. }else{
  167. $userinfo['why_single_imgs'] = explode(',',$userinfo['why_single_imgs']);
  168. }
  169. if (!$userinfo['look_life_imgs']){
  170. $userinfo['look_life_imgs'] = [];
  171. }else{
  172. $userinfo['look_life_imgs'] = explode(',',$userinfo['look_life_imgs']);
  173. }
  174. if (!$userinfo['real_auth_img']){
  175. $userinfo['real_auth_img'] = [];
  176. }else{
  177. $userinfo['real_auth_img'] = explode(',',$userinfo['real_auth_img']);
  178. }
  179. if (!$userinfo['work_auth_img']){
  180. $userinfo['work_auth_img'] = [];
  181. }else{
  182. $userinfo['work_auth_img'] = explode(',',$userinfo['work_auth_img']);
  183. }
  184. if (!$userinfo['education_auth_img']){
  185. $userinfo['education_auth_img'] = [];
  186. }else{
  187. $userinfo['education_auth_img'] = explode(',',$userinfo['education_auth_img']);
  188. }
  189. $userinfo['UserIformationPerfect'] = self::checkUserIformationPerfect($userid) ? true : false;
  190. $count = Collection::where('a.user_id',$userid)
  191. ->alias('a')
  192. ->where('b.is_del',1)
  193. ->join('User b','a.to_user_id=b.id')
  194. ->where('a.is_effective',1)
  195. ->count();
  196. $collect_num = Config::get_values('collect_num');
  197. $collect_num = $collect_num ? $collect_num : 10;
  198. $userinfo['remaining_collect_num'] = bcsub($collect_num,$count);
  199. $userinfo['want_know_num'] = UserWantKnow::where('a.to_user_id',$userid)
  200. ->alias('a')
  201. ->where('b.is_del',1)
  202. ->join('User b','a.user_id=b.id')
  203. ->count();
  204. if ($userinfo['stealth_switch_time'] && ($userinfo['stealth_switch_time']+(7*24*60*60))>time()){
  205. $userinfo['stealth_is_allow_open'] = false;
  206. }else{
  207. $userinfo['stealth_is_allow_open'] = true;
  208. }
  209. $userinfo['stealth_switch_end_time'] = date('Y-m-d H:i:s',$userinfo['stealth_switch_time']+(7*24*60*60)); //隐私模式下次可以开启时间
  210. $userinfo['stealth_switch_time'] = date('Y-m-d H:i:s',$userinfo['stealth_switch_time']); //隐私模式开启时间
  211. //我的动态数量
  212. $userinfo['dynamic_count'] = Dynamic::where('user_id',$userid)->where('is_del',1)->count();
  213. return $userinfo;
  214. }
  215. /**
  216. * 完善资料
  217. */
  218. public static function perfectInformation($data){
  219. $user = app()->session->get('us');
  220. if (isset($data['stealth_switch'])){
  221. if ($data['stealth_switch']==2){
  222. $userinfo = Db::name('user')->where('id',$user['id'])->find();
  223. if ($userinfo['stealth_switch_time'] && ($userinfo['stealth_switch_time']+(7*24*60*60))>time()){
  224. return Common::return_error('无法开启隐私模式');
  225. }
  226. $data['stealth_switch_time'] = time();
  227. }
  228. }
  229. $data['update_at'] = date('Y-m-d H:i:s');
  230. if (isset($data['imgs'])){
  231. $data['headimgurl'] = explode(',',$data['imgs'])[0];
  232. }
  233. Db::startTrans();
  234. try {
  235. self::where('id',$user['id'])->update($data);
  236. Db::commit();
  237. return Common::return_success('成功');
  238. }catch (Exception $e) {
  239. Db::rollback();
  240. return Common::return_error('失败');
  241. }
  242. }
  243. /**
  244. * 判断用户是否完善信息
  245. */
  246. public static function checkUserIformationPerfect($user_id){
  247. $user = self::get($user_id);
  248. // if (!$user['nickname'] || !$user['headimgurl'] || !$user['date_of_birth'] || !$user['height'] || !$user['phone'] ||
  249. // !$user['wechat_id'] || !$user['annual_income'] || !$user['household'] || !$user['education'] || !$user['graduated_from'] ||
  250. // !$user['province'] || !$user['city'] || !$user['area'] || !$user['introduce_myself'] || !$user['family_background'] || !$user['interests_hobbies'] ||
  251. // !$user['love'] || !$user['other_half'] || !$user['why_single'] || !$user['look_life'] || !$user['label'] || !$user['imgs'] || !$user['professional']){
  252. // return false;
  253. // }
  254. if (!$user['nickname'] || !$user['date_of_birth'] || !$user['height'] || !$user['phone'] ||
  255. !$user['wechat_id'] || !$user['annual_income'] || !$user['household'] || !$user['education'] || !$user['graduated_from'] ||
  256. !$user['province'] || !$user['city'] || !$user['area'] || !$user['professional']){
  257. return false;
  258. }
  259. return true;
  260. }
  261. /**
  262. * 心动区
  263. */
  264. public static function cardiacArea($Nowpage,$limits){
  265. $user = app()->session->get('us');
  266. $count = UserWantKnow::where('user_id',$user['id'])->count();
  267. if ($count){
  268. $list = UserWantKnow::where('a.user_id',$user['id'])
  269. ->alias('a')
  270. ->join('User b','a.to_user_id=b.id')
  271. ->where('b.is_del',1)
  272. ->where('a.state',2)
  273. ->field('b.id as user_id,b.nickname,b.headimgurl,a.create_at')
  274. ->page($Nowpage,$limits)
  275. ->order('a.id desc')
  276. ->select()
  277. ->toArray();
  278. }else{
  279. $list = [];
  280. }
  281. $data['count'] = $count;
  282. $data['list'] = $list;
  283. return Common::return_success('成功',$data);
  284. }
  285. /**
  286. * 互选区
  287. */
  288. public static function electArea($Nowpage,$limits){
  289. $user = app()->session->get('us');
  290. $user_ids = UserWantKnow::where('to_user_id',$user['id'])->column('user_id');
  291. $count = UserWantKnow::where('user_id',$user['id'])->where('to_user_id','in',$user_ids)->count();
  292. if ($count){
  293. $list = UserWantKnow::where('user_id',$user['id'])
  294. ->alias('a')
  295. ->join('User b','a.to_user_id=b.id')
  296. ->where('b.is_del',1)
  297. ->field('b.id as user_id,b.nickname,b.headimgurl,a.create_at')
  298. ->where('a.to_user_id','in',$user_ids)
  299. ->order('a.id desc')
  300. ->page($Nowpage,$limits)
  301. ->select()->toArray();
  302. }else{
  303. $list = [];
  304. }
  305. $data['count'] = $count;
  306. $data['list'] = $list;
  307. return Common::return_success('成功',$data);
  308. }
  309. /**
  310. * 我的积分
  311. */
  312. public static function myIntegral($Nowpage,$limits,$type){
  313. $user = app()->session->get('us');
  314. $integral = self::where('id',$user['id'])->value('integral');
  315. $count = self::myintegralByWhere($type)->where('user_id',$user['id'])->count();
  316. if ($count){
  317. $list = self::myintegralByWhere($type)
  318. ->where('user_id',$user['id'])
  319. ->field('id,user_id,pm,title,change_money,create_at')
  320. ->page($Nowpage,$limits)
  321. ->order('id desc')->select();
  322. foreach ($list as $k=>$v){
  323. $list[$k]['create_at'] = date('Y-m-d',strtotime($v['create_at']));
  324. $change_money = floatval($v['change_money']);
  325. $change_money = $v['pm'] ? "+".$change_money : "-".$change_money;
  326. $list[$k]['change_money'] = $change_money;
  327. }
  328. }else{
  329. $list = [];
  330. }
  331. $data['count'] = $count;
  332. $data['list'] = $list;
  333. return Common::return_success('成功',compact('integral','data'));
  334. }
  335. /**
  336. * 我的积分where条件
  337. */
  338. public static function myintegralByWhere($type){
  339. $model = Db::name('UserIntegralLog');
  340. if ($type=='' || $type==-1){
  341. return $model;
  342. }elseif ($type==1){
  343. return $model->where('pm',1);
  344. }elseif ($type==2){
  345. return $model->where('pm',0);
  346. }
  347. }
  348. /**
  349. * 消息
  350. */
  351. public static function message($Nowpage,$limits){
  352. $user = app()->session->get('us');
  353. //系统消息
  354. $official = OfficialMessage::where('status',1)
  355. ->where('is_del',1)
  356. ->field('id,content,create_at')
  357. ->select();
  358. if ($official){
  359. $official = $official->toArray();
  360. foreach ($official as $k=>$v){
  361. $official[$k]['id'] = 'off_'.$v['id'];
  362. $official[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
  363. $official[$k]['user_id'] = 0;
  364. $official[$k]['type'] = 3;
  365. $official[$k]['title'] = '官方消息';
  366. $read = OfficialUser::where('message_id',$v['id'])->where('user_id',$user['id'])->count();
  367. $official[$k]['is_read'] = $read ? 1 : 0;
  368. }
  369. }
  370. $list = Message::where('user_id',$user['id'])
  371. ->page($Nowpage,$limits)
  372. ->order('id desc')
  373. ->select();
  374. if ($list){
  375. $list = $list->toArray();
  376. foreach ($list as $k=>$v){
  377. $list[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
  378. }
  379. }
  380. $list = array_merge($official,$list);
  381. $count = count($list);
  382. array_multisort(array_column($list,'create_at'),SORT_DESC,$list);
  383. $list = array_slice($list,($Nowpage-1)*$limits,$limits);
  384. return Common::return_success('成功',compact('count','list'));
  385. // $count = Message::where('user_id',$user['id'])->count();
  386. // if ($count){
  387. // $list = Message::where('user_id',$user['id'])
  388. // ->page($Nowpage,$limits)
  389. // ->order('id desc')
  390. // ->select()->toArray();
  391. // foreach ($list as $k=>$v){
  392. // $list[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
  393. // }
  394. // }else{
  395. // $list = [];
  396. // }
  397. // $data['count'] = $count;
  398. // $data['list'] = $list;
  399. // return Common::return_success('成功',$data);
  400. }
  401. /**
  402. * 读取消息
  403. */
  404. public static function readMessage($message_id){
  405. $user = app()->session->get('us');
  406. $message = Message::get($message_id);
  407. if (!$message){
  408. $id = explode('_',$message_id);
  409. $official = OfficialMessage::where('id',$id[1])->where('status',1)->where('is_del',1)->find();
  410. if (!$official)
  411. return Common::return_error('消息不存在');
  412. }
  413. Db::startTrans();
  414. try {
  415. if ($message){
  416. $message->is_read = 1;
  417. $message->save();
  418. }elseif ($official){
  419. $message_user = OfficialUser::where('message_id',$id[1])->where('user_id',$user['id'])->count();
  420. if (!$message_user){
  421. $data['message_id'] = $id[1];
  422. $data['user_id'] = $user['id'];
  423. OfficialUser::create($data);
  424. }
  425. }
  426. Db::commit();
  427. return Common::return_success('成功');
  428. }catch (Exception $e) {
  429. Db::rollback();
  430. return Common::return_error('失败');
  431. }
  432. }
  433. /**
  434. * 剩余未读消息数量
  435. */
  436. public static function messageCount(){
  437. $user = app()->session->get('us');
  438. if ($user){
  439. //系统消息未读数量
  440. $ids = OfficialMessage::where('status',1)->where('is_del',1)->column('id');
  441. $is_read_count = OfficialUser::whereIn('message_id',$ids)->where('user_id',$user['id'])->count();
  442. $off_count = bcsub(count($ids),$is_read_count);
  443. //消息表未读数量
  444. $count = Message::where('user_id',$user['id'])->where('is_read',0)->count();
  445. $count = bcadd($off_count,$count);
  446. }else{
  447. $count = 0;
  448. }
  449. return Common::return_success('成功',$count);
  450. }
  451. /**
  452. * 变更会员余额
  453. * @param int $money 余额
  454. * @param int $user_id 会员ID
  455. * @param string $memo 备注
  456. */
  457. public static function integral($integral, $user_id, $memo, $pm = 0)
  458. {
  459. $user = self::get($user_id);
  460. if ($user)
  461. {
  462. $before = $user->integral;
  463. if ($pm==1){
  464. $after = $user->integral + $integral;
  465. }else{
  466. $after = $user->integral - $integral;
  467. }
  468. //更新会员信息
  469. $user->save(['integral' => $after]);
  470. //写入日志
  471. MoneyLog::create(['user_id' => $user_id,'pm' => $pm, 'change_money' => $integral, 'before' => $before, 'after' => $after, 'title' => $memo]);
  472. }
  473. }
  474. /**
  475. * 变更会员余额
  476. * @param int $money 余额
  477. * @param int $user_id 会员ID
  478. * @param string $memo 备注
  479. */
  480. public static function money($money, $user_id, $memo, $pm = 0)
  481. {
  482. $user = self::get($user_id);
  483. if ($user)
  484. {
  485. $before = $user->money;
  486. if ($pm==1){
  487. $after = $user->money + $money;
  488. }else{
  489. $after = $user->money - $money;
  490. }
  491. //更新会员信息
  492. $user->save(['money' => $after]);
  493. //写入日志
  494. MoneyLog2::create(['user_id' => $user_id,'pm' => $pm, 'change_money' => $money, 'before' => $before, 'after' => $after, 'title' => $memo]);
  495. }
  496. }
  497. /**
  498. * 置顶用户列表
  499. */
  500. public static function topUser($city){
  501. $count = self::topUserByWhere($city)->count();
  502. if ($count){
  503. $list = self::topUserByWhere($city)
  504. ->order('like_count desc')
  505. ->limit(10)
  506. ->select();
  507. }else{
  508. $city = '广州市';
  509. $list = self::topUserByWhere($city)
  510. ->order('like_count desc')
  511. ->limit(10)
  512. ->select();
  513. }
  514. if ($list){
  515. foreach ($list as $k=>$v){
  516. if (!$v['imgs']){
  517. $list[$k]['imgs'] = [];
  518. }else{
  519. $list[$k]['imgs'] = explode(',',$v['imgs']);
  520. }
  521. }
  522. }
  523. return Common::return_success('成功',$list);
  524. }
  525. /**
  526. * 置顶用户条件
  527. */
  528. public static function topUserByWhere($city){
  529. $user = app()->session->get('us');
  530. $user_id = $user['id'];
  531. $user = Db::name('user')->where('id',$user['id'])->find();
  532. $sex = $user['sex'];
  533. $work_auth_status = $user['work_auth_status'];
  534. $work_auth_company_name = $user['work_auth_company_name'];
  535. return Db::name('User')
  536. ->where('is_home',1)
  537. ->where('stealth_switch',1)
  538. ->where('is_cancellation_account',1)
  539. ->where('is_del',1)
  540. ->when($city,function ($query) use ($city){
  541. if ($city)
  542. $query->whereLike('city','%'.$city.'%');
  543. })
  544. ->when($user_id,function ($query) use ($user_id,$sex){
  545. if ($user_id){
  546. $sex = $sex==1 ? 2 : 1;
  547. $query->where('sex',$sex);
  548. }
  549. })
  550. ->when($work_auth_company_name,function ($query) use ($work_auth_company_name,$work_auth_status,$user_id){
  551. if ($user_id && $work_auth_company_name && $work_auth_status==1){
  552. $query->whereRaw('work_auth_company_name like "%'.$work_auth_company_name.'%" and shielding_colleagues_switch=1 or work_auth_company_name not like "%'.$work_auth_company_name.'%" or work_auth_company_name=""');
  553. }
  554. })
  555. ->field('*,'.UserWantKnow::where('to_user_id',$user_id)->count().' as like_count');
  556. }
  557. /**
  558. * 首页推荐嘉宾列表
  559. */
  560. public static function recommendedUser($city){
  561. $user = app()->session->get('us');
  562. $user = Db::name('user')->where('id',$user['id'])->find();
  563. if ($user){
  564. $list = self::byWhere($city)
  565. ->order('like_count desc')
  566. ->limit(5)
  567. ->select();
  568. if (!$list){
  569. $city = '广州市';
  570. $list = self::topUserByWhere($city)
  571. ->order('like_count desc')
  572. ->limit(5)
  573. ->select();
  574. }
  575. }else{
  576. $city = '广州市';
  577. $list = self::topUserByWhere($city)
  578. ->order('like_count desc')
  579. ->limit(5)
  580. ->select();
  581. }
  582. if ($list){
  583. foreach ($list as $k=>$v){
  584. if (!$v['imgs']){
  585. $list[$k]['imgs'] = [];
  586. }else{
  587. $list[$k]['imgs'] = explode(',',$v['imgs']);
  588. }
  589. if ($v['household']){
  590. $household = explode('-',$v['household']);
  591. $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';
  592. }else{
  593. $list[$k]['household_city'] = '';
  594. }
  595. }
  596. }
  597. return Common::return_success('成功',$list);
  598. }
  599. /**
  600. * 单身广场
  601. */
  602. public static function singleUser($city,$keywords,$Nowpage,$limits){
  603. $count = self::byWhere($city)->count();
  604. if ($count){
  605. $list = self::byWhere($city,$keywords)
  606. ->orderRand()
  607. //->order('like_count desc')
  608. ->page($Nowpage,$limits)
  609. ->select();
  610. }else{
  611. $city = '广州市';
  612. $list = self::topUserByWhere($city)
  613. ->orderRand()
  614. // ->order('like_count desc')
  615. ->page($Nowpage,$limits)
  616. ->select();
  617. }
  618. if ($list){
  619. foreach ($list as $k=>$v){
  620. if ($v['household']){
  621. $household = explode('-',$v['household']);
  622. $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';
  623. }else{
  624. $list[$k]['household_city'] = '';
  625. }
  626. if (!$v['imgs']){
  627. $list[$k]['imgs'] = [];
  628. }else{
  629. $list[$k]['imgs'] = explode(',',$v['imgs']);
  630. }
  631. }
  632. }
  633. return Common::return_success('成功',compact('count','list'));
  634. }
  635. /**
  636. * where条件
  637. */
  638. public static function byWhere($city,$keywords=''){
  639. $user = app()->session->get('us');
  640. $user = Db::name('user')->where('id',$user['id'])->find();
  641. $sex = $user['sex'];
  642. $hope_age = $user['hope_age'];
  643. $hope_height = $user['hope_height'];
  644. $hope_city = $user['hope_city'];
  645. $hope_hometown = $user['hope_hometown'];
  646. $hope_education = $user['hope_education'];
  647. $hope_marriage = $user['hope_marriage'];
  648. $household = $user['household'];
  649. $work_auth_status = $user['work_auth_status'];
  650. $work_auth_company_name = $user['work_auth_company_name'];
  651. return Db::name('User')
  652. ->where('stealth_switch',1)
  653. ->where('is_cancellation_account',1)
  654. ->where('is_del',1)
  655. ->when($keywords,function ($query) use ($keywords){
  656. if ($keywords){
  657. $query->whereLike('nickname','%'.$keywords.'%');
  658. }
  659. })
  660. ->when($sex,function ($query) use ($sex){
  661. $sex = $sex==1 ? 2 : 1;
  662. $query->where('sex',$sex);
  663. $user = Db::name('User')->where('sex',$sex)->where('is_del',1)
  664. ->field('id,nickname,headimgurl,date_of_birth,height,phone,wechat_id,annual_income,household,education,graduated_from,province,city,area,introduce_myself,family_background,interests_hobbies,love,other_half,why_single,look_life,label,imgs,professional')
  665. ->select();
  666. $ids = [];
  667. if ($user){
  668. foreach ($user as &$k){
  669. $improve = intval(count(array_filter($k))/count($k)*100); //完善度
  670. if ($improve>=50){
  671. $ids[] = $k['id'];
  672. }
  673. }
  674. }
  675. if (count($ids)>0){
  676. $query->whereIn('id',$ids);
  677. }
  678. })
  679. ->when($hope_age,function ($query) use ($hope_age){
  680. if ($hope_age){
  681. $query->whereBetween('age',$hope_age);
  682. }
  683. })
  684. ->when($hope_height,function ($query) use ($hope_height){
  685. if ($hope_height){
  686. $query->whereBetween('height',$hope_height);
  687. }
  688. })
  689. ->when($hope_city,function ($query) use ($hope_city,$city){
  690. if ($hope_city && $hope_city==2 && $city){
  691. $query->whereLike('city','%'.$city.'%');
  692. }elseif ($hope_city && $hope_city==1 && $city){
  693. $query->orderRaw('city="'.$city.'" desc');
  694. }
  695. })
  696. ->when($hope_education,function ($query) use ($hope_education){
  697. if ($hope_education==1){
  698. $array = ['本科','硕士','博士'];
  699. $query->whereIn('education',$array);
  700. }elseif ($hope_education==2){
  701. $array = ['硕士','博士'];
  702. $query->whereIn('education',$array);
  703. }
  704. })
  705. ->when($hope_marriage,function ($query) use ($hope_marriage){
  706. if ($hope_marriage && $hope_marriage==1){
  707. $query->where('marriage',1);
  708. }
  709. })
  710. ->when($work_auth_company_name,function ($query) use ($work_auth_company_name,$work_auth_status){
  711. if ($work_auth_company_name && $work_auth_status==1){
  712. $query->whereRaw('work_auth_company_name like "%'.$work_auth_company_name.'%" and shielding_colleagues_switch=1 or work_auth_company_name not like "%'.$work_auth_company_name.'%" or work_auth_company_name=""' );
  713. }
  714. })
  715. ->when($hope_hometown,function ($query) use ($hope_hometown,$household){
  716. if ($hope_hometown && $hope_hometown==2){
  717. $query->orderRaw('household="'.$household.'" desc');
  718. }
  719. })
  720. ->field('*,'.UserWantKnow::where('to_user_id',$user['id'])->count().' as like_count');
  721. }
  722. /**
  723. * 判断认证信息
  724. * type 1:实名认证 2:工作认证 3:学历认证
  725. */
  726. public static function check_auth($type){
  727. $user = app()->session->get('us');
  728. $user = Db::name('user')->where('id',$user['id'])->find();
  729. switch ($type){
  730. case 1:
  731. if ($user['real_auth_status']==1){
  732. return false;
  733. }
  734. break;
  735. case 2:
  736. if ($user['work_auth_status']==1){
  737. return false;
  738. }
  739. break;
  740. case 3:
  741. if ($user['education_auth_status']==1){
  742. return false;
  743. }
  744. break;
  745. }
  746. return true;
  747. }
  748. /**
  749. * 收藏用户
  750. */
  751. public static function collectUser($user_id){
  752. $user = app()->session->get('us');
  753. if ($user_id==$user['id'])
  754. return Common::return_error('不能收藏自己');
  755. $collect = Collection::where('user_id',$user['id'])
  756. ->where('to_user_id',$user_id)
  757. ->where('is_effective',1)
  758. ->find();
  759. if ($collect)
  760. return Common::return_error('已收藏');
  761. $count = Collection::where('a.user_id',$user['id'])
  762. ->alias('a')
  763. ->where('b.is_del',1)
  764. ->join('User b','a.to_user_id=b.id')
  765. ->where('a.is_effective',1)
  766. ->count();
  767. $collect_num = Config::get_values('collect_num');
  768. $collect_num = $collect_num ? $collect_num : 10;
  769. if ($count>=$collect_num)
  770. return Common::return_error('收藏卡数量不足');
  771. $data['user_id'] = $user['id'];
  772. $data['to_user_id'] = $user_id;
  773. if (Collection::create($data)){
  774. return Common::return_success('收藏成功');
  775. }else{
  776. return Common::return_error('收藏失败');
  777. }
  778. }
  779. /**
  780. * 取消收藏用户
  781. */
  782. public static function delCollectUser($user_id){
  783. $user = app()->session->get('us');
  784. $collect = Collection::where('user_id',$user['id'])
  785. ->where('to_user_id',$user_id)
  786. ->where('is_effective',1)
  787. ->find();
  788. if (!$collect)
  789. return Common::return_error('未收藏过');
  790. if (Collection::where('id',$collect['id'])->delete()){
  791. return Common::return_success('取消成功');
  792. }else{
  793. return Common::return_error('取消失败');
  794. }
  795. }
  796. /**
  797. * 收藏列表
  798. */
  799. public static function collectList(){
  800. $user = app()->session->get('us');
  801. $list = Collection::where('a.user_id',$user['id'])->alias('a')
  802. ->where('a.is_effective',1)
  803. ->where('b.is_del',1)
  804. ->join('User b','a.to_user_id=b.id')
  805. ->order('a.id desc')
  806. ->field('b.*')
  807. ->select();
  808. if ($list) $list = $list->toArray();
  809. foreach ($list as $k=>$v){
  810. if (!$v['imgs']){
  811. $list[$k]['imgs'] = [];
  812. }else{
  813. $list[$k]['imgs'] = explode(',',$v['imgs']);
  814. }
  815. if ($v['household']){
  816. $household = explode('-',$v['household']);
  817. $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';
  818. }else{
  819. $list[$k]['household_city'] = '';
  820. }
  821. }
  822. return Common::return_success('成功',$list);
  823. }
  824. /**
  825. * 特权价格列表
  826. */
  827. public static function privilegePriceList(){
  828. $list = PrivilegePrice::where('is_del',1)
  829. ->where('status',1)
  830. ->order('integral asc')
  831. ->field('status,is_del,create_at,update_at',true)
  832. ->select();
  833. if ($list) $list = $list->toArray();
  834. return Common::return_success('成功',$list);
  835. }
  836. /**
  837. * 开通特权
  838. */
  839. public static function openPrivilege($privilege_id){
  840. $user = app()->session->get('us');
  841. $user = Db::name('user')->where('id',$user['id'])->find();
  842. $privilege = PrivilegePrice::where('id',$privilege_id)
  843. ->where('status',1)
  844. ->where('is_del',1)
  845. ->find();
  846. if (!$privilege)
  847. return Common::return_error('价格不存在');
  848. if ($user['integral']<$privilege['integral'])
  849. return Common::return_error('积分不足');
  850. Db::startTrans();
  851. try {
  852. if ($user['open_privilege']==1)
  853. $privilege_overdue_time = $user['privilege_overdue_time']+$privilege['day']*24*60*60;
  854. else
  855. $privilege_overdue_time = time() + $privilege['day']*24*60*60;
  856. //扣除积分
  857. self::integral($privilege['integral'],$user['id'],'开通特权');
  858. self::where('id',$user['id'])->update(['open_privilege'=>1,'privilege_overdue_time'=>$privilege_overdue_time]);
  859. $data['user_id'] = $user['id'];
  860. $data['privilege_id'] = $privilege_id;
  861. $data['title'] = $privilege['title'];
  862. $data['day'] = $privilege['day'];
  863. PrivilegeLog::create($data);
  864. Db::commit();
  865. return Common::return_success('开成通功');
  866. }catch (Exception $e) {
  867. Db::rollback();
  868. return Common::return_error('开通失败');
  869. }
  870. }
  871. /**
  872. * 想认识我列表
  873. */
  874. public static function wantToMeList($Nowpage,$limits){
  875. $user = app()->session->get('us');
  876. $user = Db::name('user')->where('id',$user['id'])->find();
  877. if (!$user['open_privilege'])
  878. return Common::return_error('未开通特权');
  879. $count = UserWantKnow::where('a.to_user_id',$user['id'])
  880. ->alias('a')
  881. ->where('b.is_del',1)
  882. ->join('User b','a.user_id=b.id')
  883. ->count();
  884. if ($count){
  885. $list = UserWantKnow::where('a.to_user_id',$user['id'])
  886. ->alias('a')
  887. ->where('b.is_del',1)
  888. ->join('User b','a.user_id=b.id')
  889. ->field('b.id as user_id,b.nickname,b.headimgurl,a.create_at')
  890. ->page($Nowpage,$limits)
  891. ->order('a.id desc')
  892. ->select()
  893. ->toArray();
  894. }else{
  895. $list = [];
  896. }
  897. return Common::return_success('成功',compact('count','list'));
  898. }
  899. /**
  900. * 我想认识-收到的
  901. */
  902. public static function ReceiveWantKnow(){
  903. $user = app()->session->get('us');
  904. //待处理列表
  905. $pending = UserWantKnow::where('to_user_id',$user['id'])
  906. ->where('state',1)
  907. ->field('id,leave_message,state,deal_at,refused_why,create_at,user_id')
  908. ->order('id desc')
  909. ->all()
  910. ->toArray();
  911. if ($pending){
  912. foreach ($pending as &$v){
  913. $seven = date('Y-m-d H:i:s',strtotime($v['create_at'])+(7*24*60*60));
  914. $v['seven'] = Common::timeTranRun($seven);
  915. $touser = Db::name('User')->where('id',$v['user_id'])->find();
  916. if (!$touser)
  917. return Common::return_error('用户不存在');
  918. if (!$touser['label']){
  919. $touser['label'] = [];
  920. }else{
  921. $touser['label'] = explode(',', $touser['label']);
  922. }
  923. if (!$touser['imgs']){
  924. $touser['imgs'] = [];
  925. }else{
  926. $touser['imgs'] = explode(',',$touser['imgs']);
  927. }
  928. if (!$touser['hope_age']){
  929. $touser['hope_age'] = [];
  930. }else{
  931. $touser['hope_age'] = explode(',',$touser['hope_age']);
  932. }
  933. if (!$touser['hope_height']){
  934. $touser['hope_height'] = [];
  935. }else{
  936. $touser['hope_height'] = explode(',',$touser['hope_height']);
  937. }
  938. if (!$touser['introduce_myself_imgs']) {
  939. $touser['introduce_myself_imgs'] = [];
  940. }else{
  941. $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
  942. }
  943. if (!$touser['family_background_imgs']) {
  944. $touser['family_background_imgs'] = [];
  945. }else{
  946. $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
  947. }
  948. if (!$touser['interests_hobbies_imgs']) {
  949. $touser['interests_hobbies_imgs'] = [];
  950. }else{
  951. $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
  952. }
  953. if (!$touser['love_imgs']){
  954. $touser['love_imgs'] = [];
  955. }else{
  956. $touser['love_imgs'] = explode(',',$touser['love_imgs']);
  957. }
  958. if (!$touser['other_half_imgs']){
  959. $touser['other_half_imgs'] = [];
  960. }else{
  961. $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
  962. }
  963. if (!$touser['why_single_imgs']){
  964. $touser['why_single_imgs'] = [];
  965. }else{
  966. $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
  967. }
  968. if (!$touser['look_life_imgs']){
  969. $touser['look_life_imgs'] = [];
  970. }else{
  971. $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
  972. }
  973. if (!$touser['real_auth_img']){
  974. $touser['real_auth_img'] = [];
  975. }else{
  976. $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
  977. }
  978. if (!$touser['work_auth_img']){
  979. $touser['work_auth_img'] = [];
  980. }else{
  981. $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
  982. }
  983. if (!$touser['education_auth_img']){
  984. $touser['education_auth_img'] = [];
  985. }else{
  986. $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
  987. }
  988. if ($touser['household']){
  989. $household = explode('-',$touser['household']);
  990. $touser['household_city'] = $household[1];
  991. }else{
  992. $touser['household_city'] = '';
  993. }
  994. $v['userinfo'] = $touser;
  995. }
  996. }
  997. $pend['count'] = count($pending);
  998. $pend['list'] = $pending;
  999. $array['pending'] = $pend;
  1000. //已处理
  1001. $have_deal = UserWantKnow::where('to_user_id',$user['id'])
  1002. ->alias('a')
  1003. ->join('User b','a.user_id=b.id')
  1004. ->where('a.state','neq',1)
  1005. ->field('a.id,a.user_id,a.leave_message,a.state,a.deal_at,a.refused_why,a.create_at,b.nickname,b.headimgurl')
  1006. ->order('id desc')
  1007. ->all()
  1008. ->toArray();
  1009. if ($have_deal){
  1010. foreach ($have_deal as &$v){
  1011. $seven = date('Y-m-d H:i:s',strtotime($v['create_at'])+(7*24*60*60));
  1012. $v['seven'] = Common::timeTranRun($seven);
  1013. $touser = Db::name('User')->where('id',$v['user_id'])->find();
  1014. if (!$touser)
  1015. return Common::return_error('用户不存在');
  1016. if (!$touser['label']){
  1017. $touser['label'] = [];
  1018. }else{
  1019. $touser['label'] = explode(',', $touser['label']);
  1020. }
  1021. if (!$touser['imgs']){
  1022. $touser['imgs'] = [];
  1023. }else{
  1024. $touser['imgs'] = explode(',',$touser['imgs']);
  1025. }
  1026. if (!$touser['hope_age']){
  1027. $touser['hope_age'] = [];
  1028. }else{
  1029. $touser['hope_age'] = explode(',',$touser['hope_age']);
  1030. }
  1031. if (!$touser['hope_height']){
  1032. $touser['hope_height'] = [];
  1033. }else{
  1034. $touser['hope_height'] = explode(',',$touser['hope_height']);
  1035. }
  1036. if (!$touser['introduce_myself_imgs']) {
  1037. $touser['introduce_myself_imgs'] = [];
  1038. }else{
  1039. $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
  1040. }
  1041. if (!$touser['family_background_imgs']) {
  1042. $touser['family_background_imgs'] = [];
  1043. }else{
  1044. $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
  1045. }
  1046. if (!$touser['interests_hobbies_imgs']) {
  1047. $touser['interests_hobbies_imgs'] = [];
  1048. }else{
  1049. $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
  1050. }
  1051. if (!$touser['love_imgs']){
  1052. $touser['love_imgs'] = [];
  1053. }else{
  1054. $touser['love_imgs'] = explode(',',$touser['love_imgs']);
  1055. }
  1056. if (!$touser['other_half_imgs']){
  1057. $touser['other_half_imgs'] = [];
  1058. }else{
  1059. $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
  1060. }
  1061. if (!$touser['why_single_imgs']){
  1062. $touser['why_single_imgs'] = [];
  1063. }else{
  1064. $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
  1065. }
  1066. if (!$touser['look_life_imgs']){
  1067. $touser['look_life_imgs'] = [];
  1068. }else{
  1069. $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
  1070. }
  1071. if (!$touser['real_auth_img']){
  1072. $touser['real_auth_img'] = [];
  1073. }else{
  1074. $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
  1075. }
  1076. if (!$touser['work_auth_img']){
  1077. $touser['work_auth_img'] = [];
  1078. }else{
  1079. $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
  1080. }
  1081. if (!$touser['education_auth_img']){
  1082. $touser['education_auth_img'] = [];
  1083. }else{
  1084. $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
  1085. }
  1086. if ($touser['household']){
  1087. $household = explode('-',$touser['household']);
  1088. $touser['household_city'] = $household[1];
  1089. }else{
  1090. $touser['household_city'] = '';
  1091. }
  1092. $v['userinfo'] = $touser;
  1093. }
  1094. }
  1095. $deal['count'] = count($have_deal);
  1096. $deal['list'] = $have_deal;
  1097. $array['have_deal'] = $deal;
  1098. return Common::return_success('成功',$array);
  1099. }
  1100. /**
  1101. * 我想认识-我发出的
  1102. */
  1103. public static function ApplyWantKnow(){
  1104. $user = app()->session->get('us');
  1105. $list = UserWantKnow::where('user_id',$user['id'])
  1106. ->field('id,leave_message,state,deal_at,refused_why,create_at,to_user_id')
  1107. ->whereNotIn('state','4,5')
  1108. ->order('id desc')
  1109. ->all()
  1110. ->toArray();
  1111. foreach ($list as &$v){
  1112. $seven = date('Y-m-d H:i:s',strtotime($v['create_at'])+(7*24*60*60));
  1113. $v['seven'] = Common::timeTranRun($seven);
  1114. $touser = Db::name('User')->where('id',$v['to_user_id'])->find();
  1115. if (!$touser)
  1116. return Common::return_error('用户不存在');
  1117. if (!$touser['label']){
  1118. $touser['label'] = [];
  1119. }else{
  1120. $touser['label'] = explode(',', $touser['label']);
  1121. }
  1122. if (!$touser['imgs']){
  1123. $touser['imgs'] = [];
  1124. }else{
  1125. $touser['imgs'] = explode(',',$touser['imgs']);
  1126. }
  1127. if (!$touser['hope_age']){
  1128. $touser['hope_age'] = [];
  1129. }else{
  1130. $touser['hope_age'] = explode(',',$touser['hope_age']);
  1131. }
  1132. if (!$touser['hope_height']){
  1133. $touser['hope_height'] = [];
  1134. }else{
  1135. $touser['hope_height'] = explode(',',$touser['hope_height']);
  1136. }
  1137. if (!$touser['introduce_myself_imgs']) {
  1138. $touser['introduce_myself_imgs'] = [];
  1139. }else{
  1140. $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
  1141. }
  1142. if (!$touser['family_background_imgs']) {
  1143. $touser['family_background_imgs'] = [];
  1144. }else{
  1145. $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
  1146. }
  1147. if (!$touser['interests_hobbies_imgs']) {
  1148. $touser['interests_hobbies_imgs'] = [];
  1149. }else{
  1150. $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
  1151. }
  1152. if (!$touser['love_imgs']){
  1153. $touser['love_imgs'] = [];
  1154. }else{
  1155. $touser['love_imgs'] = explode(',',$touser['love_imgs']);
  1156. }
  1157. if (!$touser['other_half_imgs']){
  1158. $touser['other_half_imgs'] = [];
  1159. }else{
  1160. $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
  1161. }
  1162. if (!$touser['why_single_imgs']){
  1163. $touser['why_single_imgs'] = [];
  1164. }else{
  1165. $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
  1166. }
  1167. if (!$touser['look_life_imgs']){
  1168. $touser['look_life_imgs'] = [];
  1169. }else{
  1170. $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
  1171. }
  1172. if (!$touser['real_auth_img']){
  1173. $touser['real_auth_img'] = [];
  1174. }else{
  1175. $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
  1176. }
  1177. if (!$touser['work_auth_img']){
  1178. $touser['work_auth_img'] = [];
  1179. }else{
  1180. $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
  1181. }
  1182. if (!$touser['education_auth_img']){
  1183. $touser['education_auth_img'] = [];
  1184. }else{
  1185. $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
  1186. }
  1187. if ($touser['household']){
  1188. $household = explode('-',$touser['household']);
  1189. $touser['household_city'] = $household[1];
  1190. }else{
  1191. $touser['household_city'] = '';
  1192. }
  1193. $v['userinfo'] = $touser;
  1194. }
  1195. $count = count($list);
  1196. return Common::return_success('成功',compact('count','list'));
  1197. }
  1198. /**
  1199. * 我想认识-查看详情
  1200. */
  1201. public static function WantKnowDetail($id){
  1202. $user = app()->session->get('us');
  1203. $info = UserWantKnow::where('id',$id)->find()->toArray();
  1204. $seven = date('Y-m-d H:i:s',strtotime($info['create_at'])+(7*24*60*60));
  1205. $info['seven'] = Common::timeTranRun($seven);
  1206. $times = Common::timeTranRun2($seven);
  1207. $info['day'] = $times['date'];
  1208. $info['hour'] = $times['hour'];
  1209. $info['minute'] = $times['minute'];
  1210. $info['seconds'] = $times['seconds'];
  1211. $info['list'] = UserWantKnowRecord::where('know_id',$id)
  1212. ->where('user_id',$user['id'])
  1213. ->order('sort desc')
  1214. ->all()
  1215. ->toArray();
  1216. $array['info'] = $info;
  1217. return Common::return_success('成功',$info);
  1218. }
  1219. /**
  1220. * 好友列表
  1221. */
  1222. public static function FriendList(){
  1223. $user = app()->session->get('us');
  1224. $array = array();
  1225. //系统消息
  1226. $official = OfficialMessage::where('status',1)
  1227. ->where('is_del',1)
  1228. ->field('id,content,create_at')
  1229. ->select();
  1230. if ($official){
  1231. $official = $official->toArray();
  1232. foreach ($official as $k=>$v){
  1233. $official[$k]['id'] = 'off_'.$v['id'];
  1234. $official[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
  1235. $official[$k]['user_id'] = 0;
  1236. $official[$k]['type'] = 3;
  1237. $official[$k]['title'] = '官方消息';
  1238. $read = OfficialUser::where('message_id',$v['id'])->where('user_id',$user['id'])->count();
  1239. $official[$k]['is_read'] = $read ? 1 : 0;
  1240. }
  1241. }
  1242. $list = Message::where('user_id',$user['id'])
  1243. ->order('id desc')
  1244. ->select();
  1245. if ($list){
  1246. $list = $list->toArray();
  1247. foreach ($list as $k=>$v){
  1248. $list[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
  1249. }
  1250. }
  1251. $list = array_merge($official,$list);
  1252. array_multisort(array_column($list,'create_at'),SORT_DESC,$list);
  1253. $array['message_list'] = $list;
  1254. //获取环信好友ID
  1255. $ids = Common::friend_list('huxuanmao-'.$user['id']);
  1256. //全部好友
  1257. $good_friends = Db::name('user')->whereIn('huanxinID',$ids)
  1258. ->field('id,nickname,headimgurl,age,education,height,work_auth_company_name,graduated_from')
  1259. ->select();
  1260. if ($good_friends){
  1261. foreach ($good_friends as &$v){
  1262. $star = UserStar::where('user_id',$user['id'])->where('to_user_id',$v['id'])->count();
  1263. $v['star'] = $star ? true : false;
  1264. //我是否屏蔽对方
  1265. $shielding_user =ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$v['id'])->count();
  1266. $v['shielding_to'] = $shielding_user > 0 ? true : false;
  1267. //对方是否屏蔽我
  1268. $shielding_my =ShieldingKnowUsers::where('user_id',$v['id'])->where('to_user_id',$user['id'])->count();
  1269. $v['shielding_my'] = $shielding_my > 0 ? true : false;
  1270. }
  1271. }
  1272. $array['good_friends'] = $good_friends;
  1273. //星标好友
  1274. $toUserIds = UserStar::where('user_id',$user['id'])->column('to_user_id');
  1275. $star_friends = Db::name('user')->whereIn('huanxinID',$ids)
  1276. ->whereIn('id',$toUserIds)
  1277. ->field('id,nickname,headimgurl,age,education,height,work_auth_company_name,graduated_from')
  1278. ->select();
  1279. if ($star_friends){
  1280. foreach ($star_friends as &$v){
  1281. //我是否屏蔽对方
  1282. $shielding_user =ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$v['id'])->count();
  1283. $v['shielding_to'] = $shielding_user > 0 ? true : false;
  1284. //对方是否屏蔽我
  1285. $shielding_my =ShieldingKnowUsers::where('user_id',$v['id'])->where('to_user_id',$user['id'])->count();
  1286. $v['shielding_my'] = $shielding_my > 0 ? true : false;
  1287. }
  1288. }
  1289. $array['star_friends'] = $star_friends;
  1290. return Common::return_success('成功',$array);
  1291. }
  1292. /**
  1293. * 聊天小图标列表
  1294. */
  1295. public static function IconList(){
  1296. $list = Icon::where('status',1)
  1297. ->field('is_del,status,update_at',true)
  1298. ->where('is_del',1)
  1299. ->all();
  1300. return Common::return_success('成功',$list);
  1301. }
  1302. /**
  1303. * 积分充值
  1304. */
  1305. public static function userRecharge($integral){
  1306. $user = app()->session->get('us');
  1307. $userinfo = self::where('id',$user['id'])->find();
  1308. //获取支付金额
  1309. $pay_money = $integral;
  1310. $wx = new WxPay();//实例化微信torganizationid支付控制器
  1311. $notify_url = 'https://'.$_SERVER['SERVER_NAME'].'/api/pay/pay_check_order';//回调地址
  1312. $config = $wx->retrunconfig();
  1313. $config['notify_url'] = $notify_url;
  1314. $order_no = Common::getNewOrderId($user['id']);
  1315. $body = '订单号' . $order_no;//支付说明
  1316. $total_fee = $pay_money * 100;//支付金额(乘以100)
  1317. Db::startTrans();
  1318. try{
  1319. $data['user_id'] = $user['id'];
  1320. $data['order_no'] = $order_no;
  1321. $data['price'] = $pay_money;
  1322. UserRecharge::create($data);
  1323. $app = Factory::payment($config);
  1324. $order = $app->order->unify([
  1325. 'body' => $body,
  1326. 'out_trade_no' => $order_no,
  1327. 'total_fee' => $total_fee,
  1328. 'trade_type' => "JSAPI", // JSAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
  1329. 'openid' => $userinfo['openid'],
  1330. ]);
  1331. if ($order['return_msg']=='OK'){
  1332. if ($order['result_code']=='FAIL'){
  1333. Db::rollback();
  1334. return Common::return_error($order['err_code_des']);
  1335. }else{
  1336. $order1 = $app->jssdk->bridgeConfig($order['prepay_id']);//执行二次签名返回参数
  1337. $retrun_data['order_no'] = $order_no;
  1338. $retrun_data['pay'] = json_decode($order1,true);
  1339. Db::commit();
  1340. return Common::return_success('成功',$retrun_data);
  1341. }
  1342. } else {
  1343. Db::rollback();
  1344. return Common::return_error($order['return_msg']);
  1345. }
  1346. }catch (Exception $e){
  1347. Db::rollback();
  1348. return Common::return_error($order['return_msg']);
  1349. }
  1350. }
  1351. /**
  1352. * 余额提现
  1353. */
  1354. public static function userWithdraw($money){
  1355. $user = app()->session->get('us');
  1356. $userinfo = self::where('id',$user['id'])->find();
  1357. $withdraw_min_price = Config::get_values('withdraw_min_price'); //最小提现金额
  1358. $withdraw_max_price = Config::get_values('withdraw_max_price'); //最大提现金额
  1359. if ($money < $withdraw_min_price)
  1360. return Common::return_error('最低提现'.$withdraw_min_price.'元');
  1361. if ($money > $withdraw_max_price)
  1362. return Common::return_error('最大提现'.$withdraw_min_price.'元');
  1363. if ($userinfo['integral']<$money)
  1364. return Common::return_error('余额不足');
  1365. if (!$userinfo['wechat_id'])
  1366. return Common::return_error('微信号未设置,请先完善资料');
  1367. $data['user_id'] = $user['id'];
  1368. $order_no = Common::getNewOrderId($user['id']);
  1369. $data['order_no'] = $order_no;
  1370. $data['price'] = $money;
  1371. $poundage_proportion = Config::get_values('poundage_proportion'); //手续费百分比
  1372. $data['poundage_proportion'] = $poundage_proportion;
  1373. $proportion = sprintf("%.2f", $money*($poundage_proportion/100)); //四舍五入保留两位小数点
  1374. $data['proportion'] = $proportion;
  1375. $real_money = $money-$proportion;
  1376. $data['real_money'] = $real_money;
  1377. Db::startTrans();
  1378. try {
  1379. UserWithdraw::create($data);
  1380. User::integral($money,$user['id'],'微信提现'.$money);
  1381. //消息推送
  1382. $openid = User::where('administrator',1)->where('is_del',1)->order('id asc')->limit(1)->value('openid');
  1383. $template_id = "gJRFKgj0PSYrz0Yg0HxMZUH0Sm3r9Uux1mDFOkDBc44";
  1384. $path = "";
  1385. $data = [
  1386. 'first'=>[
  1387. "value"=>'你好,有一笔提现申请未处理',
  1388. "color"=>"#173177"
  1389. ],
  1390. 'keyword1'=>[
  1391. "value"=>$user['nickname'],
  1392. "color"=>"#173177"
  1393. ],
  1394. 'keyword2'=>[
  1395. "value"=>date('Y-m-d H:i:s'),
  1396. "color"=>"#173177"
  1397. ],
  1398. 'keyword3'=>[
  1399. "value"=>$money."元",
  1400. "color"=>"#173177"
  1401. ],
  1402. 'keyword4'=>[
  1403. "value"=>"微信提现",
  1404. "color"=>"#173177"
  1405. ],
  1406. 'remark'=>[
  1407. "value"=>'快去处理吧',
  1408. "color"=>"#173177"
  1409. ]
  1410. ];
  1411. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  1412. Db::commit();
  1413. return Common::return_success('提交成功,等待审核');
  1414. // $opend_id = $userinfo['openid'];
  1415. // if (!$opend_id)
  1416. // return Common::return_error('未绑定微信,无法提现');
  1417. // $wx = new WxMerchPay();
  1418. // $result = $wx->sendMoney($real_money,$opend_id,$order_no,'余额提现');
  1419. // if ($result['return_code']=='SUCCESS' && $result['result_code']=='SUCCESS'){
  1420. // User::integral($money,$user['id'],'微信提现'.$money);
  1421. // UserWithdraw::where('order_no',$order_no)->update(['paid'=>1,'pay_time'=>time(),'return_info'=>json_encode($result,true)]);
  1422. // Db::commit();
  1423. // return Common::return_success('提现成功');
  1424. // }else{
  1425. // UserWithdraw::where('order_no',$order_no)->update(['return_info'=>json_encode($result,true)]);
  1426. // Db::commit();
  1427. // return Common::return_error('提现失败');
  1428. // }
  1429. }catch (Exception $e) {
  1430. Db::rollback();
  1431. return Common::return_error('提现失败');
  1432. }
  1433. }
  1434. /**
  1435. * 提现记录
  1436. */
  1437. public static function userWithdrawLog(){
  1438. $user = app()->session->get('us');
  1439. $list = UserWithdraw::where('user_id',$user['id'])->select();
  1440. return Common::return_success('成功',$list);
  1441. }
  1442. /**
  1443. * 注销账号
  1444. */
  1445. public static function cancellationAccount(){
  1446. $user = app()->session->get('us');
  1447. $userInfo = self::where('id',$user['id'])->find();
  1448. $userInfo->is_cancellation_account = 0;
  1449. $userInfo->cancellation_time = time();
  1450. if ($userInfo->save()){
  1451. app()->session->clear();
  1452. app()->session->destroy();
  1453. return Common::return_success('注销成功');
  1454. }
  1455. return Common::return_error('注销失败');
  1456. }
  1457. /**
  1458. * 特权到期脚本
  1459. */
  1460. public static function privilegeOverdue(){
  1461. self::where('open_privilege',1)->where('privilege_overdue_time','lt',time())->update(['open_privilege'=>0]);
  1462. }
  1463. /**
  1464. * 每周五24后收藏卡清空
  1465. */
  1466. public static function collectionEmpty(){
  1467. Collection::where('is_effective',1)->update(['is_effective'=>0]);
  1468. }
  1469. /**
  1470. * 判断禁用时间是否到期
  1471. */
  1472. public static function disableOverdue(){
  1473. User::where('status',0)
  1474. ->whereNotNull('due_time')
  1475. ->where('is_del',1)
  1476. ->where('is_cancellation_account',1)
  1477. ->chunk(20,function ($list){
  1478. foreach ($list as &$v){
  1479. if (time()>strtotime($v['due_time'])){
  1480. User::where('id',$v['id'])->update(
  1481. [
  1482. 'status'=>1
  1483. ]
  1484. );
  1485. }
  1486. }
  1487. });
  1488. }
  1489. /**
  1490. * 判断好友申请七天是否过期
  1491. */
  1492. public static function applyOverdue(){
  1493. UserWantKnow::where('state',1)
  1494. ->chunk('20',function ($list){
  1495. foreach ($list as &$v) {
  1496. $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
  1497. $seven = strtotime($v['create_at'])+(7*24*60*60);
  1498. if ($seven<time()){
  1499. UserWantKnow::where('id',$v['id'])->update(
  1500. [
  1501. 'state'=>4,
  1502. 'deal_at'=>date('Y-m-d H:i:s'),
  1503. 'refused_why'=>'七天未处理,自动拒绝'
  1504. ]
  1505. );
  1506. //返积分
  1507. $fan_integral = round($v['integral']*($notAgreeReturnIntegral/100));
  1508. User::integral($fan_integral,$v['user_id'],'申请七天未处理返积分',1);
  1509. }
  1510. }
  1511. },'id','asc');
  1512. }
  1513. /**
  1514. * 晚上八点推荐单身广场
  1515. */
  1516. public static function recommended(){
  1517. User::where('is_cancellation_account',1)->where('is_del',1)->where('daily_recommendation_switch',1)
  1518. ->field('id,openid,nickname')
  1519. ->chunk('20',function ($list){
  1520. foreach ($list as &$v){
  1521. $openid = $v['openid'];
  1522. $template_id = "BFPD1LVboI1ZGGj4bdC6shb9Eec0uNGaSo1WYyt127U";
  1523. $path = "";
  1524. $data = [
  1525. 'first'=>[
  1526. "value"=>'平台推荐通知',
  1527. "color"=>"#173177"
  1528. ],
  1529. 'keyword1'=>[
  1530. "value"=>$v['nickname'],
  1531. "color"=>"#173177"
  1532. ],
  1533. 'keyword2'=>[
  1534. "value"=>date('Y-m-d H:i'),
  1535. "color"=>"#173177"
  1536. ],
  1537. 'remark'=>[
  1538. "value"=>'今日份推荐已生成,快去看看吧',
  1539. "color"=>"#173177"
  1540. ]
  1541. ];
  1542. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  1543. }
  1544. },'id','asc');
  1545. }
  1546. }