lizhen_gitee 1 yıl önce
ebeveyn
işleme
07aa1e9902

+ 102 - 0
application/api/controller/Relation.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 关系
+ */
+class Relation extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    //发布一种新关系
+    public function addone(){
+        $relationname = input('relationname','','trim');
+        $price        = input('price',0,'intval');
+
+        if(empty($relationname) || empty($price)){
+            $this->error();
+        }
+
+        $data = [
+            'uid' => $this->auth->id,
+            'relationname' => $relationname,
+            'price' => $price,
+            'createtime' => time(),
+        ];
+
+        $id = Db::name('user_relation')->insertGetId($data);
+
+        $this->success('添加成功',$id);
+
+    }
+
+    //关系墙,列表
+    public function lists(){
+        $userid = input('uid',0,'intval');
+        $userid = $userid ? $userid : $this->auth->id;
+
+        $list = Db::name('user_relation')->alias('r')
+            ->field('r.id,r.relationname,r.price,r.to_uid,user.u_id,user.nickname,user.avatar,user.id as user_id')
+            ->join('user','r.to_uid = user.id','LEFT')
+            ->where('r.uid',$userid)
+            ->order('id desc')
+            ->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success(1,$list);
+    }
+
+    //绑定关系
+    public function joinin(){
+        $id = input('id',0);
+
+        Db::startTrans();
+
+        $info = Db::name('user_relation')->where('id',$id)->lock(true)->find();
+        //检查
+        if(empty($info)){
+            Db::rollback();
+            $this->error('不存在的关系');
+        }
+        //检查
+        if($info['to_uid'] > 0){
+            Db::rollback();
+            $this->error('该关系已被他人绑定');
+        }
+        //检查
+        if($info['uid'] == $this->auth->id){
+            Db::rollback();
+            $this->error('不能绑定自己发布的关系');
+        }
+
+        //更新
+        $update = [
+            'to_uid' => $this->auth->id,
+            'updatetime' => time(),
+        ];
+        $rs = Db::name('user_relation')->where('id',$id)->update($update);
+        if($rs === false){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+
+        //扣钱
+        if($info['price'] > 0){
+            $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,$info['price'],'-',0,'绑定关系消费',19,'jewel');
+            if($rs_wallet['status'] === false){
+                Db::rollback();
+                $this->error($rs_wallet['msg']);
+            }
+        }
+
+        Db::commit();
+        $this->success('绑定成功');
+    }
+
+
+
+}

+ 2 - 1
application/extra/wallet.php

@@ -24,6 +24,7 @@ return [
         16 => '签到得钻石',//增加
         17 => '平台充值',//增加
         18 => '充值退款',//减少                              需要测试
+        19 => '绑定关系',//减少
 
         32 => '购买家族卡', //减少
         33 => '充值', //增加 ios
@@ -40,7 +41,7 @@ return [
         //堤防3,15的出现
     ],
     'moneyname' => [
-        'jewel'    => '钻石',
+        'jewel'    => '金币',
         'money'    => '余额',
     ],
     'withdraw_type' => [