afa 8 ヶ月 前
コミット
877a3c73fb

+ 3 - 8
application/admin/view/product/popular/add.html

@@ -29,9 +29,9 @@
         <div class="col-xs-12 col-sm-3">
             <input id="c-pv" data-rule="required" class="form-control" step="0.01" name="row[pv]" type="number" value="0.00">
         </div>
-        <label class="control-label col-xs-12 col-sm-2">{:__('最低转让价')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
         <div class="col-xs-12 col-sm-3">
-            <input id="c-min_transfer" data-rule="required" class="form-control" step="0.01" name="row[min_transfer]" type="number" value="0.00">
+            <input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="0">
         </div>
     </div>
 
@@ -55,12 +55,7 @@
             <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="number" value="0">
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="0">
-        </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">

+ 3 - 8
application/admin/view/product/popular/edit.html

@@ -23,9 +23,9 @@
         <div class="col-xs-12 col-sm-3">
             <input id="c-pv" data-rule="required" class="form-control" step="0.01" name="row[pv]" type="number" value="{$row.pv|htmlentities}">
         </div>
-        <label class="control-label col-xs-12 col-sm-2">{:__('最低转让价')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
         <div class="col-xs-12 col-sm-3">
-            <input id="c-min_transfer" data-rule="required" class="form-control" step="0.01" name="row[min_transfer]" type="number" value="{$row.min_transfer|htmlentities}">
+            <input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">
         </div>
     </div>
 
@@ -49,12 +49,7 @@
             <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="number" value="{$row.stock|htmlentities}">
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|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">

+ 14 - 17
application/api/controller/Order.php

@@ -90,15 +90,14 @@ class Order extends Api
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
         if(!$validate->scene('pick')->check($params)) $this->error($validate->getError());
-        $order_info = $productOrder->where('id', $params['order_id'])->find();
-        if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
+        $order_info = $productOrder::getProductOrder($params['order_id'], productOrder::Paid, 'b.freight,b.is_freight');
+        if(empty($order_info) || empty($order_info->is_freight)) $this->error( __("参数有误,无可用产品"));
         // 启动事务
         Db::startTrans();
         try {
 
-            $freight= getConfig('logistics_freight');
-            $amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
-            if(bccomp($freight, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+            $amount = $ledgerWalletModel::getWalletTotalChaBao($this->auth->id);
+            if(bccomp($order_info->freight, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
 
             // 生成订单
             $userArea->create(['name'=>$params['name'], 'type_id'=>$userArea::TakeAdders, 'phone'=>$params['phone'],'address'=>$params['address'],'order_id'=>$params['order_id']]);
@@ -107,7 +106,7 @@ class Order extends Api
             if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($order_info->user_id, $userModel::getByParentId($order_info->user_id), 1, '-');
 
             //扣除运费
-            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$freight, $ledgerWalletModel::Freight, $this->auth->id);
+            if($order_info->freight > 0) $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info->freight, $ledgerWalletModel::Freight, $this->auth->id);
 
             $order_info->status= $productOrder::Shipped; 
             $order_info->save();
@@ -123,7 +122,7 @@ class Order extends Api
 
 
     /**
-     * 订单转让
+     * 订单寄售转让
      * @return void
      */
     public function transfer(ProductOrder $productOrder, ProductTransfer $productTransfer, ProductPopular $productPopular)
@@ -134,12 +133,9 @@ class Order extends Api
         //启动事务
         Db::startTrans();
         try {
-
-            $order_info = $productOrder->where('id', $params['order_id'])->where('status', $productOrder::Paid)->find();
-            if(empty($order_info)) throw new Exception(__("订单不存在"));
-
-            $min_transfer = $productPopular::where('id', $order_info->order_id)->value('min_transfer');
-            if(bccomp($params['price'],$min_transfer, 2) < 0) throw new Exception(__("当前订单最低转让金额为").$min_transfer);
+            $order_info = $productOrder::getProductOrder($params['order_id'], productOrder::Paid, 'b.is_transfer,b.min_transfer_fee,b.max_transfer_fee');
+            if(empty($order_info) || empty($order_info->is_transfer)) throw new Exception(__("订单不存在"));
+            if($params['price'] < $order_info->min_transfer_fee || $params['price'] > $order_info->max_transfer_fee) throw new Exception(__("当前订单转让金额为").$order_info->min_transfer_fee.'~'.$order_info->max_transfer_fee);
 
             //转让订单
             $fee = getConfig('transfer_fee');
@@ -219,15 +215,16 @@ class Order extends Api
         // 启动事务
         Db::startTrans();
          try {
-            $order_info = $productOrder->where('id', $params['order_id'])->where('status', $productOrder::Paid)->find();
-            if(empty($order_info)) throw new Exception(__("参数有误,无可用产品"));
+
+            $order_info = $productOrder::getProductOrder($params['order_id'], $productOrder::Paid, 'b.is_gift,b.gift_fee');
+            if(empty($order_info) || empty($order_info->is_gift)) throw new Exception(__("参数有误,无可用产品"));
 
             $user = $userModel->getByAddress($params['address']);
             if(empty($user)) throw new Exception(__("赠送用户不存在"));    
             if($user['id'] == $order_info['user_id']) throw new Exception(__("赠送用户不能是自己"));  
 
-            $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
-            $fees   = bcmul($order_info['price'], getConfig('giveaway'), 2);   
+            $chabao = $ledgerWalletModel::getWalletTotalChaBao($this->auth->id);
+            $fees   = bcmul($order_info['price'], $order_info->gift_fee, 2);   
             if(bccomp($fees, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
            
             //添加记录

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

@@ -26,7 +26,7 @@ return [
     '赠送支出'                               => 'Gift Expenses',
     '赠送收款'                                                                    => 'Gift Receipt',
     '抢购未开始'                                                                  => 'The flash sale has not started yet',
-    '当前订单最低转让金额为'                                                       => 'The current minimum consignment amount for an order is',
+    '当前订单转让金额为'                                                           => 'The current order transfer amount is',
     '已购买'                                                                      => 'Purchased',
     '转让中'                                                                      => 'On consignment',
     '已赠送'                                                                      => 'Gifted',

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

@@ -115,7 +115,7 @@ return [
     '社区津贴'                                                                    => '社区津贴',
     '服务津贴'                                                                    => '服务津贴',
     '共创津贴'                                                                    => '共创津贴',
-    '当前订单最低转让金额为'                                                       => '当前订单最低寄售金额为',
+    '当前订单转让金额为'                                                           => '当前订单转让金额为',
     '已购买'                                                                      => '已购买',
     '转让中'                                                                      => '寄售中',
     '已赠送'                                                                      => '已赠送',

+ 24 - 15
application/common/model/LedgerWalletModel.php

@@ -70,6 +70,10 @@ class LedgerWalletModel extends Model
         return self::where('user_id', $userID)->value('token');
     }
 
+    public static function getWalletTotalChaBao($userID)
+    {
+        return self::where('user_id', $userID)->value('token + frozen');
+    }
 
     public static function getWallet($userID)
     {
@@ -107,12 +111,8 @@ class LedgerWalletModel extends Model
     public function changeWalletAccount(int $uid, string $asset, string $amount, int $action, int $from_id = 0)
     {
         $available = $this->getWallet($uid);
-        if (empty($available)) {
-            // 创建钱包
-            (new LedgerWalletModel())->insertGetId([
-                'user_id' => $uid,
-            ]);
-        }
+        if (empty($available)) (new LedgerWalletModel())->insertGetId(['user_id' => $uid]);  // 创建钱包
+        $frozen = 0; //冻结金额
         // 账变资产模型
         switch ($asset) {
             case Asset::POWER:
@@ -123,6 +123,7 @@ class LedgerWalletModel extends Model
                 break;
             case Asset::TOKEN:
                 $changeModel = new LedgerTokenChangeModel();
+                if($action == self::Giveaway || $action == self::Freight) $frozen = $available->frozen;
                 break;
             case Asset::DECLARATION:
                 $changeModel = new LedgerDeclarationChangeModel();
@@ -138,7 +139,7 @@ class LedgerWalletModel extends Model
         }
 
         // 更新钱包余额
-        $newAmount = $this->changeWalletOnly($uid, $asset, $amount);
+        $newAmount = $this->changeWalletOnly($uid, $asset, $amount, $frozen);
 
         // 创建账变记录
         $insertRs = $changeModel->insert([
@@ -164,7 +165,7 @@ class LedgerWalletModel extends Model
      * @return string 变动后的金额
      * @throws Exception
      */
-    public function changeWalletOnly(int $uid, string $asset, string $amount): string
+    public function changeWalletOnly(int $uid, string $asset, string $amount, string $freeze): string
     {
         $available = $this->getWalletTX($uid);
         if (empty($available)) {
@@ -177,17 +178,25 @@ class LedgerWalletModel extends Model
             throw new Exception('金额变动为0');
         }
 
+        //总金额+冻结金额
+        $totalAmount = bcadd($available[$asset], $freeze, 6);
         // 余额不足的判断
-        if ($amount < 0 && $available[$asset] < -$amount) {
+        if ($amount < 0 && $totalAmount < -$amount) {
             throw new Exception($asset . '余额不足');
         }
 
-        $newAmount    = bcadd($available[$asset], $amount, 6); // 新余额
-        $walletUpdate = [
-            $asset        => $newAmount,
-            'update_time' => time(),
-        ];
-
+        //扣除冻结金额
+        if($freeze > 0){
+            if($freeze > -$amount) $walletUpdate['freeze']  = bcsub($freeze, -$amount, 6);
+            if($freeze <= -$amount) $walletUpdate = [$asset => bcadd($totalAmount, $amount, 6), 'freeze' => 0];
+        }else{
+            $newAmount    = bcadd($totalAmount, $amount, 6); // 新余额
+            $walletUpdate = [$asset => $newAmount, 'update_time' => time()];
+        }
+        
+        echo $freeze;
+        dump($walletUpdate);die;
+        
         // 更新余额
         $changeRs = $this->save($walletUpdate, ['user_id' => $uid]);
         if (empty($changeRs)) {

+ 5 - 1
application/common/model/ProductLists.php

@@ -54,7 +54,11 @@ class ProductLists extends Model
     {
         return $this->hasOne('ProductPopular', 'product_id', 'id', [], 'INNER')->order('start_time')->setEagerlyType(0);
     }
-
+    
+    //获取状态
+    public function getStatusTextAttr($value, $data){
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+    }
         
 
     protected static function init()

+ 9 - 1
application/common/model/ProductOrder.php

@@ -84,7 +84,7 @@ class ProductOrder extends Model
 
 
     /**
-     * @param int $orderId 订单id
+     * @param int   $orderId 订单id
      * @param array $orderInfo 订单详情
      * @param int   $typeId    订单类型
      * @param int   $userId    用户id
@@ -110,6 +110,14 @@ class ProductOrder extends Model
         ]);
     }
 
+    // 获取订单状态
+    public static function getProductOrder($orderId, $status, string $field){
+        return self::alias('a')->where('a.id', $orderId)
+                ->join("product_list b", "a.product_id = b.id", "left")
+                ->field('a.*,'.$field)
+                ->where('status', $status)
+                ->find();
+    }
 
     public static function getStatusList()
     {

+ 1 - 1
public/assets/js/backend/product/popular.js

@@ -32,7 +32,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'title', title: __('期数')},
                         {field: 'price', title: __('Price'), operate: false},
                         {field: 'cost_price', title: __('Cost_price'), operate:false},
-                        {field: 'min_transfer', title: __('最低转让价'), operate:false}, 
+                        
                         {field: 'stock', title: __('Stock'), operate:false},
                         {field: 'init_num', title: __('初始销量'), operate:false},
                         {field: 'weigh', title: __('Weigh'), operate: false},