hrjy 3 年之前
父節點
當前提交
f560d6a955

+ 29 - 4
app/admin/controller/auction/Auction.php

@@ -79,7 +79,16 @@ class Auction extends AuthController
         $f[] = Form::dateTimes('radd_time', '入场时间');
         $f[] = Form::dateTimes('rend_time', '结束时间');
         $f[] = Form::input('sort', '排序', '0');
-        $f[] = Form::textarea('info', '介绍')->col(12);
+        $f[] = Form::input('sort', '排序', '0');
+        $f[] =  Form::checkbox('site', '开场日期', [1])->options([
+            ['value' => 1, 'label' => '周一'],
+            ['value' => 2, 'label' => '周二'],
+            ['value' => 3, 'label' => '周三'],
+            ['value' => 4, 'label' => '周四'],
+            ['value' => 5, 'label' => '周五'],
+            ['value' => 6, 'label' => '周六'],
+            ['value' => 7, 'label' => '周七'],
+        ]);
 
         $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
         $this->assign(compact('form'));
@@ -109,7 +118,8 @@ class Auction extends AuthController
             'rend_time',
             'info',
             'anticipate',
-            'auction_gu_id'
+            'auction_gu_id',
+            'site'
         ]);
         $validate = Validate::rule('nickname', 'require')->rule([
             'nickname' => 'require',
@@ -121,6 +131,7 @@ class Auction extends AuthController
             'radd_time' => 'require',
             'rend_time' => 'require',
             'auction_gu_id' => 'require',
+            'site' => 'require'
         ]);
         $validate->message([
             'nickname.require' => '名称不能为空',
@@ -132,7 +143,9 @@ class Auction extends AuthController
             'radd_time.require' => '请选择进场时间',
             'rend_time.require' => '请选择结束时间',
             'auction_gu_id.require' => '请选择绑定场馆',
+            'site.require' => '请选择开场日期',
         ]);
+        $data['site'] = implode($data['site'], ',');
         if (!$validate->check($data)) {
             return Json::fail($validate->getError());
         }
@@ -203,7 +216,15 @@ class Auction extends AuthController
         $f[] = Form::dateTimes('rend_time', '结束时间', $data->getData('rend_time'));
         $f[] = Form::input('sort', '排序', '0', $data->getData('sort'));
         $f[] = Form::textarea('info', '介绍', $data->getData('info'))->col(12);
-
+        $f[] =  Form::checkbox('site', '开场日期', explode(',', $data->getData('site')))->options([
+            ['value' => 1, 'label' => '周一'],
+            ['value' => 2, 'label' => '周二'],
+            ['value' => 3, 'label' => '周三'],
+            ['value' => 4, 'label' => '周四'],
+            ['value' => 5, 'label' => '周五'],
+            ['value' => 6, 'label' => '周六'],
+            ['value' => 7, 'label' => '周七'],
+        ]);
         $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
         $this->assign(compact('form'));
         return $this->fetch('public/form-builder');
@@ -234,7 +255,8 @@ class Auction extends AuthController
             'rend_time',
             'info',
             'anticipate',
-            'auction_gu_id'
+            'auction_gu_id',
+            'site'
         ]);
         $validate = Validate::rule('nickname', 'require')->rule([
             'nickname' => 'require',
@@ -246,6 +268,7 @@ class Auction extends AuthController
             'radd_time' => 'require',
             'rend_time' => 'require',
             'auction_gu_id' => 'require',
+            'site' => 'require'
         ]);
         $validate->message([
             'nickname.require' => '名称不能为空',
@@ -257,7 +280,9 @@ class Auction extends AuthController
             'radd_time.require' => '请选择进场时间',
             'rend_time.require' => '请选择结束时间',
             'auction_gu_id.require' => '请选择绑定场馆',
+            'site.require' => '请选择开场日期',
         ]);
+        $data['site'] = implode($data['site'], ',');
         if (!$validate->check($data)) {
             return Json::fail($validate->getError());
         }

+ 1 - 0
app/admin/view/auction/auction/index.php

@@ -129,6 +129,7 @@
             {field: 'frequency', title: '场次', templet: '#frequency', align: 'center'},
             {field: 'b_count', title: '今日预约人数', templet: '#frequency', align: 'center'},
             {field: 'sort', title: '排序', templet: '#sort', align: 'center'},
+            {field: 'site', title: '开场日期', templet: '#site', align: 'center'},
             {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '10%'},
         ];
     });

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

@@ -9,6 +9,7 @@ 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;
@@ -21,6 +22,7 @@ use crmeb\services\{
 };
 use crmeb\services\UtilService;
 use crmeb\repositories\OrderRepository;
+use think\facade\Db;
 
 
 class AuctionProductController
@@ -280,5 +282,113 @@ class AuctionProductController
         return app('json')->successful($order);
     }
 
+    /**
+     * 挂售详情
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+   public function gsxq(Request $request)
+   {
+       $data = UtilService::getMore([
+           ['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;
+
+
+       return app('json')->successful($data);
+
+   }
+
+
+    /**
+     * 挂售商品
+     * @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'],
+            ['gs_time']
+        ]);
+        $product = AuctionProduct::where('id', $data['id'])->find();
+        $user = User::where('uid', $request->uid())->find();
+        if (!$product) return app('json')->fail('商品不存在');
+
+        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('预约券不足');
+
+        $product['price'] = $product['hanging_price'];
+        $product['hanging_price'] += $hanging_price;
+        $product['is_show'] = 1;
+        $product['is_admin'] = 2;
+        $user['anticipate'] -= $anticipate;
+        try {
+            Db::startTrans();
+            AuctionTime::create([
+                'uid' => $request->uid(),
+                'product_id' => $product['id'],
+                'auction_id' => $product['auction_id'],
+                'add_time' => strtotime($data['gs_time'])
+            ]);
+
+            $product->save();
+            $user->save();
+            UserBill::expend('挂售扣除预约券', $user['uid'], 'anticipate', 'reduce_anticipate', $anticipate, $user['spread_uid'], $user['anticipate'], '挂售商品扣除预约券');
+
+            Db::commit();
+            return app('json')->successful('挂售成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return app('json')->fail('挂售失败');
+        }
+
+
+    }
+
 
 }

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

@@ -57,6 +57,7 @@ class AllowOriginMiddleware implements MiddlewareInterface
         }
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         Auction::frequency(); // 更新场次
+        Auction::is_new(); // 更新新人
         try {
             Db::startTrans();
             AuctionOrder::deduction();//订单一个小时内未上传扣除预约卷

+ 25 - 0
app/models/auction/Auction.php

@@ -3,6 +3,7 @@
 namespace app\models\auction;
 
 use app\models\store\StoreProduct;
+use app\models\user\User;
 use crmeb\services\SystemConfigService;
 use think\facade\Db;
 use crmeb\traits\ModelTrait;
@@ -62,6 +63,13 @@ class Auction extends BaseModel
         return $list;
     }
 
+    /**
+     * 更新场次
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public static function frequency()
     {
         $list = self::select();
@@ -75,4 +83,21 @@ 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]);
+                }
+
+            }
+        }
+
+
+    }
+
 }

+ 4 - 4
app/models/auction/AuctionOrder.php

@@ -174,10 +174,10 @@ class AuctionOrder extends BaseModel
 
             ]);
         }
-        $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]); //下架等待挂售
 
     }
 

+ 13 - 13
app/models/auction/AuctionProduct.php

@@ -41,6 +41,7 @@ class AuctionProduct extends BaseModel
         if ($data['name']) $model->where('name', 'like', '%'.$data['name'].'%');
         $list = $model->select();
         $list = empty($list)? [] : $list->toArray();
+        $lists = [];
         if ($list){
             foreach ($list as $k => $v) {
                 $auction = Auction::where('id', $v['auction_id'])->find();
@@ -52,9 +53,19 @@ class AuctionProduct extends BaseModel
                     $list[$k]['status'] = 1;// 能购买
                     $list[$k]['str'] = '购买';
                 }
+                if ($v['is_admin'] == 2){
+                    $time = AuctionTime::where([['auction_id', '=', $auction['id']], ['product_id', '=', $v['id']], ['add_time', '=', strtotime(date('Y-m-d', time()))]])->find();
+                    if (!$time){
+                        unset($list);
+                    } else{
+                        $lists[] = $v;
+                    }
+                }else{
+                    $lists[] = $v;
+                }
             }
-        }
-        return $list;
+        };
+        return $lists;
     }
 
     /**
@@ -72,17 +83,6 @@ class AuctionProduct extends BaseModel
 
         $list = $model->select();
         $list = empty($list)? [] : $list->toArray();
-        foreach ($list as $k => $v)
-        {
-            $auction = Auction::where('id', $v['auction_id'])->find();
-            if (strtotime(date('Y-m-d',strtotime($v['update_time']))) < strtotime(date('Y-m-d'))){
-                $list[$k]['g_time'] = date('Y-m-d H:i:s', strtotime($auction['radd_time']));
-            }else{
-                $list[$k]['g_time'] = date('Y-m-d', strtotime('+1 day')).' '.$auction['radd_time'];
-            }
-
-
-        }
 
         return $list;
     }

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

@@ -0,0 +1,28 @@
+<?php
+
+namespace app\models\auction;
+
+use crmeb\basic\BaseModel;
+use crmeb\traits\ModelTrait;
+
+/**
+ * TODO 场馆model
+ * Class Article
+ * @package app\models\article
+ */
+class AuctionTime extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'auction_time';
+
+    use ModelTrait;
+}

+ 3 - 0
crmeb/subscribes/TaskSubscribe.php

@@ -3,6 +3,7 @@
 namespace crmeb\subscribes;
 
 use app\admin\model\system\SystemAttachment;
+use app\models\auction\Auction;
 use app\models\auction\AuctionOrder;
 use app\models\store\StoreBargainUser;
 use app\models\store\StoreOrder;
@@ -93,6 +94,8 @@ class TaskSubscribe
         } catch (\Exception $e) {
             Db::rollback();
         }
+        Auction::frequency(); // 更新场次
+        Auction::is_new(); // 更新新人
     }
 
     /**

+ 3 - 0
route/api/route.php

@@ -188,6 +188,9 @@ Route::group(function () {
     Route::post('auction/apply', 'auction.auctionController/apply')->name('apply');// 馆长申请
     Route::get('auction/apply_status', 'auction.auctionController/apply_status')->name('apply_status');// 申请馆长状态
 
+    Route::get('auction/gsxq', 'auction.auctionProductController/gsxq')->name('gsxq');// 挂售详情
+    Route::post('auction/hanging_sale', 'auction.auctionProductController/hanging_sale')->name('hanging_sale');// 挂售
+
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 Route::group(function () {