Browse Source

茶宝赠送

afa 10 months ago
parent
commit
81a2141574

+ 2 - 1
application/admin/lang/zh-cn/general/config.php

@@ -90,5 +90,6 @@ return [
     'Giveaway'                             => '赠送手续费',
     'Giveaway txt'                         => '赠送描述',
     'Pv rate'                              => '直推收益比例',
-    
+    'Chabao giveaway'                      => '茶宝赠送比例',
+    'Chabao giveaway txt'                  => '茶宝赠送描述',
 ];

+ 39 - 24
application/api/controller/Ledger.php

@@ -6,7 +6,7 @@ use app\admin\model\LedgerDeclarationChange;
 use app\common\controller\Api;
 use app\common\model\LedgerPowerChangeModel;
 use app\common\model\LedgerQubicChangeModel;
-use app\common\model\LedgerServersPowerChangeModel;
+use app\common\model\UserModel;
 use app\common\model\LedgerSmhChangeModel;
 use app\common\model\LedgerTokenChangeModel;
 use app\common\model\LedgerUsdtChangeModel;
@@ -15,6 +15,9 @@ use app\common\model\OfflineWithdrawRecordModel;
 use fast\Action;
 use think\Log;
 use think\Env;
+use think\Db;
+use fast\Asset;
+use think\Exception;
 
 /**
  * 首页接口
@@ -162,40 +165,52 @@ class Ledger extends Api
     }
 
     /**
-     * 算力明细
+     * 茶宝赠送明细
      * @return void
      */
-    public function powerList()
+    public function chabao()
     {
-        $type  = $this->request->post('query.action'); // 账变类型
-        $where = [
-            'user_id' => $this->auth->getTokenUserID(),
-        ];
-        if ($type != Action::All) {
-            $where['action'] = $type;
-        }
-        $paginator = (new LedgerPowerChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
-        $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
+      
+        $this->success('', ['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')]);
     }
 
     /**
-     * USDT明细
+     * 茶宝赠送
      * @return void
      */
-    public function usdtList()
+    public function chabaoGift(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
     {
-        $type  = $this->request->post('query.action'); // 账变类型
-        $where = [
-            'user_id' => $this->auth->getTokenUserID(),
-        ];
-        if ($type != Action::All) {
-            $where['action'] = $type;
+   
+        $amount = $this->request->post('amount'); // 茶宝
+        $address = $this->request->post('address'); // 地址
+        if(empty($amount) || empty($address)){
+            $this->error(__('Parameter error'));
         }
-        $paginator = (new LedgerUsdtChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
-        foreach ($paginator as $key => $item){
-            $paginator[$key]['action_name'] = Action::getText($item['action']);
+        $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
+
+        // 启动事务
+        Db::startTrans();
+        try {
+
+            $user = $userModel->getByAddress($address);
+            if(empty($user)) throw new Exception(__("赠送用户不存在"));    
+            if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));  
+            $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
+            if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+        
+            // 更新USDT和账变
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, $ledgerWalletModel::GiftPay);
+
+            $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, $ledgerWalletModel::GiftReceipt);
+            // 提交事务
+            Db::commit();
+        } catch (Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error('提交失败:' . $e->getMessage());
         }
-        $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
+
+        $this->success('ok');
     }
 
     /**

+ 0 - 69
application/api/controller/User.php

@@ -156,75 +156,6 @@ class User extends Api
 
 
 
-    /**
-     * 报单算力互转
-     * @return void
-     */
-    public function declarationTransfer()
-    {
-        $amount = $this->request->post('amount'); // 金额
-        $sign = $this->request->post('sign'); // 签名信
-        $address = $this->request->post('address'); // 提现地址
-//        $sign = 'test';
-        if(empty($sign)){
-            $this->error('参数错误');
-        }
-
-        $real   = $amount; // 实际到账
-        $min    = (new ParametersModel)->getValue('declarationMinAmount') ?? '0';
-        if ($amount <= 0) {
-            $this->error('互转金额必须大于0');
-        } else if ($amount < $min) {
-            $this->error('互转金额不能小于' . $min);
-        }
-
-        $uid = $this->auth->getTokenUserID();
-
-        // 用户信息
-        $from_user = (new UserModel())->getById($uid);
-        if (empty($from_user)) {
-            $this->error('用户不存在');
-        }
-
-        $to_user = (new UserModel())
-            ->where('address', $address)
-            ->find();
-        if (empty($to_user)) {
-            $this->error('接收用户不存在');
-        }
-
-        $wallet = (new LedgerWalletModel())->getWallet($from_user['id']);
-        if (empty($wallet)) {
-            $this->error('用户不存在');
-        }
-
-        if($amount > $wallet['declaration']){
-            $this->error('余额不足');
-        }
-
-        // 验签
-        $signMsg = "DeclarationWithdraw"; // 与前端约定的固定值
-        if (!checkSign($signMsg, $sign, $from_user['address'])) {
-            $this->error('签名校验失败');
-        }
-
-        // 启动事务
-        Db::startTrans();
-        try {
-            // 更新USDT和账变
-            (new LedgerWalletModel())->changeWalletAccount($from_user['id'], Asset::DECLARATION, -$amount, Action::TransferOut);
-
-            (new LedgerWalletModel())->changeWalletAccount($to_user['id'], Asset::DECLARATION, $amount, Action::TransferIn);
-            // 提交事务
-            Db::commit();
-        } catch (Exception $e) {
-            // 回滚事务
-            Db::rollback();
-            $this->error('提交失败:' . $e->getMessage());
-        }
-
-        $this->success('提现申请已提交');
-    }
 
     /**
      * 获取smh出款信息

+ 2 - 0
application/api/lang/en.php

@@ -20,4 +20,6 @@ return [
     '赠送'                                   => 'Gift fee',
     '直推收益'                               => 'Direct income',
     '系统调整'                               => 'System Adjustments',
+    '赠送支出'                               => 'Gift Expenses',
+    '赠送收款'                               => 'Gift Receipt',
 ]; 

+ 1 - 0
application/api/lang/en/user.php

@@ -45,4 +45,5 @@ return [
     '退回'                                   => 'Return',
     '赠送'                                   => 'Gift fee',
     '直推收益'                               => 'Direct income',
+    'Parameter error'                       => 'Parameter error',
 ];

+ 5 - 1
application/api/lang/zh-cn.php

@@ -107,5 +107,9 @@ return [
     'The withdrawal amount cannot be less than'                                  => '提现金额不能小于',
     'Withdrawal failed, please contact customer service.'                        => '提现失败,请联系客服。',
     'Signature verification failed'                                              => '签名校验失败',
-    '系统调整'                                                                    => '系统调整'
+    '系统调整'                                                                    => '系统调整',
+    '赠送支出'                                                                    => '赠送支出',
+    '赠送收款'                                                                    => '赠送收款',
+
+
 ];

+ 1 - 0
application/api/lang/zh-cn/user.php

@@ -45,4 +45,5 @@ return [
     '退回'                                  => '退回',
     '赠送'                                  => '赠送手续费',
     '直推收益'                              => '直推收益',
+    'Parameter error'                      => '参数有误',
 ];

+ 5 - 2
application/common/model/LedgerWalletModel.php

@@ -35,7 +35,8 @@ class LedgerWalletModel extends Model
     const Giveaway          = 7;
     const Direct            = 8;
     const System            = 9;
-
+    const GiftPay           = 10; //Gift Expenses
+    const GiftReceipt       = 11;
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败
@@ -52,6 +53,8 @@ class LedgerWalletModel extends Model
         self::Giveaway          => '赠送手续费',
         self::Direct            => '直推收益',
         self::System            => '系统调整',
+        self::GiftPay           => '赠送支出',
+        self::GiftReceipt       => '赠送收款',
     ];
 
     public static function getWalletChaBao($userID)
@@ -80,7 +83,7 @@ class LedgerWalletModel extends Model
     {
         return [self::Popular => __('热销支付'), self::Payment  => __('转让支付'), self::Receive => __('转让收款'), self::Recharge => __('充值'), 
         self::Withdraw  => __('提现'), self::Share => __('分享'), self::Return => __('退回'), self::Giveaway => __('赠送'), self::Direct => __('直推收益'),
-        self::System => __('系统调整')];
+        self::System => __('系统调整'),self::GiftPay => __('赠送支出'),self::GiftReceipt => __('赠送收款')];
     }
 
     /**

+ 11 - 2
application/extra/site.php

@@ -37,7 +37,16 @@ return array (
     'category2' => '分类二',
     'custom' => '自定义',
   ),
-  'direct_income' => '0.05',
+  'direct_income' => '10',
   'transfer_fee' => '0.8',
-  'recharge_address' => 'xxddddss',
+  'recharge_txt' => 'xxddddss',
+  'chabao_rate' => '0.7',
+  'withdrawal_fee' => '0.1',
+  'withdraw_min_amount' => '100',
+  'convert_rate' => '7.2',
+  'giveaway' => '0.12',
+  'giveaway_txt' => '赠送订单xxxx',
+  'pv_rate' => '0.1',
+  'chabao_giveaway' => '0.3',
+  'chabao_giveaway_txt' => '茶宝赠送xxxxx',
 );

+ 2 - 0
public/assets/js/backend/ledger/ledger_token_change.js

@@ -44,6 +44,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 7: '赠送手续费',
                                 8: '直推收益',
                                 9: '系统赠送',
+                                10: '赠送支出',
+                                11: '赠送收款'
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },
                     ]