Browse Source

手续费

afa 4 months ago
parent
commit
03535abb87

+ 37 - 0
application/admin/controller/general/Sharingfees.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\admin\controller\general;
+
+use app\common\controller\Backend;
+
+/**
+ * 手续费分润设置管理
+ *
+ * @icon fa fa-circle-o
+ */
+class Sharingfees extends Backend
+{
+
+    /**
+     * Sharingfees模型对象
+     * @var \app\admin\model\general\Sharingfees
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\common\model\Sharingfees;
+
+    }
+
+
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+
+
+}

+ 10 - 0
application/admin/lang/zh-cn/general/sharingfees.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'Product_id'  => '持有产品',
+    'Num'         => '每人持有量',
+    'Fees'        => '分润',
+    'Status'      => '状态',
+    'Create_time' => '创建时间',
+    'Update_time' => '更新时间'
+];

+ 27 - 0
application/admin/validate/general/Sharingfees.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate\general;
+
+use think\Validate;
+
+class Sharingfees extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 29 - 0
application/admin/view/general/sharingfees/add.html

@@ -0,0 +1,29 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_id" data-rule="required" data-source="product/lists/index" data-multiple="true" class="form-control selectpage" data-field="zh_name" name="row[product_id]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Num')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-num" data-rule="required" class="form-control" name="row[num]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Fees')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-fees" data-rule="required" class="form-control" step="0.001" name="row[fees]" type="number" value="0.000">
+        </div>
+    </div>
+   
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 35 - 0
application/admin/view/general/sharingfees/edit.html

@@ -0,0 +1,35 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Product_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-product_id" data-rule="required" data-source="product/index" class="form-control selectpage" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Num')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-num" data-rule="required" class="form-control" name="row[num]" type="number" value="{$row.num|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Fees')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-fees" data-rule="required" class="form-control" step="0.001" name="row[fees]" type="number" value="{$row.fees|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-status" data-rule="required" class="form-control" name="row[status]" type="number" value="{$row.status|htmlentities}">
+        </div>
+    </div>
+
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 35 - 0
application/admin/view/general/sharingfees/index.html

@@ -0,0 +1,35 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('general/sharingfees/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('general/sharingfees/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('general/sharingfees/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        
+
+                        <div class="dropdown btn-group {:$auth->check('general/sharingfees/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('general/sharingfees/edit')}"
+                           data-operate-del="{:$auth->check('general/sharingfees/del')}"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 62 - 0
application/api/command/SharingFees.php

@@ -0,0 +1,62 @@
+<?php
+
+
+namespace app\api\command;
+
+use app\common\logic\ScanLogic;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use app\common\model\ProductOrder;
+use app\common\model\UserModel;
+use think\Model;
+
+
+class SharingFees extends Command
+{
+    protected function configure()
+    {
+        $this->setName('sharingFees')->setDescription('手续费分润');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        /* 永不超时 */
+//        ini_set('max_execution_time', 0);
+
+        // 记录开始运行的时间
+        $GLOBALS['_beginTime'] = microtime(TRUE);
+        $output->writeln('定时任务开始执行:' . date('Y-m-d H:i:s', time()));
+
+        /*** 发放分红收益 ***/
+        $output->writeln("开始发放空投:");
+        $i = 0;
+        $count = $this->reset_user_pledge($i);
+        $output->writeln('定时任务执行结束,总执行:' .  $count  . '个');
+    }
+
+
+    /*手续费分润
+      当日使用(交易、赠送扣除)的茶宝手续费和茶宝(手续费账户)分别统计一下总量。
+      比如茶宝手续费有1000,茶宝(手续费账户)有2000,持有A的分润10%,则分别为100和200
+      1)先算出所有人产品A的持有量(如300),根据持有量算出每份产品应发放茶宝和茶宝(手续费账户)的数量。
+      (茶宝:100/300=0.333 茶宝(手续费账户)200/300=0.666)
+      2)再算出持有A产品的用户,每人持有量;根据每人持有量*每份应发数量,计算出每人应发总额,发放到该用户的茶宝账户上。
+      3)按上述算法,以此计算持有B和持有CDE的用户
+
+    */
+
+
+    public  function reset_user_pledge(){
+
+      
+
+
+
+
+
+    }
+
+
+
+}

+ 18 - 8
application/api/controller/Ledger.php

@@ -114,14 +114,16 @@ class Ledger extends Api
      * 标记茶宝资产转账
      * @return void
      */
-    public function frozenTransfer(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
+    public function frozenTransfer(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel, LedgerFrozenChangeModel $ledgerFrozenChangeModel)
+
     {
         $amount = $this->request->post('amount'); // 茶宝
         $account= $this->request->post('account', ''); // 账号
         if(empty($amount) || empty($account)){
             $this->error(__('Parameter error'));
         }
-        $real   = bcsub($amount, bcmul(getConfig('frozen_transfer'), $amount, 2), 2) ; // 手续费
+        $fee = bcmul(getConfig('frozen_transfer'), $amount, 2);
+        $real   = bcsub($amount, $fee, 2) ; // 手续费
         // 启动事务
         Db::startTrans();
         try {
@@ -136,9 +138,13 @@ class Ledger extends Api
             if(bccomp($amount, $available, 2) > 0) throw new Exception(__("转账后余额不能低于9.9"), 15001);
             
             // 更新USDT和账变
-            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, -$amount, LedgerFrozenChangeModel::Payment, $user['id']);
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, -$amount, $ledgerFrozenChangeModel::Payment, $user['id']);
+
+            $newFrozen = $ledgerWalletModel->changeWalletAccount($user['id'], Asset::FROZEN, $real, $ledgerFrozenChangeModel::Receive, $this->auth->id);
+
+            //添加手续费
+            $ledgerFrozenChangeModel::createChangeFees($user['id'], $this->auth->id, -$fee, $newFrozen);
 
-            $ledgerWalletModel->changeWalletAccount($user['id'], Asset::FROZEN, $real, LedgerFrozenChangeModel::Receive, $this->auth->id);
             // 提交事务
             Db::commit();
         } catch (Exception $e) {
@@ -165,14 +171,15 @@ class Ledger extends Api
      * 茶宝赠送 0x
      * @return void
      */
-    public function chabaoGift(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
+    public function chabaoGift(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel, LedgerTokenChangeModel $ledgerTokenChangeModel)
     {
         $amount = $this->request->post('amount'); // 茶宝
         $account= $this->request->post('account', ''); // 账号 
         if(empty($amount) || empty($account)){
             $this->error(__('Parameter error'));
         }
-        $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
+        $fee = bcmul(getConfig('chabao_giveaway'), $amount, 2); 
+        $real   = bcsub($amount, $fee, 2) ; // 手续费
         // 启动事务
         Db::startTrans();
         try {
@@ -183,9 +190,12 @@ class Ledger extends Api
             if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
         
             // 更新USDT和账变
-            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, LedgerTokenChangeModel::GiftPay, $user['id']);
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, $ledgerTokenChangeModel::GiftPay, $user['id']);
+
+            $newChabao = $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, $ledgerTokenChangeModel::GiftReceipt, $this->auth->id);
+            //添加手续费
+            $ledgerTokenChangeModel::createChangeFees($user['id'], $this->auth->id, -$fee, $newChabao);
 
-            $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, LedgerTokenChangeModel::GiftReceipt, $this->auth->id);
             // 提交事务
             Db::commit();
         } catch (Exception $e) {

+ 6 - 6
application/api/controller/Market.php

@@ -7,15 +7,12 @@ use app\common\controller\Api;
 use app\common\model\AnnouncementModel;
 use app\common\model\UserCollect;
 use app\common\model\ProductBuying;
-use app\common\model\UserModel;
 use app\common\model\LedgerWalletModel;
 use app\common\model\ProductTransfer;
 use app\api\logic\MarketLogic;
-use app\common\logic\BscApi;
 use app\common\model\ProductLists;
 use app\common\model\ProductOrder;
 use app\common\model\UserBuying;
-use fast\Action;
 use fast\Asset;
 use think\Db;
 use Exception;
@@ -146,7 +143,7 @@ class Market extends Api
 
 
     //出售求购
-    public function sellBuying(LedgerWalletModel $ledgerWalletModel, ProductBuying $productBuying, UserBuying $userBuying, ProductOrder $productOrder)
+    public function sellBuying(LedgerWalletModel $ledgerWalletModel, ProductBuying $productBuying, UserBuying $userBuying, ProductOrder $productOrder, LedgerTokenChangeModel $ledgerTokenChangeModel)
     {
         $params = $this->request->post();
         $validate = \think\Loader::validate('Market');
@@ -161,10 +158,10 @@ class Market extends Api
         try {
 
             // 记录出售订单
-            $chabao =$userBuying::getCreateUserBuying($this->auth->id, $params['buying_id'], $params['order_id'], $buying->user_id, $buying->min_price);
+            list($chabao, $fee)=$userBuying::getCreateUserBuying($this->auth->id, $params['buying_id'], $params['order_id'], $buying->user_id, $buying->min_price);
 
             // 添加扣除茶币
-            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, $chabao, LedgerTokenChangeModel::BuySellg, $buying->user_id);
+            $newChabao = $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, $chabao, $ledgerTokenChangeModel::BuySellg, $buying->user_id);
 
             // 扣除冻结金额
             $ledgerWalletModel->changeWalletOnly($buying->user_id, Asset::BUYING, -$buying->min_price); //解冻金额
@@ -172,6 +169,9 @@ class Market extends Api
             //添加订单
             $productOrder::setCreateOrder($params['order_id'], ['product_id' => $buying->product_id, 'area_id' => 0,'price' =>$buying->min_price], ProductOrder::Buying, $buying->user_id,  $this->auth->id, getOrderSN('R'), 0, $buying->min_price);
 
+            //记录转让手续费
+            $ledgerTokenChangeModel::createChangeFees($this->auth->id, $buying->user_id, -$fee, $newChabao);
+
             //关闭订单
             $productOrder::where('id', $params['order_id'])->where('user_id', $this->auth->id)->setField(['status' => ProductOrder::Closure]);
 

+ 6 - 2
application/api/logic/OrderLogic.php

@@ -8,6 +8,8 @@ use think\Env;
 use think\Cache;
 use think\Loader ;
 use fast\Asset;
+use app\common\model\LedgerTokenChangeModel;
+
 use app\common\model\ProductOrder;
 use app\common\model\ProductLists;
 use app\common\model\ProductPopular;
@@ -92,7 +94,7 @@ class OrderLogic
                   
                   //增加转让人余额
                   $amount = bcsub($item->price, $item->fees, 2);
-                  $ledgerWalletModel->changeWalletAccount($item->user_id, Asset::TOKEN, $amount, $ledgerTokenChangeModel::Receive, $uid);
+                  $newAmount = $ledgerWalletModel->changeWalletAccount($item->user_id, Asset::TOKEN, $amount, $ledgerTokenChangeModel::Receive, $uid);
                   $show = $productLists::where('id', $item->product_id)->value('is_show');
                   if(!empty($show) && $popular_order->popular_price > config('min_rwa_price')) {
                         //扣除转让人Rwa有效  
@@ -106,11 +108,13 @@ class OrderLogic
                   $popular_order->status=$productOrder::Closure;
                   $popular_order->save();
 
+                  //记录转让手续费
+                  $ledgerTokenChangeModel::createChangeFees($item->user_id, $uid, -$item->fees, $newAmount);
+
                   //修改状态
                   $item->status = $productTransfer::Stop;
                   $item->save();
             }
-
             return true;
       }
 

+ 8 - 3
application/api/logic/TeacLogin.php

@@ -65,7 +65,10 @@ class TeacLogin
 
 
         //添加来源茶宝
-        $ledgerWalletModel->changeWalletAccount($fromUid, Asset::TOKEN, bcsub($total_price, $fee, 4), LedgerTokenChangeModel::BuySellg, $uid);
+        $newChabao = $ledgerWalletModel->changeWalletAccount($fromUid, Asset::TOKEN, bcsub($total_price, $fee, 4), LedgerTokenChangeModel::BuySellg, $uid);
+
+        //添加手续费
+        LedgerTokenChangeModel::createChangeFees($fromUid, $uid, -$fee, $newChabao);
 
         return true;
     }
@@ -84,9 +87,11 @@ class TeacLogin
         $fee = bcmul($total_price, $fee, 4); //手续费
 
         //添加用户茶宝
-        $ledgerWalletModel->changeWalletAccount($uid, Asset::TOKEN, bcsub($total_price, $fee, 4), LedgerTokenChangeModel::BuySellg, $fromUid);
+        $newChabao = $ledgerWalletModel->changeWalletAccount($uid, Asset::TOKEN, bcsub($total_price, $fee, 4), LedgerTokenChangeModel::BuySellg, $fromUid);
+
+        //添加手续费
+        LedgerTokenChangeModel::createChangeFees($uid, $fromUid, -$fee, $newChabao);
 
-     
         //扣除用户Teac
         $ledgerWalletModel->changeWalletAccount($uid, Asset::TEAC, -$num, LedgerTeacChangeModel::BuySell, $fromUid);
      

+ 1 - 0
application/command.php

@@ -22,5 +22,6 @@ return [
     'app\api\command\RechargeTxHashVerify',
     'app\api\command\SendBonusRewards', //奖金
     'app\api\command\SenAirdrop', //空投
+    'app\api\command\SharingFees', //手续费分润
     'app\api\command\Task',
 ];

+ 19 - 3
application/common/model/LedgerFrozenChangeModel.php

@@ -12,7 +12,7 @@ class LedgerFrozenChangeModel extends Model
     //ledger_declaration_change
     protected $name = "ledger_frozen_change";
 
-    const Giveaway          = 0; //赠送手续费
+    const Giveaway          = 0; //赠送手续费  1
     const Super             = 1; //茶宝标记激活
     const Freight           = 2; //物流运费
     const Payment           = 3; //转让
@@ -21,7 +21,9 @@ class LedgerFrozenChangeModel extends Model
     const RwaExchangeRecord = 6;
     const Ecology           = 7; //生态节点
     const TeamLevel         = 8; //等级分佣
-    const Pledge            = 9; //质押
+    const Pledge            = 9; //质押服务费  2
+    const TransferFees      = 10; //转让手续费
+
 
     public static function getStatusList()
     {
@@ -37,10 +39,24 @@ class LedgerFrozenChangeModel extends Model
             self::Ecology => __('生态节点'),
             self::TeamLevel => __('社区服务奖励'),
             self::Pledge => __('质押'),
+            self::TransferFees => __('转让手续费'),
+
         ];
     }
 
 
-
+    //TransferFees
+    public static function createChangeFees($uid,$from_id,$amount, $newAmount)
+    {
+        if($amount == 0) return true;
+        // 创建账变记录
+        return self::create([
+            'user_id'        => $uid,
+            'from_id'        => $from_id,
+            'change_amount'  => $amount,
+            'present_amount' =>  bcsub($newAmount, abs($amount), 6),
+            'action'         => self::TransferFees,
+        ]);
+    }
 
 }

+ 70 - 52
application/common/model/LedgerTokenChangeModel.php

@@ -11,58 +11,60 @@ class LedgerTokenChangeModel extends Model
     protected $name = "ledger_token_change";
 
     //0支付 1转让支付 2 转让收款 3 充值 4 提现 5扣除书续费
-     const Popular           = 0;
-     const Payment           = 1;
-     const Receive           = 2;
-     const Recharge          = 3;
-     const Withdraw          = 4;
-     const Share             = 5;
-     const Return            = 6;
-     const Giveaway          = 7; //赠送手续费
-     const Direct            = 8;
-     const System            = 9;
-     const GiftPay           = 10; //赠送支出   
-     const GiftReceipt       = 11;
-     const Community         = 12; //社区津贴
-     const Service           = 13; //服务津贴
-     const Together          = 14; //共创津贴
-     const Super             = 15; //茶宝标记激活
-     const Buying            = 16; //求购购买
-     const BuySellg          = 17; //求购出售
-     const BuyCancel         = 18; //求购取消
-     const Ecology           = 19; //生态节点奖励
-     const Pledge            = 20; //存储服务费
-     const TeamLevel         = 21; //等级分佣
-     const ChaLink           = 22; //茶付宝转入
-     const RwaExchangeRecord = 23; //兑换Rwa
-     const Promotion         = 24; //推广奖励
-     /*
-      * 支付状态
-      * 0未支付 100支付中 200支付成功 400支付失败
-      */
-     public $pay_status = [
-         '-1'                    => '全部',
-         self::Popular           => '热销支付',
-         self::Payment           => '转让支付',
-         self::Receive           => '转让收款',
-         self::Recharge          => '充值',
-         self::Withdraw          => '提现',
-         self::Share             => '分享',
-         self::Return            => '退回',
-         self::Direct            => '布道津贴', //直推
-         self::System            => '系统调整',
-         self::GiftPay           => '转账支出',
-         self::GiftReceipt       => '转账收款',
-         self::Community         => '社区津贴',
-         self::Service           => '服务津贴',
-         self::Together          => '共创津贴',
-         self::Ecology           => '生态节点奖励',
-         self::Pledge            => '存储服务费',
-         self::TeamLevel         => '社区服务奖励',
-         self::ChaLink           => '茶付宝划转',
-         self::RwaExchangeRecord => '兑换Rwa',
-         self::Promotion         => '推广奖励',
-     ];
+    const Popular           = 0;
+    const Payment           = 1;
+    const Receive           = 2;
+    const Recharge          = 3;
+    const Withdraw          = 4;
+    const Share             = 5;
+    const Return            = 6;
+    const Giveaway          = 7; //赠送手续费 1
+    const Direct            = 8;
+    const System            = 9;
+    const GiftPay           = 10; //赠送支出   
+    const GiftReceipt       = 11;
+    const Community         = 12; //社区津贴
+    const Service           = 13; //服务津贴
+    const Together          = 14; //共创津贴
+    const Super             = 15; //茶宝标记激活
+    const Buying            = 16; //求购购买
+    const BuySellg          = 17; //求购出售
+    const BuyCancel         = 18; //求购取消
+    const Ecology           = 19; //生态节点奖励
+    const Pledge            = 20; //存储服务费 2
+    const TeamLevel         = 21; //等级分佣
+    const ChaLink           = 22; //茶付宝转入
+    const RwaExchangeRecord = 23; //兑换Rwa
+    const Promotion         = 24; //推广奖励
+    const TransferFee       = 25; //转让手续费 3
+
+    /*
+    * 支付状态
+    * 0未支付 100支付中 200支付成功 400支付失败
+    */
+    public $pay_status = [
+        '-1'                    => '全部',
+        self::Popular           => '热销支付',
+        self::Payment           => '转让支付',
+        self::Receive           => '转让收款',
+        self::Recharge          => '充值',
+        self::Withdraw          => '提现',
+        self::Share             => '分享',
+        self::Return            => '退回',
+        self::Direct            => '布道津贴', //直推
+        self::System            => '系统调整',
+        self::GiftPay           => '转账支出',
+        self::GiftReceipt       => '转账收款',
+        self::Community         => '社区津贴',
+        self::Service           => '服务津贴',
+        self::Together          => '共创津贴',
+        self::Ecology           => '生态节点奖励',
+        self::Pledge            => '存储服务费',
+        self::TeamLevel         => '社区服务奖励',
+        self::ChaLink           => '茶付宝划转',
+        self::RwaExchangeRecord => '兑换Rwa',
+        self::Promotion         => '推广奖励',
+    ];
 
            
     public static function getStatusList()
@@ -93,8 +95,24 @@ class LedgerTokenChangeModel extends Model
             self::ChaLink => __('茶付宝转入'),
             self::RwaExchangeRecord => __('兑换Rwa'),
             self::Promotion => __('推广奖励'),
+            self::TransferFee => __('转让手续费'),
+
            ];
     }
    
 
+    //创建账变手续费记录
+    public static function createChangeFees($uid,$from_id,$amount, $newAmount)
+    {
+        if($amount == 0) return true;
+        // 创建账变记录
+        return self::create([
+            'user_id'        => $uid,
+            'from_id'        => $from_id,
+            'change_amount'  => $amount,
+            'present_amount' =>  bcsub($newAmount, abs($amount), 6),
+            'action'         => self::TransferFee,
+        ]);
+    }
+
 }

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

@@ -112,9 +112,8 @@ class LedgerWalletModel extends Model
             'create_time'    => time(),
             'action'         => $action
         ]);
-        if (empty($insertRs)) {
-            throw new Exception('创建' . $asset . '账变记录失败');
-        }
+        if (empty($insertRs))  throw new Exception('创建' . $asset . '账变记录失败');
+        return $newAmount;
     }
  
     /**

+ 57 - 0
application/common/model/Sharingfees.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+
+class Sharingfees extends Model
+{
+
+    // 表名
+    protected $table = 'sharing_fees';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'create_time';
+    protected $updateTime = 'update_time';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'create_time_text',
+        'update_time_text'
+    ];
+    
+
+    
+
+
+
+    public function getCreateTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getUpdateTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setCreateTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setUpdateTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+}

+ 1 - 1
application/common/model/UserBuying.php

@@ -55,7 +55,7 @@ class UserBuying  extends Model
             'fee'           => $fee,
             'income'        => $income,
         ]);
-        return $income;
+        return [$income,$fee];
     }
 
     //users

+ 56 - 0
public/assets/js/backend/general/sharingfees.js

@@ -0,0 +1,56 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'general/sharingfees/index' + location.search,
+                    add_url: 'general/sharingfees/add',
+                    edit_url: 'general/sharingfees/edit',
+                    del_url: 'general/sharingfees/del',
+                    multi_url: 'general/sharingfees/multi',
+                    import_url: 'general/sharingfees/import',
+                    table: 'sharing_fees',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'product_id', title: __('Product_id'), operate: 'LIKE'},
+                        {field: 'num', title: __('Num')},
+                        {field: 'fees', title: __('Fees'), operate:'BETWEEN'},
+                        {field: 'status', title: __('Status')},
+                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});