From 8b4ae168739967a1651f1bf1356dd0769de5d233 Mon Sep 17 00:00:00 2001 From: liqianjin <949671634@qq.com> Date: Fri, 3 Mar 2023 15:26:53 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91myDetail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon/futures/api/controller/Futures.php | 51 +++++++++--- addon/futures/event/OrderPay.php | 2 +- addon/futures/model/Futures.php | 79 ++++++++++++++++--- addon/futures/model/User.php | 64 ++++++++++++++- .../model/order/FuturesOrderCreate.php | 6 +- addon/futures/shop/view/config/basics.html | 1 + .../view/many_goods_list/js/design.js | 8 ++ 7 files changed, 189 insertions(+), 22 deletions(-) diff --git a/addon/futures/api/controller/Futures.php b/addon/futures/api/controller/Futures.php index 0522e792..ecfafbd6 100644 --- a/addon/futures/api/controller/Futures.php +++ b/addon/futures/api/controller/Futures.php @@ -17,7 +17,8 @@ class Futures extends BaseApi{ $status = input('status', 'miaosha'); $condition = [ - ['a.site_id','=',$this->site_id] + ['a.site_id','=',$this->site_id], + ['release_time', '<', time() ], ]; $futuresModel = new FuturesModel; @@ -25,19 +26,24 @@ class Futures extends BaseApi{ case 'miaosha': $condition[] = ['a.status', '=', '2']; $times = $futuresModel->checkTimes($this->site_id, $this->member_id, 2); + if($times['code'] != 0){ + return $this->response($times); + } break; case 'jianlou': $condition[] = ['a.status', '=', '7']; $times = $futuresModel->checkTimes($this->site_id, $this->member_id, 7); + if($times['code'] != 0){ + $times['message'] = '未到捡漏时间'; + return $this->response($times); + } break; default: return $this->response($this->error('','参数不合法')); break; } - if($times['code'] != 0){ - return $this->response($times); - } + // 获取内容 $field = [ @@ -46,6 +52,8 @@ class Futures extends BaseApi{ 'seller.headimg as seller_headimg', 'g.goods_name', 'g.goods_image', + 'g.market_price', + 'g.unit', 'a.id', 'a.total', 'a.unit_price', @@ -67,6 +75,8 @@ class Futures extends BaseApi{ $page_size = input('page_size', PAGE_LIST_ROWS); $list = $futuresModel->getPageList($condition, $page, $page_size, 'a.created_time desc,a.id desc', $field, 'a', $join); $list['data']['times'] = $times['data']; + $list['data']['start_time'] = strtotime(date("Y-m-d", time())) + $times['data']['start_time']; + $list['data']['end_time'] = strtotime(date("Y-m-d", time())) + $times['data']['end_time']; return $this->response($list); } @@ -107,6 +117,8 @@ class Futures extends BaseApi{ 'seller.headimg as seller_headimg', 'g.goods_name', 'g.goods_image', + 'g.market_price', + 'g.unit', 'a.id', 'a.total', 'a.unit_price', @@ -116,11 +128,13 @@ class Futures extends BaseApi{ 'a.sell_time', 'a.created_time', 'a.take_time', + 'o.order_no' ]; // 表关联 $join = [ ['member seller', 'seller.member_id = a.seller_uid', 'left'],// 获取卖家信息 ['goods g', 'g.goods_id = a.goods_id', 'left'],// 获取商品信息 + ['order o', 'o.order_id = a.order_id', 'left'],// 获取商品信息 ]; $futuresModel = new FuturesModel; @@ -149,11 +163,11 @@ class Futures extends BaseApi{ $futuresModel = new FuturesModel; $basicsConfig = $futuresModel->getBasicsConfig($this->site_id)['data']['value']; - if($price < $date['unit_price'] * (1 + $basicsConfig['price_range']['min'] / 100) || $price >= $date['unit_price'] * (1 + $basicsConfig['price_range']['max'] / 100)){// 后台配置范围 + if(!($price > $date['unit_price'] * (1 + $basicsConfig['price_range']['min'] / 100) && $price <= $date['unit_price'] * (1 + $basicsConfig['price_range']['max'] / 100))){// 后台配置范围 return $this->response($this->error('','发布失败,价格不在允许范围内')); } - //TODO 拆单 - // $futuresInfo = $futuresModel->detail($date); + + //TODO 限制发布时间 return $this->response($futuresModel->release($id, $price)); } @@ -191,7 +205,6 @@ class Futures extends BaseApi{ if(empty($date)){ return $this->response($this->error('','提货失败')); } - //TODO 提货用来减少用户买入限制 $futuresModel = new FuturesModel; return $this->response($futuresModel->pickUp($id)); @@ -213,7 +226,9 @@ class Futures extends BaseApi{ if($times['code'] != 0){ return $this->response($times); } - $detail['data']['times'] = $times; + $detail['data']['times'] = $times['data']; + $detail['data']['start_time'] = strtotime(date("Y-m-d", time())) + $times['data']['start_time']; + $detail['data']['end_time'] = strtotime(date("Y-m-d", time())) + $times['data']['end_time']; return $this->response($detail); } /** @@ -228,4 +243,22 @@ class Futures extends BaseApi{ ]; return $this->response($this->success($res)); } + /** + * 详情 + * @return false|string + */ + public function myDetail(){ + + $token = $this->checkToken(); + if ($token['code'] < 0) return $this->response($token); + + $id = input('id', 0); + + $futuresModel = new FuturesModel; + $detail = $futuresModel->detail($id, $this->site_id); + if($detail['code'] < 0 || empty($detail['data']) || $detail['data']['seller_uid'] != $this->member_id){ + return $this->response($this->error('','订单不存在')); + } + return $this->response($detail); + } } \ No newline at end of file diff --git a/addon/futures/event/OrderPay.php b/addon/futures/event/OrderPay.php index 292cf0c4..2cf5a5b8 100644 --- a/addon/futures/event/OrderPay.php +++ b/addon/futures/event/OrderPay.php @@ -20,7 +20,7 @@ class OrderPay public function handle($param){ if($param['promotion_type'] == 'futures'){ $futures_model = new Futures(); - $result = $futures_model->orderComplete($param['promotion_id']); + $result = $futures_model->orderComplete($param['promotion_id'],$param['order_id']); return $result; }else{ return success(); diff --git a/addon/futures/model/Futures.php b/addon/futures/model/Futures.php index 506ef5b2..bbe55e6d 100644 --- a/addon/futures/model/Futures.php +++ b/addon/futures/model/Futures.php @@ -5,6 +5,7 @@ use app\model\system\Config as ConfigModel; use app\model\BaseModel; use Psr\SimpleCache\InvalidArgumentException; use think\facade\Cache; +use think\facade\Db; class Futures extends BaseModel{ @@ -44,6 +45,11 @@ class Futures extends BaseModel{ 'g.goods_name', 'g.goods_image', 'g.goods_content', + 'g.market_price', + 'g.unit', + 'a.site_id', + 'a.seller_uid', + 'a.goods_id', 'a.id', 'a.total', 'a.unit_price', @@ -53,11 +59,14 @@ class Futures extends BaseModel{ 'a.sell_time', 'a.created_time', 'a.take_time', + 'o.order_no', + 'o.buyer_message', ]; // 表关联 $join = [ ['member seller', 'seller.member_id = a.seller_uid', 'left'],// 获取卖家信息 ['goods g', 'g.goods_id = a.goods_id', 'left'],// 获取商品信息 + ['order o', 'o.order_id = a.order_id', 'left'],// 获取商品信息 ]; $detail = model('futures')->getInfo($condition, $field, 'a', $join); @@ -92,13 +101,49 @@ class Futures extends BaseModel{ if(!Cache::store('redis_concurrent')->delete('addon_futures_stock_'.$id)){ return $this->error('','发布失败'); } - model('futures')->update([ - 'status' => 2, - 'release_time' => time(), - 'price' => $price - ], [['id', '=', $id]]); - Cache::store('redis_concurrent')->set('addon_futures_'.$id,'1'); - return $this->success(); + + model('futures')->startTrans(); + try{ + //拆单 + $futuresInfo = $this->detail($id,$date['site_id'])['data']; + $futuresInfo['status'] = 2; + if($price >= $futuresInfo['market_price'] * $futuresInfo['total']){ + $futuresInfo['total'] *= 2; + if($futuresInfo['total'] > pow(2,3)){//TODO 配置单订单商品最大裂变次数 + //拆单 + $futuresInfo['status'] = 8; + for($i = 0;$i < $futuresInfo['total'];$i++){ + $newSmallFuturesId = $this->add([ + 'site_id' => $futuresInfo['site_id'], + 'seller_uid' => $futuresInfo['seller_uid'], + 'old_futures_id' => $id, + 'goods_id' => $futuresInfo['goods_id'], + 'total' => 1, + 'unit_price' => $futuresInfo['unit_price'] / $futuresInfo['total'], + 'status' => 1, + 'order_id' => $futuresInfo['order_id'], + 'created_time' => time() + ])['data']; + $this->release($newSmallFuturesId,$price / $futuresInfo['total']); + } + } + } + model('futures')->update([ + 'status' => $futuresInfo['status'], + 'release_time' => time() + 3 * 24 * 60 * 60,//TODO 配置上线延迟时间 + 'price' => $price, + 'total' => $futuresInfo['total'] + ],[['id','=',$id]]); + model('futures')->commit(); + + Cache::store('redis_concurrent')->set('addon_futures_'.$id,'1'); + return $this->success(); + + } catch (\Exception $e) { + model('futures')->rollback(); + Cache::store('redis_concurrent')->set('addon_futures_stock_'.$id,'1'); + return $this->error('', $e->getMessage() . $e->getFile() . $e->getLine()); + } } /** @@ -135,6 +180,8 @@ class Futures extends BaseModel{ model('futures')->update([ 'status' => 5, ], [['id', '=', $id]]); + + //TODO 提货用来减少用户买入限制 return $this->success(); } @@ -153,9 +200,11 @@ class Futures extends BaseModel{ model('futures')->update([ 'status' => 6, 'created_time' => time(), - 'order_id' => $order_id, 'member_id' => $member_id ], [['id', '=', $id]]); + + //TODO 提前秒杀扣除钻石 + //TODO 增加用户已下单次数 Cache::store('redis_concurrent')->set('addon_futures_pay_'.$id,'1'); return $this->success(); } @@ -164,7 +213,7 @@ class Futures extends BaseModel{ * 订单完成 * @return array */ - public function orderComplete($id){ + public function orderComplete($id,$order_id){ $date = model('futures')->getInfo([['id', '=', $id]]); if(empty($date) || $date['status'] !== 6){ return $this->error($date,'完成失败'); @@ -185,7 +234,9 @@ class Futures extends BaseModel{ 'total' => (int)$date['total'], 'unit_price' => $date['price'], 'status' => 1, + 'order_id' => $order_id, 'created_time' => time()]); + //TODO 给用户增加余额 return $this->success(); } @@ -205,6 +256,16 @@ class Futures extends BaseModel{ 'status' => 7, ], [['id', '=', $id]]); Cache::store('redis_concurrent')->set('addon_futures_'.$id,'1'); + // 订单取消后 添加违规次数 + Db::name('futures_user') + ->where('member_id',$date['member_id']) + ->update([ + 'violation_num' => Db::raw('violation_num+1'), + 'total_violation_num' => Db::raw('total_violation_num+1'), + ]); + + + return $this->success(); } diff --git a/addon/futures/model/User.php b/addon/futures/model/User.php index 0c939993..c61bc0bd 100644 --- a/addon/futures/model/User.php +++ b/addon/futures/model/User.php @@ -1,6 +1,7 @@ error('',$e->getMessage()); } } - //TODO 回收 + // 回收 + public function buyBack(){ + $nowTime = time() - strtotime("today"); + $futuresModel = new Futures(); + $basics = $futuresModel->getBasicsConfig($this->site_id)['data']['value']; + $status = 0; + foreach($basics['times'] as $times){ + if($nowTime <= $times['jianlou_end_time'] && $nowTime >= $times['jianlou_end_time'] - 5 * 60){//TODO 配置在结束时间前多久开始回购 + $status = 7; + break; + } + + if($nowTime <= $times['miaosha_end_time'] && $nowTime >= $times['miaosha_end_time'] - 5 * 60){//TODO 配置在结束时间前多久开始回购 + $status = 2; + break; + } + } + if($status == 0){ + return $this->success('','未达到回购时间'); + } + $menberList = model('futures_user')->getList([['is_special', '=', 1]]); + + $futuresList = model('futures')->getList([ + ['status', '=', $status], + ['release_time', '<', time()] + ]); + foreach($futuresList as $futures){ + //创建订单 + $order_create = new OrderCreateModel(); + $data = [ + 'futures_id' => $futures[ 'futures_id' ], + 'member_id' => $menberList[0]['member_id'], + 'site_id' => $this->site_id,//站点id + 'order_from' => 'weapp', + 'order_from_name' => '微信小程序', + 'is_balance' => 0,//是否使用余额 + 'buyer_message' => '', + 'delivery' => isset($this->params[ 'delivery' ]) && !empty($this->params[ 'delivery' ]) ? json_decode($this->params[ 'delivery' ], true) : [], + 'coupon' => isset($this->params[ 'coupon' ]) && !empty($this->params[ 'coupon' ]) ? json_decode($this->params[ 'coupon' ], true) : [], + 'member_address' => isset($this->params[ 'member_address' ]) && !empty($this->params[ 'member_address' ]) ? json_decode($this->params[ 'member_address' ], true) : [], + + 'latitude' => $this->params[ 'latitude' ] ?? '', + 'longitude' => $this->params[ 'longitude' ] ?? '', + + 'is_invoice' => $this->params[ 'is_invoice' ] ?? 0, + 'invoice_type' => $this->params[ 'invoice_type' ] ?? 0, + 'invoice_title' => $this->params[ 'invoice_title' ] ?? '', + 'taxpayer_number' => $this->params[ 'taxpayer_number' ] ?? '', + 'invoice_content' => $this->params[ 'invoice_content' ] ?? '', + 'invoice_full_address' => $this->params[ 'invoice_full_address' ] ?? '', + 'is_tax_invoice' => $this->params[ 'is_tax_invoice' ] ?? 0, + 'invoice_email' => $this->params[ 'invoice_email' ] ?? '', + 'invoice_title_type' => $this->params[ 'invoice_title_type' ] ?? 0, + 'buyer_ask_delivery_time' => $this->params[ 'buyer_ask_delivery_time' ] ?? '', + 'form_data' => isset($this->params['form_data']) && !empty($this->params['form_data']) ? json_decode($this->params['form_data'], true) : [], + 'goods_sku_list' => !empty($this->params['goods_sku_list']) ? json_decode($this->params['goods_sku_list'], true) : [], + 'sku_id' => isset($this->params['sku_id']) ? $this->params['sku_id'] : '', + ]; + $res = $order_create->create($data); + } + + } } \ No newline at end of file diff --git a/addon/futures/model/order/FuturesOrderCreate.php b/addon/futures/model/order/FuturesOrderCreate.php index 82a637b6..4a1d15ae 100644 --- a/addon/futures/model/order/FuturesOrderCreate.php +++ b/addon/futures/model/order/FuturesOrderCreate.php @@ -266,7 +266,7 @@ class FuturesOrderCreate extends OrderCreate ['id', '=', $futures_id], // ['member_id', '=', $member_id], ['status', 'in', [2,7] ], - ['release_time', '>', strtotime('-3 day') ], + ['release_time', '<', time() ], ); $futures_info = model('futures')->getInfo($condition) ?? []; if(empty($futures_info)) @@ -278,10 +278,12 @@ class FuturesOrderCreate extends OrderCreate return $times; } //TODO 判断用户是否有足够多的购买机会 + //TODO 判断是否本人购买 + //TODO 判断惩罚时间 $futures_id = $futures_info['id']; $data['futures_id'] = $futures_id; - $data['futures_info'] = $futures_info; + $data['futures_info'] = $futuresModel->detail($futures_id,$site_id)['data']; $data['sku_id'] = $futures_info['goods_id']; $data['num'] = $futures_info['total']; //商品列表信息 diff --git a/addon/futures/shop/view/config/basics.html b/addon/futures/shop/view/config/basics.html index bf4917ff..df8ff4ac 100644 --- a/addon/futures/shop/view/config/basics.html +++ b/addon/futures/shop/view/config/basics.html @@ -121,6 +121,7 @@
%
+
diff --git a/app/component/view/many_goods_list/js/design.js b/app/component/view/many_goods_list/js/design.js index ed8b76ee..0559130c 100644 --- a/app/component/view/many_goods_list/js/design.js +++ b/app/component/view/many_goods_list/js/design.js @@ -14,6 +14,14 @@ Vue.component("many-goods-list-sources", { text: "手动选择", icon: "iconshoudongxuanze" }, + point: { + text: "积分", + icon: "iconshoudongxuanze" + }, + jianlou: { + text: "捡漏", + icon: "iconshoudongxuanze" + }, }, sortWayList: [ {