hrjy 2 年之前
父節點
當前提交
70f7be5e6a

+ 1 - 0
app/admin/controller/auction/AuctionOrder.php

@@ -234,6 +234,7 @@ class AuctionOrder extends AuthController
             $uid = $product['uid']; // 所属人id
 
             $product['uid'] = $data['uid'];// 商品拥有人更新
+            $product['add_time'] = time();
             $res = $product->save();
             if ($res){
                 if ($uid > 0){

+ 10 - 9
app/admin/model/auction/AuctionOrder.php

@@ -10,6 +10,7 @@ namespace app\admin\model\auction;
 
 use app\admin\model\user\User;
 use app\admin\model\user\UserBill;
+use app\models\auction\AuctionProduct;
 use crmeb\services\product\Product;
 use crmeb\traits\ModelTrait;
 use crmeb\basic\BaseModel;
@@ -71,33 +72,33 @@ class AuctionOrder extends BaseModel
      */
     public static function earn($id, $price,$product)
     {
-        $userModel = new User();
-        $billModel = new UserBill();
+        $userModel = new \app\models\user\User();
         $productModel = new AuctionProduct();
         $user = $userModel->find($id);
 
         if ($user['spread_uid'] > 0){
-            $s_price = ($price - $product['price']) * 0.1; // 卖出价格减去购买价格的百分之十 为上级直推奖励
+            $s_price = number_format(($price - $product['price']) * 0.1, 2); // 卖出价格减去购买价格的百分之十 为上级直推奖励
             $spread = $userModel->find($user['spread_uid']);
             $spread['integral'] = $spread['integral'] + $s_price; //积分增加
             $spread->save();
-            $billModel->save([
+            \app\models\user\UserBill::create([
                 'uid' => $spread['uid'],
+                'link_id' => $id,
                 'pm' => 1,
                 'title' => '积分增加',
                 'category' => 'integral',
                 'type' => 'gain',
-                'mark' => '直推积分',
+                'mark' => '卖出商品直推'.$s_price.'积分',
                 'add_time' => time(),
                 'number' => $s_price,
                 'balance' => $spread['integral']
 
             ]);
         }
-        $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
-        $user->save();
-        UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, $user['anticipate'] ,'卖出扣除预约卷');
-        $productModel->where('id', $product['id'])->save(['price' => $price, 'hanging_price' => ($price+$price*($product['rise']/100))]); //修改当前画价
+//        $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
+//        $user->save();
+//        UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, $user['anticipate'] ,'卖出扣除预约卷');
+        $productModel->where('id', $product['id'])->save(['is_show' => 0]); //下架等待挂售
 
     }
 

+ 56 - 44
app/api/controller/auction/AuctionProductController.php

@@ -215,6 +215,7 @@ class AuctionProductController
             $uid = $product['uid']; // 所属人id
 
             $product['uid'] = $order['uid'];// 商品拥有人更新
+            $product['add_time'] = time();
             $res = $product->save();
             if ($res){
                 if ($uid > 0){
@@ -296,43 +297,9 @@ class AuctionProductController
            ['id']
        ]);
        $product = AuctionProduct::where('id', $data['id'])->find();
-       $auction = Auction::where('id', $product['auction_id'])->find();
        if (!$product) return app('json')->fail('商品不存在');
 
-       $data['time'] = explode(',', $auction['site']);
-
-       $date = date('w', time()); // 今天星期几
-       $data['gs_time'] = '';
-       if (in_array(1, $data['time'])){
-          if ($date >= 1 and $date <= 2){
-              $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Wednesday")); // 星期三
-          }elseif ($date >= 3 and $date <= 4){
-
-              $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Friday")); // 星期五
-          }elseif ($date >= 5 or $date == 0){
-
-              $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Monday")); // 下个星期一
-          }
-
-       }else if (in_array(2, $data['time'])){
-           if ($date >= 2 and $date <= 3){
-               $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Thursday")); // 星期四
-           }elseif ($date >= 4 and $date <= 5){
-
-               $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Saturday")); // 星期六
-           }elseif ($date >= 6 or $date == 0 or $date == 1){
-
-               $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Tuesday")); // 下个星期二
-           }
-       }
-
-       $hanging_price = number_format($product['hanging_price'] * $product['rise']/100, 2); //  溢价
-       $anticipate = number_format($product['hanging_price'] * $product['deduct']/100, 2); // 扣除
-
-       $data['hanging_price'] = $product['hanging_price'] + $hanging_price;
-       $data['anticipate'] = (float)$anticipate;
-
-
+       $data = $this->bs($data['id']);
        return app('json')->successful($data);
 
    }
@@ -350,7 +317,6 @@ class AuctionProductController
     {
         $data = UtilService::postMore([
             ['id'],
-            ['gs_time']
         ]);
         $product = AuctionProduct::where('id', $data['id'])->find();
         $user = User::where('uid', $request->uid())->find();
@@ -358,27 +324,27 @@ class AuctionProductController
 
         if ($product['is_show'] == 1) return app('json')->fail('商品已挂售');
 
-        $hanging_price = number_format($product['hanging_price'] * $product['rise']/100, 2); //  溢价
-        $anticipate = number_format($product['hanging_price'] * $product['deduct']/100, 2); // 扣除
-        if ($user['anticipate'] < $anticipate) return app('json')->fail('预约券不足');
+        $datas = $this->bs($data['id']);// 获取挂售详情
+        if ($user['anticipate'] < $datas['anticipate']) return app('json')->fail('预约券不足');
 
         $product['price'] = $product['hanging_price'];
-        $product['hanging_price'] += $hanging_price;
-        $product['is_show'] = 1;
+        $product['hanging_price'] = $datas['hanging_price']; // 商品变为挂售价格
+        $product['is_show'] = 1; // 上架
         $product['is_admin'] = 2;
-        $user['anticipate'] -= $anticipate;
+        $user['anticipate'] -= $datas['anticipate']; // 扣除预约券
         try {
             Db::startTrans();
+            // 新增挂售时间段
             AuctionTime::create([
                 'uid' => $request->uid(),
                 'product_id' => $product['id'],
                 'auction_id' => $product['auction_id'],
-                'add_time' => strtotime($data['gs_time'])
+                'add_time' => strtotime($datas['gs_time'])
             ]);
 
             $product->save();
             $user->save();
-            UserBill::expend('挂售扣除预约券', $user['uid'], 'anticipate', 'reduce_anticipate', $anticipate, $user['spread_uid'], $user['anticipate'], '挂售商品扣除预约券');
+            UserBill::expend('挂售扣除预约券', $user['uid'], 'anticipate', 'reduce_anticipate', $datas['anticipate'], $user['spread_uid'], $user['anticipate'], '挂售商品扣除预约券');
 
             Db::commit();
             return app('json')->successful('挂售成功');
@@ -390,5 +356,51 @@ class AuctionProductController
 
     }
 
+    public function bs($id)
+    {
+        $product = AuctionProduct::where('id',$id)->find();
+        $auction = Auction::where('id', $product['auction_id'])->find();
+        if (!$product) return app('json')->fail('商品不存在');
+
+        $data['time'] = explode(',', $auction['site']);
+
+        $date = date('w', time()); // 今天星期几
+        $data['gs_time'] = '';
+        $bs = 0;
+        if (in_array(1, $data['time'])){
+            if ($date >= 1 and $date <= 2){
+                $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Wednesday")); // 星期三
+                $bs = 2;
+            }elseif ($date >= 3 and $date <= 4){
+                $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Friday")); // 星期五
+                $bs = 2;
+            }elseif ($date >= 5 or $date == 0){
+                $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Monday")); // 下个星期一
+                $bs = 3;
+            }
+
+        }else if (in_array(2, $data['time'])){
+            if ($date >= 2 and $date <= 3){
+                $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Thursday")); // 星期四
+                $bs = 2;
+            }elseif ($date >= 4 and $date <= 5){
+                $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Saturday")); // 星期六
+                $bs = 2;
+            }elseif ($date >= 6 or $date == 0 or $date == 1){
+                $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Tuesday")); // 下个星期二
+                $bs = 3;
+            }
+        }
+
+        $hanging_price = round($product['hanging_price'] * $product['rise']/100, 2); //  溢价
+        $anticipate = round($product['hanging_price'] * $product['deduct']/100, 2); // 扣除
+
+        $data['hanging_price'] = (int)$product['hanging_price'] + ($hanging_price * $bs);
+        $data['anticipate'] = $anticipate;
+
+
+        return $data;
+    }
+
 
 }

+ 4 - 1
app/http/middleware/AllowOriginMiddleware.php

@@ -6,6 +6,8 @@ namespace app\http\middleware;
 
 use app\models\auction\Auction;
 use app\models\auction\AuctionOrder;
+use app\models\auction\AuctionProduct;
+use app\models\auction\AuctionTime;
 use app\Request;
 use crmeb\interfaces\MiddlewareInterface;
 use think\facade\Config;
@@ -57,7 +59,8 @@ class AllowOriginMiddleware implements MiddlewareInterface
         }
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         Auction::frequency(); // 更新场次
-        Auction::is_new(); // 更新新人
+        AuctionProduct::off_the_shelf(); // 下架未出售商品
+
         try {
             Db::startTrans();
             AuctionOrder::deduction();//订单一个小时内未上传扣除预约卷

+ 15 - 15
app/models/auction/Auction.php

@@ -84,20 +84,20 @@ class Auction extends BaseModel
     }
 
 
-    public static function is_new()
-    {
-        $user = User::where('is_new', 1)->select();
-        if ($user){
-            foreach ($user as $k => $v)
-            {
-                if ($v['add_time']+3600 < time()){
-                    User::where('uid', $v['uid'])->update(['is_new' => 0]);
-                }
-
-            }
-        }
-
-
-    }
+//    public static function is_new()
+//    {
+//        $user = User::where('is_new', 1)->select();
+//        if ($user){
+//            foreach ($user as $k => $v)
+//            {
+//                if ($v['add_time']+3600 < time()){
+//                    User::where('uid', $v['uid'])->update(['is_new' => 0]);
+//                }
+//
+//            }
+//        }
+//
+//
+//    }
 
 }

+ 6 - 17
app/models/auction/AuctionOrder.php

@@ -72,6 +72,8 @@ class AuctionOrder extends BaseModel
 
             }else if($data['type'] == 3) {
                 $list = self::where([['uid', '=', $uid], ['status', '=', 3]])->page($data['page'], $data['limit'])->select(); //完成订单
+            }else if($data['type'] == 4) {
+                $list = AuctionProduct::where([['uid', '=', $uid]])->select();
             }else{
                 $list = self::where([['uid', '=', $uid], ['status', '<', 1]])->page($data['page'], $data['limit'])->select(); //过期订单
             }
@@ -154,25 +156,12 @@ class AuctionOrder extends BaseModel
         $userModel = new \app\models\user\User();
         $productModel = new AuctionProduct();
         $user = $userModel->find($id);
-
         if ($user['spread_uid'] > 0){
-            $s_price = number_format(($price - $product['price']) * 0.1, 2); // 卖出价格减去购买价格的百分之十 为上级直推奖励
+            $s_price = round(($price - $product['price']) * 0.1, 2); // 卖出价格减去购买价格的百分之十 为上级直推奖励
             $spread = $userModel->find($user['spread_uid']);
             $spread['integral'] = $spread['integral'] + $s_price; //积分增加
             $spread->save();
-            \app\models\user\UserBill::create([
-                'uid' => $spread['uid'],
-                'link_id' => $id,
-                'pm' => 1,
-                'title' => '积分增加',
-                'category' => 'integral',
-                'type' => 'gain',
-                'mark' => '卖出商品直推'.$s_price.'积分',
-                'add_time' => time(),
-                'number' => $s_price,
-                'balance' => $spread['integral']
-
-            ]);
+            \app\models\user\UserBill::income('直推奖励', $spread['uid'], 'anticipate', 'add_anticipate', $s_price, 0, $spread['integral'], '奖励趣豆');
         }
 //        $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
 //        $user->save();
@@ -228,7 +217,7 @@ class AuctionOrder extends BaseModel
                 'title' => '预约卷退还',
                 'category' => 'anticipate',
                 'type' => 'add_anticipate',
-                'mark' => '退还预约场馆'.number_format($auction['anticipate'],2).'预约卷',
+                'mark' => '退还'.number_format($auction['anticipate'],2).'预约卷',
                 'add_time' => time(),
                 'number' => number_format($auction['anticipate'],2),
                 'balance' => $user['anticipate']
@@ -296,7 +285,7 @@ class AuctionOrder extends BaseModel
 
                             $user->save();
                             $find->save();
-                            UserBill::income('预约卷增加',$user['uid'], 'anticipate', 'add_anticipate', $value['anticipate'], 0, $user['anticipate'], '预约卷退回');
+                            UserBill::income('退回预约券',$user['uid'], 'anticipate', 'add_anticipate', $value['anticipate'], 0, $user['anticipate'], '预约卷'.$value['anticipate'].'退回');
                         }
                     }
                 }

+ 29 - 3
app/models/auction/AuctionProduct.php

@@ -58,10 +58,10 @@ class AuctionProduct extends BaseModel
                     if (!$time){
                         unset($list);
                     } else{
-                        $lists[] = $v;
+                        $lists[] = $list[$k];
                     }
                 }else{
-                    $lists[] = $v;
+                    $lists[] = $list[$k];
                 }
             }
         };
@@ -78,7 +78,7 @@ class AuctionProduct extends BaseModel
      * @throws \think\db\exception\ModelNotFoundException
      */
     public static function user_product($data, $uid){
-        $model = self::where('is_show', 1)->where('uid', $uid)->order('sort DESC,id DESC');
+        $model = self::where('uid', $uid)->order('id DESC');
         $model->page($data['page'], $data['limit']);
 
         $list = $model->select();
@@ -88,4 +88,30 @@ class AuctionProduct extends BaseModel
     }
 
 
+    /**
+     * 场次时间到期用户未出售商品下架
+     * @return void
+     */
+    public static function off_the_shelf(){
+        $auction = Auction::where('rend_time', '<', date('H:i:s'))->select();
+        if ($auction){
+            foreach ($auction as $k => $v) {
+                $productId = AuctionTime::where('auction_id', '=', $v['id'])->where('add_time', '=', strtotime(date('Y-m-d', time())))->column('product_id');
+                if ($productId){
+                    $orderId = AuctionOrder::where('product_id', 'in', $productId)->where('frequency', '=', $v['frequency'])->where('status','>', 0)->column('product_id');
+                    if ($orderId){
+                        foreach ($orderId as $value){
+                            if (in_array($value, $productId))unset($productId[$value]);
+                        }
+                    }
+                    AuctionProduct::where([['id', 'in', $productId], ['auction_id', '=', $v['id']], ['is_admin', '=', 2]])->save(['is_show' => 0]);// 查找今天场次没买出去的商品下架
+//                self::where('auction_id', '=', $v['id'])->where('add_time', '<=', strtotime(date('Y-m-d', time())))->delete(); // 清除今天挂售时间
+                }
+            }
+
+        }
+
+    }
+
+
 }

+ 1 - 0
app/models/auction/AuctionTime.php

@@ -25,4 +25,5 @@ class AuctionTime extends BaseModel
     protected $name = 'auction_time';
 
     use ModelTrait;
+
 }

+ 11 - 2
app/models/user/UserBill.php

@@ -120,12 +120,21 @@ class UserBill extends BaseModel
         }
         $data['zj'] = [];
         $data['kc'] = [];
+        $data['sr'] = 0;
+        $data['zc'] = 0;
         $list = count($list) ? $list->toArray() : [];
         foreach ($list as &$v) {
             $v['add_time'] = date('Y/m/d H:i', $v['add_time']);
             $v['number'] = floatval($v['number']);
-            if ($v['pm'] == 1) $data['zj'][] = $v;
-            if ($v['pm'] == 0) $data['kc'][] = $v;
+            if ($v['pm'] == 1) {
+                $data['zj'][] = $v;
+                $data['sr'] += $v['number'];
+            }
+            if ($v['pm'] == 0){
+                $data['kc'][] = $v;
+                $data['zc'] += $v['number'];
+            }
+
         }
         return $data;
     }

+ 5 - 2
crmeb/subscribes/TaskSubscribe.php

@@ -5,6 +5,8 @@ namespace crmeb\subscribes;
 use app\admin\model\system\SystemAttachment;
 use app\models\auction\Auction;
 use app\models\auction\AuctionOrder;
+use app\models\auction\AuctionProduct;
+use app\models\auction\AuctionTime;
 use app\models\store\StoreBargainUser;
 use app\models\store\StoreOrder;
 use app\models\store\StorePink;
@@ -94,8 +96,7 @@ class TaskSubscribe
         } catch (\Exception $e) {
             Db::rollback();
         }
-        Auction::frequency(); // 更新场次
-        Auction::is_new(); // 更新新人
+//        Auction::is_new(); // 更新新人
     }
 
     /**
@@ -103,6 +104,8 @@ class TaskSubscribe
      */
     public function onTask_60()
     {
+        Auction::frequency(); // 更新场次
+        AuctionProduct::off_the_shelf(); // 下架未出售商品
     }
 
     /**