ElectPool.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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. $touser['is_pay'] = false;
  461. }else{
  462. //查看我是否已经喜欢过
  463. $want_know = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  464. $touser['is_want_know'] = $want_know ? true : false;
  465. //查看是否已经获取了联系方式
  466. $integral_record = IntegralContactRecord::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  467. $touser['is_integral_contact'] = $integral_record ? true : false;
  468. //查看对方是否也喜欢我
  469. $want_know2 = UserWantKnow::where('user_id',$user_id)->where('to_user_id',$user['id'])->count();
  470. if (!$integral_record){
  471. if (!$want_know || !$want_know2)
  472. $touser['wechat_id'] = "";
  473. }
  474. //查看是否收藏了对方
  475. $collection = Collection::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('is_effective',1)->count();
  476. $touser['is_collection'] = $collection > 0 ? true : false;
  477. //对方是否把你屏蔽
  478. $info = ShieldingKnowUsers::where('user_id',$user_id)->where('to_user_id',$user['id'])->count();
  479. $touser['is_shielding'] = $info > 0 ? true : false;
  480. //查看申请状态
  481. $apply = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  482. if (!$apply){
  483. $touser['apply_state'] = false;
  484. }else{
  485. $touser['apply_state'] = true;
  486. }
  487. //查看是否已经支付
  488. $is_pay = UserPay::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  489. if (!$is_pay){
  490. $touser['is_pay'] = false;
  491. }else{
  492. $touser['is_pay'] = true;
  493. }
  494. //星标开关
  495. $star = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  496. $touser['star_switch'] = $star > 0 ? true : false;
  497. //是否星标好友
  498. $star2 = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  499. $touser['star'] = $star2 ? true : false;
  500. }
  501. return Common::return_success('成功',$touser);
  502. }
  503. /**
  504. * 查看申请
  505. */
  506. public static function SelApply($user_id){
  507. $user = app()->session->get('us');
  508. $touser = Db::name('User')->where('id',$user_id)->find();
  509. if (!$touser)
  510. return Common::return_error('用户不存在');
  511. $array = [];
  512. //查看我是否申请了对方
  513. $know = UserWantKnow::where('user_id',$user['id'])
  514. ->where('to_user_id',$user_id)
  515. ->whereNotIn('state','3,4,5')
  516. ->order('id desc')
  517. ->limit(1)
  518. ->field('id,leave_message,state,create_at')
  519. ->find();
  520. if ($know){
  521. $know = $know->toArray();
  522. $seven = date('Y-m-d H:i:s',strtotime($know['create_at'])+(7*24*60*60));
  523. $know['seven'] = Common::timeTranRun($seven);
  524. $know['list'] = UserWantKnowRecord::where('know_id',$know['id'])
  525. ->where('user_id',$user['id'])
  526. ->order('sort desc')
  527. ->field('id,content,create_at')
  528. ->select()->toArray();
  529. $array['type'] = 1;
  530. $array['info'] = $know;
  531. }else{
  532. $know = UserWantKnow::where('user_id',$user_id)
  533. ->where('to_user_id',$user['id'])
  534. ->whereNotIn('state','3,4,5')
  535. ->order('id desc')
  536. ->limit(1)
  537. ->field('id,leave_message,state,create_at')
  538. ->find();
  539. if ($know){
  540. $know = $know->toArray();
  541. $seven = date('Y-m-d H:i:s',strtotime($know['create_at'])+(7*24*60*60));
  542. $times = Common::timeTranRun2($seven);
  543. $know['day'] = $times['date'];
  544. $know['hour'] = $times['hour'];
  545. $know['minute'] = $times['minute'];
  546. $know['seconds'] = $times['seconds'];
  547. $know['list'] = UserWantKnowRecord::where('know_id',$know['id'])
  548. ->where('user_id',$user['id'])
  549. ->order('sort desc')
  550. ->field('id,content,create_at')
  551. ->select()->toArray();
  552. $array['type'] = 2;
  553. $array['info'] = $know;
  554. //判断是否有查看申请过
  555. $apply = UserWantKnowRecord::where('know_id',$know['id'])->where('user_id',$user['id'])->where('content','查看申请')->count();
  556. if (!$apply){
  557. UserWantKnowRecord::create(
  558. [
  559. 'know_id'=>$know['id'],
  560. 'user_id'=>$user['id'],
  561. 'content'=>'查看申请',
  562. 'sort'=>2
  563. ]
  564. );
  565. UserWantKnowRecord::create(
  566. [
  567. 'know_id'=>$know['id'],
  568. 'user_id'=>$user['id'],
  569. 'content'=>'等待处理',
  570. 'sort'=>3
  571. ]
  572. );
  573. UserWantKnowRecord::create(
  574. [
  575. 'know_id'=>$know['id'],
  576. 'user_id'=>$user_id,
  577. 'content'=>'对方查看了你的申请',
  578. 'sort'=>3
  579. ]
  580. );
  581. }
  582. }else{
  583. return Common::return_error('对方已取消');
  584. }
  585. }
  586. return Common::return_success('成功',$array);
  587. }
  588. /**
  589. * 终止申请
  590. */
  591. public static function TerminationApply($id){
  592. $user = app()->session->get('us');
  593. $info = UserWantKnow::where('id',$id)->where('user_id',$user['id'])->where('state',1)->find();
  594. $info = $info->toArray();
  595. if (!$info)
  596. return Common::return_error('申请不存在');
  597. Db::startTrans();
  598. try {
  599. UserWantKnow::where('id',$id)->update(
  600. [
  601. 'state'=>5,
  602. 'deal_at'=>date('Y-m-d H:i:s')
  603. ]
  604. );
  605. //记录
  606. UserWantKnowRecord::create(
  607. [
  608. 'know_id'=>$id,
  609. 'user_id'=>$user['id'],
  610. 'content'=>'终止申请',
  611. 'sort'=>4
  612. ]
  613. );
  614. UserWantKnowRecord::create(
  615. [
  616. 'know_id'=>$id,
  617. 'user_id'=>$info['to_user_id'],
  618. 'content'=>'终止申请',
  619. 'sort'=>4
  620. ]
  621. );
  622. //返积分(如果被拒绝过)
  623. $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
  624. $fan_integral = round($info['integral']*($notAgreeReturnIntegral/100));
  625. User::integral($fan_integral,$info['user_id'],'终止申请返积分',1);
  626. Db::commit();
  627. return Common::return_success('成功');
  628. }catch (Exception $e) {
  629. Db::rollback();
  630. return Common::return_error('失败');
  631. }
  632. }
  633. /**
  634. * 同意申请
  635. */
  636. public static function AgreeApply($id){
  637. $user = app()->session->get('us');
  638. $info = UserWantKnow::where('id',$id)->where('to_user_id',$user['id'])->where('state',1)->find();
  639. if (!$info)
  640. return Common::return_error('申请不存在');
  641. $info = $info->toArray();
  642. Db::startTrans();
  643. try {
  644. UserWantKnow::where('id',$id)->update(
  645. [
  646. 'state'=>2,
  647. 'deal_at'=>date('Y-m-d H:i:s')
  648. ]
  649. );
  650. //记录
  651. UserWantKnowRecord::create(
  652. [
  653. 'know_id'=>$id,
  654. 'user_id'=>$info['user_id'],
  655. 'content'=>'同意申请',
  656. 'sort'=>5
  657. ]
  658. );
  659. UserWantKnowRecord::create(
  660. [
  661. 'know_id'=>$id,
  662. 'user_id'=>$info['to_user_id'],
  663. 'content'=>'同意申请',
  664. 'sort'=>5
  665. ]
  666. );
  667. //消息推送
  668. $openid = User::where('id',$info['user_id'])->value('openid');
  669. $template_id = "pF9lZHPpNpt7tudXDYiIbwLk5Y5G6qmKm6mHLnQWjTU";
  670. $path = "";
  671. $data = [
  672. 'first'=>[
  673. "value"=>'你好,您的好友申请已通过!',
  674. "color"=>"#173177"
  675. ],
  676. 'keyword1'=>[
  677. "value"=>'好友申请',
  678. "color"=>"#173177"
  679. ],
  680. 'keyword2'=>[
  681. "value"=>'通过',
  682. "color"=>"#173177"
  683. ],
  684. 'remark'=>[
  685. "value"=>'你申请的好友申请已通过,请查看',
  686. "color"=>"#173177"
  687. ]
  688. ];
  689. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  690. $openid2 = User::where('id',$info['to_user_id'])->value('openid');
  691. $template_id2 = "Sz1eunRAh_jKR0_94dZU4jJB2WuRGqG0kyzsA-WYCLk";
  692. $path2 = "";
  693. $data2 = [
  694. 'first'=>[
  695. "value"=>'通过审核!',
  696. "color"=>"#173177"
  697. ],
  698. 'keyword1'=>[
  699. "value"=>date('Y-m-d H:i'),
  700. "color"=>"#173177"
  701. ],
  702. 'keyword2'=>[
  703. "value"=>User::where('id',$info['user_id'])->value('nickname'),
  704. "color"=>"#173177"
  705. ],
  706. 'remark'=>[
  707. "value"=>'好友申请已通过,请查看',
  708. "color"=>"#173177"
  709. ]
  710. ];
  711. Common::sendTemplateMsg($openid2,$template_id2,$path2,$data2);
  712. Db::commit();
  713. return Common::return_success('成功');
  714. }catch (Exception $e) {
  715. Db::rollback();
  716. return Common::return_error('失败');
  717. }
  718. }
  719. /**
  720. * 拒绝申请
  721. */
  722. public static function RefuseApply($id,$refused_why){
  723. $user = app()->session->get('us');
  724. $info = UserWantKnow::where('id',$id)->where('to_user_id',$user['id'])->where('state',1)->find();
  725. if (!$info)
  726. return Common::return_error('申请不存在');
  727. $info = $info->toArray();
  728. Db::startTrans();
  729. try {
  730. UserWantKnow::where('id',$id)->update(
  731. [
  732. 'state'=>3,
  733. 'refused_why'=>$refused_why,
  734. 'deal_at'=>date('Y-m-d H:i:s')
  735. ]
  736. );
  737. //记录
  738. UserWantKnowRecord::create(
  739. [
  740. 'know_id'=>$id,
  741. 'user_id'=>$info['user_id'],
  742. 'content'=>'拒绝申请',
  743. 'sort'=>5
  744. ]
  745. );
  746. UserWantKnowRecord::create(
  747. [
  748. 'know_id'=>$id,
  749. 'user_id'=>$info['to_user_id'],
  750. 'content'=>'拒绝申请',
  751. 'sort'=>5
  752. ]
  753. );
  754. $openid = User::where('id',$info['user_id'])->value('openid');
  755. $template_id = "sib_d0XQVMn-pSjFNmqMEs4JltmhNnSBbu21DqswzHs";
  756. $path = "";
  757. $data = [
  758. 'first'=>[
  759. "value"=>'你好,您的好友申请被拒绝!',
  760. "color"=>"#173177"
  761. ],
  762. 'keyword1'=>[
  763. "value"=>$refused_why,
  764. "color"=>"#173177"
  765. ],
  766. 'keyword2'=>[
  767. "value"=>date('Y-m-d H:i'),
  768. "color"=>"#173177"
  769. ],
  770. 'remark'=>[
  771. "value"=>'你申请的好友申请未通过',
  772. "color"=>"#173177"
  773. ]
  774. ];
  775. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  776. //返积分(如果被拒绝过)
  777. $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
  778. $fan_integral = round($info['integral']*($notAgreeReturnIntegral/100));
  779. User::integral($fan_integral,$info['user_id'],'拒绝申请返积分',1);
  780. Db::commit();
  781. return Common::return_success('成功');
  782. }catch (Exception $e) {
  783. Db::rollback();
  784. return Common::return_error('失败');
  785. }
  786. }
  787. /**
  788. * 屏蔽用户
  789. */
  790. public static function shieldingKnowUser($to_user_id,$switch){
  791. $user = app()->session->get('us');
  792. Db::startTrans();
  793. $info = ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$to_user_id)->find();
  794. try {
  795. if ($switch==1){
  796. if (!$info){
  797. ShieldingKnowUsers::create(
  798. [
  799. 'user_id'=>$user['id'],
  800. 'to_user_id'=>$to_user_id
  801. ]
  802. );
  803. }
  804. }else{
  805. if ($info){
  806. ShieldingKnowUsers::where('id',$info['id'])->delete();
  807. }
  808. }
  809. Db::commit();
  810. return Common::return_success('成功');
  811. }catch (Exception $e) {
  812. Db::rollback();
  813. return Common::return_error('失败');
  814. }
  815. }
  816. /**
  817. * 不合适
  818. */
  819. public static function DontFit($user_id){
  820. $user = app()->session->get('us');
  821. $info = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('state',2)->find();
  822. if (!$info){
  823. $info = UserWantKnow::where('to_user_id',$user['id'])->where('user_id',$user_id)->where('state',2)->find();
  824. if (!$info)
  825. return Common::return_error('非好友');
  826. }
  827. $info = $info->toArray();
  828. Db::startTrans();
  829. try {
  830. UserWantKnow::where('id',$info['id'])->update(
  831. [
  832. 'state'=>4,
  833. 'deal_at'=>date('Y-m-d H:i:s'),
  834. 'refused_why'=>'不合适'
  835. ]
  836. );
  837. UserWantKnowRecord::create(
  838. [
  839. 'know_id'=>$info['id'],
  840. 'user_id'=>$info['to_user_id'],
  841. 'content'=>'不合适',
  842. 'sort'=>6
  843. ]
  844. );
  845. UserWantKnowRecord::create(
  846. [
  847. 'know_id'=>$info['id'],
  848. 'user_id'=>$info['user_id'],
  849. 'content'=>'不合适',
  850. 'sort'=>6
  851. ]
  852. );
  853. Db::commit();
  854. return Common::return_success('成功');
  855. }catch (Exception $e) {
  856. Db::rollback();
  857. return Common::return_error('失败');
  858. }
  859. }
  860. /**
  861. * 星标聊天开关
  862. */
  863. public static function SetStar($user_id,$switch){
  864. $user = app()->session->get('us');
  865. Db::startTrans();
  866. $info = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->find();
  867. try {
  868. if ($switch==1){
  869. if (!$info){
  870. UserStar::create(
  871. [
  872. 'user_id'=>$user['id'],
  873. 'to_user_id'=>$user_id
  874. ]
  875. );
  876. }
  877. }else{
  878. if ($info){
  879. UserStar::where('id',$info['id'])->delete();
  880. }
  881. }
  882. Db::commit();
  883. return Common::return_success('成功');
  884. }catch (Exception $e) {
  885. Db::rollback();
  886. return Common::return_error('失败');
  887. }
  888. }
  889. /**
  890. * 想认识支付
  891. */
  892. public static function wantKnowPay($user_id){
  893. $user = app()->session->get('us');
  894. $userinfo = User::get($user['id']);
  895. $touser = Db::name('User')->where('id',$user_id)->find();
  896. if (!$touser)
  897. return Common::return_error('用户不存在');
  898. $pay = UserPay::where('user_id',$user['id'])->where('to_user_id',$user_id)->find();
  899. if ($pay)
  900. return Common::return_error('已经支付过');
  901. $integral = Config::get_values('want_know_integral'); //扣除的积分
  902. if ($userinfo['integral'] < $integral)
  903. return Common::return_error('积分不足');
  904. $data['user_id'] = $user['id'];
  905. $data['to_user_id'] = $user_id;
  906. Db::startTrans();
  907. try {
  908. $get_check_money = Config::get_values('get_check_money');
  909. // $get_price = sprintf("%.2f",substr(sprintf("%.3f", ($integral*($get_check_money/100))), 0, -2));
  910. $get_price = round($integral*($get_check_money/100));
  911. $data['get_price'] = $get_price;
  912. $data['integral'] = $integral;
  913. User::integral($integral,$user['id'],'想查看 '.$touser['nickname'].'资料');
  914. User::integral($get_price,$user_id,'被查看资料',1);
  915. UserPay::create($data);
  916. Db::commit();
  917. return Common::return_success('成功');
  918. }catch (Exception $e) {
  919. Db::rollback();
  920. return Common::return_error('失败');
  921. }
  922. }
  923. /**
  924. * 想认识
  925. */
  926. public static function wantKnow($user_id,$pool_id,$leave_message){
  927. $user = app()->session->get('us');
  928. $userinfo = User::get($user['id']);
  929. $touser = Db::name('User')->where('id',$user_id)->find();
  930. if (!$touser)
  931. return Common::return_error('用户不存在');
  932. //判断是否完善资料
  933. if (!User::checkUserIformationPerfect($user['id']))
  934. return Common::return_error('未完善资料,无法获取');
  935. // $integral = Config::get_values('want_know_integral'); //扣除的积分
  936. // if ($userinfo['integral'] < $integral)
  937. // return Common::return_error('积分不足');
  938. //查看我是否已经喜欢过
  939. $want_know = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  940. if ($want_know)
  941. return Common::return_error('已经认识过');
  942. $data['user_id'] = $user['id'];
  943. $data['to_user_id'] = $user_id;
  944. $data['pool_id'] = $pool_id;
  945. Db::startTrans();
  946. try {
  947. $knowid = UserWantKnow::create($data);
  948. //消息推送
  949. // $openid = User::where('id',$user_id)->value('openid');
  950. $openid = User::where('administrator',1)->where('is_del',1)->order('id asc')->limit(1)->value('openid');
  951. $template_id = "W5AkhY0RnEFj74WwO5qwYRR5-JIuhzjHr5NMb9pACwc";
  952. $path = "pages/userInfo/index?id=".$user_id."&administrator=1";
  953. $data = [
  954. 'first'=>[
  955. "value"=>'你有一待处理事项',
  956. "color"=>"#173177"
  957. ],
  958. 'keyword1'=>[
  959. "value"=>'临沂金叶',
  960. "color"=>"#173177"
  961. ],
  962. 'keyword2'=>[
  963. "value"=>$userinfo['nickname']."(".$userinfo['phone'].")喜欢了".$touser['nickname']."(".$touser['phone'].")",
  964. "color"=>"#173177"
  965. ],
  966. 'remark'=>[
  967. "value"=>'快去处理吧',
  968. "color"=>"#173177"
  969. ]
  970. ];
  971. Common::sendTemplateMsg($openid,$template_id,$path,$data);
  972. Db::commit();
  973. return Common::return_success('成功');
  974. }catch (Exception $e) {
  975. Db::rollback();
  976. return Common::return_error('失败');
  977. }
  978. }
  979. /**
  980. * 付费查看提交
  981. */
  982. public static function payCheck($user_id){
  983. $user = app()->session->get('us');
  984. $userinfo = User::get($user['id']);
  985. $touser = Db::name('User')->where('id',$user_id)->find();
  986. if (!$touser)
  987. return Common::return_error('用户不存在');
  988. $info = PayCheck::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('paid',1)->find();
  989. if ($info)
  990. return Common::return_error('已经付费查看过');
  991. //获取支付金额
  992. $pay_money = Config::get_values('pay_check_money');
  993. $wx = new WxPay();//实例化微信torganizationid支付控制器
  994. $notify_url = 'https://'.$_SERVER['SERVER_NAME'].'/api/pay/pay_check_order';//回调地址
  995. $config = $wx->retrunconfig();
  996. $config['notify_url'] = $notify_url;
  997. $order_no = Common::getNewOrderId($user['id']);
  998. $body = '订单号' . $order_no;//支付说明
  999. $total_fee = $pay_money * 100;//支付金额(乘以100)
  1000. Db::startTrans();
  1001. try{
  1002. $data['user_id'] = $user['id'];
  1003. $data['to_user_id'] = $user_id;
  1004. $data['order_no'] = $order_no;
  1005. $data['price'] = $pay_money;
  1006. $get_check_money = Config::get_values('get_check_money');
  1007. $get_price = sprintf("%.2f",substr(sprintf("%.3f", ($pay_money*($get_check_money/100))), 0, -2));
  1008. $data['get_price'] = $get_price;
  1009. PayCheck::create($data);
  1010. $app = Factory::payment($config);
  1011. $order = $app->order->unify([
  1012. 'body' => $body,
  1013. 'out_trade_no' => $order_no,
  1014. 'total_fee' => $total_fee,
  1015. 'trade_type' => "JSAPI", // JSAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
  1016. 'openid' => $userinfo['openid'],
  1017. ]);
  1018. if ($order['return_msg']=='OK'){
  1019. if ($order['result_code']=='FAIL'){
  1020. Db::rollback();
  1021. return Common::return_error($order['err_code_des']);
  1022. }else{
  1023. $order1 = $app->jssdk->bridgeConfig($order['prepay_id']);//执行二次签名返回参数
  1024. $retrun_data['order_no'] = $order_no;
  1025. $retrun_data['pay'] = json_decode($order1,true);
  1026. Db::commit();
  1027. return Common::return_success('成功',$retrun_data);
  1028. }
  1029. } else {
  1030. Db::rollback();
  1031. return Common::return_error($order['return_msg']);
  1032. }
  1033. }catch (Exception $e){
  1034. Db::rollback();
  1035. return Common::return_error($order['return_msg']);
  1036. }
  1037. }
  1038. /**
  1039. * 积分获取联系方式
  1040. */
  1041. public static function integralContact($user_id,$pool_id){
  1042. $user = app()->session->get('us');
  1043. $userinfo = User::get($user['id']);
  1044. $touser = Db::name('User')->where('id',$user_id)->find();
  1045. if (!$touser)
  1046. return Common::return_error('用户不存在');
  1047. //判断是否完善资料
  1048. if (!User::checkUserIformationPerfect($user['id']))
  1049. return Common::return_error('未完善资料,无法获取');
  1050. if ($touser['is_integral_to_phone'] == 2)
  1051. return Common::return_error('用户设置不允许使用积分获取联系方式');
  1052. $integral = Config::get_values('integral_contact');
  1053. if ($userinfo['integral'] < $integral)
  1054. return Common::return_error('积分不足');
  1055. //查看我是否已经购买过
  1056. $integral_record = IntegralContactRecord::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
  1057. if ($integral_record)
  1058. return Common::return_error('已经购买过');
  1059. $data['user_id'] = $user['id'];
  1060. $data['to_user_id'] = $user_id;
  1061. $data['pool_id'] = $pool_id;
  1062. $data['integral'] = $integral;
  1063. Db::startTrans();
  1064. try {
  1065. IntegralContactRecord::create($data);
  1066. //扣除积分
  1067. User::integral($integral,$user['id'],'获取 '.$touser['nickname'].' 的联系方式');
  1068. Db::commit();
  1069. return Common::return_success('成功');
  1070. }catch (Exception $e) {
  1071. Db::rollback();
  1072. return Common::return_error('失败');
  1073. }
  1074. }
  1075. /**
  1076. * 群主解散互选池
  1077. */
  1078. public static function dissolutionPool($pool_id){
  1079. $user = app()->session->get('us');
  1080. $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
  1081. if (!$pool)
  1082. return Common::return_error('互选池不存在');
  1083. Db::startTrans();
  1084. try {
  1085. $pool->is_dissolution = 0;
  1086. $pool->save();
  1087. //通知群成员
  1088. $user_ids = ElectPoolMembers::where('pool_id',$pool_id)->column('user_id');
  1089. if ($user_ids){
  1090. foreach ($user_ids as $k=>$v){
  1091. //系统消息
  1092. Message::create_message($v,'群主已解散 '. $pool['name'] .' 互选池');
  1093. }
  1094. }
  1095. Db::commit();
  1096. return Common::return_success('成功');
  1097. }catch (Exception $e) {
  1098. Db::rollback();
  1099. return Common::return_error('失败');
  1100. }
  1101. }
  1102. /**
  1103. * 群主移出互选池用户
  1104. */
  1105. public static function removeUser($pool_id,$user_id){
  1106. $user = app()->session->get('us');
  1107. $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
  1108. if (!$pool)
  1109. return Common::return_error('互选池不存在');
  1110. //用户是否在群里
  1111. $group = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user_id)->count();
  1112. if (!$group)
  1113. return Common::return_error('用户已不在互选池中');
  1114. Db::startTrans();
  1115. try {
  1116. ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user_id)->delete();
  1117. $data['pool_id'] = $pool_id;
  1118. $data['user_id'] = $user_id;
  1119. ElectPoolRemovedUser::create($data);
  1120. self::where('id',$pool_id)->setDec('now_number'); //数量减1
  1121. //系统消息
  1122. Message::create_message($user_id,'您被群主移出 '. $pool['name'] .' 互选池');
  1123. Db::commit();
  1124. return Common::return_success('成功');
  1125. }catch (Exception $e) {
  1126. Db::rollback();
  1127. return Common::return_error('失败');
  1128. }
  1129. }
  1130. /**
  1131. * 分享
  1132. */
  1133. public static function share($type,$link_id){
  1134. $user = app()->session->get('us');
  1135. switch ($type){
  1136. case 1:
  1137. $share_count_day = Config::get_values('share_applet_count_day'); //一天分享几次有积分
  1138. $share_integral = Config::get_values('share_applet_integral'); //分享一次获得多少积分
  1139. $title = '分享小程序获得积分';
  1140. break;
  1141. case 2:
  1142. $share_count_day = Config::get_values('share_pool_count_day'); //一天分享几次有积分
  1143. $share_integral = Config::get_values('share_pool_integral'); //分享一次获得多少积分
  1144. $title = '分享互选池获得积分';
  1145. break;
  1146. case 3:
  1147. $share_count_day = Config::get_values('share_myinfo_count_day'); //一天分享几次有积分
  1148. $share_integral = Config::get_values('share_myinfo_integral'); //分享一次获得多少积分
  1149. $title = '分享个人资料获得积分';
  1150. break;
  1151. case 4:
  1152. $share_count_day = Config::get_values('share_others_count_day'); //一天分享几次有积分
  1153. $share_integral = Config::get_values('share_others_integral'); //分享一次获得多少积分
  1154. $title = '分享他人资料获得积分';
  1155. break;
  1156. default:
  1157. $share_count_day = 0; //一天分享几次有积分
  1158. $share_integral = 0; //分享一次获得多少积分
  1159. break;
  1160. }
  1161. //获取用户今日分享次数
  1162. $day = date('Y-m-d');
  1163. $share_count = UserShareLog::where('user_id',$user['id'])->where('day',$day)->where('type',$type)->count();
  1164. Db::startTrans();
  1165. try {
  1166. //分享记录表
  1167. $data['user_id'] = $user['id'];
  1168. $data['day'] = $day;
  1169. $data['type'] = $type;
  1170. $data['link_id'] = $link_id;
  1171. //分享获得积分
  1172. if ($share_count_day>$share_count){
  1173. //加积分
  1174. User::integral($share_integral,$user['id'], $title,1);
  1175. }else{
  1176. $share_integral = 0;
  1177. }
  1178. $data['integral'] = $share_integral;
  1179. UserShareLog::create($data);
  1180. Db::commit();
  1181. return Common::return_success('成功',$share_integral);
  1182. }catch (Exception $e) {
  1183. Db::rollback();
  1184. return Common::return_error('失败');
  1185. }
  1186. }
  1187. /**
  1188. * 举报用户
  1189. */
  1190. public static function reportUser($pool_id,$user_id,$item_type,$content,$imgs){
  1191. $user = app()->session->get('us');
  1192. if ($imgs)
  1193. $imgs = implode(',',$imgs);
  1194. Db::startTrans();
  1195. try {
  1196. //举报记录表
  1197. $data['pool_id'] = $pool_id;
  1198. $data['user_id'] = $user['id'];
  1199. $data['to_user_id'] = $user_id;
  1200. $data['item_type'] = $item_type;
  1201. $data['content'] = $content;
  1202. $data['imgs'] = $imgs;
  1203. UserReport::create($data);
  1204. Db::commit();
  1205. return Common::return_success('成功');
  1206. }catch (Exception $e) {
  1207. Db::rollback();
  1208. return Common::return_error('失败');
  1209. }
  1210. }
  1211. }