Browse Source

实时接口

hrjy 3 năm trước cách đây
mục cha
commit
26675e0a24

+ 2 - 12
app/admin/model/auction/AuctionOrder.php

@@ -96,17 +96,7 @@ class AuctionOrder extends BaseModel
             $anticipate = $user['anticipate'];
             $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
             $user->save();
-            UserBill::create([
-                'uid' => $user['uid'],
-                'pm' => 1,
-                'title' => '预约卷扣除',
-                'category' => 'anticipate',
-                'type' => 'reduce_anticipate',
-                'mark' => '卖出扣除预约卷',
-                'add_time' => time(),
-                'number' => $anticipate,
-                'balance' => $user['anticipate']
-            ]);
+            UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, '卖出扣除预约卷');
         }
         $productModel->where('id', $product['id'])->save(['price' => $price, 'hanging_price' => ($price+$price*($product['rise']/100))]); //修改当前画价
 
@@ -153,7 +143,7 @@ class AuctionOrder extends BaseModel
             $user->save();
 
 
-            UserBill::create([
+                UserBill::create([
                 'uid' => $user['uid'],
                 'pm' => 1,
                 'title' => '预约卷退还',

+ 47 - 0
app/api/controller/auction/AuctionController.php

@@ -17,6 +17,7 @@ use crmeb\services\{
 };
 use crmeb\services\UtilService;
 use crmeb\repositories\OrderRepository;
+use think\facade\Db;
 
 
 class AuctionController
@@ -131,6 +132,52 @@ class AuctionController
     }
 
 
+    /**
+     * 用户下级
+     * @param Request $request
+     * @return mixed
+     */
+    public function lower(Request $request){
+        $data = UtilService::getMore([
+            [['page', 'd'], 0],
+            [['limit', 'd'], 0],
+        ], $request);
+
+        $user = User::where('spread_uid', $request->uid())->page($data['page'], $data['limit'])->order('uid DESC')->select()->toArray();
+        return app('json')->successful($user);
+    }
+
+
+    public function transfer_accounts(Request $request){
+        $data = UtilService::getMore([
+            ['uid'],
+            ['anticipate']
+        ], $request);
+        if (!$data['uid'] or !$data['anticipate'])  return app('json')->fail('数据传入错误');
+        $user = User::find($request->uid());
+        if ($user['anticipate'] < $data['anticipate']) return app('json')->fail('预约卷不够');
+        $me = User::find($data['uid']);
+        $user['anticipate'] = $user['anticipate'] - $data['anticipate'];// 扣除预约卷
+        $me['anticipate'] = $me['anticipate'] + $data['anticipate'];// 增加预约卷
+
+        try {
+            Db::startTrans();
+            UserBill::expend('预约卷减少',$user['uid'], 'anticipate', 'reduce_anticipate', $data['anticipate'], 0, $user['anticipate'], '转账给用户'.$me['nickname'].$data['anticipate'].'预约卷');
+            UserBill::income('预约卷增加',$me['uid'], 'anticipate', 'add_anticipate', $data['anticipate'], 0, $me['anticipate'], $me['nickname'].'转账'.$data['anticipate'].'预约卷');
+            $user->save();
+            $me->save();
+
+            Db::commit();
+            return app('json')->successful('成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return app('json')->fail('失败');
+        }
+
+
+    }
+
+
 
 
 }

+ 19 - 2
app/api/controller/auction/AuctionProductController.php

@@ -36,13 +36,30 @@ class AuctionProductController
         $data = UtilService::getMore([
             [['page', 'd'], 0],
             [['limit', 'd'], 0],
-            ['id'],
-            ['user']
+            ['id']
         ]);
         if (!$data['id']) return app('json')->fail('数据传入错误');
         return app('json')->successful(AuctionProduct::list($data, $request->uid()));
     }
 
+    /**
+     * 用户商品
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function user_product(Request  $request)
+    {
+
+        $data = UtilService::getMore([
+            [['page', 'd'], 0],
+            [['limit', 'd'], 0],
+        ]);
+        return app('json')->successful(AuctionProduct::user_product( $data,$request->uid()));
+    }
+
 
     /**
      * 购买商品

+ 39 - 8
app/models/auction/AuctionOrder.php

@@ -42,16 +42,16 @@ class AuctionOrder extends BaseModel
     public static function userOrder($data,$uid)
     {
         if ($data['type'] == 1){
-            $list = self::where([['uid', '=', $uid], ['status', '=', 1]])->select()->toArray(); //待上传订单
+            $list = self::where([['uid', '=', $uid], ['status', '=', 1]])->page($data['page'], $data['limit'])->select()->toArray(); //待上传订单
 
         }else if($data['type'] == 2){
-            $list = self::where([['uid', '=', $uid], ['status', '=', 2]])->select()->toArray(); //待审核订单
+            $list = self::where([['uid', '=', $uid], ['status', '=', 2]])->page($data['page'], $data['limit'])->select()->toArray(); //待审核订单
 
         }else if($data['type'] == 3) {
-            $list = self::where([['uid', '=', $uid], ['status', '=', 3]])->select()->toArray(); //完成订单
+            $list = self::where([['uid', '=', $uid], ['status', '=', 3]])->page($data['page'], $data['limit'])->select()->toArray(); //完成订单
         }else{
 
-            $list = self::where([['uid', '=', $uid], ['status', '<', 1]])->select()->toArray(); //过期订单
+            $list = self::where([['uid', '=', $uid], ['status', '<', 1]])->page($data['page'], $data['limit'])->select()->toArray(); //过期订单
         }
 
         return $list;
@@ -69,16 +69,16 @@ class AuctionOrder extends BaseModel
     public static function seller_list($data,$uid)
     {
         if ($data['type'] == 1){
-            $list = self::where([['collection_id', '=', $uid], ['status', '=', 1]])->select()->toArray(); //待上传订单
+            $list = self::where([['collection_id', '=', $uid], ['status', '=', 1]])->page($data['page'], $data['limit'])->select()->toArray(); //待上传订单
 
         }else if($data['type'] == 2){
-            $list = self::where([['collection_id', '=', $uid], ['status', '=', 2]])->select()->toArray(); //待审核订单
+            $list = self::where([['collection_id', '=', $uid], ['status', '=', 2]])->page($data['page'], $data['limit'])->select()->toArray(); //待审核订单
 
         }else if($data['type'] == 3) {
-            $list = self::where([['collection_id', '=', $uid], ['status', '=', 3]])->select()->toArray(); //完成订单
+            $list = self::where([['collection_id', '=', $uid], ['status', '=', 3]])->page($data['page'], $data['limit'])->select()->toArray(); //完成订单
         }else{
 
-            $list = self::where([['collection_id', '=', $uid], ['status', '<', 1]])->select()->toArray(); //过期订单
+            $list = self::where([['collection_id', '=', $uid], ['status', '<', 1]])->page($data['page'], $data['limit'])->select()->toArray(); //过期订单
         }
 
         return $list;
@@ -190,6 +190,13 @@ class AuctionOrder extends BaseModel
         }
     }
 
+    /**
+     * 订单过期
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public static function deduction()
     {
         $hour = strtotime(date('Y-m-d H:i:s', strtotime('-1 hour'))); // 一小时以前
@@ -217,6 +224,30 @@ class AuctionOrder extends BaseModel
         }
     }
 
+    /**
+     * 退回预约卷
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function th()
+    {
+        $auction = Auction::where('rend_time', '<', time())->select();
+        if ($auction){
+            foreach ($auction as $k => $v){
+                $booking = AuctionBooking::where('auction_id', $v['id'])->whereBetweenTime('create_time',date('Y-m-d H:i:s',  strtotime(date('Y-m-d', time()))), date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime('+1 day')))))->select();
+                if ($booking){
+                    $user = User::where('uid', $booking['uid'])->find();
+                    $user['anticipate'] = $user['anticipate'] + $booking['anticipate'];
+                    $user->save();
+                    UserBill::income('预约卷增加',$user['uid'], 'anticipate', 'add_anticipate', $booking['anticipate'], 0, $user['anticipate'], '预约卷退回');
+
+                }
+            }
+        }
+    }
+
 
 
 

+ 27 - 14
app/models/auction/AuctionProduct.php

@@ -37,26 +37,39 @@ class AuctionProduct extends BaseModel
      */
     public static function list($data, $uid){
         $model = self::where('is_show', 1)->where('auction_id', $data['id'])->order('sort DESC,id DESC');
-        if ($data['user']){
-            $model->where('uid', $uid); // 获取用户拥有商品
-        }
+        $model->page($data['page'], $data['limit']);
         $list = $model->select()->toArray();
-        if (!$data['user']){
-            if ($list){
-                foreach ($list as $k => $v) {
-                    $order = AuctionOrder::where('product_id', $v['id'])->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 ($order){
-                        $list[$k]['status'] = 2;// 已被购买
-                        $list[$k]['str'] = '已卖完';
-                    }else{
-                        $list[$k]['status'] = 1;// 能购买
-                        $list[$k]['str'] = '购买';
-                    }
+        if ($list){
+            foreach ($list as $k => $v) {
+                $order = AuctionOrder::where('product_id', $v['id'])->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 ($order){
+                    $list[$k]['status'] = 2;// 已被购买
+                    $list[$k]['str'] = '已卖完';
+                }else{
+                    $list[$k]['status'] = 1;// 能购买
+                    $list[$k]['str'] = '购买';
                 }
             }
         }
         return $list;
     }
 
+    /**
+     * 用户商品
+     * @param $data
+     * @param $uid
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @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->page($data['page'], $data['limit']);
+
+        $list = $model->select()->toArray();
+        return $list;
+    }
+
 
 }

+ 8 - 0
crmeb/subscribes/TaskSubscribe.php

@@ -85,6 +85,14 @@ class TaskSubscribe
         } catch (\Exception $e) {
             Db::rollback();
         }
+
+        try {
+            Db::startTrans();
+            AuctionOrder::th();//退回预约卷
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
     }
 
     /**

+ 4 - 0
route/api/route.php

@@ -163,6 +163,7 @@ Route::group(function () {
     Route::post('auction/subscribe', 'auction.auctionController/subscribe')->name('subscribe');// 预约场馆
     Route::get('auction/advance', 'auction.auctionController/advance')->name('advance');// 进入场馆
     Route::get('auction/auction_product', 'auction.auctionProductController/auction_product')->name('auction_product');// 场馆商品
+    Route::get('auction/user_product', 'auction.auctionProductController/user_product')->name('user_product');// 用户商品
     Route::post('auction/purchase', 'auction.auctionProductController/purchase')->name('purchase');// 抢购商品
 
     Route::get('auction/user_auction_order', 'auction.auctionProductController/user_auction_order')->name('user_auction_order');// 用户竞拍订单
@@ -170,6 +171,9 @@ Route::group(function () {
     Route::post('auction/up_image', 'auction.auctionProductController/up_image')->name('up_image');// 上传打款凭证
     Route::post('auction/adopt', 'auction.auctionProductController/adopt')->name('adopt');// 确定订单
 
+    Route::get('auction/lower', 'auction.auctionController/lower')->name('lower');// 用户下级
+    Route::post('auction/transfer_accounts', 'auction.auctionController/transfer_accounts')->name('transfer_accounts');// 转账预约卷
+
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 Route::group(function () {