Bladeren bron

聊天送礼物

lizhen_gitee 1 jaar geleden
bovenliggende
commit
9fb84bd1e3
2 gewijzigde bestanden met toevoegingen van 125 en 11 verwijderingen
  1. 124 10
      application/api/controller/Gift.php
  2. 1 1
      application/api/controller/Usercenter.php

+ 124 - 10
application/api/controller/Gift.php

@@ -24,17 +24,17 @@ class Gift extends Api
      * 获取礼物列表
      */
     public function getGiftList() {
-        $type = $this->request->request("type"); // 礼物类型:0=活动,1=常规,2=人气,3=浪漫,4=豪华
-        $page = $this->request->request('page',1); // 分页
-        $pageNum = $this->request->request('pageNum',100); // 分页
-        // 分页搜索构建
-        $pageStart = ($page-1)*$pageNum;
+
 
         // 获取基本信息
         $where = ['is_show'=>1];
-        $type != '' && $where["type"] = $type;
-//        $giftList = $this->giftModel->where($where)->limit($pageStart,$pageNum)->select();
-        $giftList = $this->giftModel->where($where)->order("sort","asc")->select();
+
+        if(!$this->is_vip($this->auth->id)){
+            $where['is_vip'] = 0;
+        }
+
+        $giftList = Db::name('gift')->where($where)->order("weigh","desc")->select();
+        $giftList = list_domain_image($giftList,['image','special']);
         $this->success("获取成功!",$giftList);
     }
 
@@ -72,11 +72,12 @@ class Gift extends Api
      * 获取我的礼物墙
      */
     public function getMyGiftWall() {
-        $user_id = $this->request->request("user_id", 0);
+        $user_id = input("user_id", 0);
 
         $userid = $user_id ? $user_id : $this->auth->id;
+
         $list = \app\common\model\GiftUserParty::alias('a')->join("hx_gift g", "g.id = a.gift_id", "inner")->field("gift_id,g.name,g.image,sum(number) as number")
-            ->where(["user_to_id" => $userid, 'g.type' => ['<>', 6]])
+            ->where(["user_to_id" => $userid,])
             ->group("gift_id")
             ->order('g.value desc')
             ->select();
@@ -84,6 +85,24 @@ class Gift extends Api
     }
 
     /**
+     * 获取我的礼物墙
+     */
+    public function getMyGiftWall_typing() {
+        $user_id = $this->request->request("user_id", 0);
+
+        $userid = $user_id ? $user_id : $this->auth->id;
+
+        $list = Db::name('gift_user_typing')->alias('log')
+            ->join('gift', 'gift.id = log.gift_id', 'LEFT')->field('log.*,sum(number) as number,gift.name,gift.image,gift.special')
+            ->where(['log.user_to_id' => $userid])
+            ->group('log.gift_id')
+            ->order('gift.price desc')
+            ->select();
+        $list = list_domain_image($list,['image','special']);
+        $this->success("获取成功!", $list);
+    }
+
+    /**
      * 获取我的收送礼明细
      */
     public function my_gift_log(){
@@ -124,4 +143,99 @@ class Gift extends Api
         }
         $this->success(1,$rs);
     }
+
+    //聊天送礼物
+    public function givegift_typing() {
+        // 接口防并发
+        if (!$this->apiLimit(1, 1000)) {
+            $this->error(__('Operation frequently'));
+        }
+
+        $user_id = input('user_id');// 赠送对象
+        $gift_id = input('gift_id');// 礼物ID
+        $number  = input('number',1,'intval');//数量
+
+        if (!$user_id || !$gift_id || $number < 1)
+        {
+            $this->error();
+        }
+
+        // 不可以赠送给自己
+        if($this->auth->id == $user_id)
+        {
+            $this->error("不可以赠送给自己");
+        }
+
+        // 获取礼物信息
+        $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
+        if (!$giftinfo)
+        {
+            $this->error("请选择礼物");
+        }
+        $giftvalue = bcmul($giftinfo['price'],$number);
+
+        //被赠送人信息
+        $touserinfo = Db::name('user')->where('id',$user_id)->find();
+        if (!$touserinfo)
+        {
+            $this->error("不存在的用户");
+        }
+
+        // 判断当前用户余额
+        $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
+        if($user_gold < $giftvalue)
+        {
+            $this->error("您的金币余额不足");
+        }
+
+
+        Db::startTrans();
+
+
+        // 添加礼物赠送记录表
+        $data = [
+            'user_id'     => $this->auth->id,
+            'user_to_id'  => $user_id,
+            'gift_id'     => $giftinfo['id'],
+            'gift_name'   => $giftinfo['name'],
+            'number'      => $number,
+            'price'       => $giftinfo['price'],
+            'total_price' => $giftvalue,
+            'createtime'  => time(),
+        ];
+        $log_id = Db::name('gift_user_typing')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('赠送失败');
+        }
+
+        if($giftvalue > 0){
+
+            // 扣除当前用户余额
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$giftvalue,53,'赠送礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+
+            // 添加赠送用户余额
+            $money_to_gold = config('site.money_to_gold');
+            $gift_plat_scale = config('site.gift_plat_scale');
+
+            $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
+
+            $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,54,'获得礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+        }
+
+
+
+        Db::commit();
+        $this->success('赠送成功');
+
+    }
 }

+ 1 - 1
application/api/controller/Usercenter.php

@@ -184,7 +184,7 @@ class UserCenter extends Common
      */
     public function getMyVisitList(){
         $list = Db::name('user_visitlist')->alias('uv')
-            ->field('uv.user_id,uv.updatetime,user.id,user.nickname,user.avatar,user.gender,user.desc')
+            ->field('uv.user_id,uv.updatetime,user.nickname,user.avatar,user.gender,user.desc')
             ->join('user','uv.user_id = user.id','LEFT')
             ->where('uv.visit_user_id',$this->auth->id) //被访问者
             ->order('uv.id desc')->autopage()->select();