Explorar o código

聊天私聊转账钻石

lizhen_gitee hai 1 ano
pai
achega
c2640e4c58

+ 62 - 0
application/api/controller/Money.php

@@ -1562,4 +1562,66 @@ class Money extends Common
         $this->success("获取成功!",$result);
     }
 
+    ////////////////////////////////////
+
+    /**
+     * 消息-聊天-更多-转账-钻石
+     */
+    public function givejeweltouser(){
+        $money = intval(input('money',0));
+        $user_id = input('user_id',0);
+        $pay_password = input('paypassword','');
+
+        //验证用户权限是否能转账
+        if($this->auth->power->transfer == 1){
+            $this->error('您已经被限制消费-转账');
+        }
+        //验证被转账用户存在
+        $check = Db::name('user')->where('id',$user_id)->find();
+        if(empty($check)){
+            $this->error('不存在的用户');
+        }
+        //验证操作密码
+        if(!$this->auth->pay_password){
+            $this->error('请先设置支付密码');
+        }
+        if ($this->auth->pay_password != $this->getEncryptPassword($pay_password, $this->auth->pay_salt)) {
+            $this->error('支付密码有误');
+        }
+
+        Db::startTrans();
+        /*//验证余额
+        $userwallet = Db::name('user')->where('id',$this->auth->id)->lock(true)->find();
+        if($userwallet['jewel'] < $money){
+            Db::rollback();
+            $this->error('余额不足');
+        }*/
+        //减少和增加余额
+        $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,$money,'-',0,'私聊转账给:'.$check['nickname'],11,'jewel');
+        if($rs_wallet['status'] === false){
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        $rs_wallet = model('wallet')->lockChangeAccountRemain($user_id,$money,'+',0,$this->auth->nickname.':私聊到账',12,'jewel');
+        if($rs_wallet['status'] === false){
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        Db::commit();
+        $this->success('转账成功');
+    }
+
+    /**
+     * 获取密码加密后的字符串
+     * @param string $password 密码
+     * @param string $salt 密码盐
+     * @return string
+     */
+    private function getEncryptPassword($password, $salt = '')
+    {
+        return md5(md5($password) . $salt);
+    }
+
 }

+ 8 - 5
application/common/model/Wallet.php

@@ -67,7 +67,7 @@ class Wallet extends Model
      * @return array[log_table]
      * @return array[log_id]
      */
-    public function lockChangeAccountRemain($user_id,$number,$mode,$before,$remark='',$logtype='',$accountType='money')
+    public function lockChangeAccountRemain($user_id,$money,$mode,$before,$remark='',$logtype='',$accountType='money')
     {
         //初始化
         $result = array(
@@ -85,9 +85,12 @@ class Wallet extends Model
         //钱包名称
         $wallet_name = $this->getwalletname($accountType);
 
-        //正负数
+        //数字纠正
+        $money = abs($money);
         if($mode == '-'){
-            $number = -$number;
+            $number = -$money;
+        }else{
+            $number = $money;
         }
 
         //检测
@@ -124,13 +127,13 @@ class Wallet extends Model
             //钱币记录
             $data = array();
             $data['user_id'] = $user_id;
-            $data['value'] = $number;
+            $data['value'] = $money;
             $data['mode'] = $mode;
             $data['before'] = $wallet[$accountType];
             $data['balance'] = bcadd($wallet[$accountType], $number);
             $data['detail'] = $remark;
             $data['createtime'] = time();
-            $data['log_type'] = $logtype;
+            $data['type'] = $logtype;
 
             //新的方式
             $rs1 = Db::name('user')->where(['id'=>$user_id])->update([$accountType => $data['balance']]);

+ 2 - 0
application/extra/wallet.php

@@ -14,6 +14,8 @@ return [
         6  => '购买装扮',    //减少
         7  => '拒绝订单返还',    //增加
         8  => '完成用户订单获得收益',    //增加
+        11 => '私聊转账',  //减少
+        12 => '私聊到账',  //增加
     ],
     'moneyname' => [
         'jewel'    => '钻石',