hrjy 3 gadi atpakaļ
vecāks
revīzija
8aabaa807a

+ 8 - 7
app/admin/model/auction/AuctionOrder.php

@@ -173,23 +173,24 @@ class AuctionOrder extends BaseModel
         }
         $product = $productModel->where('id', $data['product_id'])->find();
         $auction = $auctionModel->where('id', $product['auction_id'])->find();
-        $booking = $bookingModel->where('auction_id', $auction['id'])->where('uid', $user['uid'])->whereBetweenTime('create_time', date('Y-m-d H:i:s', strtotime(date('Y-m-d'))), date('Y-m-d H:i:s', strtotime('+1 day')))->find();
+        $time = strtotime(date('Y-m-d' ,strtotime($data['create_time']))); // 订单当天时间段
+        $totime = strtotime(date('Y-m-d' ,strtotime($data['create_time']))) + 86400; // 订单凌晨时间段
+        $booking = $bookingModel->where('auction_id', $auction['id'])->where('uid', $user['uid'])->whereBetweenTime('create_time', $time, $totime)->find();
         if ($booking['status'] > 0){
             $booking['status'] = 0;
             $booking->save();
-            $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
+            $anticipate = $booking['anticipate'] - $booking['deduction'];
+            $user['anticipate'] = $user['anticipate'] + $anticipate;// 退还预约卷
             $user->save();
-
-
-                UserBill::create([
+            UserBill::create([
                 'uid' => $user['uid'],
                 'pm' => 1,
                 'title' => '预约卷退还',
                 'category' => 'anticipate',
                 'type' => 'add_anticipate',
-                'mark' => '退还预约卷',
+                'mark' => '退还'.$anticipate.'预约卷扣除'.$booking['deduction'],
                 'add_time' => time(),
-                'number' => $auction['anticipate'],
+                'number' => $anticipate,
                 'balance' => $user['anticipate']
             ]);
         }

+ 46 - 23
app/api/controller/auction/AuctionController.php

@@ -108,30 +108,18 @@ class AuctionController
         if (!$data['id']) return app('json')->fail('数据传入错误');
         $auction = Auction::find($data['id']);
         $booking = AuctionBooking::where([['auction_id', '=',$auction['id']], ['frequency', '=', $auction['frequency']]])->find();
-        $user = $request->user();
-        $time = strtotime(date('Y-m-d', time()));// 今天
-        $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
+        $radd_time = strtotime($auction['radd_time']) - 300; // 提前五分钟进场
 
         if (!$booking){
             return app('json')->fail('未预约');
         }
-        if ($user['is_new'] == 1 or ($user['green_time'] >= $time and $user['green_time'] <= $today)){
-            // 新人或者绿色通道提前三分钟入场
-            if (strtotime($auction['radd_time']) -180 > time()){
-                return app('json')->fail('未到进入时间');
-            }
-            if (strtotime($auction['rend_time']) < time()){
-                return app('json')->fail('进场时间已过');
-            }
-
-        }else{
-            if (strtotime($auction['radd_time']) > time()){
-                return app('json')->fail('未到进入时间');
-            }
-            if (strtotime($auction['rend_time']) < time()){
-                return app('json')->fail('进场时间已过');
-            }
+        if ($radd_time > time()){
+            return app('json')->fail('未到进入时间');
         }
+        if (strtotime($auction['rend_time']) < time()){
+            return app('json')->fail('进场时间已过');
+        }
+
         return app('json')->successful('可进入');
 
     }
@@ -403,27 +391,62 @@ class AuctionController
 
     }
 
+    /**
+     * 馆长申请
+     * @param Request $request
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public function apply_status(Request $request)
     {
         $data = AuctionApply::where('uid', $request->uid())->find();
         if (!$data){
-            return app('json')->successful(['status' => 0, 'str' => '未提交申请']); // 未提交申请
+            return app('json')->success(['status' => 0, 'str' => '未提交申请']); // 未提交申请
         }
         $data = AuctionApply::where([['status', '=', 1], ['uid', '=', $request->uid()]])->find();
         if ($data){
-            return app('json')->successful(['status' => 1, 'str' => '待审核']);// 待审核
+            return app('json')->success(['status' => 1, 'str' => '待审核']);// 待审核
         }
         $data = AuctionApply::where([['status', '=', 2], ['uid', '=', $request->uid()]])->find();
         if ($data){
-            return app('json')->successful(['status' => 2 ,'str' => '已完成']);// 已完成
+            return app('json')->success(['status' => 2 ,'str' => '已完成']);// 已完成
         }
         $data = AuctionApply::where([['status', '=', 0], ['uid', '=', $request->uid()]])->find();
         if ($data){
-            return app('json')->successful(['status' => 3, 'str' => '失败']);// 失败
+            return app('json')->success(['status' => 3, 'str' => '失败']);// 失败
         }
+    }
 
 
+    /**
+     * 倒计时
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function count_down(Request $request)
+    {
+        $data = UtilService::postMore([
+            ['id'],
+        ], $request);
+
+        $list = Auction::where('id', $data['id'])->find();
+        if (!$list)  return app('json')->fail('场次不存在');// 失败
+        $user = $request->user();
+        $time = strtotime(date('Y-m-d', time()));// 今天
+        $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
+        $datas = [];
+        if ($user['is_new'] == 1 or ($user['green_time'] >= $time and $user['green_time'] <= $today)){
+            $datas['time'] = strtotime($list['radd_time']) - 180;
+        }else{
+            $datas['time'] = strtotime($list['radd_time']);
+        }
 
+        return app('json')->success($datas);// 失败
     }
 
 

+ 14 - 0
app/api/controller/auction/AuctionProductController.php

@@ -86,6 +86,20 @@ class AuctionProductController
         if ($product['is_show'] == 0) return app('json')->fail('商品未挂售');
         $product_ids = AuctionProduct::where('auction_id', $product['auction_id'])->column('id');
         $auction  = Auction::where('id', $product['auction_id'])->find();
+
+        $user = $request->user();
+        $time = strtotime(date('Y-m-d', time()));// 今天
+        $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
+        $radd_time = strtotime($auction['radd_time']); // 抢购时间
+        if ($user['is_new'] == 1 or ($user['green_time'] >= $time and $user['green_time'] <= $today)){
+            // 新人或者绿色通道提前三分钟入场
+            if ($radd_time - 180 > time()){
+                return app('json')->fail('未到抢购时间');
+            }
+        }else if(strtotime($auction['create_time']) < time()){
+            return app('json')->fail('当前未到抢购时间');
+        }
+
         $count = AuctionOrder::where('frequency',$auction['frequency'])->where('uid', $request->uid())->where('product_id', 'in', $product_ids)->count();
 
         $config = SystemConfig::where('menu_name', 'auction_number')->find();

+ 1 - 0
app/api/controller/user/UserController.php

@@ -66,6 +66,7 @@ class UserController
         }else{
             $info['profit'] = 0; // 收益
         }
+        $info['green'] = $info['is_new'] == 1? 1: $info['green_time'] >= strtotime(date('Y-m-d', time()))? 1 :0;
 
 
         return app('json')->success($info);

+ 34 - 18
app/models/auction/AuctionOrder.php

@@ -208,11 +208,14 @@ class AuctionOrder extends BaseModel
         }
         $product = $productModel->where('id', $data['product_id'])->find();
         $auction = $auctionModel->where('id', $product['auction_id'])->find();
-        $booking = $bookingModel->where('auction_id', $auction['id'])->where('uid', $user['uid'])->whereBetweenTime('create_time', date('Y-m-d H:i:s', strtotime(date('Y-m-d'))), date('Y-m-d H:i:s', strtotime('+1 day')))->find();
+        $time = strtotime(date('Y-m-d' ,strtotime($data['create_time']))); // 订单当天时间段
+        $totime = strtotime(date('Y-m-d' ,strtotime($data['create_time']))) + 86400; // 订单凌晨时间段
+        $booking = $bookingModel->where('auction_id', $auction['id'])->where('uid', $user['uid'])->whereBetweenTime('create_time', $time, $totime)->find();
         if ($booking['status'] > 0){
             $booking['status'] = 0;
             $booking->save();
-            $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
+            $anticipate = $booking['anticipate'] - $booking['deduction'];
+            $user['anticipate'] = $user['anticipate'] + $anticipate;// 退还预约卷
             $user->save();
 
 
@@ -222,9 +225,9 @@ class AuctionOrder extends BaseModel
                 'title' => '预约卷退还',
                 'category' => 'anticipate',
                 'type' => 'add_anticipate',
-                'mark' => '退还'.number_format($auction['anticipate'],2).'预约卷',
+                'mark' => '退还'.$anticipate.'预约卷扣除'.$booking['deduction'],
                 'add_time' => time(),
-                'number' => number_format($auction['anticipate'],2),
+                'number' => $anticipate,
                 'balance' => $user['anticipate']
             ]);
         }
@@ -240,24 +243,37 @@ class AuctionOrder extends BaseModel
     public static function deduction()
     {
         $hour = strtotime(date('Y-m-d H:i:s', strtotime('-1 hour'))); // 一小时以前
-
-        $order = AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->select(); // 查询不在当前一个小时内的订单
+        $time = $hour - 1800; // 一个半小时
+        $order = AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->select(); // 查询不在当前一个小时内的所有订单
         if ($order){
             foreach ($order as $K => $v){
                 $product = AuctionProduct::where('id', $v['product_id'])->find();
-
                 $auction = Auction::where('id', $product['auction_id'])->find();
-
-                $booking = AuctionBooking::where([['uid', '=', $v['uid']], ['status', '=', 1], ['auction_id', '=', $auction['id']]])->where('status', '=', 1)->find(); // 找到预约订单
-                if ($booking){
-                    $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
-                    $user['anticipate'] = $user['anticipate'] + $auction['anticipate']; // 卖家增加预约卷
-                    UserBill::income('增加预约卷', $v['collection_id'], 'anticipate', 'add_anticipate',  $auction['anticipate'], $v['uid'], $user['anticipate'], '卖出订单未上传支付凭证,增加'.$auction['anticipate'].'预约卷');
-
-                    $user->save();
-                    AuctionBooking::where('id', $booking['id'])->update(['status' => 2]); // 修改预约订单状态 为扣除
+                $booking = AuctionBooking::where([['uid', '=', $v['uid']], ['status', '=', 1], ['auction_id', '=', $auction['id']]])->find(); // 找到预约订单
+                if (strtotime($v['create_time']) <= $hour and strtotime($v['create_time']) > $time){
+                    // 订单在一个小时到一个半小时内
+                    if ($booking){
+                        if ($booking['deduction'] == 0){
+                            $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
+                            $user['anticipate'] = $user['anticipate'] + $auction['anticipate']/2; // 卖家增加预约卷
+                            $booking['deduction'] = $auction['anticipate']/2;
+                            UserBill::income('增加预约卷', $v['collection_id'], 'anticipate', 'add_anticipate',  $auction['anticipate']/2, $v['uid'], $user['anticipate'], '卖出订单未上传支付凭证,增加'.($auction['anticipate']/2).'预约卷');
+                            $booking->save();
+                            $user->save();
+                        }
+                    }
+                }elseif (strtotime($v['create_time']) <= $time){
+                    if ($booking) {
+                        $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
+                        $user['anticipate'] = $user['anticipate'] + ($auction['anticipate'] - $auction['deduction']); // 卖家增加预约卷
+                        $booking['deduction'] = $auction['anticipate'];
+                        UserBill::income('增加预约卷', $v['collection_id'], 'anticipate', 'add_anticipate', $auction['anticipate'] - $auction['deduction'], $v['uid'], $user['anticipate'], '卖出订单未上传支付凭证,增加' . ($auction['anticipate'] - $auction['deduction']) . '预约卷');
+                        $booking->save();
+                        $user->save();
+                        AuctionBooking::where('id', $booking['id'])->update(['status' => 2]); // 修改预约订单状态 为扣除
+                        AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->update(['status' => 0]); // 修改为已过期订单
+                    }
                 }
-                AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->update(['status' => 0]); // 修改为已过期订单
             }
 
         }
@@ -280,7 +296,7 @@ class AuctionOrder extends BaseModel
                 if ($booking){
                     foreach ($booking as $key => $value){
                         $product = AuctionProduct::where('auction_id', $value['auction_id'])->column('id');
-                        $order = AuctionOrder::where([['product_id', 'in', $product], ['frequency', '=', $value['frequency']], ['uid', '=', $value['uid']]])->where('status','>', 0)->find();
+                        $order = AuctionOrder::where([['product_id', 'in', $product], ['frequency', '=', $value['frequency']], ['uid', '=', $value['uid']]])->find();
                         if (!$order){
                             $find = AuctionBooking::find($value['id']);
                             $find['status'] = 0;

+ 1 - 0
route/api/route.php

@@ -192,6 +192,7 @@ Route::group(function () {
     Route::post('auction/hanging_sale', 'auction.auctionProductController/hanging_sale')->name('hanging_sale');// 挂售
     Route::post('auction/cancel', 'auction.auctionProductController/cancel')->name('cancel');// 取消挂售
     Route::get('auction/untreated', 'auction.auctionProductController/untreated')->name('untreated');// 订单数量
+    Route::get('auction/count_down', 'auction.auctionController/count_down')->name('count_down');// 倒计时
 
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口