hrjy před 3 roky
rodič
revize
91c20ed123

+ 20 - 0
app/http/middleware/AllowOriginMiddleware.php

@@ -5,9 +5,12 @@ namespace app\http\middleware;
 
 
 use app\models\auction\Auction;
+use app\models\auction\AuctionOrder;
+use app\models\store\StoreBargainUser;
 use app\Request;
 use crmeb\interfaces\MiddlewareInterface;
 use think\facade\Config;
+use think\facade\Db;
 use think\Response;
 
 /**
@@ -55,6 +58,23 @@ class AllowOriginMiddleware implements MiddlewareInterface
         }
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         Auction::frequency(); // 更新场次
+        try {
+            // 更新订单日期
+            Db::startTrans();
+            AuctionOrder::deduction();// 更新订单
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+        try {
+            // 更新订单日期
+            Db::startTrans();
+            AuctionOrder::th();// 退回广告值
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+
         return $response;
     }
 }

+ 9 - 12
app/models/auction/AuctionOrder.php

@@ -118,9 +118,9 @@ class AuctionOrder extends BaseModel
      */
     public static function deduction()
     {
-        $hour = strtotime(date('Y-m-d H:i:s', strtotime('-1 hour'))); // 一小时以前
+        $hour = strtotime(date('Y-m-d H:i:s', strtotime('-30 minute'))); // 一小时以前
 
-        $order = AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->select(); // 查询不在当前一个小时内的订单
+        $order = AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->select(); // 查询不在当前30分钟前的订单
         if ($order){
             foreach ($order as $K => $v){
                 $product = AuctionProduct::where('id', $v['product_id'])->find();
@@ -129,11 +129,6 @@ class AuctionOrder extends BaseModel
 
                 $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]); // 修改预约订单状态 为扣除
                 }
                 AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->update(['status' => 0]); // 修改为已过期订单
@@ -143,7 +138,7 @@ class AuctionOrder extends BaseModel
     }
 
     /**
-     * 退回预约卷
+     * 退回广告值
      * @return void
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
@@ -158,16 +153,18 @@ class AuctionOrder extends BaseModel
                 $booking = AuctionBooking::where([['auction_id', '=', $v['id']], ['status','=' , 1]])->select();
 
                 if ($booking){
+                    $bf = 0.1; // 广告值扣除倍率
                     foreach ($booking as $key => $value){
+                        $userBok = AuctionBooking::where('uid', '=',$value['uid'])->where('deduct_advert', '>', 0)->count();
+                        $bf =  (0.1*$userBok >= 1)? 1: 0.1*$userBok;
                         $find = AuctionBooking::find($value['id']);
                         $find['status'] = 0;
-
+                        $find['deduct_advert'] = $value['advert']*$bf; // 扣除广告书
                         $user = User::where('uid', $value['uid'])->find();
-                        $user['anticipate'] = $user['anticipate'] + $value['anticipate'];
-
+                        $user['aid_val'] = $user['aid_val'] + ($value['advert'] - ($value['advert'] * $bf)); // 增加用户广告值
                         $user->save();
                         $find->save();
-                        UserBill::income('预约卷增加',$user['uid'], 'anticipate', 'add_anticipate', $value['anticipate'], 0, $user['anticipate'], '预约卷退回');
+                        UserBill::income('未购买解冻但扣除'. $find['deduct_advert'].'广告值',$user['uid'], 'aid_val', 'add_aid_val',$value['advert'] - ($value['advert'] * $bf), 0, $user['aid_val'], '未购买解冻但扣除'. $find['deduct_advert'].'广告值');
                     }
                 }
             }

+ 15 - 0
crmeb/subscribes/TaskSubscribe.php

@@ -3,6 +3,7 @@
 namespace crmeb\subscribes;
 
 use app\admin\model\system\SystemAttachment;
+use app\models\auction\AuctionOrder;
 use app\models\store\StoreBargainUser;
 use app\models\store\StoreOrder;
 use app\models\store\StorePink;
@@ -75,6 +76,20 @@ class TaskSubscribe
         } catch (\Exception $e) {
             Db::rollback();
         }
+        try {
+            Db::startTrans();
+            AuctionOrder::deduction();// 更新订单
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+        try {
+            Db::startTrans();
+            AuctionOrder::th();// 退回广告值
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
     }
 
     /**