afa 11 сар өмнө
parent
commit
fedbed2823

+ 4 - 3
application/api/controller/Member.php

@@ -7,7 +7,7 @@ use app\common\library\Token;
 use app\common\model\LedgerWalletModel;
 use app\common\model\UserModel;
 use app\common\model\UserPathModel;
-use fast\Random;
+use fast\Asset;
 use think\Config;
 use think\Db;
 use think\Exception;
@@ -43,6 +43,7 @@ class Member extends Api
             if (empty($parent))  throw new Exception('邀请人不存在');
         }
         $user = $this->model->getByAddress($address);
+        $ledgerWalletModel = new LedgerWalletModel();
         if (!empty($user)) { // 已存在
             if ($user['parent_id'] == 0) {
                 // 绑定上级
@@ -51,7 +52,7 @@ class Member extends Api
                     // 创建网体
                     (new UserPathModel())->createPath($user['id'], $parentID);
                     //添加推荐人奖励
-                    $this->model::updateParentData($parentID, $user['id']);
+                    $ledgerWalletModel->changeWalletAccount($parentID, Asset::TOKEN,  getConfig('direct_income'), $ledgerWalletModel::Share, $user['id']);
                 }
             }
         } else { // 不存在
@@ -73,7 +74,7 @@ class Member extends Api
                 // 创建网体
                 (new UserPathModel())->createPath($newUserID, $parentID);
                 //推荐人奖励
-                $this->model::updateParentData($parentID, $newUserID);
+                $ledgerWalletModel->changeWalletAccount($parentID, Asset::TOKEN,  getConfig('direct_income'), $ledgerWalletModel::Share, $newUserID);
             }
         }
     }

+ 1 - 27
application/common/model/UserModel.php

@@ -69,31 +69,5 @@ class UserModel extends Model
         }
     }
 
-    /**
-     * 添加上级的分享奖励和直推人数
-     * @return void
-     * @throws DbException
-     * @throws Exception
-     * @throws DataNotFoundException
-     * @throws ModelNotFoundException
-     */
-    public static function updateParentData(string $uid, string $from_id)
-    {
-        $parent = self::where('id', $uid)->find();
-        $amount =  getConfig('direct_income');
-        UserBalanceLog::create([
-            'user_id'        => $uid,
-            'from_id'        => $from_id,
-            'type_id'        => UserBalanceLog::Share,
-            'amount'         => $amount,
-            'before'         => $parent['balance'],
-            'after'          => $parent['balance'] + $amount,
-            'action'         => '+'
-        ]);
-        $parent['balance']    = $parent['balance'] + $amount;
-        $parent['team_num']   = $parent['team_num'] +1;
-        $parent['direct_num'] = $parent['direct_num'] +1;
-        $parent->save();
-
-    }
+   
 }