chore(src): 所有代码上传
This commit is contained in:
@@ -1,68 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\api\controller;
|
||||
|
||||
use addon\seckill\model\Seckill as SeckillModel;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
|
||||
/**
|
||||
* 秒杀
|
||||
*/
|
||||
class Seckill extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 列表信息
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
|
||||
$today_time = strtotime(date("Y-m-d"), time());
|
||||
$time = time() - $today_time;//当日时间戳
|
||||
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'seckill_end_time', '>=', $time ]
|
||||
];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = 'id,name,seckill_start_time,seckill_end_time';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$today_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
|
||||
$today_list = is_array($today_list[ 'data' ]) ? array_values($today_list[ 'data' ]) : [];
|
||||
foreach ($today_list as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$today_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$today_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
$today_list[ $key ][ 'type' ] = "today";
|
||||
}
|
||||
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'seckill_end_time', '<', $time ]
|
||||
];
|
||||
|
||||
$tomorrow_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
|
||||
$tomorrow_list = is_array($tomorrow_list[ 'data' ]) ? array_values($tomorrow_list[ 'data' ]) : [];
|
||||
foreach ($tomorrow_list as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$tomorrow_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$tomorrow_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
$tomorrow_list[ $key ][ 'type' ] = "tomorrow";
|
||||
}
|
||||
|
||||
$res = [
|
||||
'list' => array_merge($today_list, $tomorrow_list)
|
||||
];
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\api\controller;
|
||||
|
||||
use addon\seckill\model\Seckill as SeckillModel;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
|
||||
/**
|
||||
* 秒杀
|
||||
*/
|
||||
class Seckill extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 列表信息
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
|
||||
$today_time = strtotime(date("Y-m-d"), time());
|
||||
$time = time() - $today_time;//当日时间戳
|
||||
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'seckill_end_time', '>=', $time ]
|
||||
];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = 'id,name,seckill_start_time,seckill_end_time';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$today_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
|
||||
$today_list = is_array($today_list[ 'data' ]) ? array_values($today_list[ 'data' ]) : [];
|
||||
foreach ($today_list as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$today_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$today_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
$today_list[ $key ][ 'type' ] = "today";
|
||||
}
|
||||
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'seckill_end_time', '<', $time ]
|
||||
];
|
||||
|
||||
$tomorrow_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
|
||||
$tomorrow_list = is_array($tomorrow_list[ 'data' ]) ? array_values($tomorrow_list[ 'data' ]) : [];
|
||||
foreach ($tomorrow_list as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$tomorrow_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$tomorrow_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
$tomorrow_list[ $key ][ 'type' ] = "tomorrow";
|
||||
}
|
||||
|
||||
$res = [
|
||||
'list' => array_merge($today_list, $tomorrow_list)
|
||||
];
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
}
|
||||
@@ -1,222 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\api\controller;
|
||||
|
||||
use addon\seckill\model\Poster;
|
||||
use addon\seckill\model\Seckill as SeckillModel;
|
||||
use addon\seckill\model\SeckillOrder;
|
||||
use addon\seckill\model\SeckillOrderCreate;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\api\controller\Goodssku;
|
||||
use app\model\goods\GoodsApi;
|
||||
|
||||
/**
|
||||
* 秒杀商品
|
||||
*/
|
||||
class Seckillgoods extends BaseApi
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 【PC端在用】基础信息
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$seckill_id = $this->params[ 'seckill_id' ] ?? 0;
|
||||
$sku_id = $this->params[ 'sku_id' ] ?? 0;
|
||||
if (empty($seckill_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
if (empty($sku_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$seckill_model = new SeckillModel();
|
||||
$order_model = new SeckillOrder();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.sku_id', '=', $sku_id ],
|
||||
[ 'psg.site_id', '=', $this->site_id ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition, '')[ 'data' ];
|
||||
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
if (!empty($goods_sku_detail)) {
|
||||
$num = $order_model->getGoodsSeckillNum($seckill_id);
|
||||
$time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
|
||||
$goods_sku_detail[ 'sale_num' ] = $num;
|
||||
$goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
|
||||
$goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
|
||||
//判断商品规格项
|
||||
$goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
|
||||
$res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
} else {
|
||||
$sku_id = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, '');
|
||||
$res = [ 'type' => 'again', 'sku_id' => $sku_id ];
|
||||
}
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情信息
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$this->checkToken();
|
||||
$seckill_id = $this->params[ 'seckill_id' ] ?? 0;
|
||||
if (empty($seckill_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$seckill_model = new SeckillModel();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.site_id', '=', $this->site_id ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition)[ 'data' ];
|
||||
|
||||
$time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
|
||||
$goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
|
||||
$goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
|
||||
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
if (empty($goods_sku_detail)) return $this->response($this->error($res));
|
||||
|
||||
if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
|
||||
//判断商品规格项
|
||||
$goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
|
||||
$res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
}
|
||||
|
||||
// 处理公共数据
|
||||
$goods_sku_api = new GoodsApi();
|
||||
$goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ], $this->member_id, $this->site_id);
|
||||
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品SKU集合
|
||||
* @return false|string
|
||||
*/
|
||||
public function goodsSku()
|
||||
{
|
||||
$goods_id = $this->params[ 'goods_id' ] ?? 0;
|
||||
$seckill_id = $this->params[ 'seckill_id' ] ?? 0;
|
||||
if (empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
if (empty($seckill_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$seckill_model = new SeckillModel();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.goods_id', '=', $goods_id ],
|
||||
[ 'psg.site_id', '=', $this->site_id ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$list = $seckill_model->getSeckillGoodsSkuList($condition);
|
||||
if (!empty($list[ 'data' ])) {
|
||||
foreach ($list[ 'data' ] as $k => $v) {
|
||||
if (!empty($v[ 'goods_spec_format' ])) {
|
||||
//判断商品规格项
|
||||
$goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $v[ 'goods_spec_format' ]);
|
||||
$list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
public function page()
|
||||
{
|
||||
$seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
if (empty($seckill_time_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
|
||||
}
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillGoodsPageList($seckill_time_id, $this->site_id, $page, $page_size);
|
||||
foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
|
||||
if ($val[ 'price' ] != 0) {
|
||||
$discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
|
||||
} else {
|
||||
$discount_rate = 100;
|
||||
}
|
||||
$res[ 'data' ][ 'list' ][ $key ][ 'discount_rate' ] = $discount_rate;
|
||||
}
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
public function lists()
|
||||
{
|
||||
$seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
|
||||
$num = $this->params[ 'num' ] ?? null;
|
||||
|
||||
if (empty($seckill_time_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
|
||||
}
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillList($seckill_time_id, $this->site_id, $num);
|
||||
$list = $res[ 'data' ];
|
||||
foreach ($list as $key => $val) {
|
||||
if ($val[ 'price' ] != 0) {
|
||||
$discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
|
||||
} else {
|
||||
$discount_rate = 100;
|
||||
}
|
||||
$list[ $key ][ 'discount_rate' ] = $discount_rate;
|
||||
}
|
||||
|
||||
return $this->response($this->success($list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品海报
|
||||
*/
|
||||
public function poster()
|
||||
{
|
||||
$this->checkToken();
|
||||
|
||||
$promotion_type = 'seckill';
|
||||
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
|
||||
$qrcode_param[ 'source_member' ] = $this->member_id;
|
||||
$poster = new Poster();
|
||||
$res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享图片
|
||||
* @return false|string
|
||||
*/
|
||||
public function shareImg()
|
||||
{
|
||||
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
|
||||
|
||||
$poster = new Poster();
|
||||
$res = $poster->shareImg($this->params[ 'page' ] ?? '', $qrcode_param, $this->site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\api\controller;
|
||||
|
||||
use addon\seckill\model\Poster;
|
||||
use addon\seckill\model\Seckill as SeckillModel;
|
||||
use addon\seckill\model\SeckillOrder;
|
||||
use addon\seckill\model\SeckillOrderCreate;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\api\controller\Goodssku;
|
||||
use app\model\goods\GoodsApi;
|
||||
|
||||
/**
|
||||
* 秒杀商品
|
||||
*/
|
||||
class Seckillgoods extends BaseApi
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 【PC端在用】基础信息
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$seckill_id = $this->params[ 'seckill_id' ] ?? 0;
|
||||
$sku_id = $this->params[ 'sku_id' ] ?? 0;
|
||||
if (empty($seckill_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
if (empty($sku_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$seckill_model = new SeckillModel();
|
||||
$order_model = new SeckillOrder();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.sku_id', '=', $sku_id ],
|
||||
[ 'psg.site_id', '=', $this->site_id ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition, '')[ 'data' ];
|
||||
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
if (!empty($goods_sku_detail)) {
|
||||
$num = $order_model->getGoodsSeckillNum($seckill_id);
|
||||
$time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
|
||||
$goods_sku_detail[ 'sale_num' ] = $num;
|
||||
$goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
|
||||
$goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
|
||||
//判断商品规格项
|
||||
$goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
|
||||
$res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
} else {
|
||||
$sku_id = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, '');
|
||||
$res = [ 'type' => 'again', 'sku_id' => $sku_id ];
|
||||
}
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情信息
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$this->checkToken();
|
||||
$seckill_id = $this->params[ 'seckill_id' ] ?? 0;
|
||||
if (empty($seckill_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$seckill_model = new SeckillModel();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.site_id', '=', $this->site_id ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition)[ 'data' ];
|
||||
|
||||
$time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
|
||||
$goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
|
||||
$goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
|
||||
|
||||
$res[ 'goods_sku_detail' ] = $goods_sku_detail;
|
||||
if (empty($goods_sku_detail)) return $this->response($this->error($res));
|
||||
|
||||
if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
|
||||
//判断商品规格项
|
||||
$goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
|
||||
$res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
}
|
||||
|
||||
// 处理公共数据
|
||||
$goods_sku_api = new GoodsApi();
|
||||
$goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ], $this->member_id, $this->site_id);
|
||||
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品SKU集合
|
||||
* @return false|string
|
||||
*/
|
||||
public function goodsSku()
|
||||
{
|
||||
$goods_id = $this->params[ 'goods_id' ] ?? 0;
|
||||
$seckill_id = $this->params[ 'seckill_id' ] ?? 0;
|
||||
if (empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
if (empty($seckill_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_ID'));
|
||||
}
|
||||
$seckill_model = new SeckillModel();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.goods_id', '=', $goods_id ],
|
||||
[ 'psg.site_id', '=', $this->site_id ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$list = $seckill_model->getSeckillGoodsSkuList($condition);
|
||||
if (!empty($list[ 'data' ])) {
|
||||
foreach ($list[ 'data' ] as $k => $v) {
|
||||
if (!empty($v[ 'goods_spec_format' ])) {
|
||||
//判断商品规格项
|
||||
$goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $v[ 'goods_spec_format' ]);
|
||||
$list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
public function page()
|
||||
{
|
||||
$seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
if (empty($seckill_time_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
|
||||
}
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillGoodsPageList($seckill_time_id, $this->site_id, $page, $page_size);
|
||||
foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
|
||||
if ($val[ 'price' ] != 0) {
|
||||
$discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
|
||||
} else {
|
||||
$discount_rate = 100;
|
||||
}
|
||||
$res[ 'data' ][ 'list' ][ $key ][ 'discount_rate' ] = $discount_rate;
|
||||
}
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
public function lists()
|
||||
{
|
||||
$seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
|
||||
$num = $this->params[ 'num' ] ?? null;
|
||||
|
||||
if (empty($seckill_time_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
|
||||
}
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillList($seckill_time_id, $this->site_id, $num);
|
||||
$list = $res[ 'data' ];
|
||||
foreach ($list as $key => $val) {
|
||||
if ($val[ 'price' ] != 0) {
|
||||
$discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
|
||||
} else {
|
||||
$discount_rate = 100;
|
||||
}
|
||||
$list[ $key ][ 'discount_rate' ] = $discount_rate;
|
||||
}
|
||||
|
||||
return $this->response($this->success($list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品海报
|
||||
*/
|
||||
public function poster()
|
||||
{
|
||||
$this->checkToken();
|
||||
|
||||
$promotion_type = 'seckill';
|
||||
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
|
||||
$qrcode_param[ 'source_member' ] = $this->member_id;
|
||||
$poster = new Poster();
|
||||
$res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享图片
|
||||
* @return false|string
|
||||
*/
|
||||
public function shareImg()
|
||||
{
|
||||
$qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
|
||||
|
||||
$poster = new Poster();
|
||||
$res = $poster->shareImg($this->params[ 'page' ] ?? '', $qrcode_param, $this->site_id);
|
||||
return $this->response($res);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
return [
|
||||
|
||||
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
|
||||
'template' => [],
|
||||
|
||||
// 后台自定义组件——装修
|
||||
'util' => [
|
||||
[
|
||||
'name' => 'Seckill',
|
||||
'title' => '秒杀',
|
||||
'type' => 'PROMOTION',
|
||||
'value' => '{"style":"style-1","sources":"initial","count":6,"goodsId":[],"goodsMarginType":"default","goodsMarginNum":10,"ornament":{"type":"default","color":"#EDEDED"},"nameLineMode":"single","template":"row1-of1","btnStyle":{"text":"去秒杀","textColor":"#FFFFFF","theme":"default","aroundRadius":25,"control":true,"support":true,"bgColorStart":"#FF7B1D","bgColorEnd":"#FF1544"},"imgAroundRadius":5,"saleStyle":{"color":"#999CA7","control":true,"support":true},"progressStyle":{"control":true,"support":true,"currColor":"#FDBE6C","bgColor":"#FCECD7"},"titleStyle":{"backgroundImage":"","isShow":true,"leftStyle":"text","leftImg":"","style":"style-1","styleName":"风格1","leftText":"限时秒杀","fontSize":16,"fontWeight":true,"textColor":"#303133","bgColorStart":"#FFFFFF","bgColorEnd":"#FFFFFF","more":"查看更多","moreColor":"#999999","moreFontSize":12,"timeBgColor":"","timeImageUrl":"","moreSupport":true,"colonColor":"#303133","numBgColorStart":"#303133","numBgColorEnd":"#303133","numTextColor":"#FFFFFF"},"slideMode":"scroll","theme":"default","priceStyle":{"mainColor":"#FF1745","mainControl":true,"lineColor":"#999CA7","lineControl":true,"lineSupport":true},"goodsNameStyle":{"color":"#303133","control":true,"fontWeight":false}}',
|
||||
'sort' => '30003',
|
||||
'support_diy_view' => '',
|
||||
'max_count' => 1,
|
||||
'icon' => 'iconfont iconmiaosha1'
|
||||
]
|
||||
],
|
||||
|
||||
// 自定义页面路径
|
||||
'link' => [
|
||||
[
|
||||
'name' => 'SECKILL',
|
||||
'title' => '秒杀',
|
||||
'parent' => 'MARKETING_LINK',
|
||||
'wap_url' => '',
|
||||
'web_url' => '',
|
||||
'sort' => 0,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'SECKILL_PREFECTURE',
|
||||
'title' => '秒杀抢购',
|
||||
'wap_url' => '/pages_promotion/seckill/list',
|
||||
'web_url' => '',
|
||||
'sort' => 0
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
// 自定义图标库
|
||||
'icon_library' => [],
|
||||
|
||||
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
|
||||
'component' => [],
|
||||
|
||||
// uni-app 页面,多个逗号隔开
|
||||
'pages' => [],
|
||||
|
||||
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
|
||||
'info' => [],
|
||||
|
||||
// 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
|
||||
'theme' => [],
|
||||
|
||||
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
|
||||
'data' => []
|
||||
<?php
|
||||
return [
|
||||
|
||||
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
|
||||
'template' => [],
|
||||
|
||||
// 后台自定义组件——装修
|
||||
'util' => [
|
||||
[
|
||||
'name' => 'Seckill',
|
||||
'title' => '秒杀',
|
||||
'type' => 'PROMOTION',
|
||||
'value' => '{"style":"style-1","sources":"initial","count":6,"goodsId":[],"goodsMarginType":"default","goodsMarginNum":10,"ornament":{"type":"default","color":"#EDEDED"},"nameLineMode":"single","template":"row1-of1","btnStyle":{"text":"去秒杀","textColor":"#FFFFFF","theme":"default","aroundRadius":25,"control":true,"support":true,"bgColorStart":"#FF7B1D","bgColorEnd":"#FF1544"},"imgAroundRadius":5,"saleStyle":{"color":"#999CA7","control":true,"support":true},"progressStyle":{"control":true,"support":true,"currColor":"#FDBE6C","bgColor":"#FCECD7"},"titleStyle":{"backgroundImage":"","isShow":true,"leftStyle":"text","leftImg":"","style":"style-1","styleName":"风格1","leftText":"限时秒杀","fontSize":16,"fontWeight":true,"textColor":"#303133","bgColorStart":"#FFFFFF","bgColorEnd":"#FFFFFF","more":"查看更多","moreColor":"#999999","moreFontSize":12,"timeBgColor":"","timeImageUrl":"","moreSupport":true,"colonColor":"#303133","numBgColorStart":"#303133","numBgColorEnd":"#303133","numTextColor":"#FFFFFF"},"slideMode":"scroll","theme":"default","priceStyle":{"mainColor":"#FF1745","mainControl":true,"lineColor":"#999CA7","lineControl":true,"lineSupport":true},"goodsNameStyle":{"color":"#303133","control":true,"fontWeight":false}}',
|
||||
'sort' => '30003',
|
||||
'support_diy_view' => '',
|
||||
'max_count' => 1,
|
||||
'icon' => 'iconfont iconmiaosha1'
|
||||
]
|
||||
],
|
||||
|
||||
// 自定义页面路径
|
||||
'link' => [
|
||||
[
|
||||
'name' => 'SECKILL',
|
||||
'title' => '秒杀',
|
||||
'parent' => 'MARKETING_LINK',
|
||||
'wap_url' => '',
|
||||
'web_url' => '',
|
||||
'sort' => 0,
|
||||
'child_list' => [
|
||||
[
|
||||
'name' => 'SECKILL_PREFECTURE',
|
||||
'title' => '秒杀抢购',
|
||||
'wap_url' => '/pages_promotion/seckill/list',
|
||||
'web_url' => '',
|
||||
'sort' => 0
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
// 自定义图标库
|
||||
'icon_library' => [],
|
||||
|
||||
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
|
||||
'component' => [],
|
||||
|
||||
// uni-app 页面,多个逗号隔开
|
||||
'pages' => [],
|
||||
|
||||
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
|
||||
'info' => [],
|
||||
|
||||
// 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
|
||||
'theme' => [],
|
||||
|
||||
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
|
||||
'data' => []
|
||||
];
|
||||
@@ -1,20 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
return [
|
||||
'name' => 'seckill',
|
||||
'title' => '秒杀抢购',
|
||||
'description' => '低价、限购,吸引更多会员',
|
||||
'type' => 'promotion', //插件类型 system :系统插件 promotion:营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.3.1',
|
||||
'version_no' => '525231212001',
|
||||
'content' => '',
|
||||
<?php
|
||||
return [
|
||||
'name' => 'seckill',
|
||||
'title' => '秒杀抢购',
|
||||
'description' => '低价、限购,吸引更多会员',
|
||||
'type' => 'promotion', //插件类型 system :系统插件 promotion:营销插件 tool:工具插件
|
||||
'status' => 1,
|
||||
'author' => '',
|
||||
'version' => '5.3.1',
|
||||
'version_no' => '525231212001',
|
||||
'content' => '',
|
||||
];
|
||||
@@ -1,27 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
|
||||
/**
|
||||
* 关闭活动
|
||||
*/
|
||||
class CloseSeckill
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$seckill = new Seckill();
|
||||
$res = $seckill->cronCloseSeckill($params[ 'relate_id' ]);
|
||||
return $res;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
|
||||
/**
|
||||
* 关闭活动
|
||||
*/
|
||||
class CloseSeckill
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$seckill = new Seckill();
|
||||
$res = $seckill->cronCloseSeckill($params[ 'relate_id' ]);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\SeckillOrder;
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
*/
|
||||
class CronOrderClose
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单关闭
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function handle($params)
|
||||
{
|
||||
$seckill = new SeckillOrder();
|
||||
$res = $seckill->cronOrderClose($params[ 'order_id' ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\SeckillOrder;
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
*/
|
||||
class CronOrderClose
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单关闭
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function handle($params)
|
||||
{
|
||||
$seckill = new SeckillOrder();
|
||||
$res = $seckill->cronOrderClose($params[ 'order_id' ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
use app\model\goods\Goods as GoodsModel;
|
||||
|
||||
/**
|
||||
* 商品营销活动信息
|
||||
*/
|
||||
class GoodsPromotion
|
||||
{
|
||||
|
||||
/**
|
||||
* 商品营销活动信息
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function handle($param)
|
||||
{
|
||||
if (isset($param['goods_sku_detail'])) {
|
||||
$goods_info = $param['goods_sku_detail'];
|
||||
if (!empty($goods_info['promotion_addon'])) {
|
||||
$promotion_addon = json_decode($goods_info['promotion_addon'], true);
|
||||
if (!empty($promotion_addon['seckill'])) {
|
||||
return [
|
||||
'promotion_type' => 'seckill',
|
||||
'promotion_name' => '限时秒杀',
|
||||
'id' => $promotion_addon['seckill']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (empty($param['goods_id'])) return [];
|
||||
$goods_model = new GoodsModel();
|
||||
$goods_info = $goods_model->getGoodsInfo([['goods_id', '=', $param['goods_id']]], 'promotion_addon')['data'];
|
||||
if (!empty($goods_info['promotion_addon'])) {
|
||||
$promotion_addon = json_decode($goods_info['promotion_addon'], true);
|
||||
if (!empty($promotion_addon['seckill'])) {
|
||||
$seckill_model = new Seckill();
|
||||
$goods_detail = $seckill_model->getSeckillInfo($promotion_addon['seckill'])['data'];
|
||||
if (!empty($goods_detail)) {
|
||||
$time = time() - strtotime(date('Y-m-d'), time());
|
||||
if ($time > $goods_detail['seckill_start_time'] && $time < $goods_detail['seckill_end_time']) {
|
||||
$goods_detail['promotion_type'] = 'seckill';
|
||||
$goods_detail['promotion_name'] = '限时秒杀';
|
||||
return $goods_detail;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
use app\model\goods\Goods as GoodsModel;
|
||||
|
||||
/**
|
||||
* 商品营销活动信息
|
||||
*/
|
||||
class GoodsPromotion
|
||||
{
|
||||
|
||||
/**
|
||||
* 商品营销活动信息
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function handle($param)
|
||||
{
|
||||
if (isset($param['goods_sku_detail'])) {
|
||||
$goods_info = $param['goods_sku_detail'];
|
||||
if (!empty($goods_info['promotion_addon'])) {
|
||||
$promotion_addon = json_decode($goods_info['promotion_addon'], true);
|
||||
if (!empty($promotion_addon['seckill'])) {
|
||||
return [
|
||||
'promotion_type' => 'seckill',
|
||||
'promotion_name' => '限时秒杀',
|
||||
'id' => $promotion_addon['seckill']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (empty($param['goods_id'])) return [];
|
||||
$goods_model = new GoodsModel();
|
||||
$goods_info = $goods_model->getGoodsInfo([['goods_id', '=', $param['goods_id']]], 'promotion_addon')['data'];
|
||||
if (!empty($goods_info['promotion_addon'])) {
|
||||
$promotion_addon = json_decode($goods_info['promotion_addon'], true);
|
||||
if (!empty($promotion_addon['seckill'])) {
|
||||
$seckill_model = new Seckill();
|
||||
$goods_detail = $seckill_model->getSeckillInfo($promotion_addon['seckill'])['data'];
|
||||
if (!empty($goods_detail)) {
|
||||
$time = time() - strtotime(date('Y-m-d'), time());
|
||||
if ($time > $goods_detail['seckill_start_time'] && $time < $goods_detail['seckill_end_time']) {
|
||||
$goods_detail['promotion_type'] = 'seckill';
|
||||
$goods_detail['promotion_name'] = '限时秒杀';
|
||||
return $goods_detail;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class GoodsPromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return ['name' => '限时秒杀', 'short' => '秒', 'type' => 'seckill', 'color' => '#89689D', 'url' => 'seckill://shop/seckill/goodslist'];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class GoodsPromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return ['name' => '限时秒杀', 'short' => '秒', 'type' => 'seckill', 'color' => '#89689D', 'url' => 'seckill://shop/seckill/goodslist'];
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/* try{
|
||||
execute_sql('addon/seckill/data/install.sql');
|
||||
return success();
|
||||
}catch (\Exception $e)
|
||||
{
|
||||
return error('', $e->getMessage());
|
||||
} */
|
||||
return success();
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 应用安装
|
||||
*/
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/* try{
|
||||
execute_sql('addon/seckill/data/install.sql');
|
||||
return success();
|
||||
}catch (\Exception $e)
|
||||
{
|
||||
return error('', $e->getMessage());
|
||||
} */
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
|
||||
/**
|
||||
* 开启活动
|
||||
*/
|
||||
class OpenSeckill
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$seckill = new Seckill();
|
||||
$res = $seckill->cronOpenSeckill($params[ 'relate_id' ]);
|
||||
return $res;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
|
||||
/**
|
||||
* 开启活动
|
||||
*/
|
||||
class OpenSeckill
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
$seckill = new Seckill();
|
||||
$res = $seckill->cronOpenSeckill($params[ 'relate_id' ]);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
*/
|
||||
class OrderPromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "秒杀", "type" => "seckill" ];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
*/
|
||||
class OrderPromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单营销活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "秒杀", "type" => "seckill" ];
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class PromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "秒杀", "type" => "seckill" ];
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
class PromotionType
|
||||
{
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
return [ "name" => "秒杀", "type" => "seckill" ];
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
|
||||
/**
|
||||
* 活动专区——限时秒杀页面配置
|
||||
*/
|
||||
class SeckillZoneConfig
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
if (empty($params) || $params[ 'name' ] == 'seckill') {
|
||||
$data = [
|
||||
'name' => 'seckill', // 标识
|
||||
'title' => '限时秒杀', // 名称
|
||||
'url' => 'shop/adv/lists?keyword=NS_SECKILL', // 自定义跳转链接
|
||||
'preview' => 'addon/seckill/shop/view/public/img/zone_preview.png', // 预览图
|
||||
// 页面配置
|
||||
'value' => [
|
||||
'bg_color' => '#F83530'
|
||||
],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
|
||||
/**
|
||||
* 活动专区——限时秒杀页面配置
|
||||
*/
|
||||
class SeckillZoneConfig
|
||||
{
|
||||
|
||||
public function handle($params)
|
||||
{
|
||||
if (empty($params) || $params[ 'name' ] == 'seckill') {
|
||||
$data = [
|
||||
'name' => 'seckill', // 标识
|
||||
'title' => '限时秒杀', // 名称
|
||||
'url' => 'shop/adv/lists?keyword=NS_SECKILL', // 自定义跳转链接
|
||||
'preview' => 'addon/seckill/shop/view/public/img/zone_preview.png', // 预览图
|
||||
// 页面配置
|
||||
'value' => [
|
||||
'bg_color' => '#F83530'
|
||||
],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,91 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
*/
|
||||
class ShowPromotion
|
||||
{
|
||||
public $promotion_type = 'time_limit';
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function handle($params = [])
|
||||
{
|
||||
$data = [
|
||||
'shop' => [
|
||||
[
|
||||
//插件名称
|
||||
'name' => 'seckill',
|
||||
//展示分类(根据平台端设置,shop:店铺营销,member:会员营销, tool:应用工具)
|
||||
'show_type' => 'shop',
|
||||
//展示主题
|
||||
'title' => '限时秒杀',
|
||||
//展示介绍
|
||||
'description' => '限时抢购引导客户快速下单',
|
||||
//展示图标
|
||||
'icon' => 'addon/seckill/icon.png',
|
||||
//跳转链接
|
||||
'url' => 'seckill://shop/seckill/goodslist',
|
||||
'summary' => $this->summary($params)
|
||||
]
|
||||
]
|
||||
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 营销活动概况
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
private function summary($params)
|
||||
{
|
||||
if (empty($params)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取活动数量
|
||||
if (isset($params[ 'count' ])) {
|
||||
$count = model("promotion_seckill")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
|
||||
return [
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
//获取活动概况,需要获取开始时间与结束时间
|
||||
if (isset($params[ 'summary' ])) {
|
||||
$list = model("promotion_seckill")->getList([
|
||||
[ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
|
||||
[ 'site_id', '=', $params[ 'site_id' ] ],
|
||||
[ 'status', '<>', 2 ],
|
||||
[ 'status', '<>', -1 ]
|
||||
], 'seckill_name as promotion_name,id as promotion_id,start_time,end_time', '', 'a', null, 'seckill_name');
|
||||
return !empty($list) ? [
|
||||
'time_limit' => [
|
||||
'count' => count($list),
|
||||
'detail' => $list,
|
||||
'color' => '#6D66FF'
|
||||
]
|
||||
] : [];
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
*/
|
||||
class ShowPromotion
|
||||
{
|
||||
public $promotion_type = 'time_limit';
|
||||
|
||||
/**
|
||||
* 活动展示
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function handle($params = [])
|
||||
{
|
||||
$data = [
|
||||
'shop' => [
|
||||
[
|
||||
//插件名称
|
||||
'name' => 'seckill',
|
||||
//展示分类(根据平台端设置,shop:店铺营销,member:会员营销, tool:应用工具)
|
||||
'show_type' => 'shop',
|
||||
//展示主题
|
||||
'title' => '限时秒杀',
|
||||
//展示介绍
|
||||
'description' => '限时抢购引导客户快速下单',
|
||||
//展示图标
|
||||
'icon' => 'addon/seckill/icon.png',
|
||||
//跳转链接
|
||||
'url' => 'seckill://shop/seckill/goodslist',
|
||||
'summary' => $this->summary($params)
|
||||
]
|
||||
]
|
||||
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 营销活动概况
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
private function summary($params)
|
||||
{
|
||||
if (empty($params)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取活动数量
|
||||
if (isset($params[ 'count' ])) {
|
||||
$count = model("promotion_seckill")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
|
||||
return [
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
//获取活动概况,需要获取开始时间与结束时间
|
||||
if (isset($params[ 'summary' ])) {
|
||||
$list = model("promotion_seckill")->getList([
|
||||
[ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
|
||||
[ 'site_id', '=', $params[ 'site_id' ] ],
|
||||
[ 'status', '<>', 2 ],
|
||||
[ 'status', '<>', -1 ]
|
||||
], 'seckill_name as promotion_name,id as promotion_id,start_time,end_time', '', 'a', null, 'seckill_name');
|
||||
return !empty($list) ? [
|
||||
'time_limit' => [
|
||||
'count' => count($list),
|
||||
'detail' => $list,
|
||||
'color' => '#6D66FF'
|
||||
]
|
||||
] : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/* try{
|
||||
execute_sql('addon/seckill/data/uninstall.sql');
|
||||
return success();
|
||||
}catch (\Exception $e)
|
||||
{
|
||||
return error('', $e->getMessage());
|
||||
} */
|
||||
return error("系统插件不能删除");
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\event;
|
||||
|
||||
/**
|
||||
* 应用卸载
|
||||
*/
|
||||
class UnInstall
|
||||
{
|
||||
/**
|
||||
* 执行卸载
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/* try{
|
||||
execute_sql('addon/seckill/data/uninstall.sql');
|
||||
return success();
|
||||
}catch (\Exception $e)
|
||||
{
|
||||
return error('', $e->getMessage());
|
||||
} */
|
||||
return error("系统插件不能删除");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,75 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\model;
|
||||
|
||||
use app\dict\order_refund\OrderRefundDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\Order;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\order\OrderRefund;
|
||||
use app\model\system\Pay;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 订单创建(秒杀)
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class SeckillOrder extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单关闭
|
||||
* @param $order_id
|
||||
*/
|
||||
public function cronOrderClose($order_id)
|
||||
{
|
||||
$order_info = model('order')->getInfo([['order_id', '=', $order_id], ['promotion_type', '=', 'seckill'], ['order_status', '=', -1]], 'promotion_id');
|
||||
if (!empty($order_info)) {
|
||||
$condition = array(
|
||||
["order_id", "=", $order_id]
|
||||
);
|
||||
$order_goods_list = model('order_goods')->getList($condition, "order_goods_id,sku_id,num,refund_status,use_point");
|
||||
foreach ($order_goods_list as $k => $v) {
|
||||
// 返还库存
|
||||
model("promotion_seckill")->setInc([['id', '=', $order_info["promotion_id"]]], "goods_stock", $v["num"]);
|
||||
model("promotion_seckill_goods")->setInc([["sku_id", '=', $v["sku_id"]], ["seckill_id", '=', $order_info["promotion_id"]]], "stock", $v["num"]);
|
||||
// 减少销量
|
||||
model("promotion_seckill")->setDec([['id', '=', $order_info["promotion_id"]]], "sale_num", $v["num"]);
|
||||
}
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取商品已秒杀数
|
||||
* @param $goods_id
|
||||
* @param $member_id
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodsSeckillNum($seckill_id)
|
||||
{
|
||||
$join = [
|
||||
['order o', 'o.order_id = og.order_id', 'left']
|
||||
];
|
||||
$num = model('order_goods')->getSum([
|
||||
['o.order_status', '<>', Order::ORDER_CLOSE],
|
||||
['o.promotion_type', '=', 'seckill'],
|
||||
['o.promotion_id', '=', $seckill_id],
|
||||
['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
|
||||
], 'og.num', 'og', $join);
|
||||
return $num;
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\model;
|
||||
|
||||
use app\dict\order_refund\OrderRefundDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\Order;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\order\OrderRefund;
|
||||
use app\model\system\Pay;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 订单创建(秒杀)
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class SeckillOrder extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单关闭
|
||||
* @param $order_id
|
||||
*/
|
||||
public function cronOrderClose($order_id)
|
||||
{
|
||||
$order_info = model('order')->getInfo([['order_id', '=', $order_id], ['promotion_type', '=', 'seckill'], ['order_status', '=', -1]], 'promotion_id');
|
||||
if (!empty($order_info)) {
|
||||
$condition = array(
|
||||
["order_id", "=", $order_id]
|
||||
);
|
||||
$order_goods_list = model('order_goods')->getList($condition, "order_goods_id,sku_id,num,refund_status,use_point");
|
||||
foreach ($order_goods_list as $k => $v) {
|
||||
// 返还库存
|
||||
model("promotion_seckill")->setInc([['id', '=', $order_info["promotion_id"]]], "goods_stock", $v["num"]);
|
||||
model("promotion_seckill_goods")->setInc([["sku_id", '=', $v["sku_id"]], ["seckill_id", '=', $order_info["promotion_id"]]], "stock", $v["num"]);
|
||||
// 减少销量
|
||||
model("promotion_seckill")->setDec([['id', '=', $order_info["promotion_id"]]], "sale_num", $v["num"]);
|
||||
}
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取商品已秒杀数
|
||||
* @param $goods_id
|
||||
* @param $member_id
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodsSeckillNum($seckill_id)
|
||||
{
|
||||
$join = [
|
||||
['order o', 'o.order_id = og.order_id', 'left']
|
||||
];
|
||||
$num = model('order_goods')->getSum([
|
||||
['o.order_status', '<>', Order::ORDER_CLOSE],
|
||||
['o.promotion_type', '=', 'seckill'],
|
||||
['o.promotion_id', '=', $seckill_id],
|
||||
['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
|
||||
], 'og.num', 'og', $join);
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
@@ -1,310 +1,302 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\model;
|
||||
|
||||
use addon\store\model\StoreGoodsSku;
|
||||
use app\dict\order_refund\OrderRefundDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\Order;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\order\OrderRefund;
|
||||
use app\model\store\Store;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
use app\model\express\Express;
|
||||
use app\model\system\Pay;
|
||||
use app\model\express\Config as ExpressConfig;
|
||||
use app\model\order\Config;
|
||||
use app\model\express\Local;
|
||||
|
||||
/**
|
||||
* 订单创建(秒杀)
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class SeckillOrderCreate extends BaseModel
|
||||
{
|
||||
|
||||
use OrderCreateTool;
|
||||
|
||||
public $seckill_id = 0;
|
||||
public $seckill_info = [];
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'seckill';
|
||||
$this->promotion_type_name = '秒杀';
|
||||
}
|
||||
/**
|
||||
* 订单创建
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//计算
|
||||
$this->confirm();
|
||||
if ($this->error > 0) {
|
||||
return $this->error(['error_code' => $this->error], $this->error_msg);
|
||||
}
|
||||
//订单创建数据
|
||||
$order_insert_data = $this->getOrderInsertData(['discount'], 'invert');
|
||||
$order_insert_data['store_id'] = $this->store_id;
|
||||
$order_insert_data['create_time'] = time();
|
||||
$order_insert_data['is_enable_refund'] = 0;
|
||||
//订单类型以及状态
|
||||
$this->orderType();
|
||||
$order_insert_data['order_type'] = $this->order_type['order_type_id'];
|
||||
$order_insert_data['order_type_name'] = $this->order_type['order_type_name'];
|
||||
$order_insert_data['order_status_name'] = $this->order_type['order_status']['name'];
|
||||
$order_insert_data['order_status_action'] = json_encode($this->order_type['order_status'], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
model('order')->startTrans();
|
||||
//循环生成多个订单
|
||||
try {
|
||||
$this->order_id = model('order')->add($order_insert_data);
|
||||
$order_goods_insert_data = [];
|
||||
//订单项目表
|
||||
foreach ($this->goods_list as &$order_goods_v) {
|
||||
$order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
|
||||
|
||||
model("promotion_seckill_goods")->setDec([['sku_id', '=', $order_goods_v['sku_id']], ['seckill_id', '=', $this->seckill_info["id"]]], "stock", $order_goods_v['num']);
|
||||
model("promotion_seckill")->setDec([['id', '=', $this->seckill_info["id"]]], "goods_stock", $order_goods_v['num']);
|
||||
// 增加销量
|
||||
model("promotion_seckill")->setInc([['id', '=', $this->seckill_info["id"]]], "sale_num", $order_goods_v['num']);
|
||||
}
|
||||
model('order_goods')->addList($order_goods_insert_data);
|
||||
|
||||
//扣除余额(统一扣除)
|
||||
$this->useBalance();
|
||||
//批量库存处理(卡密商品支付后在扣出库存)
|
||||
$this->batchDecOrderGoodssStock();
|
||||
model('order')->commit();
|
||||
//订单创建后事件
|
||||
$this->orderCreateAfter();
|
||||
//支付单据
|
||||
$pay = new Pay();
|
||||
$pay->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '');
|
||||
return $this->success($this->out_trade_no);
|
||||
} catch ( \Exception $e ) {
|
||||
model('order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算后的进一步计算(不存缓存,每次都是重新计算)
|
||||
* @return array
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$order_key = $this->param['order_key'];
|
||||
$this->getOrderCache($order_key);
|
||||
//初始化地址
|
||||
$this->initMemberAddress();
|
||||
//初始化门店信息
|
||||
$this->initStore();
|
||||
//配送计算
|
||||
$this->calculateDelivery();
|
||||
//批量校验配送方式
|
||||
$this->batchCheckDeliveryType();
|
||||
//计算发票相关
|
||||
$this->calculateInvoice();
|
||||
//计算余额
|
||||
$this->calculateBalcnce();
|
||||
$this->pay_money = $this->order_money - $this->balance_money;
|
||||
//设置过的商品项信息
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单计算
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
//初始化会员地址
|
||||
$this->initMemberAddress();
|
||||
$this->initMemberAccount();//初始化会员账户
|
||||
//商品列表信息
|
||||
$this->getOrderGoodsCalculate();
|
||||
//查询秒杀信息
|
||||
$seckill_model = new Seckill();
|
||||
$seckill_info = $seckill_model->getSeckillInfo($this->seckill_id)['data'] ?? [];
|
||||
if (empty($seckill_info)) throw new OrderException("找不到可用的秒杀活动");
|
||||
$this->seckill_info = $seckill_info;
|
||||
//判断秒杀时间段是否符合
|
||||
$today_time = strtotime(date("Y-m-d"), time());
|
||||
$time = time() - $today_time;//当日时间戳
|
||||
if ($time < $this->seckill_info["seckill_start_time"] || $time > $this->seckill_info["seckill_end_time"]) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = "当前商品秒杀活动未开启或已过期!";
|
||||
}
|
||||
|
||||
//秒杀库存
|
||||
if ($this->goods_list[0]) {
|
||||
$seckill_goods = $seckill_model->getSeckillGoodsInfo([['psg.seckill_id', '=', $this->seckill_id], ['psg.sku_id', '=', $this->goods_list[0]['sku_id']]], 'psg.stock')['data'] ?? [];
|
||||
$seckill_goods_stock = $seckill_goods['stock'];
|
||||
if ($this->goods_list[0]['num'] > $seckill_goods_stock) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = "该商品库存不足";
|
||||
}
|
||||
}
|
||||
|
||||
// 秒杀商品限购 按每日某时段限购
|
||||
if ($this->goods_list[0]['limit_num'] > 0) {
|
||||
$purchased_num = $this->getGoodsPurchasedNum($this->goods_list[0]['sku_id'], $this->member_id, $this->seckill_info['id']);
|
||||
if (($purchased_num + $this->goods_list[0]['num']) > $this->goods_list[0]['limit_num']) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = "该商品每人限购{$this->goods_list[ 0 ]['limit_num']}件,您已购买{$purchased_num}件";
|
||||
}
|
||||
}
|
||||
$this->shopOrderCalculate();
|
||||
//获取发票相关
|
||||
$this->getInovice();
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待付款订单
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function orderPayment()
|
||||
{
|
||||
//计算
|
||||
$this->calculate();
|
||||
//查询配送信息
|
||||
$this->getDeliveryData();
|
||||
//订单初始项
|
||||
event('OrderPayment', ['order_object' => $this]);
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的计算信息
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function getOrderGoodsCalculate()
|
||||
{
|
||||
$this->getSeckillGoodsInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒杀商品列表信息
|
||||
* @param $id
|
||||
* @param $num
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function getSeckillGoodsInfo()
|
||||
{
|
||||
$id = $this->param['id'];
|
||||
$sku_id = $this->param['sku_id'];
|
||||
$num = $this->param['num'];
|
||||
//组装商品列表
|
||||
$field = 'npsg.sku_id,npsg.seckill_id,npsg.seckill_price,npsg.max_buy as limit_num,ngs.sku_name, ngs.sku_no,
|
||||
ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image,
|
||||
ngs.site_id, ns.site_name, ngs.goods_state, ngs.is_virtual,ngs.supplier_id,
|
||||
ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name,ngs.goods_id,ngs.sku_spec_format,ngs.goods_name,ngs.support_trade_type';
|
||||
$alias = 'npsg';
|
||||
$join = [
|
||||
[
|
||||
'goods_sku ngs',
|
||||
'npsg.sku_id = ngs.sku_id',
|
||||
'inner'
|
||||
],
|
||||
[
|
||||
'site ns',
|
||||
'ngs.site_id = ns.site_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
|
||||
$condition = [
|
||||
['npsg.sku_id', '=', $sku_id],
|
||||
['npsg.seckill_id', '=', $id],
|
||||
['npsg.site_id', '=', $this->site_id]
|
||||
];
|
||||
$info = model("promotion_seckill_goods")->getInfo($condition, $field, $alias, $join);
|
||||
if (empty($info)) throw new OrderException('无效的商品!');
|
||||
//判断是否是虚拟订单
|
||||
$this->seckill_id = $info['seckill_id'];
|
||||
if ($info['is_virtual']) {
|
||||
$this->is_virtual = 1;
|
||||
} else {
|
||||
$this->is_virtual = 0;
|
||||
}
|
||||
$info["num"] = $num;
|
||||
$price = $info["seckill_price"];//订单项商品单价
|
||||
$goods_money = $price * $info['num'];
|
||||
$info["price"] = $price;
|
||||
$info['goods_money'] = $goods_money;//订单项商品总价
|
||||
$info['real_goods_money'] = $goods_money;//真实商品金额
|
||||
$info['coupon_money'] = 0;//优惠券金额
|
||||
$info['promotion_money'] = 0;//优惠金额
|
||||
|
||||
$this->site_name = $info['site_name'];
|
||||
$this->goods_money = $goods_money;
|
||||
$this->goods_list_str = $info['sku_id'] . ':' . $info['num'];
|
||||
$this->order_name = string_split("", ",", $info['sku_name']);
|
||||
$this->goods_num = $info['num'];
|
||||
$this->goods_list[] = $info;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺订单计算
|
||||
*/
|
||||
public function shopOrderCalculate()
|
||||
{
|
||||
//重新计算订单总额
|
||||
$this->getOrderMoney();
|
||||
//理论上是多余的操作
|
||||
if ($this->order_money < 0) {
|
||||
$this->order_money = 0;
|
||||
}
|
||||
//总结计算
|
||||
$this->pay_money = $this->order_money;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取会员该秒杀时段已购该商品数
|
||||
* @param $goods_id
|
||||
* @param $member_id
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodsPurchasedNum($sku_id, $member_id, $seckill_id)
|
||||
{
|
||||
$join = [
|
||||
['order o', 'o.order_id = og.order_id', 'left']
|
||||
];
|
||||
$num = model('order_goods')->getSum([
|
||||
['og.member_id', '=', $member_id],
|
||||
['og.sku_id', '=', $sku_id],
|
||||
['o.order_status', '<>', Order::ORDER_CLOSE],
|
||||
['o.promotion_type', '=', 'seckill'],
|
||||
['o.promotion_id', '=', $seckill_id],
|
||||
['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
|
||||
['o.create_time', 'between', [date_to_time(date('Y-m-d 00:00:00')), time()]]
|
||||
], 'og.num', 'og', $join);
|
||||
return $num;
|
||||
}
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\model;
|
||||
|
||||
use addon\store\model\StoreGoodsSku;
|
||||
use app\dict\order_refund\OrderRefundDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\Order;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\order\OrderRefund;
|
||||
use app\model\store\Store;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
use app\model\express\Express;
|
||||
use app\model\system\Pay;
|
||||
use app\model\express\Config as ExpressConfig;
|
||||
use app\model\order\Config;
|
||||
use app\model\express\Local;
|
||||
|
||||
/**
|
||||
* 订单创建(秒杀)
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class SeckillOrderCreate extends BaseModel
|
||||
{
|
||||
|
||||
use OrderCreateTool;
|
||||
|
||||
public $seckill_id = 0;
|
||||
public $seckill_info = [];
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'seckill';
|
||||
$this->promotion_type_name = '秒杀';
|
||||
}
|
||||
/**
|
||||
* 订单创建
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//计算
|
||||
$this->confirm();
|
||||
if ($this->error > 0) {
|
||||
return $this->error(['error_code' => $this->error], $this->error_msg);
|
||||
}
|
||||
//订单创建数据
|
||||
$order_insert_data = $this->getOrderInsertData(['discount'], 'invert');
|
||||
$order_insert_data['store_id'] = $this->store_id;
|
||||
$order_insert_data['create_time'] = time();
|
||||
$order_insert_data['is_enable_refund'] = 0;
|
||||
//订单类型以及状态
|
||||
$this->orderType();
|
||||
$order_insert_data['order_type'] = $this->order_type['order_type_id'];
|
||||
$order_insert_data['order_type_name'] = $this->order_type['order_type_name'];
|
||||
$order_insert_data['order_status_name'] = $this->order_type['order_status']['name'];
|
||||
$order_insert_data['order_status_action'] = json_encode($this->order_type['order_status'], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
model('order')->startTrans();
|
||||
//循环生成多个订单
|
||||
try {
|
||||
$this->order_id = model('order')->add($order_insert_data);
|
||||
$order_goods_insert_data = [];
|
||||
//订单项目表
|
||||
foreach ($this->goods_list as &$order_goods_v) {
|
||||
$order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
|
||||
|
||||
model("promotion_seckill_goods")->setDec([['sku_id', '=', $order_goods_v['sku_id']], ['seckill_id', '=', $this->seckill_info["id"]]], "stock", $order_goods_v['num']);
|
||||
model("promotion_seckill")->setDec([['id', '=', $this->seckill_info["id"]]], "goods_stock", $order_goods_v['num']);
|
||||
// 增加销量
|
||||
model("promotion_seckill")->setInc([['id', '=', $this->seckill_info["id"]]], "sale_num", $order_goods_v['num']);
|
||||
}
|
||||
model('order_goods')->addList($order_goods_insert_data);
|
||||
|
||||
//扣除余额(统一扣除)
|
||||
$this->useBalance();
|
||||
//批量库存处理(卡密商品支付后在扣出库存)
|
||||
$this->batchDecOrderGoodssStock();
|
||||
model('order')->commit();
|
||||
//订单创建后事件
|
||||
$this->orderCreateAfter();
|
||||
//支付单据
|
||||
$pay = new Pay();
|
||||
$pay->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '');
|
||||
return $this->success($this->out_trade_no);
|
||||
} catch ( \Exception $e ) {
|
||||
model('order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算后的进一步计算(不存缓存,每次都是重新计算)
|
||||
* @return array
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$order_key = $this->param['order_key'];
|
||||
$this->getOrderCache($order_key);
|
||||
//初始化地址
|
||||
$this->initMemberAddress();
|
||||
//初始化门店信息
|
||||
$this->initStore();
|
||||
//配送计算
|
||||
$this->calculateDelivery();
|
||||
//批量校验配送方式
|
||||
$this->batchCheckDeliveryType();
|
||||
//计算发票相关
|
||||
$this->calculateInvoice();
|
||||
//计算余额
|
||||
$this->calculateBalcnce();
|
||||
$this->pay_money = $this->order_money - $this->balance_money;
|
||||
//设置过的商品项信息
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单计算
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
//初始化会员地址
|
||||
$this->initMemberAddress();
|
||||
$this->initMemberAccount();//初始化会员账户
|
||||
//商品列表信息
|
||||
$this->getOrderGoodsCalculate();
|
||||
//查询秒杀信息
|
||||
$seckill_model = new Seckill();
|
||||
$seckill_info = $seckill_model->getSeckillInfo($this->seckill_id)['data'] ?? [];
|
||||
if (empty($seckill_info)) throw new OrderException("找不到可用的秒杀活动");
|
||||
$this->seckill_info = $seckill_info;
|
||||
//判断秒杀时间段是否符合
|
||||
$today_time = strtotime(date("Y-m-d"), time());
|
||||
$time = time() - $today_time;//当日时间戳
|
||||
if ($time < $this->seckill_info["seckill_start_time"] || $time > $this->seckill_info["seckill_end_time"]) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = "当前商品秒杀活动未开启或已过期!";
|
||||
}
|
||||
|
||||
//秒杀库存
|
||||
if ($this->goods_list[0]) {
|
||||
$seckill_goods = $seckill_model->getSeckillGoodsInfo([['psg.seckill_id', '=', $this->seckill_id], ['psg.sku_id', '=', $this->goods_list[0]['sku_id']]], 'psg.stock')['data'] ?? [];
|
||||
$seckill_goods_stock = $seckill_goods['stock'];
|
||||
if ($this->goods_list[0]['num'] > $seckill_goods_stock) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = "该商品库存不足";
|
||||
}
|
||||
}
|
||||
|
||||
// 秒杀商品限购 按每日某时段限购
|
||||
if ($this->goods_list[0]['limit_num'] > 0) {
|
||||
$purchased_num = $this->getGoodsPurchasedNum($this->goods_list[0]['sku_id'], $this->member_id, $this->seckill_info['id']);
|
||||
if (($purchased_num + $this->goods_list[0]['num']) > $this->goods_list[0]['limit_num']) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = "该商品每人限购{$this->goods_list[ 0 ]['limit_num']}件,您已购买{$purchased_num}件";
|
||||
}
|
||||
}
|
||||
$this->shopOrderCalculate();
|
||||
//获取发票相关
|
||||
$this->getInovice();
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待付款订单
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function orderPayment()
|
||||
{
|
||||
//计算
|
||||
$this->calculate();
|
||||
//查询配送信息
|
||||
$this->getDeliveryData();
|
||||
//订单初始项
|
||||
event('OrderPayment', ['order_object' => $this]);
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的计算信息
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function getOrderGoodsCalculate()
|
||||
{
|
||||
$this->getSeckillGoodsInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒杀商品列表信息
|
||||
* @param $id
|
||||
* @param $num
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function getSeckillGoodsInfo()
|
||||
{
|
||||
$id = $this->param['id'];
|
||||
$sku_id = $this->param['sku_id'];
|
||||
$num = $this->param['num'];
|
||||
//组装商品列表
|
||||
$field = 'npsg.sku_id,npsg.seckill_id,npsg.seckill_price,npsg.max_buy as limit_num,ngs.sku_name, ngs.sku_no,
|
||||
ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image,
|
||||
ngs.site_id, ns.site_name, ngs.goods_state, ngs.is_virtual,ngs.supplier_id,
|
||||
ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name,ngs.goods_id,ngs.sku_spec_format,ngs.goods_name,ngs.support_trade_type';
|
||||
$alias = 'npsg';
|
||||
$join = [
|
||||
[
|
||||
'goods_sku ngs',
|
||||
'npsg.sku_id = ngs.sku_id',
|
||||
'inner'
|
||||
],
|
||||
[
|
||||
'site ns',
|
||||
'ngs.site_id = ns.site_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
|
||||
$condition = [
|
||||
['npsg.sku_id', '=', $sku_id],
|
||||
['npsg.seckill_id', '=', $id],
|
||||
['npsg.site_id', '=', $this->site_id]
|
||||
];
|
||||
$info = model("promotion_seckill_goods")->getInfo($condition, $field, $alias, $join);
|
||||
if (empty($info)) throw new OrderException('无效的商品!');
|
||||
//判断是否是虚拟订单
|
||||
$this->seckill_id = $info['seckill_id'];
|
||||
if ($info['is_virtual']) {
|
||||
$this->is_virtual = 1;
|
||||
} else {
|
||||
$this->is_virtual = 0;
|
||||
}
|
||||
$info["num"] = $num;
|
||||
$price = $info["seckill_price"];//订单项商品单价
|
||||
$goods_money = $price * $info['num'];
|
||||
$info["price"] = $price;
|
||||
$info['goods_money'] = $goods_money;//订单项商品总价
|
||||
$info['real_goods_money'] = $goods_money;//真实商品金额
|
||||
$info['coupon_money'] = 0;//优惠券金额
|
||||
$info['promotion_money'] = 0;//优惠金额
|
||||
|
||||
$this->site_name = $info['site_name'];
|
||||
$this->goods_money = $goods_money;
|
||||
$this->goods_list_str = $info['sku_id'] . ':' . $info['num'];
|
||||
$this->order_name = string_split("", ",", $info['sku_name']);
|
||||
$this->goods_num = $info['num'];
|
||||
$this->goods_list[] = $info;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺订单计算
|
||||
*/
|
||||
public function shopOrderCalculate()
|
||||
{
|
||||
//重新计算订单总额
|
||||
$this->getOrderMoney();
|
||||
//理论上是多余的操作
|
||||
if ($this->order_money < 0) {
|
||||
$this->order_money = 0;
|
||||
}
|
||||
//总结计算
|
||||
$this->pay_money = $this->order_money;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取会员该秒杀时段已购该商品数
|
||||
* @param $goods_id
|
||||
* @param $member_id
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodsPurchasedNum($sku_id, $member_id, $seckill_id)
|
||||
{
|
||||
$join = [
|
||||
['order o', 'o.order_id = og.order_id', 'left']
|
||||
];
|
||||
$num = model('order_goods')->getSum([
|
||||
['og.member_id', '=', $member_id],
|
||||
['og.sku_id', '=', $sku_id],
|
||||
['o.order_status', '<>', Order::ORDER_CLOSE],
|
||||
['o.promotion_type', '=', 'seckill'],
|
||||
['o.promotion_id', '=', $seckill_id],
|
||||
['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
|
||||
['o.create_time', 'between', [date_to_time(date('Y-m-d 00:00:00')), time()]]
|
||||
], 'og.num', 'og', $join);
|
||||
return $num;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,141 +1,132 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\model\share;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
use app\model\share\WchatShareBase as BaseModel;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WchatShare extends BaseModel
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '秒杀分享',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_PROMOTE',
|
||||
'path' => [ '/pages_promotion/seckill/detail' ],
|
||||
'method_prefix' => 'goodsDetail',
|
||||
],
|
||||
[
|
||||
'title' => '秒杀列表',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_LIST_PROMOTE',
|
||||
'path' => [ '/pages_promotion/seckill/list' ],
|
||||
'method_prefix' => 'goodsList',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 8;
|
||||
|
||||
/**
|
||||
* 秒杀列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsListShareData($param)
|
||||
{
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$config_data = $this->goodsListShareConfig($param)[ 'value' ];
|
||||
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $config_data[ 'desc' ],
|
||||
'imgUrl' => $config_data[ 'imgUrl' ],
|
||||
'title' => $config_data[ 'title' ]
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀列表分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function goodsListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "秒杀列表",
|
||||
'desc' => "秒杀进行时\n快来参与吧",
|
||||
'imgUrl' => ''
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/seckill/icon.png');
|
||||
}
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsDetailShareData($param)
|
||||
{
|
||||
$url = $param[ 'url' ];
|
||||
|
||||
$parse_res = parse_url($url);
|
||||
parse_str($parse_res[ 'query' ] ?? '', $query);
|
||||
|
||||
if (isset($query[ 'seckill_id' ]) || $query[ 'id' ]) {
|
||||
$seckill_id = $query['seckill_id'] ?? $query['id'];
|
||||
$goods = new Seckill();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.site_id', '=', 1 ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$sku_info = $goods->getSeckillGoodsInfo($condition)[ 'data' ];
|
||||
if (!empty($sku_info)) {
|
||||
$config_model = new \app\model\share\WchatShare();
|
||||
$config_data = $config_model->goodsDetailShareConfig($param);
|
||||
|
||||
$title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$desc = str_replace('{price}', $sku_info[ 'seckill_price' ], $config_data[ 'value' ][ 'desc' ]);
|
||||
$link = $this->getShareLink($param);
|
||||
$image_url = $sku_info[ 'sku_image' ];
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\model\share;
|
||||
|
||||
use addon\seckill\model\Seckill;
|
||||
use app\model\share\WchatShareBase as BaseModel;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WchatShare extends BaseModel
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '秒杀分享',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_PROMOTE',
|
||||
'path' => [ '/pages_promotion/seckill/detail' ],
|
||||
'method_prefix' => 'goodsDetail',
|
||||
],
|
||||
[
|
||||
'title' => '秒杀列表',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_LIST_PROMOTE',
|
||||
'path' => [ '/pages_promotion/seckill/list' ],
|
||||
'method_prefix' => 'goodsList',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 8;
|
||||
|
||||
/**
|
||||
* 秒杀列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsListShareData($param)
|
||||
{
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$config_data = $this->goodsListShareConfig($param)[ 'value' ];
|
||||
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $config_data[ 'desc' ],
|
||||
'imgUrl' => $config_data[ 'imgUrl' ],
|
||||
'title' => $config_data[ 'title' ]
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀列表分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function goodsListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "秒杀列表",
|
||||
'desc' => "秒杀进行时\n快来参与吧",
|
||||
'imgUrl' => ''
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/seckill/icon.png');
|
||||
}
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsDetailShareData($param)
|
||||
{
|
||||
$url = $param[ 'url' ];
|
||||
|
||||
$parse_res = parse_url($url);
|
||||
parse_str($parse_res[ 'query' ] ?? '', $query);
|
||||
|
||||
if (isset($query[ 'seckill_id' ]) || $query[ 'id' ]) {
|
||||
$seckill_id = $query['seckill_id'] ?? $query['id'];
|
||||
$goods = new Seckill();
|
||||
$condition = [
|
||||
[ 'ps.id', '=', $seckill_id ],
|
||||
[ 'psg.site_id', '=', 1 ],
|
||||
[ 'psg.status', '=', 1 ],
|
||||
[ 'ps.status', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
];
|
||||
$sku_info = $goods->getSeckillGoodsInfo($condition)[ 'data' ];
|
||||
if (!empty($sku_info)) {
|
||||
$config_model = new \app\model\share\WchatShare();
|
||||
$config_data = $config_model->goodsDetailShareConfig($param);
|
||||
|
||||
$title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$desc = str_replace('{price}', $sku_info[ 'seckill_price' ], $config_data[ 'value' ][ 'desc' ]);
|
||||
$link = $this->getShareLink($param);
|
||||
$image_url = $sku_info[ 'sku_image' ];
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,394 +1,386 @@
|
||||
<?php
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
namespace addon\seckill\shop\controller;
|
||||
|
||||
use app\shop\controller\BaseShop;
|
||||
use addon\seckill\model\Seckill as SeckillModel;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* 秒杀控制器
|
||||
*/
|
||||
class Seckill extends BaseShop
|
||||
{
|
||||
public function __construct(App $app = null)
|
||||
{
|
||||
$this->replace = [
|
||||
'SECKILL_CSS' => __ROOT__ . '/addon/seckill/shop/view/public/css',
|
||||
'SECKILL_JS' => __ROOT__ . '/addon/seckill/shop/view/public/js',
|
||||
'SECKILL_IMG' => __ROOT__ . '/addon/seckill/shop/view/public/img',
|
||||
];
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀时间段列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = '*';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
|
||||
foreach ($res[ 'data' ] as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
}
|
||||
return $res;
|
||||
} else {
|
||||
|
||||
return $this->fetch("seckill/lists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加秒杀时间段
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$start_hour = input('start_hour', 0);
|
||||
$start_minute = input('start_minute', 0);
|
||||
$start_second = input('start_second', 0);
|
||||
|
||||
$end_hour = input('end_hour', 0);
|
||||
$end_minute = input('end_minute', 0);
|
||||
$end_second = input('end_second', 0);
|
||||
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'name' => input('name', ''),
|
||||
'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
|
||||
'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
|
||||
'create_time' => time(),
|
||||
];
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->addSeckillTime($data);
|
||||
} else {
|
||||
return $this->fetch("seckill/add");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑秒杀时间段
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$seckill_model = new SeckillModel();
|
||||
if (request()->isJson()) {
|
||||
$start_hour = input('start_hour', 0);
|
||||
$start_minute = input('start_minute', 0);
|
||||
$start_second = input('start_second', 0);
|
||||
|
||||
$end_hour = input('end_hour', 0);
|
||||
$end_minute = input('end_minute', 0);
|
||||
$end_second = input('end_second', 0);
|
||||
|
||||
$data = [
|
||||
'name' => input('name', ''),
|
||||
'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
|
||||
'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
|
||||
'create_time' => time(),
|
||||
'id' => input('id', 0),
|
||||
];
|
||||
return $seckill_model->editSeckillTime($data, $this->site_id);
|
||||
} else {
|
||||
$id = input('id', 0);
|
||||
$this->assign('id', $id);
|
||||
|
||||
//秒杀详情
|
||||
$time_info = $seckill_model->getSeckillTimeInfo([ [ 'id', '=', $id ] ]);
|
||||
if (!empty($time_info[ 'data' ])) {
|
||||
$time_info[ 'data' ] = $seckill_model->transformSeckillTime($time_info[ 'data' ]);
|
||||
}
|
||||
$this->assign('time_info', $time_info[ 'data' ]);
|
||||
|
||||
return $this->fetch("seckill/edit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除秒杀时间段
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_time_id = input('id', 0);
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->deleteSeckillTime($seckill_time_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加秒杀商品
|
||||
*/
|
||||
public function addGoods()
|
||||
{
|
||||
$seckill_model = new SeckillModel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'seckill_name' => input('seckill_name', ''),
|
||||
'remark' => input('remark', ''),
|
||||
'seckill_time_id' => input('seckill_time_id', ''),
|
||||
'start_time' => strtotime(input('start_time', '')),
|
||||
'end_time' => strtotime(input('end_time', '')),
|
||||
'goods_data' => input('goods_data', ''),
|
||||
'goods_ids' => input('goods_ids', ''),
|
||||
'sort' => input('sort', '')
|
||||
];
|
||||
$res = $seckill_model->addSeckillGoods($data);
|
||||
return $res;
|
||||
} else {
|
||||
return $this->fetch("seckill/editgoods");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品(秒杀价格)
|
||||
*/
|
||||
public function updateGoods()
|
||||
{
|
||||
$seckill_model = new SeckillModel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'id' => input('id', ''),
|
||||
'seckill_name' => input('seckill_name', ''),
|
||||
'remark' => input('remark', ''),
|
||||
'seckill_time_id' => input('seckill_time_id', ''),
|
||||
'start_time' => strtotime(input('start_time', '')),
|
||||
'end_time' => strtotime(input('end_time', '')),
|
||||
'sku_list' => input('sku_list', ''),
|
||||
'goods_ids' => input('goods_ids', ''),
|
||||
'sort' => input('sort', ''),
|
||||
];
|
||||
$res = $seckill_model->editSeckillGoods($data);
|
||||
return $res;
|
||||
} else {
|
||||
$seckill_id = input('id', '');
|
||||
if (empty($seckill_id)) {
|
||||
$this->error('缺少参数id');
|
||||
}
|
||||
$seckill_info = $seckill_model->getSeckillDetail([ [ 'id', '=', $seckill_id ] ])[ 'data' ];
|
||||
|
||||
$seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
|
||||
$time_list = $seckill_model->getSeckillTimeList([ [ 'id', 'in', $seckill_time_id ] ])[ 'data' ];
|
||||
|
||||
$this->assign('seckill_info', $seckill_info);
|
||||
$this->assign('time_list', $time_list);
|
||||
|
||||
return $this->fetch("seckill/editgoods");
|
||||
}
|
||||
}
|
||||
|
||||
public function seckillSort()
|
||||
{
|
||||
$sort = input('sort', 0);
|
||||
$id = input('id', 0);
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->seckillSort($id, $sort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
public function deleteGoods()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_id = input('id', 0);
|
||||
$site_id = $this->site_id;
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->deleteSeckillGoods($seckill_id, $site_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀商品
|
||||
*/
|
||||
public function goodslist()
|
||||
{
|
||||
$seckill_time_id = input('seckill_time_id', '');
|
||||
if (request()->isJson()) {
|
||||
$page = input('page', 1);
|
||||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||||
$goods_name = input('goods_name', '');
|
||||
$status = input('status', '');
|
||||
$link_sort = input('order', 'start_time');
|
||||
$sort = input('sort', 'desc');
|
||||
|
||||
$condition = [];
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'goods_name', 'like', '%' . $goods_name . '%' ];
|
||||
|
||||
if ($status !== '') $condition[] = [ 'status', '=', $status ];
|
||||
//排序
|
||||
if ($link_sort == 'sort') {
|
||||
$order_by = $link_sort . ' ' . $sort;
|
||||
} else {
|
||||
$order_by = $link_sort . ' ' . $sort . ',sort desc';
|
||||
}
|
||||
|
||||
if (!empty($seckill_time_id)) {
|
||||
$condition[] = [ '', 'exp', \think\facade\Db::raw("FIND_IN_SET({$seckill_time_id},seckill_time_id)") ];
|
||||
}
|
||||
|
||||
$start_time = input('start_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
|
||||
if ($start_time && !$end_time) {
|
||||
$condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
|
||||
} elseif (!$start_time && $end_time) {
|
||||
$condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
|
||||
} elseif ($start_time && $end_time) {
|
||||
$start_timestamp = date_to_time($start_time);
|
||||
$end_timestamp = date_to_time($end_time);
|
||||
$sql = "start_time between {$start_timestamp} and {$end_timestamp}";
|
||||
$sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
|
||||
$sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
|
||||
$condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
|
||||
}
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_list = $seckill_model->getSeckillPageList($condition, $page, $page_size, $order_by);
|
||||
|
||||
$seckill_condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
|
||||
$time_list = $seckill_model->getSeckillTimeList($seckill_condition);
|
||||
foreach ($seckill_list[ 'data' ][ 'list' ] as $k => $v) {
|
||||
$seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ] = [];
|
||||
foreach ($time_list[ 'data' ] as $index => $item) {
|
||||
if (strpos(',' . $v[ 'seckill_time_id' ] . ',', ',' . $item[ 'id' ] . ',') !== false) {
|
||||
$seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $seckill_list;
|
||||
} else {
|
||||
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = '*';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
|
||||
$this->assign('seckill_time_id', $seckill_time_id);
|
||||
$this->assign('res', $res[ 'data' ]);
|
||||
return $this->fetch("seckill/goodslist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀时段
|
||||
*/
|
||||
public function seckilltimeselect()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = '*';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
|
||||
foreach ($res[ 'data' ] as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
}
|
||||
return $res;
|
||||
} else {
|
||||
|
||||
return $this->fetch("seckill/seckilltimeselect");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品列表
|
||||
* @return array
|
||||
*/
|
||||
public function getSkuList()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_id = input('seckill_id', '');
|
||||
$goods_list = $seckill_model->getSeckillGoodsList($seckill_id);
|
||||
return $goods_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动关闭秒杀
|
||||
* @return array
|
||||
*/
|
||||
public function closeSeckill()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_id = input('seckill_id', '');
|
||||
$goods_list = $seckill_model->closeSeckill($seckill_id);
|
||||
return $goods_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀推广
|
||||
*/
|
||||
public function seckillUrl()
|
||||
{
|
||||
$seckill_id = input('seckill_id', '');
|
||||
$app_type = input('app_type', 'all');
|
||||
$seckill_model = new SeckillModel();
|
||||
|
||||
$res = $seckill_model->urlQrcode('/pages_promotion/seckill/detail', [ 'id' => $seckill_id ], 'seckill', $app_type, $this->site_id);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除商品
|
||||
*/
|
||||
public function deleteGoodsAll()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_id = input('seckill_id', 0);
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
foreach ($seckill_id as $k => $v){
|
||||
$res = $seckill_model->deleteSeckillGoods($v, $this->site_id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量关闭秒杀
|
||||
* @return array
|
||||
*/
|
||||
public function closeSeckillAll()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_id = input('seckill_id', '');
|
||||
|
||||
foreach ($seckill_id as $k => $v){
|
||||
$res = $seckill_model->closeSeckill($v);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
namespace addon\seckill\shop\controller;
|
||||
|
||||
use app\shop\controller\BaseShop;
|
||||
use addon\seckill\model\Seckill as SeckillModel;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* 秒杀控制器
|
||||
*/
|
||||
class Seckill extends BaseShop
|
||||
{
|
||||
public function __construct(App $app = null)
|
||||
{
|
||||
$this->replace = [
|
||||
'SECKILL_CSS' => __ROOT__ . '/addon/seckill/shop/view/public/css',
|
||||
'SECKILL_JS' => __ROOT__ . '/addon/seckill/shop/view/public/js',
|
||||
'SECKILL_IMG' => __ROOT__ . '/addon/seckill/shop/view/public/img',
|
||||
];
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀时间段列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = '*';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
|
||||
foreach ($res[ 'data' ] as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
}
|
||||
return $res;
|
||||
} else {
|
||||
|
||||
return $this->fetch("seckill/lists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加秒杀时间段
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$start_hour = input('start_hour', 0);
|
||||
$start_minute = input('start_minute', 0);
|
||||
$start_second = input('start_second', 0);
|
||||
|
||||
$end_hour = input('end_hour', 0);
|
||||
$end_minute = input('end_minute', 0);
|
||||
$end_second = input('end_second', 0);
|
||||
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'name' => input('name', ''),
|
||||
'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
|
||||
'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
|
||||
'create_time' => time(),
|
||||
];
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->addSeckillTime($data);
|
||||
} else {
|
||||
return $this->fetch("seckill/add");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑秒杀时间段
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$seckill_model = new SeckillModel();
|
||||
if (request()->isJson()) {
|
||||
$start_hour = input('start_hour', 0);
|
||||
$start_minute = input('start_minute', 0);
|
||||
$start_second = input('start_second', 0);
|
||||
|
||||
$end_hour = input('end_hour', 0);
|
||||
$end_minute = input('end_minute', 0);
|
||||
$end_second = input('end_second', 0);
|
||||
|
||||
$data = [
|
||||
'name' => input('name', ''),
|
||||
'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
|
||||
'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
|
||||
'create_time' => time(),
|
||||
'id' => input('id', 0),
|
||||
];
|
||||
return $seckill_model->editSeckillTime($data, $this->site_id);
|
||||
} else {
|
||||
$id = input('id', 0);
|
||||
$this->assign('id', $id);
|
||||
|
||||
//秒杀详情
|
||||
$time_info = $seckill_model->getSeckillTimeInfo([ [ 'id', '=', $id ] ]);
|
||||
if (!empty($time_info[ 'data' ])) {
|
||||
$time_info[ 'data' ] = $seckill_model->transformSeckillTime($time_info[ 'data' ]);
|
||||
}
|
||||
$this->assign('time_info', $time_info[ 'data' ]);
|
||||
|
||||
return $this->fetch("seckill/edit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除秒杀时间段
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_time_id = input('id', 0);
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->deleteSeckillTime($seckill_time_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加秒杀商品
|
||||
*/
|
||||
public function addGoods()
|
||||
{
|
||||
$seckill_model = new SeckillModel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'seckill_name' => input('seckill_name', ''),
|
||||
'remark' => input('remark', ''),
|
||||
'seckill_time_id' => input('seckill_time_id', ''),
|
||||
'start_time' => strtotime(input('start_time', '')),
|
||||
'end_time' => strtotime(input('end_time', '')),
|
||||
'goods_data' => input('goods_data', ''),
|
||||
'goods_ids' => input('goods_ids', ''),
|
||||
'sort' => input('sort', '')
|
||||
];
|
||||
$res = $seckill_model->addSeckillGoods($data);
|
||||
return $res;
|
||||
} else {
|
||||
return $this->fetch("seckill/editgoods");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品(秒杀价格)
|
||||
*/
|
||||
public function updateGoods()
|
||||
{
|
||||
$seckill_model = new SeckillModel();
|
||||
if (request()->isJson()) {
|
||||
$data = [
|
||||
'site_id' => $this->site_id,
|
||||
'id' => input('id', ''),
|
||||
'seckill_name' => input('seckill_name', ''),
|
||||
'remark' => input('remark', ''),
|
||||
'seckill_time_id' => input('seckill_time_id', ''),
|
||||
'start_time' => strtotime(input('start_time', '')),
|
||||
'end_time' => strtotime(input('end_time', '')),
|
||||
'sku_list' => input('sku_list', ''),
|
||||
'goods_ids' => input('goods_ids', ''),
|
||||
'sort' => input('sort', ''),
|
||||
];
|
||||
$res = $seckill_model->editSeckillGoods($data);
|
||||
return $res;
|
||||
} else {
|
||||
$seckill_id = input('id', '');
|
||||
if (empty($seckill_id)) {
|
||||
$this->error('缺少参数id');
|
||||
}
|
||||
$seckill_info = $seckill_model->getSeckillDetail([ [ 'id', '=', $seckill_id ] ])[ 'data' ];
|
||||
|
||||
$seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
|
||||
$time_list = $seckill_model->getSeckillTimeList([ [ 'id', 'in', $seckill_time_id ] ])[ 'data' ];
|
||||
|
||||
$this->assign('seckill_info', $seckill_info);
|
||||
$this->assign('time_list', $time_list);
|
||||
|
||||
return $this->fetch("seckill/editgoods");
|
||||
}
|
||||
}
|
||||
|
||||
public function seckillSort()
|
||||
{
|
||||
$sort = input('sort', 0);
|
||||
$id = input('id', 0);
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->seckillSort($id, $sort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
public function deleteGoods()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_id = input('id', 0);
|
||||
$site_id = $this->site_id;
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
return $seckill_model->deleteSeckillGoods($seckill_id, $site_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀商品
|
||||
*/
|
||||
public function goodslist()
|
||||
{
|
||||
$seckill_time_id = input('seckill_time_id', '');
|
||||
if (request()->isJson()) {
|
||||
$page = input('page', 1);
|
||||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||||
$goods_name = input('goods_name', '');
|
||||
$status = input('status', '');
|
||||
$link_sort = input('order', 'start_time');
|
||||
$sort = input('sort', 'desc');
|
||||
|
||||
$condition = [];
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'goods_name', 'like', '%' . $goods_name . '%' ];
|
||||
|
||||
if ($status !== '') $condition[] = [ 'status', '=', $status ];
|
||||
//排序
|
||||
if ($link_sort == 'sort') {
|
||||
$order_by = $link_sort . ' ' . $sort;
|
||||
} else {
|
||||
$order_by = $link_sort . ' ' . $sort . ',sort desc';
|
||||
}
|
||||
|
||||
if (!empty($seckill_time_id)) {
|
||||
$condition[] = [ '', 'exp', \think\facade\Db::raw("FIND_IN_SET({$seckill_time_id},seckill_time_id)") ];
|
||||
}
|
||||
|
||||
$start_time = input('start_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
|
||||
if ($start_time && !$end_time) {
|
||||
$condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
|
||||
} elseif (!$start_time && $end_time) {
|
||||
$condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
|
||||
} elseif ($start_time && $end_time) {
|
||||
$start_timestamp = date_to_time($start_time);
|
||||
$end_timestamp = date_to_time($end_time);
|
||||
$sql = "start_time between {$start_timestamp} and {$end_timestamp}";
|
||||
$sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
|
||||
$sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
|
||||
$condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
|
||||
}
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_list = $seckill_model->getSeckillPageList($condition, $page, $page_size, $order_by);
|
||||
|
||||
$seckill_condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
|
||||
$time_list = $seckill_model->getSeckillTimeList($seckill_condition);
|
||||
foreach ($seckill_list[ 'data' ][ 'list' ] as $k => $v) {
|
||||
$seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ] = [];
|
||||
foreach ($time_list[ 'data' ] as $index => $item) {
|
||||
if (strpos(',' . $v[ 'seckill_time_id' ] . ',', ',' . $item[ 'id' ] . ',') !== false) {
|
||||
$seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $seckill_list;
|
||||
} else {
|
||||
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = '*';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
|
||||
$this->assign('seckill_time_id', $seckill_time_id);
|
||||
$this->assign('res', $res[ 'data' ]);
|
||||
return $this->fetch("seckill/goodslist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀时段
|
||||
*/
|
||||
public function seckilltimeselect()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$condition[] = [ 'site_id', '=', $this->site_id ];
|
||||
$order = 'seckill_start_time asc';
|
||||
$field = '*';
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
$res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
|
||||
foreach ($res[ 'data' ] as $key => $val) {
|
||||
$val = $seckill_model->transformSeckillTime($val);
|
||||
$res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
|
||||
$res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
|
||||
}
|
||||
return $res;
|
||||
} else {
|
||||
|
||||
return $this->fetch("seckill/seckilltimeselect");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品列表
|
||||
* @return array
|
||||
*/
|
||||
public function getSkuList()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_id = input('seckill_id', '');
|
||||
$goods_list = $seckill_model->getSeckillGoodsList($seckill_id);
|
||||
return $goods_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动关闭秒杀
|
||||
* @return array
|
||||
*/
|
||||
public function closeSeckill()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_id = input('seckill_id', '');
|
||||
$goods_list = $seckill_model->closeSeckill($seckill_id);
|
||||
return $goods_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀推广
|
||||
*/
|
||||
public function seckillUrl()
|
||||
{
|
||||
$seckill_id = input('seckill_id', '');
|
||||
$app_type = input('app_type', 'all');
|
||||
$seckill_model = new SeckillModel();
|
||||
|
||||
$res = $seckill_model->urlQrcode('/pages_promotion/seckill/detail', [ 'id' => $seckill_id ], 'seckill', $app_type, $this->site_id);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除商品
|
||||
*/
|
||||
public function deleteGoodsAll()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_id = input('seckill_id', 0);
|
||||
|
||||
$seckill_model = new SeckillModel();
|
||||
foreach ($seckill_id as $k => $v){
|
||||
$res = $seckill_model->deleteSeckillGoods($v, $this->site_id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量关闭秒杀
|
||||
* @return array
|
||||
*/
|
||||
public function closeSeckillAll()
|
||||
{
|
||||
if (request()->isJson()) {
|
||||
$seckill_model = new SeckillModel();
|
||||
$seckill_id = input('seckill_id', '');
|
||||
|
||||
foreach ($seckill_id as $k => $v){
|
||||
$res = $seckill_model->closeSeckill($v);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user