afa 6 сар өмнө
parent
commit
da862af7d3

+ 6 - 9
application/api/controller/Teac.php

@@ -32,9 +32,7 @@ class Teac extends Api
              ->where('product_teac.status', ProductTeac::Normal)->where('type_id', $type_id)
              ->order('create_time desc')
              ->paginate($this->pageSize);
-        // foreach ($list as &$item) {
-        //     $item->users->avatar = !empty($item->users->avatar)? $item->users->avatar:$this->request->domain().'/assets/img/logo.png'; // 头像
-        // }
+    
         $this->success('ok', $list);
     }
 
@@ -49,7 +47,6 @@ class Teac extends Api
         if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
         if(config('teac_trade.buy_min_num') > $params['stock']) $this->error('数量不能低于'.config('teac_trade.buy_min_num'));
         if(config('teac_trade.buy_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.buy_min_price'));
-
         $chabao = bcmul($params['price'], $params['stock'], 2) ;
         if($ledgerWalletModel->getWalletChaBao($this->auth->id) < $chabao) $this->error('您的钱包茶宝余额不足');
       
@@ -114,14 +111,14 @@ class Teac extends Api
         if($params['num'] > $row['stock'] - $row['num']) $this->error('库存不足');
         $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
         $tatal = bcmul($row['price'], $params['num'], 2);
-        if($chabao < bcmul($row['price'], $tatal, 2)) $this->error('您的钱包茶宝余额不足');
+        if($chabao < $tatal) $this->error('您的钱包茶宝余额不足');
 
         // 启动事务
         Db::startTrans();
         try {
 
-            $fee = config('teac_trade.sell_fee');
-         
+            $fee = config('teac_trade.sell_serve_fee');
+            
             // 出售购买
             $userTeac::setUserCreateOrder($this->auth->id, $row['id'], ProductTeac::Sell, $params['num'], $row['price'],  $fee);
 
@@ -157,13 +154,13 @@ class Teac extends Api
         if($params['num'] > $row['stock'] - $row['num']) $this->error('库存不足');
         $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
         $tatal = bcmul($row['price'], $params['num'], 2);
-        if($chabao < bcmul($row['price'], $tatal, 2)) $this->error('您的钱包茶宝余额不足');
+        if($chabao < $tatal) $this->error('您的钱包茶宝余额不足');
 
         // 启动事务
         Db::startTrans();
         try {
 
-            $fee = config('teac_trade.sell_fee');
+            $fee = config('teac_trade.buy_serve_fee');
             $chabao = bcmul($row['price'], $params['num'], 2);
             // 出售购买
             $userTeac::setUserCreateOrder($this->auth->id, $row['id'], ProductTeac::Buying, $params['num'], $row['price'],  $fee);

+ 5 - 2
application/api/logic/TeacLogin.php

@@ -19,7 +19,10 @@ use app\common\model\LedgerTokenChangeModel;
  */
 class TeacLogin
 {
-    
+    protected static $feeList = [
+        1 => 'sell_serve_fee' , //出售服务费
+        2 => 'buy_serve_fee' , //求购服务费
+    ];
      
     /**
      * 发布求购出售信息
@@ -30,7 +33,7 @@ class TeacLogin
         if($rows)  throw new Exception(__("你有未完成的求购订单、不能重复发布"));
 
         //添加订单信息
-        return ProductTeac::setUserCreateOrder($uid, $typeId, $price, $stock, $frozen);
+        return ProductTeac::setUserCreateOrder($uid, $typeId, $price, $stock, config('teac_trade.'. self::$feeList[$typeId]), $frozen);
     }
 
     /**

+ 2 - 2
application/common/model/ProductTeac.php

@@ -47,7 +47,7 @@ class ProductTeac extends Model
 
 
     //添加订单信息
-    public static function setUserCreateOrder(int $uid, int $typeId, float $price, int $stock, float $frozen): object
+    public static function setUserCreateOrder(int $uid, int $typeId, float $price, int $stock, float $fee, float $frozen): object
     {
         $total_price = bcmul($price, $stock, 2);
         return self::create([
@@ -56,7 +56,7 @@ class ProductTeac extends Model
             'price'   => $price,
             'stock'   => $stock,
             'total_price'=> $total_price,
-            'fee'        => bcmul($total_price, config('market_transfer.serve_fee'), 2),
+            'fee'        => bcmul($total_price, $fee, 2),
             'frozen'     => $frozen,
         ]);