afa 4 сар өмнө
parent
commit
325376970f

+ 5 - 10
application/api/controller/Ledger.php

@@ -119,16 +119,14 @@ class Ledger extends Api
     public function frozenTransfer(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
     {
         $amount = $this->request->post('amount'); // 茶宝
-        $account= $this->request->post('account', ''); // 账号
-        $type   = (substr($account, 0, 2) == '0x')? 0: 1;    // type: 0地址 1uid
+        $account= $this->request->post('account', ''); // 账号 
         if(empty($amount) || empty($account)) $this->error(__('Parameter error'));
-        
         $real   = bcsub($amount, bcmul(getConfig('frozen_transfer'), $amount, 2), 2) ; // 手续费
         // 启动事务
         Db::startTrans();
         try {
-
-            $user = (empty($type))? $userModel->getByAddress($account): $userModel->getById($account); 
+            // type: 0x, 地址 1uid
+            $user = (substr($account, 0, 2) == '0x')? $userModel->getByAddress($account): $userModel->getByUid($account); 
             if(empty($user)) throw new Exception(__("赠送用户不存在"));    
             if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));
 
@@ -170,17 +168,14 @@ class Ledger extends Api
     {
         $amount = $this->request->post('amount'); // 茶宝
         $account= $this->request->post('account', ''); // 账号
-        $type    = (substr($account, 0, 2) == '0x')? 0: 1;    // type: 0地址 1uid
         if(empty($amount) || empty($account)) $this->error(__('Parameter error'));
-        
-      
         $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
 
         // 启动事务
         Db::startTrans();
         try {
-
-            $user = (empty($type))? $userModel->getByAddress($account): $userModel->getById($account); 
+            // type: 0x地址 1uid
+            $user = (substr($account, 0, 2) == '0x')? $userModel->getByAddress($account): $userModel->getByUid($account); 
             if(empty($user)) throw new Exception(__("赠送用户不存在"));    
             if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));  
             $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);

+ 4 - 0
application/common/model/UserModel.php

@@ -60,6 +60,10 @@ class UserModel extends Model
         return $this->where("mobile", $mobile)->find();
     }
 
+    public function getByUid($nickname){
+        return self::where('nickname', $nickname)->find();
+    }
+
     public function getByAddress($address)
     {
         return $this->where("address", $address)->find();