hrjy 2 years ago
parent
commit
ac2ad0966c

+ 1 - 1
.env

@@ -1 +1 @@
-APP_DEBUG = true

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai

[DATABASE]
TYPE = mysql
HOSTNAME = 192.168.2.17
DATABASE = sxg
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true

[LANG]
default_lang = zh-cn
+APP_DEBUG = true

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai

[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = sxg
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true

[LANG]
default_lang = zh-cn

+ 43 - 1
app/api/controller/auction/AuctionController.php

@@ -77,7 +77,7 @@ class AuctionController
 
         if ($res){
             AuctionBooking::booking($user['uid'], $auction);
-            UserBill::expend('预约场馆', $user['uid'], 'aid_val','add_aid_val', $auction['advert'], 0, $user['aid_val'], '预约冻结广告值'); // 写入记录
+            UserBill::expend('预约场馆', $user['uid'], 'aid_val','sub_aid_val', $auction['advert'], 0, $user['aid_val'], '预约冻结广告值'); // 写入记录
 
             User::commitTrans();
             return app('json')->successful('预约成功');
@@ -91,5 +91,47 @@ class AuctionController
 
     }
 
+    /**
+     * 进入场馆
+     * @param Request $request
+     * @return void
+     */
+    public function advance(Request $request)
+    {
+        $data = UtilService::getMore([
+            ['id']
+        ]);
+        $auction = Auction::find($data['id']);
+        if (!$auction) return app('json')->fail('场次不存在');
+        $booking = AuctionBooking::where([['auction_id', '=',$auction['id']], ['frequency', '=', $auction['frequency']]])->find();
+        $user = $request->user();
+        $time = $user['add_time'] + (3600*48);
+
+        if (!$booking){
+            return app('json')->fail('未预约');
+        }
+        if (time() < $time or $user['is_real'] == 1){
+            // 注册四十八小时或者团长提前入场
+            if (strtotime($auction['radd_time']) - 180 > time()){
+                return app('json')->fail('未到进入时间');
+            }else if (strtotime($auction['rend_time']) < time()){
+                return app('json')->fail('进场时间已过');
+            }
+
+        }else{
+            if (strtotime($auction['radd_time']) > time()){
+                return app('json')->fail('未到进场时间');
+            }else if (strtotime($auction['rend_time']) < time()){
+                return app('json')->fail('进场时间已过');
+            }
+        }
+
+        if ($booking){
+            return app('json')->successful('可进入');
+        }else{
+            return app('json')->fail('未预约');
+        }
+    }
+
 
 }

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

@@ -3,23 +3,15 @@
 namespace app\api\controller\auction;
 
 
-use app\admin\model\system\SystemConfig;
 use app\models\auction\Auction;
 use app\models\auction\AuctionBooking;
 use app\models\auction\AuctionOrder;
 use app\models\auction\AuctionProduct;
+use app\models\auction\AuctionTime;
 use app\models\user\User;
 use app\models\user\UserBill;
 use app\Request;
-use Monolog\Handler\Curl\Util;
-use think\facade\Cache;
-use crmeb\services\{
-    CacheService,
-    ExpressService,
-    SystemConfigService
-};
 use crmeb\services\UtilService;
-use crmeb\repositories\OrderRepository;
 use think\facade\Db;
 
 
@@ -146,6 +138,49 @@ class AuctionProductController
     }
 
 
+    /**
+     * 挂售商品
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function hanging_sale(Request $request)
+    {
+        $data = UtilService::postMore([
+            ['id']
+        ]);
+        $product = AuctionProduct::where('id', $data['id'])->find();
+        if ($product['is_show'] == 1) return app('json')->fail('商品已挂售');
+        $user = User::where('uid', $request->uid())->find();
+        if (!$product) return app('json')->fail('商品不存在');
+
+        $aid_val = $product['hanging_price'] * 0.0485; // 需要的广告值
+        $hanging_price = $product['hanging_price'] * 0.06; // 第二天溢价
+        if ($user['aid_val'] < $aid_val) return app('json')->fail('挂售需要广告值不足');
+
+        $product['hanging_price'] += $hanging_price;
+        $product['is_show'] = 1;
+        $user['aid_val'] -= $aid_val;
+
+        try {
+            Db::startTrans();
+            $product->save();
+            $user->save();
+            UserBill::expend('挂售扣除广告值', $user['uid'], 'aid_val', 'sub_aid_val', $aid_val, $user['spread_uid'], $user['aid_val'], '挂售商品扣除广告值');
+
+            Db::commit();
+            return app('json')->successful('挂售成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return app('json')->fail('挂售失败');
+        }
+
+
+    }
+
+
 
 
 }

+ 28 - 101
app/models/auction/AuctionOrder.php

@@ -109,103 +109,6 @@ class AuctionOrder extends BaseModel
         return $list;
     }
 
-    /**
-     * 卖家操作
-     * @param $id  //商品所属人
-     * @param $price //卖出价格
-     * @param $product //商品详情
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    public static function earn($id, $price,$product)
-    {
-        $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); // 卖出价格减去购买价格的百分之十 为上级直推奖励
-            $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']
-
-            ]);
-        }
-        $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))]); //修改当前画价
-
-    }
-
-    /**
-     * 购买成功退预约卷
-     * @param $id
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    public static function return($id)
-    {
-        $data = self::find($id);
-        $userModel = new User();
-        $productModel = new AuctionProduct();
-        $auctionModel = new Auction();
-        $bookingModel = new AuctionBooking();
-
-
-        $user = $userModel->find($data['uid']);
-        if ($user['is_new'] == 1){
-
-            if ($user['spread_uid']) {
-                $spread = $userModel->where('uid', $user['spread_uid'])->find();
-                $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
-            }
-            $orderCount = AuctionOrder::where([['uid', '=',  $user['uid']], ['status','=', 3]])->count();
-            if ($orderCount >= 5){
-                $user['is_new'] = 0;
-            }
-
-
-        }
-        $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();
-        if ($booking['status'] > 0){
-            $booking['status'] = 0;
-            $booking->save();
-            $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
-            $user->save();
-
-
-            \app\models\user\UserBill::create([
-                'uid' => $user['uid'],
-                'pm' => 1,
-                'title' => '预约卷退还',
-                'category' => 'anticipate',
-                'type' => 'add_anticipate',
-                'mark' => '退还预约场馆'.number_format($auction['anticipate'],2).'预约卷',
-                'add_time' => time(),
-                'number' => number_format($auction['anticipate'],2),
-                'balance' => $user['anticipate']
-            ]);
-        }
-    }
-
     /**
      * 订单过期
      * @return void
@@ -285,13 +188,17 @@ class AuctionOrder extends BaseModel
         $user = User::where('uid', $uid)->find();
 
         $bk = AuctionBooking::where([['uid', '=', $uid], ['auction_id', '=', $order['auction_id']], ['frequency', '=', $order['frequency']]])->find();
-        $bk['status'] = 0;
-        $user['now_money'] -= $order['actual_price'];
-        $user['aid_val'] += $bk['advert'];
+        $bk['status'] = 0; //解冻广告值
+        $user['now_money'] -= $order['actual_price']; // 扣除用户余额
+        $user['aid_val'] += $bk['advert']; // 退回用户广告值
 
-        AuctionProduct::where('id', $order['product_id'])->update(['uid' => $uid]); // 修改商品拥有人
+        AuctionProduct::where('id', $order['product_id'])->update(['uid' => $uid, 'is_show' => 0]); // 修改商品拥有人,商品下架等待挂售
         $user->save();
         $bk->save();
+        if ($order['collection_id'] > 0){
+            self::m_user($order['collection_id'], $order['actual_price']);
+        }
+
 
         AuctionOrder::where('id', $order['id'])->update(['status' => 2]); // 修改订单状态
         UserBill::expend('购买商品支付', $uid, 'now_money', 'sub_money', $order['actual_price'], $user['spread_uid'], $user['now_money'], '购买商品支付订单');
@@ -300,6 +207,26 @@ class AuctionOrder extends BaseModel
 
     }
 
+    /**
+     * 卖家增加余额
+     * @param $uid
+     * @param $price
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function m_user($uid, $price)
+    {
+        $user = User::where('uid', $uid)->find();
+        $user['now_money'] += $price; // 卖家增加余额
+
+        $user->save();
+        UserBill::income('卖出商品', $uid, 'now_money', 'add_money', $price, $user['spread_uid'], $user['now_money'], '商品卖出');
+
+    }
+
+
 
 
 

+ 2 - 0
route/api/route.php

@@ -167,12 +167,14 @@ Route::group(function () {
 
     Route::get('auction', 'auction.AuctionController/list')->name('auction');//场次列表
     Route::post('subscribe', 'auction.AuctionController/subscribe')->name('subscribe');//预约
+    Route::get('advance', 'auction.AuctionController/advance')->name('advance');//进场
     Route::get('purchase', 'auction.AuctionProductController/purchase')->name('purchase');//随机商品
 
     Route::get('user_auction_order', 'auction.AuctionProductController/user_auction_order')->name('user_auction_order');//用户订单
     Route::get('seller', 'auction.AuctionProductController/seller')->name('seller');//卖家订单
     Route::get('user_product', 'auction.AuctionProductController/user_product')->name('user_product');//用户商品
     Route::post('zfpay', 'auction.AuctionProductController/zfpay')->name('zfpay');//支付订单
+    Route::post('hanging_sale', 'auction.AuctionProductController/hanging_sale')->name('hanging_sale');//挂售商品