Greet.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 打招呼
  7. */
  8. class Greet extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //打招呼/搭讪
  13. public function greet() {
  14. /*if ($this->auth->gender == 0 && $this->auth->real_status != 1 && $this->auth->idcard_status != 1) {
  15. $this->error('请先完成实名认证或真人认证');
  16. }*/
  17. $other_uid = input('user_id', 0, 'intval');
  18. if(!$other_uid) {
  19. $this->error(__('Invalid parameters'));
  20. }
  21. if($other_uid == $this->auth->id){
  22. $this->error('这是您自己');
  23. }
  24. $checkuser = Db::name('user')->find($other_uid);
  25. if(empty($checkuser)) {
  26. $this->error('此用户不存在');
  27. }
  28. $map = [
  29. 'user_id' => $this->auth->id,
  30. 'user_to_id' => $other_uid,
  31. ];
  32. // 取消限制 2023年12月14日 18点47分
  33. // $check = Db::name('user_greet')->where($map)->find();
  34. // if($check){
  35. // $this->error('已经打过招呼了');
  36. // }
  37. $map['createtime'] = time();
  38. Db::startTrans();
  39. $id = Db::name('user_greet')->insertGetId($map);
  40. if (!$id) {
  41. Db::rollback();
  42. $this->error('您的网络开小差了~');
  43. }
  44. //tag任务赠送金币
  45. //搭讪奖励
  46. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
  47. if($task_rs === false){
  48. Db::rollback();
  49. $this->error('完成任务赠送奖励失败');
  50. }
  51. Db::commit();
  52. //不需要送礼物了
  53. /*$gift_greet = Db::name('gift_greet')->find();
  54. if ($gift_greet) {
  55. $gift_greet['special'] = one_domain_image($gift_greet['special']);
  56. $gift_greet['image'] = one_domain_image($gift_greet['image']);
  57. } else {
  58. $gift_greet = (object)[];
  59. }*/
  60. $gift_greet = (object)[];
  61. $this->success('操作成功', $gift_greet);
  62. }
  63. //查询每天弹出搭讪框次数
  64. public function freegreetnum() {
  65. $user = $this->auth->getUser();
  66. if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
  67. $data['free_greet_num'] = 0;
  68. $data['vip_free_greet_num'] = 0;
  69. $data['boy_free_greet_num'] = 0;
  70. $data['boy_vip_free_greet_num'] = 0;
  71. }else{
  72. //非会员每天弹出搭讪框次数
  73. $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
  74. //vip每天弹出搭讪框次数
  75. $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
  76. // 男性 非会员每天弹出搭讪框次数
  77. $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
  78. // 男性 vip每天弹出搭讪框次数
  79. $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
  80. }
  81. $this->success('success', $data);
  82. }
  83. /**
  84. * 男性打招呼内容
  85. * @return void
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @throws \think\exception\DbException
  89. */
  90. public function greetBoy()
  91. {
  92. $data = Db::name('user_greet_boy')->select();
  93. $this->success('success', $data);
  94. }
  95. }