ElectPool.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\WxPay;
  4. use EasyWeChat\Factory;
  5. use think\Model;
  6. use app\common\library\Common;
  7. use think\Db;
  8. /**
  9. * 互选池
  10. */
  11. class ElectPool Extends Model
  12. {
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'TIMESTAMP';
  15. // 定义时间戳字段名
  16. protected $createTime = 'create_at';
  17. protected $updateTime = 'update_at';
  18. /**
  19. * 创建互选池
  20. */
  21. public static function createElectPool($data,$pool_id){
  22. $user = app()->session->get('us');
  23. $data['user_id'] = $user['id'];
  24. if ($pool_id){
  25. $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
  26. if (!$pool)
  27. return Common::return_error('互选池不存在');
  28. }else{
  29. $data['password'] = mt_rand(1000, 9999);
  30. }
  31. Db::startTrans();
  32. try {
  33. if (!$pool_id){
  34. $pool = self::create($data);
  35. //群主加入互选池
  36. $da['pool_id'] = $pool->id;
  37. $da['user_id'] = $user['id'];
  38. ElectPoolMembers::create($da);
  39. Db::commit();
  40. $elect_pool = Db::name('ElectPool')->where('id',$pool->id)->find();
  41. return Common::return_success('创建成功',$elect_pool);
  42. }else{
  43. self::where('id',$pool_id)->update($data);
  44. Db::commit();
  45. $elect_pool = Db::name('ElectPool')->where('id',$pool_id)->find();
  46. return Common::return_success('编辑成功',$elect_pool);
  47. }
  48. }catch (Exception $e) {
  49. Db::rollback();
  50. return Common::return_error('失败');
  51. }
  52. }
  53. /**
  54. * 首页互选池列表
  55. */
  56. public static function poolList($city,$keywords,$Nowpage,$limits){
  57. $count = self::byWhere($city,$keywords)->count();
  58. if (!$count){
  59. $city = '广州市';
  60. $count = self::byWhere($city,$keywords)->count();
  61. }
  62. $list = self::byWhere($city,$keywords)->page($Nowpage, $limits)->select();
  63. foreach ($list as $k=>$v){
  64. $list[$k]['education'] = explode(',',$v['education']);
  65. $list[$k]['pool_have_user'] = self::checkUserToPool($v['id']) ? true : false;
  66. }
  67. $data['count'] = $count;
  68. $data['list'] = $list;
  69. return Common::return_success('成功',$data);
  70. }
  71. /**
  72. * where条件
  73. */
  74. public static function byWhere($city,$keywords){
  75. $user = app()->session->get('us');
  76. $audit = Config::get_values('audit');
  77. $is_audit = $audit == 1 ? 0 : 1;
  78. $model = Db::name('ElectPool');
  79. //$model = $model->where('id','100615');
  80. $model = $model->where('is_audit',$is_audit);
  81. if ($keywords){
  82. $model = $model->where('name','like','%'.$keywords.'%');
  83. }else{
  84. if ($city){
  85. $model = $model->where('city','like','%'.$city.'%');
  86. }
  87. }
  88. $model = $model->where('is_dissolution',1);
  89. if ($user){
  90. $model = $model->orderRaw("user_id=".$user['id']." desc,now_number desc");
  91. }else{
  92. $model = $model->order('now_number desc');
  93. }
  94. return $model;
  95. }
  96. /**
  97. * 我创建的和加入的互选池
  98. */
  99. public static function myCreateJoinPool($city,$Nowpage,$limits){
  100. $count = self::byWhere2($city)
  101. ->alias('a')
  102. ->join('ElectPool b','a.pool_id=b.id')
  103. ->count();
  104. $data['count'] = $count;
  105. if ($count){
  106. $list = self::byWhere2($city)
  107. ->alias('a')
  108. ->field('b.*')
  109. ->join('ElectPool b','a.pool_id=b.id')
  110. ->page($Nowpage, $limits)
  111. ->select()
  112. ->toArray();
  113. foreach ($list as $k=>$v){
  114. $list[$k]['education'] = explode(',',$v['education']);
  115. $list[$k]['pool_have_user'] = self::checkUserToPool($v['id']) ? true : false;
  116. }
  117. }else{
  118. $list = [];
  119. }
  120. $data['list'] = $list;
  121. return Common::return_success('成功',$data);
  122. }
  123. /**
  124. * where条件
  125. */
  126. public static function byWhere2($city){
  127. $user = app()->session->get('us');
  128. $model = new ElectPoolMembers();
  129. // if ($city){
  130. // $model = $model->where('b.city','like','%'.$city.'%');
  131. // }
  132. $model = $model->where('a.user_id',$user['id'])->where('b.is_dissolution',1)
  133. ->orderRaw("b.user_id=".$user['id']." desc,now_number desc");
  134. return $model;
  135. }
  136. /**
  137. * 互选池详情页
  138. */
  139. public static function poolDetail($pool_id){
  140. $detail = Db::name('ElectPool')->where('id',$pool_id)->where('is_dissolution',1)->find();
  141. if (!$detail)
  142. return Common::return_error('互选池不存在或已解散');
  143. $detail['education'] = explode(',',$detail['education']);
  144. $detail['pool_have_user'] = self::checkUserToPool($pool_id) ? true : false;
  145. return Common::return_success('成功',$detail);
  146. }
  147. /**
  148. * 判断用户是否在互选池中
  149. */
  150. public static function checkUserToPool($pool_id){
  151. $user = app()->session->get('us');
  152. if (!$user)
  153. return false;
  154. $hive = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
  155. if (!$hive)
  156. return false;
  157. return true;
  158. }
  159. /**
  160. * 进入互选池
  161. */
  162. public static function intoPool($pool_id,$password=''){
  163. $user = app()->session->get('us');
  164. //判断是否完善资料
  165. $audit = Config::get_values('audit');
  166. if ($audit==1){
  167. if (!User::checkUserIformationPerfect($user['id'])){
  168. return Common::return_error('未完善资料,无法进入');
  169. }
  170. }
  171. //互选池资料
  172. $pool_detail = Db::name('ElectPool')->where('id',$pool_id)->where('is_dissolution',1)->find();
  173. if (!$pool_detail)
  174. return Common::return_error('互选池不存在或已解散');
  175. $member = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
  176. if ($pool_detail['type']==2){
  177. //如果已经在互选池中,不再判断密码
  178. if (!$member){
  179. if (!$password)
  180. return Common::return_error('密码为空');
  181. if ($password != $pool_detail['password'])
  182. return Common::return_error('密码不正确');
  183. }
  184. }
  185. //判断是否是被群主移出的
  186. $is_remove = ElectPoolRemovedUser::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
  187. if ($is_remove)
  188. return Common::return_error('被群主移出,无法再进入');
  189. if ($pool_detail['group_number']!=0){
  190. if (!$member){
  191. $all_count = ElectPoolMembers::where('pool_id',$pool_id)
  192. ->count();
  193. if ($all_count>=$pool_detail['group_number'])
  194. return Common::return_error('群人数已满,无法加入');
  195. }
  196. }
  197. $pool_detail['education'] = explode(',',$pool_detail['education']);
  198. $userinfo = User::get($user['id']);
  199. if ($userinfo['sex']==1)
  200. $sex = 2;
  201. else
  202. $sex = 1;
  203. $count = ElectPoolMembers::where('a.pool_id',$pool_id)
  204. ->alias('a')
  205. ->where('b.sex',$sex)
  206. ->join('User b','a.user_id=b.id')
  207. ->count();
  208. if ($count){
  209. $list = ElectPoolMembers::where('a.pool_id',$pool_id)
  210. ->alias('a')
  211. ->where('b.sex',$sex)
  212. ->join('User b','a.user_id=b.id')
  213. ->field('a.user_id,b.nickname,b.headimgurl,b.height,b.graduated_from,b.date_of_birth')
  214. ->order('a.id desc')
  215. ->select();
  216. foreach ($list as $k=>$v){
  217. $list[$k]['like_count'] = UserWantKnow::where('to_user_id',$v['user_id'])->count();
  218. $list[$k]['year'] = date('Y',strtotime($v['date_of_birth']));
  219. }
  220. }else
  221. $list = [];
  222. $data['count'] = $count;
  223. $data['list'] = $list;
  224. //进入互选池
  225. if (!$member){
  226. $da['pool_id'] = $pool_id;
  227. $da['user_id'] = $user['id'];
  228. Db::startTrans();
  229. try {
  230. ElectPoolMembers::create($da);
  231. self::where('id',$pool_id)->setInc('now_number'); //数量加1
  232. Db::commit();
  233. }catch (Exception $e) {
  234. Db::rollback();
  235. return Common::return_error('进入失败');
  236. }
  237. }
  238. return Common::return_success('成功',compact('pool_detail','data'));
  239. }
  240. /**
  241. * 获取互选池异性用户列表
  242. */
  243. public static function poolUserList($pool_id,$Nowpage,$limits){
  244. $user = app()->session->get('us');
  245. $userinfo = User::get($user['id']);
  246. $sex = $userinfo['sex']==1 ? 2 : 1;
  247. $work_auth_status = $userinfo['work_auth_status'];
  248. $work_auth_company_name = $userinfo['work_auth_company_name'];
  249. $count = ElectPoolMembers::where('a.pool_id',$pool_id)
  250. ->alias('a')
  251. ->where('b.sex',$sex)
  252. ->where('b.stealth_switch',1)
  253. ->where('b.is_cancellation_account',1)
  254. ->where('b.is_del',1)
  255. ->when($work_auth_company_name,function ($query) use ($work_auth_company_name,$work_auth_status){
  256. if ($work_auth_company_name && $work_auth_status==1){
  257. $query->whereRaw('b.work_auth_company_name like "%'.$work_auth_company_name.'%" and b.shielding_colleagues_switch=1 or b.work_auth_company_name not like "%'.$work_auth_company_name.'%" or b.work_auth_company_name=""');
  258. }
  259. })
  260. ->join('User b','a.user_id=b.id')
  261. ->count();
  262. if ($count){
  263. $list = ElectPoolMembers::where('a.pool_id',$pool_id)
  264. ->alias('a')
  265. ->where('b.sex',$sex)
  266. ->where('b.stealth_switch',1)
  267. ->where('b.is_cancellation_account',1)
  268. ->where('b.is_del',1)
  269. ->when($work_auth_company_name,function ($query) use ($work_auth_company_name,$work_auth_status){
  270. if ($work_auth_company_name && $work_auth_status==1){
  271. $query->whereRaw('b.work_auth_company_name like "%'.$work_auth_company_name.'%" and b.shielding_colleagues_switch=1 or b.work_auth_company_name not like "%'.$work_auth_company_name.'%" or b.work_auth_company_name=""');
  272. }
  273. })
  274. ->join('User b','a.user_id=b.id')
  275. ->field('a.user_id,b.*')
  276. ->order('a.id desc')
  277. ->page($Nowpage,$limits)
  278. ->select();
  279. foreach ($list as $k=>$v){
  280. $list[$k]['like_count'] = UserWantKnow::where('to_user_id',$v['user_id'])->count();
  281. $list[$k]['year'] = date('Y',strtotime($v['date_of_birth']));
  282. if ($v['household']){
  283. $household = explode('-',$v['household']);
  284. $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';;
  285. }else{
  286. $list[$k]['household_city'] = '';
  287. }
  288. if (!$v['introduce_myself_imgs']) {
  289. $list[$k]['introduce_myself_imgs'] = [];
  290. }else{
  291. $list[$k]['introduce_myself_imgs'] = explode(',',$v['introduce_myself_imgs']);
  292. }
  293. if (!$v['family_background_imgs']) {
  294. $list[$k]['family_background_imgs'] = [];
  295. }else{
  296. $list[$k]['family_background_imgs'] = explode(',',$v['family_background_imgs']);
  297. }
  298. if (!$v['interests_hobbies_imgs']) {
  299. $list[$k]['interests_hobbies_imgs'] = [];
  300. }else{
  301. $list[$k]['interests_hobbies_imgs'] = explode(',',$v['interests_hobbies_imgs']);
  302. }
  303. if (!$v['love_imgs']){
  304. $list[$k]['love_imgs'] = [];
  305. }else{
  306. $list[$k]['love_imgs'] = explode(',',$v['love_imgs']);
  307. }
  308. if (!$v['imgs']){
  309. $list[$k]['imgs'] = [];
  310. }else{
  311. $list[$k]['imgs'] = explode(',',$v['imgs']);
  312. }
  313. if (!$v['label']){
  314. $list[$k]['label'] = [];
  315. }else{
  316. $list[$k]['label'] = explode(',',$v['label']);
  317. }
  318. if (!$v['other_half_imgs']){
  319. $list[$k]['other_half_imgs'] = [];
  320. }else{
  321. $list[$k]['other_half_imgs'] = explode(',',$v['other_half_imgs']);
  322. }
  323. if (!$v['why_single_imgs']){
  324. $list[$k]['why_single_imgs'] = [];
  325. }else{
  326. $list[$k]['why_single_imgs'] = explode(',',$v['why_single_imgs']);
  327. }
  328. if (!$v['look_life_imgs']){
  329. $list[$k]['look_life_imgs'] = [];
  330. }else{
  331. $list[$k]['look_life_imgs'] = explode(',',$v['look_life_imgs']);
  332. }
  333. }
  334. }else
  335. $list = [];
  336. $data['count'] = $count;
  337. $data['list'] = $list;
  338. return Common::return_success('成功',$data);
  339. }
  340. /**
  341. * 退出互选池
  342. */
  343. public static function exitPool($pool_id){
  344. $user = app()->session->get('us');
  345. //互选池资料
  346. $pool_detail = Db::name('ElectPool')->where('id',$pool_id)->where('is_dissolution',1)->find();
  347. if (!$pool_detail)
  348. return Common::return_error('互选池不存在或已解散');
  349. $member = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
  350. if (!$member)
  351. return Common::return_error('不在互选池中');
  352. Db::startTrans();
  353. try {
  354. ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->delete();
  355. self::where('id',$pool_id)->setDec('now_number'); //数量减1
  356. Db::commit();
  357. return Common::return_success('退出成功');
  358. }catch (Exception $e) {
  359. Db::rollback();
  360. return Common::return_error('退出失败');
  361. }
  362. }
  363. /**
  364. * 查看用户资料
  365. */
  366. public static function SelUser($user_id){
  367. $user = app()->session->get('us');
  368. $touser = Db::name('User')->where('id',$user_id)->find();
  369. if (!$touser)
  370. return Common::return_error('用户不存在');
  371. if (!$touser['label']){
  372. $touser['label'] = [];
  373. }else{
  374. $touser['label'] = explode(',', $touser['label']);
  375. }
  376. if (!$touser['imgs']){
  377. $touser['imgs'] = [];
  378. }else{
  379. $touser['imgs'] = explode(',',$touser['imgs']);
  380. }
  381. if (!$touser['hope_age']){
  382. $touser['hope_age'] = [];
  383. }else{
  384. $touser['hope_age'] = explode(',',$touser['hope_age']);
  385. }
  386. if (!$touser['hope_height']){
  387. $touser['hope_height'] = [];
  388. }else{
  389. $touser['hope_height'] = explode(',',$touser['hope_height']);
  390. }
  391. if (!$touser['introduce_myself_imgs']) {
  392. $touser['introduce_myself_imgs'] = [];
  393. }else{
  394. $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
  395. }
  396. if (!$touser['family_background_imgs']) {
  397. $touser['family_background_imgs'] = [];
  398. }else{
  399. $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
  400. }
  401. if (!$touser['interests_hobbies_imgs']) {
  402. $touser['interests_hobbies_imgs'] = [];
  403. }else{
  404. $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
  405. }
  406. if (!$touser['love_imgs']){
  407. $touser['love_imgs'] = [];
  408. }else{
  409. $touser['love_imgs'] = explode(',',$touser['love_imgs']);
  410. }
  411. if (!$touser['other_half_imgs']){
  412. $touser['other_half_imgs'] = [];
  413. }else{
  414. $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
  415. }
  416. if (!$touser['why_single_imgs']){
  417. $touser['why_single_imgs'] = [];
  418. }else{
  419. $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
  420. }
  421. if (!$touser['look_life_imgs']){
  422. $touser['look_life_imgs'] = [];
  423. }else{
  424. $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
  425. }
  426. if (!$touser['real_auth_img']){
  427. $touser['real_auth_img'] = [];
  428. }else{
  429. $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
  430. }
  431. if (!$touser['work_auth_img']){
  432. $touser['work_auth_img'] = [];
  433. }else{
  434. $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
  435. }
  436. if (!$touser['education_auth_img']){
  437. $touser['education_auth_img'] = [];
  438. }else{
  439. $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
  440. }
  441. if ($touser['household']){
  442. $household = explode('-',$touser['household']);
  443. if (isset($household[1])){
  444. $touser['household_city'] = $household[1];
  445. }else{
  446. $touser['household_city'] = '';
  447. }
  448. }else{
  449. $touser['household_city'] = '';
  450. }
  451. if (!$user){
  452. $touser['is_want_know'] = false;
  453. $touser['is_integral_contact'] = false;
  454. $touser['wechat_id'] = "";
  455. $touser['is_collection'] = false;
  456. $touser['is_shielding'] = false;
  457. $touser['apply_state'] = false;
  458. $touser['star_switch'] = false;
  459. $touser['star'] = false;
  460. }else{
  461. //查看我是否已经喜欢过
  462. $want_know = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  463. $touser['is_want_know'] = $want_know ? true : false;
  464. //查看是否已经获取了联系方式
  465. $integral_record = IntegralContactRecord::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  466. $touser['is_integral_contact'] = $integral_record ? true : false;
  467. //查看对方是否也喜欢我
  468. $want_know2 = UserWantKnow::where('user_id',$user_id)->where('to_user_id',$user['id'])->count();
  469. if (!$integral_record){
  470. if (!$want_know || !$want_know2)
  471. $touser['wechat_id'] = "";
  472. }
  473. //查看是否收藏了对方
  474. $collection = Collection::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('is_effective',1)->count();
  475. $touser['is_collection'] = $collection > 0 ? true : false;
  476. //对方是否把你屏蔽
  477. $info = ShieldingKnowUsers::where('user_id',$user_id)->where('to_user_id',$user['id'])->count();
  478. $touser['is_shielding'] = $info > 0 ? true : false;
  479. //查看申请状态
  480. $apply = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  481. if (!$apply){
  482. $touser['apply_state'] = false;
  483. }else{
  484. $touser['apply_state'] = true;
  485. }
  486. //星标开关
  487. $star = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  488. $touser['star_switch'] = $star > 0 ? true : false;
  489. //是否星标好友
  490. $star2 = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  491. $touser['star'] = $star2 ? true : false;
  492. }
  493. return Common::return_success('成功',$touser);
  494. }
  495. /**
  496. * 查看申请
  497. */
  498. public static function SelApply($user_id){
  499. $user = app()->session->get('us');
  500. $touser = Db::name('User')->where('id',$user_id)->find();
  501. if (!$touser)
  502. return Common::return_error('用户不存在');
  503. $array = [];
  504. //查看我是否申请了对方
  505. $know = UserWantKnow::where('user_id',$user['id'])
  506. ->where('to_user_id',$user_id)
  507. ->whereNotIn('state','3,4,5')
  508. ->order('id desc')
  509. ->limit(1)
  510. ->field('id,leave_message,state,create_at')
  511. ->find();
  512. if ($know){
  513. $know = $know->toArray();
  514. $seven = date('Y-m-d H:i:s',strtotime($know['create_at'])+(7*24*60*60));
  515. $know['seven'] = Common::timeTranRun($seven);
  516. $know['list'] = UserWantKnowRecord::where('know_id',$know['id'])
  517. ->where('user_id',$user['id'])
  518. ->order('sort desc')
  519. ->field('id,content,create_at')
  520. ->select()->toArray();
  521. $array['type'] = 1;
  522. $array['info'] = $know;
  523. }else{
  524. $know = UserWantKnow::where('user_id',$user_id)
  525. ->where('to_user_id',$user['id'])
  526. ->whereNotIn('state','3,4,5')
  527. ->order('id desc')
  528. ->limit(1)
  529. ->field('id,leave_message,state,create_at')
  530. ->find();
  531. if ($know){
  532. $know = $know->toArray();
  533. $seven = date('Y-m-d H:i:s',strtotime($know['create_at'])+(7*24*60*60));
  534. $times = Common::timeTranRun2($seven);
  535. $know['day'] = $times['date'];
  536. $know['hour'] = $times['hour'];
  537. $know['minute'] = $times['minute'];
  538. $know['seconds'] = $times['seconds'];
  539. $know['list'] = UserWantKnowRecord::where('know_id',$know['id'])
  540. ->where('user_id',$user['id'])
  541. ->order('sort desc')
  542. ->field('id,content,create_at')
  543. ->select()->toArray();
  544. $array['type'] = 2;
  545. $array['info'] = $know;
  546. //判断是否有查看申请过
  547. $apply = UserWantKnowRecord::where('know_id',$know['id'])->where('user_id',$user['id'])->where('content','查看申请')->count();
  548. if (!$apply){
  549. UserWantKnowRecord::create(
  550. [
  551. 'know_id'=>$know['id'],
  552. 'user_id'=>$user['id'],
  553. 'content'=>'查看申请',
  554. 'sort'=>2
  555. ]
  556. );
  557. UserWantKnowRecord::create(
  558. [
  559. 'know_id'=>$know['id'],
  560. 'user_id'=>$user['id'],
  561. 'content'=>'等待处理',
  562. 'sort'=>3
  563. ]
  564. );
  565. UserWantKnowRecord::create(
  566. [
  567. 'know_id'=>$know['id'],
  568. 'user_id'=>$user_id,
  569. 'content'=>'对方查看了你的申请',
  570. 'sort'=>3
  571. ]
  572. );
  573. }
  574. }else{
  575. return Common::return_error('对方已取消');
  576. }
  577. }
  578. return Common::return_success('成功',$array);
  579. }
  580. /**
  581. * 终止申请
  582. */
  583. public static function TerminationApply($id){
  584. $user = app()->session->get('us');
  585. $info = UserWantKnow::where('id',$id)->where('user_id',$user['id'])->where('state',1)->find();
  586. $info = $info->toArray();
  587. if (!$info)
  588. return Common::return_error('申请不存在');
  589. Db::startTrans();
  590. try {
  591. UserWantKnow::where('id',$id)->update(
  592. [
  593. 'state'=>5,
  594. 'deal_at'=>date('Y-m-d H:i:s')
  595. ]
  596. );
  597. //记录
  598. UserWantKnowRecord::create(
  599. [
  600. 'know_id'=>$id,
  601. 'user_id'=>$user['id'],
  602. 'content'=>'终止申请',
  603. 'sort'=>4
  604. ]
  605. );
  606. UserWantKnowRecord::create(
  607. [
  608. 'know_id'=>$id,
  609. 'user_id'=>$info['to_user_id'],
  610. 'content'=>'终止申请',
  611. 'sort'=>4
  612. ]
  613. );
  614. //返积分(如果被拒绝过)
  615. $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
  616. $fan_integral = round($info['integral']*($notAgreeReturnIntegral/100));
  617. User::integral($fan_integral,$info['user_id'],'终止申请返积分',1);
  618. Db::commit();
  619. return Common::return_success('成功');
  620. }catch (Exception $e) {
  621. Db::rollback();
  622. return Common::return_error('失败');
  623. }
  624. }
  625. /**
  626. * 同意申请
  627. */
  628. public static function AgreeApply($id){
  629. $user = app()->session->get('us');
  630. $info = UserWantKnow::where('id',$id)->where('to_user_id',$user['id'])->where('state',1)->find();
  631. if (!$info)
  632. return Common::return_error('申请不存在');
  633. $info = $info->toArray();
  634. Db::startTrans();
  635. try {
  636. UserWantKnow::where('id',$id)->update(
  637. [
  638. 'state'=>2,
  639. 'deal_at'=>date('Y-m-d H:i:s')
  640. ]
  641. );
  642. //记录
  643. UserWantKnowRecord::create(
  644. [
  645. 'know_id'=>$id,
  646. 'user_id'=>$info['user_id'],
  647. 'content'=>'同意申请',
  648. 'sort'=>5
  649. ]
  650. );
  651. UserWantKnowRecord::create(
  652. [
  653. 'know_id'=>$id,
  654. 'user_id'=>$info['to_user_id'],
  655. 'content'=>'同意申请',
  656. 'sort'=>5
  657. ]
  658. );
  659. //消息推送
  660. $openid = User::where('id',$info['user_id'])->value('openid');
  661. $template_id = "pF9lZHPpNpt7tudXDYiIbwLk5Y5G6qmKm6mHLnQWjTU";
  662. $path = "";
  663. $data = [
  664. 'first'=>[
  665. "value"=>'你好,您的好友申请已通过!',
  666. "color"=>"#173177"
  667. ],
  668. 'keyword1'=>[
  669. "value"=>'好友申请',
  670. "color"=>"#173177"
  671. ],
  672. 'keyword2'=>[
  673. "value"=>'通过',
  674. "color"=>"#173177"
  675. ],
  676. 'remark'=>[
  677. "value"=>'你申请的好友申请已通过,请查看',
  678. "color"=>"#173177"
  679. ]
  680. ];
  681. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  682. $openid2 = User::where('id',$info['to_user_id'])->value('openid');
  683. $template_id2 = "Sz1eunRAh_jKR0_94dZU4jJB2WuRGqG0kyzsA-WYCLk";
  684. $path2 = "";
  685. $data2 = [
  686. 'first'=>[
  687. "value"=>'通过审核!',
  688. "color"=>"#173177"
  689. ],
  690. 'keyword1'=>[
  691. "value"=>date('Y-m-d H:i'),
  692. "color"=>"#173177"
  693. ],
  694. 'keyword2'=>[
  695. "value"=>User::where('id',$info['user_id'])->value('nickname'),
  696. "color"=>"#173177"
  697. ],
  698. 'remark'=>[
  699. "value"=>'好友申请已通过,请查看',
  700. "color"=>"#173177"
  701. ]
  702. ];
  703. Common::sendTemplateMsg($openid2,$template_id2,$path2,$data2);
  704. Db::commit();
  705. return Common::return_success('成功');
  706. }catch (Exception $e) {
  707. Db::rollback();
  708. return Common::return_error('失败');
  709. }
  710. }
  711. /**
  712. * 拒绝申请
  713. */
  714. public static function RefuseApply($id,$refused_why){
  715. $user = app()->session->get('us');
  716. $info = UserWantKnow::where('id',$id)->where('to_user_id',$user['id'])->where('state',1)->find();
  717. if (!$info)
  718. return Common::return_error('申请不存在');
  719. $info = $info->toArray();
  720. Db::startTrans();
  721. try {
  722. UserWantKnow::where('id',$id)->update(
  723. [
  724. 'state'=>3,
  725. 'refused_why'=>$refused_why,
  726. 'deal_at'=>date('Y-m-d H:i:s')
  727. ]
  728. );
  729. //记录
  730. UserWantKnowRecord::create(
  731. [
  732. 'know_id'=>$id,
  733. 'user_id'=>$info['user_id'],
  734. 'content'=>'拒绝申请',
  735. 'sort'=>5
  736. ]
  737. );
  738. UserWantKnowRecord::create(
  739. [
  740. 'know_id'=>$id,
  741. 'user_id'=>$info['to_user_id'],
  742. 'content'=>'拒绝申请',
  743. 'sort'=>5
  744. ]
  745. );
  746. $openid = User::where('id',$info['user_id'])->value('openid');
  747. $template_id = "sib_d0XQVMn-pSjFNmqMEs4JltmhNnSBbu21DqswzHs";
  748. $path = "";
  749. $data = [
  750. 'first'=>[
  751. "value"=>'你好,您的好友申请被拒绝!',
  752. "color"=>"#173177"
  753. ],
  754. 'keyword1'=>[
  755. "value"=>$refused_why,
  756. "color"=>"#173177"
  757. ],
  758. 'keyword2'=>[
  759. "value"=>date('Y-m-d H:i'),
  760. "color"=>"#173177"
  761. ],
  762. 'remark'=>[
  763. "value"=>'你申请的好友申请未通过',
  764. "color"=>"#173177"
  765. ]
  766. ];
  767. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  768. //返积分(如果被拒绝过)
  769. $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
  770. $fan_integral = round($info['integral']*($notAgreeReturnIntegral/100));
  771. User::integral($fan_integral,$info['user_id'],'拒绝申请返积分',1);
  772. Db::commit();
  773. return Common::return_success('成功');
  774. }catch (Exception $e) {
  775. Db::rollback();
  776. return Common::return_error('失败');
  777. }
  778. }
  779. /**
  780. * 屏蔽用户
  781. */
  782. public static function shieldingKnowUser($to_user_id,$switch){
  783. $user = app()->session->get('us');
  784. Db::startTrans();
  785. $info = ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$to_user_id)->find();
  786. try {
  787. if ($switch==1){
  788. if (!$info){
  789. ShieldingKnowUsers::create(
  790. [
  791. 'user_id'=>$user['id'],
  792. 'to_user_id'=>$to_user_id
  793. ]
  794. );
  795. }
  796. }else{
  797. if ($info){
  798. ShieldingKnowUsers::where('id',$info['id'])->delete();
  799. }
  800. }
  801. Db::commit();
  802. return Common::return_success('成功');
  803. }catch (Exception $e) {
  804. Db::rollback();
  805. return Common::return_error('失败');
  806. }
  807. }
  808. /**
  809. * 不合适
  810. */
  811. public static function DontFit($user_id){
  812. $user = app()->session->get('us');
  813. $info = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('state',2)->find();
  814. if (!$info){
  815. $info = UserWantKnow::where('to_user_id',$user['id'])->where('user_id',$user_id)->where('state',2)->find();
  816. if (!$info)
  817. return Common::return_error('非好友');
  818. }
  819. $info = $info->toArray();
  820. Db::startTrans();
  821. try {
  822. UserWantKnow::where('id',$info['id'])->update(
  823. [
  824. 'state'=>4,
  825. 'deal_at'=>date('Y-m-d H:i:s'),
  826. 'refused_why'=>'不合适'
  827. ]
  828. );
  829. UserWantKnowRecord::create(
  830. [
  831. 'know_id'=>$info['id'],
  832. 'user_id'=>$info['to_user_id'],
  833. 'content'=>'不合适',
  834. 'sort'=>6
  835. ]
  836. );
  837. UserWantKnowRecord::create(
  838. [
  839. 'know_id'=>$info['id'],
  840. 'user_id'=>$info['user_id'],
  841. 'content'=>'不合适',
  842. 'sort'=>6
  843. ]
  844. );
  845. Db::commit();
  846. return Common::return_success('成功');
  847. }catch (Exception $e) {
  848. Db::rollback();
  849. return Common::return_error('失败');
  850. }
  851. }
  852. /**
  853. * 星标聊天开关
  854. */
  855. public static function SetStar($user_id,$switch){
  856. $user = app()->session->get('us');
  857. Db::startTrans();
  858. $info = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->find();
  859. try {
  860. if ($switch==1){
  861. if (!$info){
  862. UserStar::create(
  863. [
  864. 'user_id'=>$user['id'],
  865. 'to_user_id'=>$user_id
  866. ]
  867. );
  868. }
  869. }else{
  870. if ($info){
  871. UserStar::where('id',$info['id'])->delete();
  872. }
  873. }
  874. Db::commit();
  875. return Common::return_success('成功');
  876. }catch (Exception $e) {
  877. Db::rollback();
  878. return Common::return_error('失败');
  879. }
  880. }
  881. /**
  882. * 想认识支付
  883. */
  884. public static function wantKnowPay($user_id){
  885. $user = app()->session->get('us');
  886. $userinfo = User::get($user['id']);
  887. $touser = Db::name('User')->where('id',$user_id)->find();
  888. if (!$touser)
  889. return Common::return_error('用户不存在');
  890. $pay = UserPay::where('user_id',$user['id'])->where('to_user_id',$user_id)->find();
  891. if ($pay)
  892. return Common::return_error('已经支付过');
  893. $integral = Config::get_values('want_know_integral'); //扣除的积分
  894. if ($userinfo['integral'] < $integral)
  895. return Common::return_error('积分不足');
  896. $data['user_id'] = $user['id'];
  897. $data['to_user_id'] = $user_id;
  898. Db::startTrans();
  899. try {
  900. User::integral($integral,$user['id'],'想查看 '.$touser['nickname'].'资料');
  901. $data['integral'] = $integral;
  902. UserPay::create($data);
  903. Db::commit();
  904. return Common::return_success('成功');
  905. }catch (Exception $e) {
  906. Db::rollback();
  907. return Common::return_error('失败');
  908. }
  909. }
  910. /**
  911. * 想认识
  912. */
  913. public static function wantKnow($user_id,$pool_id,$leave_message){
  914. $user = app()->session->get('us');
  915. $userinfo = User::get($user['id']);
  916. $touser = Db::name('User')->where('id',$user_id)->find();
  917. if (!$touser)
  918. return Common::return_error('用户不存在');
  919. //判断是否完善资料
  920. if (!User::checkUserIformationPerfect($user['id']))
  921. return Common::return_error('未完善资料,无法获取');
  922. // $integral = Config::get_values('want_know_integral'); //扣除的积分
  923. // if ($userinfo['integral'] < $integral)
  924. // return Common::return_error('积分不足');
  925. //查看我是否已经喜欢过
  926. $want_know = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  927. if ($want_know)
  928. return Common::return_error('已经认识过');
  929. $data['user_id'] = $user['id'];
  930. $data['to_user_id'] = $user_id;
  931. $data['pool_id'] = $pool_id;
  932. Db::startTrans();
  933. try {
  934. $knowid = UserWantKnow::create($data);
  935. //消息推送
  936. // $openid = User::where('id',$user_id)->value('openid');
  937. $openid = User::where('administrator',1)->where('is_del',1)->order('id asc')->limit(1)->value('openid');
  938. $template_id = "W5AkhY0RnEFj74WwO5qwYRR5-JIuhzjHr5NMb9pACwc";
  939. $path = "pages/userInfo/index?id=".$user_id."&administrator=1";
  940. $data = [
  941. 'first'=>[
  942. "value"=>'你有一待处理事项',
  943. "color"=>"#173177"
  944. ],
  945. 'keyword1'=>[
  946. "value"=>'临沂金叶',
  947. "color"=>"#173177"
  948. ],
  949. 'keyword2'=>[
  950. "value"=>$userinfo['nickname']."(".$userinfo['phone'].")喜欢了".$touser['nickname']."(".$touser['phone'].")",
  951. "color"=>"#173177"
  952. ],
  953. 'remark'=>[
  954. "value"=>'快去处理吧',
  955. "color"=>"#173177"
  956. ]
  957. ];
  958. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  959. Db::commit();
  960. return Common::return_success('成功');
  961. }catch (Exception $e) {
  962. Db::rollback();
  963. return Common::return_error('失败');
  964. }
  965. }
  966. /**
  967. * 付费查看提交
  968. */
  969. public static function payCheck($user_id){
  970. $user = app()->session->get('us');
  971. $userinfo = User::get($user['id']);
  972. $touser = Db::name('User')->where('id',$user_id)->find();
  973. if (!$touser)
  974. return Common::return_error('用户不存在');
  975. $info = PayCheck::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('paid',1)->find();
  976. if ($info)
  977. return Common::return_error('已经付费查看过');
  978. //获取支付金额
  979. $pay_money = Config::get_values('pay_check_money');
  980. $wx = new WxPay();//实例化微信torganizationid支付控制器
  981. $notify_url = 'https://'.$_SERVER['SERVER_NAME'].'/api/pay/pay_check_order';//回调地址
  982. $config = $wx->retrunconfig();
  983. $config['notify_url'] = $notify_url;
  984. $order_no = Common::getNewOrderId($user['id']);
  985. $body = '订单号' . $order_no;//支付说明
  986. $total_fee = $pay_money * 100;//支付金额(乘以100)
  987. Db::startTrans();
  988. try{
  989. $data['user_id'] = $user['id'];
  990. $data['to_user_id'] = $user_id;
  991. $data['order_no'] = $order_no;
  992. $data['price'] = $pay_money;
  993. $get_check_money = Config::get_values('get_check_money');
  994. $get_price = sprintf("%.2f",substr(sprintf("%.3f", ($pay_money*($get_check_money/100))), 0, -2));
  995. $data['get_price'] = $get_price;
  996. PayCheck::create($data);
  997. $app = Factory::payment($config);
  998. $order = $app->order->unify([
  999. 'body' => $body,
  1000. 'out_trade_no' => $order_no,
  1001. 'total_fee' => $total_fee,
  1002. 'trade_type' => "JSAPI", // JSAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
  1003. 'openid' => $userinfo['openid'],
  1004. ]);
  1005. if ($order['return_msg']=='OK'){
  1006. if ($order['result_code']=='FAIL'){
  1007. Db::rollback();
  1008. return Common::return_error($order['err_code_des']);
  1009. }else{
  1010. $order1 = $app->jssdk->bridgeConfig($order['prepay_id']);//执行二次签名返回参数
  1011. $retrun_data['order_no'] = $order_no;
  1012. $retrun_data['pay'] = json_decode($order1,true);
  1013. Db::commit();
  1014. return Common::return_success('成功',$retrun_data);
  1015. }
  1016. } else {
  1017. Db::rollback();
  1018. return Common::return_error($order['return_msg']);
  1019. }
  1020. }catch (Exception $e){
  1021. Db::rollback();
  1022. return Common::return_error($order['return_msg']);
  1023. }
  1024. }
  1025. /**
  1026. * 积分获取联系方式
  1027. */
  1028. public static function integralContact($user_id,$pool_id){
  1029. $user = app()->session->get('us');
  1030. $userinfo = User::get($user['id']);
  1031. $touser = Db::name('User')->where('id',$user_id)->find();
  1032. if (!$touser)
  1033. return Common::return_error('用户不存在');
  1034. //判断是否完善资料
  1035. if (!User::checkUserIformationPerfect($user['id']))
  1036. return Common::return_error('未完善资料,无法获取');
  1037. if ($touser['is_integral_to_phone'] == 2)
  1038. return Common::return_error('用户设置不允许使用积分获取联系方式');
  1039. $integral = Config::get_values('integral_contact');
  1040. if ($userinfo['integral'] < $integral)
  1041. return Common::return_error('积分不足');
  1042. //查看我是否已经购买过
  1043. $integral_record = IntegralContactRecord::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  1044. if ($integral_record)
  1045. return Common::return_error('已经购买过');
  1046. $data['user_id'] = $user['id'];
  1047. $data['to_user_id'] = $user_id;
  1048. $data['pool_id'] = $pool_id;
  1049. $data['integral'] = $integral;
  1050. Db::startTrans();
  1051. try {
  1052. IntegralContactRecord::create($data);
  1053. //扣除积分
  1054. User::integral($integral,$user['id'],'获取 '.$touser['nickname'].' 的联系方式');
  1055. Db::commit();
  1056. return Common::return_success('成功');
  1057. }catch (Exception $e) {
  1058. Db::rollback();
  1059. return Common::return_error('失败');
  1060. }
  1061. }
  1062. /**
  1063. * 群主解散互选池
  1064. */
  1065. public static function dissolutionPool($pool_id){
  1066. $user = app()->session->get('us');
  1067. $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
  1068. if (!$pool)
  1069. return Common::return_error('互选池不存在');
  1070. Db::startTrans();
  1071. try {
  1072. $pool->is_dissolution = 0;
  1073. $pool->save();
  1074. //通知群成员
  1075. $user_ids = ElectPoolMembers::where('pool_id',$pool_id)->column('user_id');
  1076. if ($user_ids){
  1077. foreach ($user_ids as $k=>$v){
  1078. //系统消息
  1079. Message::create_message($v,'群主已解散 '. $pool['name'] .' 互选池');
  1080. }
  1081. }
  1082. Db::commit();
  1083. return Common::return_success('成功');
  1084. }catch (Exception $e) {
  1085. Db::rollback();
  1086. return Common::return_error('失败');
  1087. }
  1088. }
  1089. /**
  1090. * 群主移出互选池用户
  1091. */
  1092. public static function removeUser($pool_id,$user_id){
  1093. $user = app()->session->get('us');
  1094. $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
  1095. if (!$pool)
  1096. return Common::return_error('互选池不存在');
  1097. //用户是否在群里
  1098. $group = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user_id)->count();
  1099. if (!$group)
  1100. return Common::return_error('用户已不在互选池中');
  1101. Db::startTrans();
  1102. try {
  1103. ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user_id)->delete();
  1104. $data['pool_id'] = $pool_id;
  1105. $data['user_id'] = $user_id;
  1106. ElectPoolRemovedUser::create($data);
  1107. self::where('id',$pool_id)->setDec('now_number'); //数量减1
  1108. //系统消息
  1109. Message::create_message($user_id,'您被群主移出 '. $pool['name'] .' 互选池');
  1110. Db::commit();
  1111. return Common::return_success('成功');
  1112. }catch (Exception $e) {
  1113. Db::rollback();
  1114. return Common::return_error('失败');
  1115. }
  1116. }
  1117. /**
  1118. * 分享
  1119. */
  1120. public static function share($type,$link_id){
  1121. $user = app()->session->get('us');
  1122. switch ($type){
  1123. case 1:
  1124. $share_count_day = Config::get_values('share_applet_count_day'); //一天分享几次有积分
  1125. $share_integral = Config::get_values('share_applet_integral'); //分享一次获得多少积分
  1126. $title = '分享小程序获得积分';
  1127. break;
  1128. case 2:
  1129. $share_count_day = Config::get_values('share_pool_count_day'); //一天分享几次有积分
  1130. $share_integral = Config::get_values('share_pool_integral'); //分享一次获得多少积分
  1131. $title = '分享互选池获得积分';
  1132. break;
  1133. case 3:
  1134. $share_count_day = Config::get_values('share_myinfo_count_day'); //一天分享几次有积分
  1135. $share_integral = Config::get_values('share_myinfo_integral'); //分享一次获得多少积分
  1136. $title = '分享个人资料获得积分';
  1137. break;
  1138. case 4:
  1139. $share_count_day = Config::get_values('share_others_count_day'); //一天分享几次有积分
  1140. $share_integral = Config::get_values('share_others_integral'); //分享一次获得多少积分
  1141. $title = '分享他人资料获得积分';
  1142. break;
  1143. default:
  1144. $share_count_day = 0; //一天分享几次有积分
  1145. $share_integral = 0; //分享一次获得多少积分
  1146. break;
  1147. }
  1148. //获取用户今日分享次数
  1149. $day = date('Y-m-d');
  1150. $share_count = UserShareLog::where('user_id',$user['id'])->where('day',$day)->where('type',$type)->count();
  1151. Db::startTrans();
  1152. try {
  1153. //分享记录表
  1154. $data['user_id'] = $user['id'];
  1155. $data['day'] = $day;
  1156. $data['type'] = $type;
  1157. $data['link_id'] = $link_id;
  1158. //分享获得积分
  1159. if ($share_count_day>$share_count){
  1160. //加积分
  1161. User::integral($share_integral,$user['id'], $title,1);
  1162. }else{
  1163. $share_integral = 0;
  1164. }
  1165. $data['integral'] = $share_integral;
  1166. UserShareLog::create($data);
  1167. Db::commit();
  1168. return Common::return_success('成功',$share_integral);
  1169. }catch (Exception $e) {
  1170. Db::rollback();
  1171. return Common::return_error('失败');
  1172. }
  1173. }
  1174. /**
  1175. * 举报用户
  1176. */
  1177. public static function reportUser($pool_id,$user_id,$item_type,$content,$imgs){
  1178. $user = app()->session->get('us');
  1179. if ($imgs)
  1180. $imgs = implode(',',$imgs);
  1181. Db::startTrans();
  1182. try {
  1183. //举报记录表
  1184. $data['pool_id'] = $pool_id;
  1185. $data['user_id'] = $user['id'];
  1186. $data['to_user_id'] = $user_id;
  1187. $data['item_type'] = $item_type;
  1188. $data['content'] = $content;
  1189. $data['imgs'] = $imgs;
  1190. UserReport::create($data);
  1191. Db::commit();
  1192. return Common::return_success('成功');
  1193. }catch (Exception $e) {
  1194. Db::rollback();
  1195. return Common::return_error('失败');
  1196. }
  1197. }
  1198. }