123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 打招呼
- */
- class Greet extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //打招呼/搭讪
- public function greet() {
- $other_uids = input('user_ids', '', 'trim');
- if(!$other_uids) {
- $this->error(__('Invalid parameters'));
- }
- $other_uids = explode(',',$other_uids);
- if(empty($other_uids)){
- $this->error(__('Invalid parameters'));
- }
- //打招呼内容
- $greet = null;
- if($this->auth->gender == 0){
- $where['user_id'] = $this->auth->id;
- $greet = Db::name('user_greet_content')->where($where)->orderRaw('rand()')->find();
- if(empty($greet)){
- $this->add_girl_greet($this->auth->id);
- $greet = Db::name('user_greet_content')->where($where)->orderRaw('rand()')->find();
- }
- if(!empty($greet) && $greet['type'] != 0){
- $greet['content'] = one_domain_image($greet['content']);
- }
- }else{
- $greet = Db::name('user_greet_boy')->orderRaw('rand()')->find();
- }
- //
- $map = [];
- foreach($other_uids as $key => $other_uid){
- $map[] = [
- 'user_id' => $this->auth->id,
- 'user_to_id' => $other_uid,
- 'createtime' => time(),
- ];
- }
- Db::startTrans();
- $id = Db::name('user_greet')->insertAll($map);
- if (!$id) {
- Db::rollback();
- $this->error('您的网络开小差了~');
- }
- //tag任务赠送金币
- //搭讪奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- Db::commit();
- $rs = [
- 'gender' => $this->auth->gender,
- 'greet' => $greet,
- ];
- $this->success('操作成功', $rs);
- }
- private function add_girl_greet($user_id){
- $girl_greet = [
- [
- 'user_id' => $user_id,
- 'title' => '默认',
- 'content' => '你好,想认识你,可以聊聊吗?',
- 'is_default' => 1,
- 'createtime' => time(),
- ],
- [
- 'user_id' => $user_id,
- 'title' => '默认',
- 'content' => '听说主动打招呼的人运气都不会太差,所以我来试试!',
- 'createtime' => time(),
- ],
- [
- 'user_id' => $user_id,
- 'title' => '默认',
- 'content' => '嗨!看到你的资料觉得挺有意思的,认识一下?',
- 'createtime' => time(),
- ],
- [
- 'user_id' => $user_id,
- 'title' => '默认',
- 'content' => '我猜你收到很多消息,但我的这条一定最特别!',
- 'createtime' => time(),
- ],
- ];
- Db::name('user_greet_content')->insertAll($girl_greet);
- }
- //查询每天弹出搭讪框次数
- public function freegreetnum() {
- $user = $this->auth->getUser();
- if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
- $data['free_greet_num'] = 0;
- $data['vip_free_greet_num'] = 0;
- $data['boy_free_greet_num'] = 0;
- $data['boy_vip_free_greet_num'] = 0;
- }else{
- //非会员每天弹出搭讪框次数
- $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
- //vip每天弹出搭讪框次数
- $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
- // 男性 非会员每天弹出搭讪框次数
- $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
- // 男性 vip每天弹出搭讪框次数
- $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
- }
- $this->success('success', $data);
- }
- /**
- * 男性打招呼内容
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function greetBoy()
- {
- $data = Db::name('user_greet_boy')->select();
- $this->success('success', $data);
- }
- }
|