浏览代码

判断是否锁定

afa 7 月之前
父节点
当前提交
335e44e592
共有 3 个文件被更改,包括 16 次插入15 次删除
  1. 2 2
      application/api/controller/Market.php
  2. 12 11
      application/api/logic/MarketLogic.php
  3. 2 2
      application/config.php

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

@@ -70,7 +70,7 @@ class Market extends Api
         if(!$validate->scene('transferlock')->check($params)) $this->error($validate->getError());
         try {
 
-            $marketLogic::setTransferLock($productTransfer, config('market_transfer.lock_time'), $params['transfer_id']);
+            $marketLogic::setTransferLock($productTransfer, config('market_transfer.lock_time'), $this->auth->id, $params['transfer_id']);
         } catch (Exception $e) {
             // 回滚事务
             $this->error($e->getMessage());
@@ -151,7 +151,7 @@ class Market extends Api
         Db::startTrans();
         try {
 
-            // 记录出售订单 
+            // 记录出售订单
             $chabao =$userBuying::getCreateUserBuying($this->auth->id, $params['buying_id'], $buying->user_id, $buying->min_price);
 
             // 添加扣除茶币

+ 12 - 11
application/api/logic/MarketLogic.php

@@ -84,19 +84,20 @@ class MarketLogic
 
 
       //判断是否锁定
-      public static function setTransferLock(object $productTransfer, int $endTime, string $transferId)
+      public static function setTransferLock(object $productTransfer, int $endTime, int $uid, string $transferId)
       {
             $time = time();
-            $lockCount = $productTransfer
-                        ->whereIn('id', $transferId)
-                        ->where('is_lock', $productTransfer::Lock)
-                        ->whereTime('lock_time','>', - $endTime)
-                        ->count();
-            if(!empty($lockCount)) throw new Exception(__("茶权已被他人锁定,无法操作"));
-
-            return $productTransfer->whereIn('id', $transferId)
-                  ->update(['lock_time'=> $time, 'is_lock' => $productTransfer::Lock]);
-
+            $lockList = $productTransfer->whereIn('id', $transferId)->select();
+            foreach ($lockList as &$item) {
+
+                  if($item->user_id == $uid)  throw new Exception(__("不能锁自己的寄售单"));
+                  if($item->is_lock == $productTransfer::Lock && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
+                  
+                  $item->is_lock = $productTransfer::Lock;
+                  $item->lock_time = $time;
+                  $item->save();
+            }            
+            return true;
       }
 
 }

+ 2 - 2
application/config.php

@@ -325,8 +325,8 @@ return [
 
     //市场配置 
     'market_transfer' => [
-        'lock_time'         => 300, //锁定时间秒
-        'min_buy_price'         => 10,  //最小求购价格
+        'lock_time'         => 180, //锁定时间秒
+        'min_buy_price'     => 10,  //最小求购价格
         'serve_desc'        => "服务描述",
         'serve_fee'         => 0.045, //服务费
         'max_buying_count'  => 10, //最大求购套数