Greet.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. $map = [];
  23. foreach($other_uids as $key => $other_uid){
  24. $map[] = [
  25. 'user_id' => $this->auth->id,
  26. 'user_to_id' => $other_uid,
  27. 'createtime' => time(),
  28. ];
  29. }
  30. Db::startTrans();
  31. $id = Db::name('user_greet')->insertAll($map);
  32. if (!$id) {
  33. Db::rollback();
  34. $this->error('您的网络开小差了~');
  35. }
  36. //tag任务赠送金币
  37. //搭讪奖励
  38. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
  39. if($task_rs === false){
  40. Db::rollback();
  41. $this->error('完成任务赠送奖励失败');
  42. }
  43. Db::commit();
  44. $greet = null;
  45. if($this->auth->gender == 0){
  46. $where['user_id'] = $this->auth->id;
  47. $greet = Db::name('user_greet_content')->where($where)->orderRaw('rand()')->find();
  48. if(!empty($greet) && $greet['type'] != 0){
  49. $greet['content'] = one_domain_image($greet['content']);
  50. }
  51. }else{
  52. $greet = Db::name('user_greet_boy')->orderRaw('rand()')->find();
  53. }
  54. $rs = [
  55. 'gender' => $this->auth->gender,
  56. 'greet' => $greet,
  57. ];
  58. $this->success('操作成功', $rs);
  59. }
  60. //查询每天弹出搭讪框次数
  61. public function freegreetnum() {
  62. $user = $this->auth->getUser();
  63. if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
  64. $data['free_greet_num'] = 0;
  65. $data['vip_free_greet_num'] = 0;
  66. $data['boy_free_greet_num'] = 0;
  67. $data['boy_vip_free_greet_num'] = 0;
  68. }else{
  69. //非会员每天弹出搭讪框次数
  70. $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
  71. //vip每天弹出搭讪框次数
  72. $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
  73. // 男性 非会员每天弹出搭讪框次数
  74. $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
  75. // 男性 vip每天弹出搭讪框次数
  76. $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
  77. }
  78. $this->success('success', $data);
  79. }
  80. /**
  81. * 男性打招呼内容
  82. * @return void
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. * @throws \think\exception\DbException
  86. */
  87. public function greetBoy()
  88. {
  89. $data = Db::name('user_greet_boy')->select();
  90. $this->success('success', $data);
  91. }
  92. }