【增加】售卖列表 时间段判断、当前秒杀时间段返回
【增加】发布 价格范围配置读取 【增加】提货接口 【增加】详情 当前秒杀时间段返回 【增加】获取设置接口
This commit is contained in:
parent
76c2256794
commit
836d9ef8c4
|
|
@ -14,48 +14,29 @@ class Futures extends BaseApi{
|
|||
$token = $this->checkToken();
|
||||
if ($token['code'] < 0) return $this->response($token);
|
||||
|
||||
//判断当前时间是否在秒杀开启时间,并区分有无钻石用户
|
||||
|
||||
$status = input('status', 'miaosha');
|
||||
|
||||
$condition = [
|
||||
['a.site_id','=',$this->site_id]
|
||||
];
|
||||
|
||||
$futuresModel = new FuturesModel;
|
||||
switch($status){
|
||||
case 'miaosha':
|
||||
$condition[] = ['a.status', '=', '2'];
|
||||
$startTimeKey = 'miaosha_start_time';
|
||||
$endTimeKey = 'miaosha_end_time';
|
||||
$fenxiao = model('fenxiao')->getInfo([['member_id', '=', $this->member_id]]);
|
||||
if(!empty($fenxiao) && $fenxiao['diamond'] > 0){
|
||||
$startTimeKey = 'miaosha_early_start_time';
|
||||
}
|
||||
$times = $futuresModel->checkTimes($this->site_id, $this->member_id, 2);
|
||||
break;
|
||||
case 'jianlou':
|
||||
$condition[] = ['a.status', '=', '7'];
|
||||
$startTimeKey = 'jianlou_start_time';
|
||||
$endTimeKey = 'jianlou_end_time';
|
||||
$times = $futuresModel->checkTimes($this->site_id, $this->member_id, 7);
|
||||
break;
|
||||
default:
|
||||
return $this->response($this->error('','参数不合法'));
|
||||
break;
|
||||
}
|
||||
|
||||
$nowTime = time() - strtotime("today");
|
||||
$is_read = FALSE;
|
||||
|
||||
$futuresModel = new FuturesModel;
|
||||
$basics = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
|
||||
foreach($basics['times'] as $times){
|
||||
if($times[$startTimeKey] <= $nowTime && $times[$endTimeKey] >= $nowTime){
|
||||
$is_read = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$is_read){
|
||||
return $this->response($this->error('','未到秒杀时间'));
|
||||
if($times['code'] != 0){
|
||||
return $this->response($times);
|
||||
}
|
||||
|
||||
// 获取内容
|
||||
|
|
@ -85,6 +66,7 @@ class Futures extends BaseApi{
|
|||
$page = input('page', 1);
|
||||
$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'];
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
|
|
@ -164,12 +146,15 @@ class Futures extends BaseApi{
|
|||
if(empty($date)){
|
||||
return $this->response($this->error('','发布失败'));
|
||||
}
|
||||
if($price <= $date['unit_price'] * (1 + 0 / 100) || $price >= $date['unit_price'] * (1 + 8 / 100)){//TODO 后台配置范围
|
||||
|
||||
$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)){// 后台配置范围
|
||||
return $this->response($this->error('','发布失败,价格不在允许范围内'));
|
||||
}
|
||||
//TODO 拆单
|
||||
// $futuresInfo = $futuresModel->detail($date);
|
||||
|
||||
$futuresModel = new FuturesModel;
|
||||
return $this->response($futuresModel->release($id, $price));
|
||||
}
|
||||
|
||||
|
|
@ -191,8 +176,26 @@ class Futures extends BaseApi{
|
|||
$futuresModel = new FuturesModel;
|
||||
return $this->response($futuresModel->stock($id));
|
||||
}
|
||||
/**
|
||||
* 提货
|
||||
* @return false|string
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
public function pickUp(){
|
||||
$token = $this->checkToken();
|
||||
if ($token['code'] < 0) return $this->response($token);
|
||||
|
||||
//TODO 提货
|
||||
$id = input('id', 0);
|
||||
|
||||
$date = model('futures')->getInfo([['id', '=', $id],['seller_uid', '=', $this->member_id]]);
|
||||
if(empty($date)){
|
||||
return $this->response($this->error('','提货失败'));
|
||||
}
|
||||
//TODO 提货用来减少用户买入限制
|
||||
|
||||
$futuresModel = new FuturesModel;
|
||||
return $this->response($futuresModel->pickUp($id));
|
||||
}
|
||||
/**
|
||||
* 详情
|
||||
* @return false|string
|
||||
|
|
@ -206,7 +209,23 @@ class Futures extends BaseApi{
|
|||
|
||||
$futuresModel = new FuturesModel;
|
||||
$detail = $futuresModel->detail($id, $this->site_id);
|
||||
$times = $futuresModel->checkTimes($this->site_id, $this->member_id, $detail['data']['status']);
|
||||
if($times['code'] != 0){
|
||||
return $this->response($times);
|
||||
}
|
||||
$detail['data']['times'] = $times;
|
||||
return $this->response($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置
|
||||
* @return false|string
|
||||
*/
|
||||
public function getBasicsConfig(){
|
||||
$futuresModel = new FuturesModel;
|
||||
$basicsConfig = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
|
||||
$res = [
|
||||
'price_range' => $basicsConfig['price_range']
|
||||
];
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,13 @@ return [
|
|||
'is_show' => 1,
|
||||
'sort' => 2,
|
||||
],
|
||||
[
|
||||
'name' => 'TRADING_MARKET_CONFIG',
|
||||
'title' => '基础设置',
|
||||
'url' => 'futures://shop/config/basics',
|
||||
'is_show' => 1,
|
||||
'sort' => 2,
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
namespace addon\futures\model;
|
||||
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{
|
||||
|
||||
|
|
@ -63,16 +63,35 @@ class Futures extends BaseModel{
|
|||
$detail = model('futures')->getInfo($condition, $field, 'a', $join);
|
||||
return $this->success($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加库存
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function add($data){
|
||||
$id = model('futures')->add($data);
|
||||
if(!($id > 0)){
|
||||
return $this->error('','添加失败');
|
||||
}
|
||||
Cache::store('redis_concurrent')->set('addon_futures_stock_'.$id,'1');
|
||||
return $this->success($id);
|
||||
}
|
||||
/**
|
||||
* 发布
|
||||
* @param $id
|
||||
* @param $price
|
||||
* @return array
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function release($id, $price){
|
||||
$date = model('futures')->getInfo([['id', '=', $id]]);
|
||||
if(empty($date) || $date['status'] !== 1){
|
||||
return $this->error('','发布失败');
|
||||
}
|
||||
if(!Cache::store('redis_concurrent')->delete('addon_futures_stock_'.$id)){
|
||||
return $this->error('','发布失败');
|
||||
}
|
||||
model('futures')->update([
|
||||
'status' => 2,
|
||||
'release_time' => time(),
|
||||
|
|
@ -99,6 +118,25 @@ class Futures extends BaseModel{
|
|||
], [['id', '=', $id]]);
|
||||
return $this->success();
|
||||
}
|
||||
/**
|
||||
* 提货
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function pickUp($id){
|
||||
$date = model('futures')->getInfo([['id', '=', $id]]);
|
||||
if(empty($date) || $date['status'] !== 1){
|
||||
return $this->error($date,'提货失败');
|
||||
}
|
||||
if(!Cache::store('redis_concurrent')->delete('addon_futures_stock_'.$id)){
|
||||
return $this->error('','提货失败');
|
||||
}
|
||||
model('futures')->update([
|
||||
'status' => 5,
|
||||
], [['id', '=', $id]]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
|
|
@ -139,7 +177,7 @@ class Futures extends BaseModel{
|
|||
'status' => 3,
|
||||
'sell_time' => time()
|
||||
], [['id', '=', $id]]);
|
||||
model('futures')->add([
|
||||
$this->add([
|
||||
'site_id' => $date['site_id'],
|
||||
'seller_uid' => $date['member_id'],
|
||||
'old_futures_id' => $id,
|
||||
|
|
@ -193,4 +231,51 @@ class Futures extends BaseModel{
|
|||
$config = new ConfigModel();
|
||||
return $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'MIAOSHA_BASICS_CONFIG']]);
|
||||
}
|
||||
/**
|
||||
* 判断当前时间是否在秒杀开启时间,并区分有无钻石用户
|
||||
* @param $site_id
|
||||
* @param $member_id
|
||||
* @param $status
|
||||
* @return array
|
||||
*/
|
||||
public function checkTimes($site_id, $member_id, $status = 2){
|
||||
switch($status){
|
||||
case '2':
|
||||
$startTimeKey = 'miaosha_start_time';
|
||||
$endTimeKey = 'miaosha_end_time';
|
||||
$fenxiao = model('fenxiao')->getInfo([['member_id', '=', $member_id]]);
|
||||
if(!empty($fenxiao) && $fenxiao['diamond'] > 0){
|
||||
$startTimeKey = 'miaosha_early_start_time';
|
||||
}
|
||||
break;
|
||||
case '7':
|
||||
$startTimeKey = 'jianlou_start_time';
|
||||
$endTimeKey = 'jianlou_end_time';
|
||||
break;
|
||||
default:
|
||||
return $this->error('','参数不合法');
|
||||
break;
|
||||
}
|
||||
|
||||
$nowTime = time() - strtotime("today");
|
||||
$is_read = FALSE;
|
||||
$nowtimes = [];
|
||||
|
||||
$basics = $this->getBasicsConfig($site_id)['data']['value'];
|
||||
foreach($basics['times'] as $times){
|
||||
if($times[$startTimeKey] <= $nowTime && $times[$endTimeKey] >= $nowTime){
|
||||
$is_read = TRUE;
|
||||
$nowtimes = [
|
||||
'start_time' => $times[$startTimeKey],
|
||||
'end_time' => $times[$endTimeKey]
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$is_read){
|
||||
return $this->error('','未到秒杀时间');
|
||||
}
|
||||
return $this->success($nowtimes);
|
||||
}
|
||||
}
|
||||
|
|
@ -109,10 +109,11 @@ class User extends BaseModel{
|
|||
if($memberId <= 0) return $this->error('','用户信息错误!');
|
||||
// 赠送商品
|
||||
try{
|
||||
$futuresModel = new Futures();
|
||||
$time = time();
|
||||
$insert = [];
|
||||
// $insert = [];
|
||||
for($i=0;$i<$info['order_num'];$i++){
|
||||
$insert[] = [
|
||||
$futuresModel->add([
|
||||
'site_id' => $this->site_id,
|
||||
'seller_uid' => $memberId,
|
||||
'goods_id' => (int)$info['goods_id'],
|
||||
|
|
@ -120,20 +121,24 @@ class User extends BaseModel{
|
|||
'unit_price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
|
||||
'status' => 1,
|
||||
'created_time' => $time,
|
||||
];
|
||||
]);
|
||||
// $insert[] = [
|
||||
// 'site_id' => $this->site_id,
|
||||
// 'seller_uid' => $memberId,
|
||||
// 'goods_id' => (int)$info['goods_id'],
|
||||
// 'total' => (int)$info['goods_num'],
|
||||
// 'unit_price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
|
||||
// 'status' => 1,
|
||||
// 'created_time' => $time,
|
||||
// ];
|
||||
}
|
||||
|
||||
Db::name('futures')->insertAll($insert);
|
||||
// Db::name('futures')->insertAll($insert);
|
||||
|
||||
return $this->success();
|
||||
}catch(Exception $e){
|
||||
return $this->error('',$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//TODO 回收
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ namespace addon\futures\model\order;
|
|||
|
||||
use addon\cardservice\model\MemberCard;
|
||||
use addon\futures\model\Futures;
|
||||
use addon\futures\model\Futures as FuturesModel;
|
||||
use app\model\order\Config;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\goods\GoodsStock;
|
||||
|
|
@ -271,6 +272,13 @@ class FuturesOrderCreate extends OrderCreate
|
|||
if(empty($futures_info))
|
||||
return $this->error([], '该秒杀不存在!');
|
||||
|
||||
$futuresModel = new FuturesModel;
|
||||
$times = $futuresModel->checkTimes($site_id, $member_id, $futures_info['status']);
|
||||
if($times['code'] != 0){
|
||||
return $times;
|
||||
}
|
||||
//TODO 判断用户是否有足够多的购买机会
|
||||
|
||||
$futures_id = $futures_info['id'];
|
||||
$data['futures_id'] = $futures_id;
|
||||
$data['futures_info'] = $futures_info;
|
||||
|
|
|
|||
|
|
@ -104,6 +104,23 @@
|
|||
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-card-header">
|
||||
<span class="card-title">秒杀价格设置</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-form-item time-type-view-all" >
|
||||
<label class="layui-form-label">价格涨幅区间设置:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" class="layui-input" name="price_range[min]" placeholder="最小涨幅" value="<?= empty($info['price_range']) ? '' :$info['price_range']['min'] ?>">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">%</div>
|
||||
<div class="layui-form-mid layui-word-aux">~</div>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" class="layui-input" name="price_range[max]" placeholder="最大涨幅" value="<?= empty($info['price_range']) ? '' : $info['price_range']['max'] ?>">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue