Greet.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. $other_uids = input('user_ids', '', 'trim');
  15. if(!$other_uids) {
  16. $this->error(__('Invalid parameters'));
  17. }
  18. $other_uids = explode(',',$other_uids);
  19. if(empty($other_uids)){
  20. $this->error(__('Invalid parameters'));
  21. }
  22. //打招呼内容
  23. $greet = null;
  24. if($this->auth->gender == 0){
  25. $where['user_id'] = $this->auth->id;
  26. $greet = Db::name('user_greet_content')->where($where)->orderRaw('rand()')->find();
  27. if(empty($greet)){
  28. $this->add_girl_greet($this->auth->id);
  29. $greet = Db::name('user_greet_content')->where($where)->orderRaw('rand()')->find();
  30. }
  31. if(!empty($greet) && $greet['type'] != 0){
  32. $greet['content'] = one_domain_image($greet['content']);
  33. }
  34. }else{
  35. $greet = Db::name('user_greet_boy')->orderRaw('rand()')->find();
  36. }
  37. //
  38. $map = [];
  39. foreach($other_uids as $key => $other_uid){
  40. $map[] = [
  41. 'user_id' => $this->auth->id,
  42. 'user_to_id' => $other_uid,
  43. 'createtime' => time(),
  44. ];
  45. }
  46. Db::startTrans();
  47. $id = Db::name('user_greet')->insertAll($map);
  48. if (!$id) {
  49. Db::rollback();
  50. $this->error('您的网络开小差了~');
  51. }
  52. //tag任务赠送金币
  53. //搭讪奖励
  54. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
  55. if($task_rs === false){
  56. Db::rollback();
  57. $this->error('完成任务赠送奖励失败');
  58. }
  59. Db::commit();
  60. $rs = [
  61. 'gender' => $this->auth->gender,
  62. 'greet' => $greet,
  63. ];
  64. $this->success('操作成功', $rs);
  65. }
  66. private function add_girl_greet($user_id){
  67. $girl_greet = [
  68. [
  69. 'user_id' => $user_id,
  70. 'title' => '默认',
  71. 'content' => '你好,想认识你,可以聊聊吗?',
  72. 'is_default' => 1,
  73. 'createtime' => time(),
  74. ],
  75. [
  76. 'user_id' => $user_id,
  77. 'title' => '默认',
  78. 'content' => '听说主动打招呼的人运气都不会太差,所以我来试试!',
  79. 'createtime' => time(),
  80. ],
  81. [
  82. 'user_id' => $user_id,
  83. 'title' => '默认',
  84. 'content' => '嗨!看到你的资料觉得挺有意思的,认识一下?',
  85. 'createtime' => time(),
  86. ],
  87. [
  88. 'user_id' => $user_id,
  89. 'title' => '默认',
  90. 'content' => '我猜你收到很多消息,但我的这条一定最特别!',
  91. 'createtime' => time(),
  92. ],
  93. ];
  94. Db::name('user_greet_content')->insertAll($girl_greet);
  95. }
  96. //查询每天弹出搭讪框次数
  97. public function freegreetnum() {
  98. $user = $this->auth->getUser();
  99. if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
  100. $data['free_greet_num'] = 0;
  101. $data['vip_free_greet_num'] = 0;
  102. $data['boy_free_greet_num'] = 0;
  103. $data['boy_vip_free_greet_num'] = 0;
  104. }else{
  105. //非会员每天弹出搭讪框次数
  106. $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
  107. //vip每天弹出搭讪框次数
  108. $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
  109. // 男性 非会员每天弹出搭讪框次数
  110. $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
  111. // 男性 vip每天弹出搭讪框次数
  112. $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
  113. }
  114. $this->success('success', $data);
  115. }
  116. /**
  117. * 男性打招呼内容
  118. * @return void
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\ModelNotFoundException
  121. * @throws \think\exception\DbException
  122. */
  123. public function greetBoy()
  124. {
  125. $data = Db::name('user_greet_boy')->select();
  126. $this->success('success', $data);
  127. }
  128. }