初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

618
addon/seckill/model/Poster.php Executable file
View File

@@ -0,0 +1,618 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\seckill\model;
use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
use app\model\BaseModel;
use app\model\system\Site;
use app\model\upload\Upload;
use app\model\web\Config;
use extend\Poster as PosterExtend;
/**
* 海报生成类
*/
class Poster extends BaseModel
{
/**
* 商品海报
*/
public function goods($app_type, $page, $qrcode_param, $promotion_type, $site_id)
{
try {
$goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
if (empty($goods_info)) return $this->error('未获取到商品信息');
$qrcode_param[ 'id' ] = $qrcode_param[ 'seckillId' ];
unset($qrcode_param[ 'seckillId' ]);
$qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
//判断海报是否存在或停用
$template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
if (!empty($qrcode_param[ 'source_member' ])) {
$member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
}
$upload_config_model = new Config();
$upload_config_result = $upload_config_model->getDefaultImg($site_id);
$site_model = new Site();
$condition = array (
[ "site_id", "=", $site_id ]
);
$site_info = $site_model->getSiteInfo($condition);
if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
$poster_width = 720;
$poster_height = 1150;
$poster = new PosterExtend($poster_width, $poster_height);
$option = [
[
'action' => 'setBackground', // 设背景色
'data' => [ 255, 255, 255 ]
],
[
'action' => 'imageCopy', // 写入商品图
'data' => [
explode(',', $goods_info[ 'sku_image' ])[ 0 ] ?? '',
50,
165,
620,
620,
'square',
true,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$goods_info[ 'sku_name' ],
22,
[ 35, 35, 35 ],
50,
915,
360,
2,
true,
1
]
],
[
'action' => 'imageCopy', // 写入商品二维码
'data' => [
$qrcode_info[ 'data' ][ 'path' ],
435,
825,
240,
240,
'square',
0,
1
]
],
[
'action' => 'imageText', // 写入提示
'data' => [
'长按识别二维码',
19,
[ 102, 102, 102 ],
465,
1110,
490,
1,
1,
1
]
],
[
'action' => 'imageText', // 写入商品价格单位
'data' => [
'秒杀价:¥',
22,
[ 255, 0, 0 ],
50,
860,
490,
2,
true,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
$goods_info[ 'seckill_price' ],
30,
[ 255, 0, 0 ],
188,
862,
490,
2,
true,
1
]
],
];
if (!empty($member_info)) {
$member_option = [
[
'action' => 'imageCircularCopy', // 写入用户头像
'data' => [
!empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
50,
30,
100,
100
]
],
[
'action' => 'imageText', // 写入分享人昵称
'data' => [
$member_info[ 'nickname' ],
22,
[ 10, 10, 10 ],
170,
80,
580,
1,
1,
1
]
],
[
'action' => 'imageText', // 写入分享人昵称
'data' => [
'限时秒杀,抢到就是赚到',
18,
[ 102, 102, 102 ],
170,
115,
580,
1,
1,
1
]
]
];
$option = array_merge($option, $member_option);
}
} else {
$condition = [
[ 'template_id', '=', $goods_info[ 'template_id' ] ],
[ 'site_id', '=', $site_id ]
];
$poster_template_model = new PosterTemplateModel();
$poster_data = $poster_template_model->getPosterTemplateInfo($condition);
$poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
$poster_width = 720;
$poster_height = 1280;
$poster = new PosterExtend($poster_width, $poster_height);
$fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
if (!empty($poster_data[ 'data' ][ 'background' ])) {
list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
$height = 720 * $height / $width;
$back_ground = [
'action' => 'imageCopy', // 写入背景图
'data' => [
img($poster_data[ 'data' ][ 'background' ]),
0,
0,
$poster_width,
$height,
'square',
true,
1
]
];
} else {
$back_ground = [
'action' => 'setBackground', // 设背景色
'data' => [ 255, 255, 255 ]
];
}
$ground = [
[
'action' => 'setBackground',
'data' => [ 255, 255, 255 ]
]
];
$option = [
$back_ground,
[
'action' => 'imageText', // 写入店铺名称
'data' => [
$site_info[ 'data' ][ 'site_name' ],
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
]
],
[
'action' => 'imageCopy', // 店铺logo
'data' => [
!empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
'square',
true,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
]
],
[
'action' => 'imageCopy', // 写入商品图
'data' => [
$goods_info[ 'sku_image' ],
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
!empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
0,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$goods_info[ 'sku_name' ],
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
]
],
[
'action' => 'imageCopy', // 写入商品二维码
'data' => [
$qrcode_info[ 'data' ][ 'path' ],
$poster_data[ 'data' ][ 'qrcode_left' ] * 2,
$poster_data[ 'data' ][ 'qrcode_top' ] * 2,
$poster_data[ 'data' ][ 'qrcode_width' ] * 2,
$poster_data[ 'data' ][ 'qrcode_height' ] * 2,
'square',
0,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
'¥' . $goods_info[ 'seckill_price' ],
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
]
],
];
if ($goods_info[ 'price' ] == 0) {
$line = '一一一';
} else {
$line = '一一一一';
}
$market_price = [
[
'action' => 'imageText', // 写入商品划线价格
'data' => [
'¥' . $goods_info[ 'price' ],
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ] ?? 0
]
],
[
'action' => 'imageText', // 写入线
'data' => [
$line,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2 - 5,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ]
]
],
];
$option = array_merge($option, $market_price);
if (!empty($member_info)) {
$member_option = [
[
'action' => 'imageCopy', // 写入用户头像
'data' => [
!empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
!empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
0,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
]
],
[
'action' => 'imageText', // 写入分享人昵称
'data' => [
$member_info[ 'nickname' ],
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
0,
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
]
],
];
$option = array_merge($ground, $option, $member_option);
}
}
$option_res = $poster->create($option);
if (is_array($option_res)) return $option_res;
$res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . time() . '_' . $app_type);
if ($res[ 'code' ] == 0) {
$upload = new Upload($site_id);
$cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
if ($cloud_res[ 'code' ] >= 0) {
return $this->success([ "path" => $cloud_res[ 'data' ] ]);
} else {
return $this->error();
}
}
return $res;
} catch (\Exception $e) {
return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
}
}
/**
* 获取用户信息
* @param unknown $member_id
*/
private function getMemberInfo($member_id)
{
$info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
return $info;
}
/**
* 获取商品信息
* @param unknown $sku_id
*/
private function getGoodsInfo($id)
{
$alias = 'npsg';
$join = [
[ 'goods_sku ngs', 'npsg.sku_id = ngs.sku_id', 'inner' ]
];
$field = 'ngs.sku_name,ngs.introduction,ngs.sku_image,ngs.sku_id,npsg.seckill_price, npsg.seckill_id,ngs.template_id,ngs.price';
$info = model('promotion_seckill_goods')->getInfo([ 'npsg.goods_id' => $id ], $field, $alias, $join);
return $info;
}
/**
* 获取商品二维码
* @param unknown $app_type 请求类型
* @param unknown $page uniapp页面路径
* @param unknown $qrcode_param 二维码携带参数
* @param string $promotion_type 活动类型 null为无活动
*/
private function getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id)
{
$res = event('Qrcode', [
'site_id' => $site_id,
'app_type' => $app_type,
'type' => 'create',
'data' => $qrcode_param,
'page' => $page,
'qrcode_path' => 'upload/qrcode/goods',
'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
], true);
return $res;
}
/**
* 获取海报信息
* @param unknown $template_id
*/
private function getTemplateInfo($template_id)
{
$info = model('poster_template')->getInfo([ 'template_id' => $template_id ], 'template_id,template_status');
return $info;
}
/**
* 分享图片
* @param $page
* @param $qrcode_param
* @param $site_id
* @return array|\extend\multitype|PosterExtend|string|string[]
*/
public function shareImg($page, $qrcode_param, $site_id)
{
try {
$goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
if (empty($goods_info)) return $this->error('未获取到商品信息');
$poster_width = 600;
$poster_height = 480;
$poster = new PosterExtend($poster_width, $poster_height);
$option = [
[
'action' => 'setBackground', // 设背景色
'data' => [ 255, 255, 255 ]
],
[
'action' => 'imageCopy', // 商品图
'data' => [
$goods_info[ 'sku_image' ],
30,
145,
200,
200,
'square',
50,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$goods_info[ 'sku_name' ],
22,
[ 51, 51, 51 ],
250,
190,
330,
2,
false,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
'秒杀价:¥',
15,
[ 255, 0, 0 ],
250,
300,
300,
2,
false,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
$goods_info[ 'seckill_price' ],
30,
[ 255, 0, 0 ],
345,
300,
300,
2,
false,
1,
PUBLIC_PATH . 'static/font/custom.ttf'
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
'原 价:¥',
15,
[ 153, 153, 153 ],
250,
340,
300,
2,
false,
1
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
$goods_info[ 'price' ],
16,
[ 153, 153, 153 ],
345,
338,
300,
2,
false,
1,
PUBLIC_PATH . 'static/font/custom.ttf',
]
],
// 划线(两条线)
[
'action' => 'imageline',
'data' => [
325,
330,
325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
330,
[ 153, 153, 153 ],
]
],
[
'action' => 'imageline',
'data' => [
325,
331,
325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
331,
[ 153, 153, 153 ],
]
],
[
'action' => 'imageCopy', // 背景图
'data' => [
img('upload/share_img/bg/seckill_1.png'),
0,
0,
600,
480,
'square',
0,
1
]
],
];
$option_res = $poster->create($option);
if (is_array($option_res)) {
return $option_res;
}
$res = $option_res->jpeg('upload/share_img/seckill_' . $goods_info[ 'seckill_id' ], 'sku_' . $goods_info[ 'sku_id' ]);
return $res;
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
}

949
addon/seckill/model/Seckill.php Executable file
View File

@@ -0,0 +1,949 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\seckill\model;
use app\dict\order_refund\OrderRefundDict;
use app\model\BaseModel;
use app\model\goods\Goods;
use app\model\order\Order;
use app\model\system\Config as ConfigModel;
use app\model\system\Cron;
use think\facade\Cache;
use think\facade\Db;
/**
* 限时秒杀(时段)
*/
class Seckill extends BaseModel
{
/**
* 添加秒杀时段
* @param $data
* @return array
*/
public function addSeckillTime($data)
{
if ($data[ 'seckill_start_time' ] > $data[ 'seckill_end_time' ]) {
return $this->error('', '秒杀时间段设置错误');
}
//时间段检测
$seckill_count = model('promotion_seckill_time')->getCount([
['seckill_start_time|seckill_end_time', 'between', [$data[ 'seckill_start_time' ], $data[ 'seckill_end_time' ]]],
['site_id', '=', $data[ 'site_id' ]]
]);
if ($seckill_count > 0) {
return $this->error('', '秒杀场次设置冲突');
}
$seckill_count = model('promotion_seckill_time')->getCount([
['seckill_start_time', '<=', $data[ 'seckill_start_time' ]],
['seckill_end_time', '>=', $data[ 'seckill_end_time' ]],
['site_id', '=', $data[ 'site_id' ]]
]);
if ($seckill_count > 0) {
return $this->error('', '秒杀场次设置冲突');
}
//添加数据
$data[ 'create_time' ] = time();
$seckill_id = model('promotion_seckill_time')->add($data);
Cache::tag("promotion_seckill_time")->clear();
return $this->success($seckill_id);
}
/**
* 修改秒杀时段
* @param $data
* @param $site_id
* @return array
*/
public function editSeckillTime($data, $site_id)
{
if ($data[ 'seckill_start_time' ] > $data[ 'seckill_end_time' ]) {
return $this->error('', '秒杀时间段设置错误');
}
//时间段检测
$seckill_count = model('promotion_seckill_time')->getCount([
['seckill_start_time|seckill_end_time', 'between', [$data[ 'seckill_start_time' ], $data[ 'seckill_end_time' ]]],
['site_id', '=', $site_id],
['id', '<>', $data[ 'id' ]]
]);
if ($seckill_count > 0) {
return $this->error('', '秒杀场次设置冲突');
}
$seckill_count = model('promotion_seckill_time')->getCount([
['seckill_start_time', '<=', $data[ 'seckill_start_time' ]],
['seckill_end_time', '>=', $data[ 'seckill_end_time' ]],
['site_id', '=', $site_id],
['id', '<>', $data[ 'id' ]]
]);
if ($seckill_count > 0) {
return $this->error('', '秒杀场次设置冲突');
}
//更新数据
$data[ 'modify_time' ] = time();
$res = model('promotion_seckill_time')->update($data, [['id', '=', $data[ 'id' ]]]);
Cache::tag("promotion_seckill_time")->clear();
return $this->success($res);
}
/**
* 删除秒杀时段
* @param $seckill_time_id
* @return array
*/
public function deleteSeckillTime($seckill_time_id)
{
$res = model('promotion_seckill_time')->delete([['id', '=', $seckill_time_id]]);
if ($res) {
$goods = new Goods();
$condition = [
['seckill_time_id', 'like', '%,' . $seckill_time_id . ',%']
];
$seckill_list = model('promotion_seckill')->getList($condition, 'id,seckill_time_id,goods_id');
foreach ($seckill_list as $k => $v) {
$time_ids = explode(',', trim($v[ 'seckill_time_id' ], ','));
unset($time_ids[ array_search($seckill_time_id, $time_ids) ]);
if (empty($time_ids)) {
$goods->modifyPromotionAddon($v[ 'goods_id' ], ['seckill' => $v[ 'id' ]], true);
model('promotion_seckill_goods')->delete([['seckill_id', '=', $v[ 'id' ]]]);
model('promotion_seckill')->delete([['id', '=', $v[ 'id' ]]]);
} else {
$time_id = ',' . implode(',', $time_ids) . ',';
model('promotion_seckill')->update(['seckill_time_id' => $time_id], [['id', '=', $v[ 'id' ]]]);
model('promotion_seckill_goods')->update(['seckill_time_id' => $time_id], [['seckill_id', '=', $v[ 'id' ]]]);
}
}
}
Cache::tag("promotion_seckill_time")->clear();
return $this->success($res);
}
/**
* 获取秒杀时段信息
* @param $condition
* @param string $field
* @return array
*/
public function getSeckillTimeInfo($condition, $field = '*')
{
$res = model('promotion_seckill_time')->getInfo($condition, $field);
return $this->success($res);
}
/**
* 获取秒杀时段列表
* @param array $condition
* @param string $field
* @param string $order
* @param null $limit
* @return array
*/
public function getSeckillTimeList($condition = [], $field = '*', $order = '', $limit = null)
{
$list = model('promotion_seckill_time')->getList($condition, $field, $order, '', '', '', $limit);
return $this->success($list);
}
/**
* 获取有商品的秒杀时段列表
* @param $condition
* @param $field
* @param string $order
* @return array
*/
public function getGoodsSeckillTimeList($condition, $field, $order = 'seckill_start_time asc')
{
if (empty($field)) {
$field = 'id, site_id, name, seckill_start_time, seckill_end_time';
}
$seckill_time = model('promotion_seckill_time')->getList($condition, $field, $order);
foreach ($seckill_time as $k => $v) {
$condition = [
['seckill_time_id', 'like', '%,' . $v[ 'id' ] . ',%'],
['status', '=', 1],
['g.goods_state', '=', 1],
['g.is_delete', '=', 0]
];
$join = [
['goods g', 'g.goods_id = psg.goods_id', 'inner']
];
$goods = model('promotion_seckill_goods')->getInfo($condition, 'id', 'psg', $join);
if (empty($goods)) unset($seckill_time[ $k ]);
}
return $this->success($seckill_time);
}
/**
* 转换秒杀时间
* @param $info
* @return mixed
*/
public function transformSeckillTime($info)
{
$info[ 'start_hour' ] = floor($info[ 'seckill_start_time' ] / 3600);
$info[ 'start_minute' ] = floor(($info[ 'seckill_start_time' ] % 3600) / 60);
$info[ 'start_second' ] = $info[ 'seckill_start_time' ] % 60;
$info[ 'end_hour' ] = floor($info[ 'seckill_end_time' ] / 3600);
$info[ 'end_minute' ] = floor(($info[ 'seckill_end_time' ] % 3600) / 60);
$info[ 'end_second' ] = $info[ 'seckill_end_time' ] % 60;
if ($info[ 'start_hour' ] < 10) $info[ 'start_hour' ] = '0' . $info[ 'start_hour' ];
if ($info[ 'start_minute' ] < 10) $info[ 'start_minute' ] = '0' . $info[ 'start_minute' ];
if ($info[ 'start_second' ] < 10) $info[ 'start_second' ] = '0' . $info[ 'start_second' ];
if ($info[ 'end_hour' ] < 10) $info[ 'end_hour' ] = '0' . $info[ 'end_hour' ];
if ($info[ 'end_minute' ] < 10) $info[ 'end_minute' ] = '0' . $info[ 'end_minute' ];
if ($info[ 'end_second' ] < 10) $info[ 'end_second' ] = '0' . $info[ 'end_second' ];
return $info;
}
/******************************************************秒杀商品*********************************************************************/
/**
* 添加秒杀商品
* @param $data
* @return array
*/
public function addSeckillGoods($data)
{
$cron = new Cron();
$goods_data = $data[ 'goods_data' ];
if (empty($data[ 'seckill_time_id' ])) {
return $this->error('', '请选择秒杀时段');
}
$seckill_time_id = explode(',', $data[ 'seckill_time_id' ]);
//时间段检测
foreach ($seckill_time_id as $v) {
$seckill_count = model('promotion_seckill')->getCount([
['goods_id', 'in', $data[ 'goods_ids' ]],
['status', 'in', '0,1'],
['seckill_time_id', 'like', '%,' . $v . ',%'],
['site_id', '=', $data[ 'site_id' ]],
['', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))')]//todo 修正 所有的优惠都要一样
]);
if ($seckill_count > 0) {
return $this->error('', '有商品已设置秒杀,请不要重复设置');
}
}
model('promotion_seckill')->startTrans();
try {
$seckill_data = [
'site_id' => $data[ 'site_id' ],
'seckill_name' => $data[ 'seckill_name' ],
'remark' => $data[ 'remark' ],
'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
'start_time' => $data[ 'start_time' ],
'end_time' => $data[ 'end_time' ],
'create_time' => time(),
'sort' => $data[ 'sort' ],
];
$goods = new Goods();
$add_goods_data = [];
foreach ($goods_data as $k => $v) {
$seckill_data[ 'goods_id' ] = $v[ 'goods_id' ];
$seckill_data[ 'goods_name' ] = $v[ 'sku_list' ][ 0 ][ 'sku_name' ];
$seckill_data[ 'goods_image' ] = $v[ 'sku_list' ][ 0 ][ 'sku_image' ];
$seckill_data[ 'seckill_price' ] = $v[ 'sku_list' ][ 0 ][ 'seckill_price' ];
if ($data[ 'start_time' ] <= time()) {
$seckill_data[ 'status' ] = 1;//直接启动
$seckill_id = model('promotion_seckill')->add($seckill_data);
$goods->modifyPromotionAddon($v[ 'goods_id' ], ['seckill' => $seckill_id]);
$cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
} else {
$seckill_data[ 'status' ] = 0;
$seckill_id = model('promotion_seckill')->add($seckill_data);
$cron->addCron(1, 0, "秒杀开启", "OpenSeckill", $data[ 'start_time' ], $seckill_id);
$cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
}
$goods_stock = 0; // 秒杀商品总库存
foreach ($v[ 'sku_list' ] as $key => $item) {
$sku_info = model('goods_sku')->getInfo([['sku_id', '=', $item[ 'sku_id' ]]], 'goods_id, sku_id, sku_name,price,sku_image');
$add_goods_data[] = [
'site_id' => $data[ 'site_id' ],
'seckill_id' => $seckill_id,
'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
'sku_id' => $item[ 'sku_id' ],
'goods_id' => $item[ 'goods_id' ],
'sku_image' => $sku_info[ 'sku_image' ],
'sku_name' => $sku_info[ 'sku_name' ],
'seckill_price' => $item[ 'seckill_price' ],
'price' => $sku_info[ 'price' ],
'stock' => $item[ 'seckill_stock' ],
'max_buy' => $item[ 'max_buy' ],
'status' => $seckill_data[ 'status' ]
];
$goods_stock += $item[ 'seckill_stock' ];
}
model('promotion_seckill')->update(['goods_stock' => $goods_stock], [['id', '=', $seckill_id]]);
}
model('promotion_seckill_goods')->addList($add_goods_data);
foreach ($seckill_time_id as $v) {
$count = model('promotion_seckill_goods')->getCount([['seckill_time_id', 'like', '%,' . $v . ',%']], '*', 'a', '', 'goods_id');
model('promotion_seckill_time')->update(['goods_num' => $count], [['id', '=', $v]]);
}
model('promotion_seckill')->commit();
return $this->success();
} catch (\Exception $e) {
model('promotion_seckill')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 修改秒杀商品
* @param $data
* @return array
*/
public function editSeckillGoods($data)
{
$cron = new Cron();
if (empty($data[ 'seckill_time_id' ])) {
return $this->error('', '请选择秒杀时段');
}
$seckill_time_id = explode(',', $data[ 'seckill_time_id' ]);
//时间段检测
foreach ($seckill_time_id as $v) {
$seckill_count = model('promotion_seckill')->getInfo([
['goods_id', 'in', $data[ 'goods_ids' ]],
['status', 'in', '0,1'],
['site_id', '=', $data[ 'site_id' ]],
['seckill_time_id', 'like', '%,' . $v . ',%'],
['id', '<>', $data[ 'id' ]],
['', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))')]//todo 修正 所有的优惠都要一样
]);
if ($seckill_count > 0) {
return $this->error('', '有商品已设置秒杀,请不要重复设置');
}
}
model('promotion_seckill')->startTrans();
try {
$seckill_data = [
'site_id' => $data[ 'site_id' ],
'seckill_name' => $data[ 'seckill_name' ],
'remark' => $data[ 'remark' ],
'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
'start_time' => $data[ 'start_time' ],
'end_time' => $data[ 'end_time' ],
'modify_time' => time(),
'sort' => $data[ 'sort' ],
];
$goods = new Goods();
$add_goods_data = [];
$seckill_data[ 'goods_id' ] = $data[ 'sku_list' ][ 0 ][ 'goods_id' ];
$seckill_data[ 'goods_name' ] = $data[ 'sku_list' ][ 0 ][ 'sku_name' ];
$seckill_data[ 'goods_image' ] = $data[ 'sku_list' ][ 0 ][ 'sku_image' ];
$seckill_data[ 'seckill_price' ] = $data[ 'sku_list' ][ 0 ][ 'seckill_price' ];
$seckill_id = $data[ 'id' ];
if ($data[ 'start_time' ] <= time()) {
$seckill_data[ 'status' ] = 1;//直接启动
model('promotion_seckill')->update($seckill_data, [['id', '=', $seckill_id]]);
$goods->modifyPromotionAddon($data[ 'sku_list' ][ 0 ][ 'goods_id' ], ['seckill' => $seckill_id]);
$cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
} else {
$seckill_data[ 'status' ] = 0;
model('promotion_seckill')->update($seckill_data, [['id', '=', $seckill_id]]);
$cron->addCron(1, 0, "秒杀开启", "OpenSeckill", $data[ 'start_time' ], $seckill_id);
$cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
}
model('promotion_seckill_goods')->delete([['seckill_id', '=', $seckill_id]]);
$goods_stock = 0; // 秒杀商品总库存
foreach ($data[ 'sku_list' ] as $key => $item) {
$sku_info = model('goods_sku')->getInfo([['sku_id', '=', $item[ 'sku_id' ]]], 'goods_id, sku_id, sku_name,price,sku_image');
$add_goods_data[] = [
'site_id' => $data[ 'site_id' ],
'seckill_id' => $seckill_id,
'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
'sku_id' => $item[ 'sku_id' ],
'goods_id' => $item[ 'goods_id' ],
'sku_image' => $sku_info[ 'sku_image' ],
'sku_name' => $sku_info[ 'sku_name' ],
'seckill_price' => $item[ 'seckill_price' ],
'price' => $sku_info[ 'price' ],
'stock' => $item[ 'seckill_stock' ],
'max_buy' => $item[ 'max_buy' ],
'status' => $seckill_data[ 'status' ]
];
$goods_stock += $item[ 'seckill_stock' ];
}
model('promotion_seckill')->update(['goods_stock' => $goods_stock], [['id', '=', $seckill_id]]);
model('promotion_seckill_goods')->addList($add_goods_data);
foreach ($seckill_time_id as $v) {
$count = model('promotion_seckill_goods')->getCount([['seckill_time_id', 'like', '%,' . $v . ',%']], '*', 'a', '', 'goods_id');
model('promotion_seckill_time')->update(['goods_num' => $count], [['id', '=', $v]]);
}
model('promotion_seckill')->commit();
return $this->success();
} catch (\Exception $e) {
model('promotion_seckill')->rollback();
return $this->error('', $e->getMessage());
}
}
public function seckillSort($id, $sort)
{
$res = model('promotion_seckill')->update(['sort' => $sort], [['id', '=', $id]]);
return $this->success($res);
}
/**
* 秒杀商品详情
* @param array $condition
* @param string $field
* @param string $alias
* @param array $join
* @return array
*/
public function getSeckillDetail($condition = [], $field = '*', $alias = '', $join = [])
{
$info = model("promotion_seckill")->getInfo($condition, $field, $alias, $join);
$goods_sku = model('goods_sku')->getList([['goods_id', '=', $info[ 'goods_id' ]], ['is_delete', '=', 0], ['goods_state', '=', 1]], 'stock as goods_stock, goods_id, sku_id, sku_name,price,sku_image,stock');
$discount_goods = model("promotion_seckill_goods")->getList([['goods_id', '=', $info[ 'goods_id' ]], ['seckill_id', '=', $info[ 'id' ]]], '*');
foreach ($goods_sku as $k => $v) {
$goods_sku[ $k ][ 'is_select' ] = 0;
$goods_sku[ $k ][ 'seckill_price' ] = $v[ 'price' ];
$goods_sku[ $k ][ 'seckill_stock' ] = 0;
$goods_sku[ $k ][ 'max_buy' ] = 0;
$goods_sku[ $k ][ 'stock' ] = numberFormat($goods_sku[ $k ][ 'stock' ]);
$goods_sku[ $k ][ 'goods_stock' ] = numberFormat($goods_sku[ $k ][ 'goods_stock' ]);
foreach ($discount_goods as $key => $val) {
if ($val[ 'sku_id' ] == $v[ 'sku_id' ]) {
$goods_sku[ $k ][ 'is_select' ] = 1;
$goods_sku[ $k ][ 'seckill_price' ] = $val[ 'seckill_price' ];
$goods_sku[ $k ][ 'seckill_stock' ] = $val[ 'stock' ];
$goods_sku[ $k ][ 'max_buy' ] = $val[ 'max_buy' ];
}
}
}
$info[ 'goods_sku' ] = $goods_sku;
$info[ 'seckill_goods' ] = $discount_goods;
return $this->success($info);
}
/**
* 修改秒杀商品限购数量
* @param $seckill_id
* @param $site_id
* @param $sku_id
* @param $max_buy
* @return array
*/
public function editSeckillGoodsNum($seckill_id, $site_id, $sku_id, $max_buy)
{
$data = [
'seckill_id' => $seckill_id,
'site_id' => $site_id,
'sku_id' => $sku_id,
'max_buy' => $max_buy
];
model("promotion_seckill_goods")->update($data, [['seckill_id', '=', $seckill_id], ['sku_id', '=', $sku_id], ['site_id', '=', $site_id]]);
return $this->success();
}
/**
* 删除秒杀商品
* @param $seckill_id
* @param $site_id
* @return array
*/
public function deleteSeckillGoods($seckill_id, $site_id)
{
$info = model("promotion_seckill")->getInfo([['id', '=', $seckill_id]], 'goods_id,seckill_time_id,status');
if (empty($info)) return $this->error('', '该秒杀活动不存在');
if ($info[ 'status' ] == 1) return $this->error('', '该秒杀活动正在进行');
$goods = new Goods();
$goods->modifyPromotionAddon($info[ 'goods_id' ], ['seckill' => $seckill_id], true);
model("promotion_seckill")->delete([['id', '=', $seckill_id], ['site_id', '=', $site_id]]);
$goods_num = model("promotion_seckill_goods")->delete([['seckill_id', '=', $seckill_id], ['site_id', '=', $site_id]]);
$seckill_time_id = explode(',', $info[ 'seckill_time_id' ]);
foreach ($seckill_time_id as $v) {
$count = model('promotion_seckill_goods')->getCount([['seckill_time_id', 'like', '%,' . $v . ',%']], '*', 'a', '', 'goods_id');
model('promotion_seckill_time')->update(['goods_num' => $count], [['id', '=', $v]]);
}
return $this->success();
}
/**
* 获取秒杀详情
* @param $seckill_id
* @return array
*/
public function getSeckillInfo($seckill_id)
{
$seckill_info = model('promotion_seckill')->getInfo([['id', '=', $seckill_id]]);
if (empty($seckill_info)) {
return $this->success([]);
}
$seckill_info[ 'seckill_start_time' ] = 0;
$seckill_info[ 'seckill_end_time' ] = 0;
$today_time = strtotime(date("Y-m-d"), time());
$time = time() - $today_time;//当日时间戳
$seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
$condition = [
['id', 'in', $seckill_time_id],
['seckill_start_time', '<=', $time],
['seckill_end_time', '>', $time],
];
$time_list = model('promotion_seckill_time')->getList($condition, 'seckill_start_time, seckill_end_time', 'seckill_start_time asc', '', '', '', 1);
if (count($time_list) > 0) {
$seckill_info[ 'seckill_start_time' ] = $time_list[ 0 ][ 'seckill_start_time' ];
$seckill_info[ 'seckill_end_time' ] = $time_list[ 0 ][ 'seckill_end_time' ];
}
//所有秒杀时间段
$seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
$condition = [
['id', 'in', $seckill_time_id],
];
$time_list = model('promotion_seckill_time')->getList($condition, 'seckill_start_time, seckill_end_time', 'seckill_start_time asc');
$seckill_info['time_list'] = $time_list;
return $this->success($seckill_info);
}
/**
* 获取秒杀列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return mixed
*/
public function getSeckillPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '', $alias = '', $join = [])
{
$list = model('promotion_seckill')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
return $this->success($list);
}
/**
* 获取秒杀商品列表
* @param $seckill_time_id
* @param $site_id
* @param int $page
* @param int $page_size
* @return array
*/
public function getSeckillGoodsPageList($seckill_time_id, $site_id, $page = 1, $page_size = PAGE_LIST_ROWS, $seckill_time_type = 'today')
{
//判断时间段
$seckill_time_info = model('promotion_seckill_time')->getInfo([['id', '=', $seckill_time_id]]);
$day_start_time = strtotime(date('Y-m-d'));
if($seckill_time_type == 'tomorrow'){
$day_start_time += 3600*24;
}
$start_time = $day_start_time + $seckill_time_info['seckill_start_time'];
$end_time = $day_start_time + $seckill_time_info['seckill_end_time'];
$alias = 'ps';
$join = [
['goods g', 'ps.goods_id = g.goods_id', 'inner'],
['promotion_seckill_goods psg', 'psg.seckill_id = ps.id', 'inner'],
['goods_sku gs', 'psg.sku_id = gs.sku_id', 'inner'],
];
$condition = [
['ps.seckill_time_id', 'like', '%,' . $seckill_time_id . ',%'],
['ps.status', '=', 1],
['ps.start_time', '<=', $start_time],
['ps.end_time', '>=', $end_time],
['g.goods_state', '=', 1],
['g.is_delete', '=', 0],
['ps.site_id', '=', $site_id],
];
//展示库存要和实际库存做比较,取二者的较小值
$sum_field = 'sum(IF(psg.stock < gs.stock, psg.stock, gs.stock))';
$goods_stock_field = 'IF(ps.goods_stock < '.$sum_field.', ps.goods_stock, '.$sum_field.') as goods_stock';
$field = 'ps.id,ps.site_id,ps.seckill_name,ps.status,ps.remark,ps.start_time,ps.end_time,'.$goods_stock_field.',
ps.goods_id,ps.seckill_time_id,ps.seckill_price,ps.sale_num,
g.goods_name,g.goods_image,g.price';
$order = 'ps.sort asc,g.goods_id desc';
$group = 'ps.id';
$res = model('promotion_seckill')->pageList($condition, $field, $order, $page, $page_size, $alias, $join, $group);
foreach ($res[ 'list' ] as $k => $v) {
$res[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'goods_stock' ]);
}
return $this->success($res);
}
/**
* 获取秒杀商品列表
* @param $seckill_time_id
* @param $site_id
* @param null $limit
* @return array
*/
public function getSeckillList($seckill_time_id, $site_id, $limit = null)
{
$alias = 'ps';
$join = [
['goods g', 'ps.goods_id = g.goods_id', 'inner'],
['promotion_seckill_goods psg', 'psg.seckill_id = ps.id', 'inner'],
['goods_sku gs', 'psg.sku_id = gs.sku_id', 'inner'],
];
$condition = [
['ps.seckill_time_id', 'like', '%,' . $seckill_time_id . ',%'],
['ps.status', '=', 1],
['g.goods_state', '=', 1],
['g.is_delete', '=', 0],
['ps.site_id', '=', $site_id]
];
//展示库存要和实际库存做比较,取二者的较小值
$sum_field = 'sum(IF(psg.stock < gs.stock, psg.stock, gs.stock))';
$goods_stock_field = 'IF(ps.goods_stock < '.$sum_field.', ps.goods_stock, '.$sum_field.') as goods_stock';
$field = 'ps.id,ps.site_id,ps.seckill_name,ps.status,ps.remark,ps.start_time,ps.end_time,'.$goods_stock_field.',
ps.goods_id,ps.seckill_time_id,ps.seckill_price,ps.sale_num,ps.goods_stock,
g.goods_name,g.goods_image,g.price';
$order = 'ps.sort asc';
$group = 'ps.id';
$list = model('promotion_seckill')->getList($condition, $field, $order, $alias, $join, $group, $limit);
foreach ($list as $k => $v) {
$list[ $k ][ 'goods_stock' ] = numberFormat($list[ $k ][ 'goods_stock' ]);
}
return $this->success($list);
}
/**
* 启动秒杀事件
* @param $seckill_id
* @return array
*/
public function cronOpenSeckill($seckill_id)
{
$seckill_info = model('promotion_seckill')->getInfo([['id', '=', $seckill_id]], 'start_time,status, goods_id');
if (!empty($seckill_info)) {
if ($seckill_info[ 'start_time' ] <= time() && $seckill_info[ 'status' ] == 0) {
model('promotion_seckill')->update(['status' => 1], [['id', '=', $seckill_id]]);
model('promotion_seckill_goods')->update(['status' => 1], [['seckill_id', '=', $seckill_id]]);
$goods = new Goods();
$goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], ['seckill' => $seckill_id]);
return $this->success(1);
} else {
return $this->error("", "秒杀已开启或者关闭");
}
} else {
return $this->error("", "秒杀不存在");
}
}
/**
* 结束秒杀事件
* @param $seckill_id
* @return array
*/
public function cronCloseSeckill($seckill_id)
{
$seckill_info = model('promotion_seckill')->getInfo([['id', '=', $seckill_id]], 'start_time,status, goods_id');
if (!empty($seckill_info)) {
//针对正在进行的活动
if ($seckill_info[ 'status' ] == 1) {
model('promotion_seckill')->update(['status' => 2], [['id', '=', $seckill_id]]);
model('promotion_seckill_goods')->update(['status' => 2], [['seckill_id', '=', $seckill_id]]);
$goods = new Goods();
$goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], ['seckill' => $seckill_id], true);
return $this->success();
} else {
return $this->error("", "正在进行的秒杀才能进行关闭操作");
}
} else {
return $this->error("", "活动不存在");
}
}
/**
* 手动结束秒杀事件
* @param $seckill_id
* @return array
*/
public function closeSeckill($seckill_id)
{
$seckill_info = model('promotion_seckill')->getInfo([['id', '=', $seckill_id]], 'start_time,status, goods_id');
if (!empty($seckill_info)) {
//针对正在进行的活动
if ($seckill_info[ 'status' ] == 1) {
model('promotion_seckill')->update(['status' => -1], [['id', '=', $seckill_id]]);
model('promotion_seckill_goods')->update(['status' => -1], [['seckill_id', '=', $seckill_id]]);
$goods = new Goods();
$goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], ['seckill' => $seckill_id], true);
return $this->success();
} else {
return $this->error("", "正在进行的秒杀才能进行关闭操作");
}
} else {
return $this->error("", "活动不存在");
}
}
/**
* 获取商品列表
* @param $seckill_id
* @return array
*/
public function getSeckillGoodsList($seckill_id)
{
$field = 'psg.*,sku.sku_name,sku.price,sku.sku_image';
$alias = 'psg';
$join = [
[
'goods g',
'g.goods_id = psg.goods_id',
'inner'
],
[
'goods_sku sku',
'sku.sku_id = psg.sku_id',
'inner'
]
];
$condition = [
['psg.seckill_id', '=', $seckill_id],
['g.is_delete', '=', 0], ['g.goods_state', '=', 1]
];
$list = model('promotion_seckill_goods')->getList($condition, $field, '', $alias, $join);
return $this->success($list);
}
/**
* 获取秒杀商品信息
* @param array $condition
* @param string $field
* @return array
*/
public function getSeckillGoodsInfo($condition = [], $field = '')
{
if (empty($field)) {
//展示库存要和实际库存做比较,取二者的较小值
$stock_field = 'IF(psg.stock < sku.stock, psg.stock, sku.stock) as stock';
$field = 'psg.id,psg.seckill_id,ps.goods_id,psg.sku_id,psg.seckill_price,psg.max_buy,'.$stock_field.',
ps.status,ps.start_time,ps.end_time,(ps.sale_num + g.virtual_sale) as sale_num,ps.remark,
sku.site_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,
sku.click_num,sku.collect_num,sku.sku_image,sku.sku_images,
sku.goods_content,sku.goods_state,sku.is_virtual,sku.is_free_shipping,
sku.goods_spec_format,sku.goods_attr_format,sku.introduction,sku.unit,
sku.video_url,g.evaluate,sku.goods_service_ids,sku.support_trade_type,g.goods_image,
ps.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show,g.label_name,g.category_id,g.sale_store';
}
$join = [
['goods_sku sku', 'psg.sku_id = sku.sku_id', 'inner'],
['goods g', 'g.goods_id = sku.goods_id', 'inner'],
['promotion_seckill ps', 'ps.id = psg.seckill_id', 'inner'],
];
$seckill_goods_info = model('promotion_seckill_goods')->getInfo($condition, $field, 'psg', $join);
if (!empty($seckill_goods_info)) {
if (isset($seckill_goods_info[ 'sale_num' ])) {
$seckill_goods_info[ 'sale_num' ] = numberFormat($seckill_goods_info[ 'sale_num' ]);
}
if (isset($seckill_goods_info[ 'goods_stock' ])) {
$seckill_goods_info[ 'goods_stock' ] = numberFormat($seckill_goods_info[ 'goods_stock' ]);
}
if (isset($seckill_goods_info[ 'stock' ])) {
$seckill_goods_info[ 'stock' ] = numberFormat($seckill_goods_info[ 'stock' ]);
}
}
return $this->success($seckill_goods_info);
}
/**
* 获取秒杀商品信息
* @param array $condition
* @return array
*/
public function getSeckillGoodsSkuList($condition = [])
{
//展示库存要和实际库存做比较,取二者的较小值
$stock_field = 'IF(psg.stock < sku.stock, psg.stock, sku.stock) as stock';
$field = 'psg.id,psg.seckill_id,ps.goods_id,psg.sku_id,psg.seckill_price,psg.max_buy,'.$stock_field.',
ps.status,ps.start_time,ps.end_time,ps.sale_num,sku.sku_name,sku.sku_spec_format,sku.price,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image,ps.goods_stock';
$join = [
['goods_sku sku', 'psg.sku_id = sku.sku_id', 'inner'],
['goods g', 'g.goods_id = sku.goods_id', 'inner'],
['promotion_seckill ps', 'ps.id = psg.seckill_id', 'inner'],
];
$list = model('promotion_seckill_goods')->getList($condition, $field, 'psg.id asc', 'psg', $join);
foreach ($list as $k => $v) {
$list[ $k ][ 'goods_stock' ] = numberFormat($list[ $k ][ 'goods_stock' ]);
$list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
}
return $this->success($list);
}
/**
* 判断规格值是否禁用
* @param $seckill_id
* @param $site_id
* @param string $goods_spec_format
* @return int|mixed
*/
public function getGoodsSpecFormat($seckill_id, $site_id, $goods_spec_format = '')
{
//获取活动参与的商品sku_ids
$sku_ids = model('promotion_seckill_goods')->getColumn([['seckill_id', '=', $seckill_id], ['site_id', '=', $site_id]], 'sku_id');
$goods_model = new Goods();
$res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
return $res;
}
/**
* 生成砍价二维码
* @param $seckill_id
* @param string $name
* @param string $type 类型 create创建 get获取
* @return mixed|array
*/
public function qrcode($seckill_id, $name, $site_id, $type = 'create')
{
$data = [
'site_id' => $site_id,
'app_type' => "all", // all为全部
'type' => $type, // 类型 create创建 get获取
'data' => [
"seckill_id" => $seckill_id
],
'page' => '/pages_promotion/seckill/detail',
'qrcode_path' => 'upload/qrcode/seckill',
'qrcode_name' => "seckill_qrcode_" . $seckill_id
];
event('Qrcode', $data, true);
$app_type_list = config('app_type');
$path = [];
foreach ($app_type_list as $k => $v) {
switch ($k) {
case 'h5':
$wap_domain = getH5Domain();
$path[ $k ][ 'status' ] = 1;
$path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?id=' . $seckill_id;
$path[ $k ][ 'img' ] = "upload/qrcode/seckill/seckill_qrcode_" . $seckill_id . "_" . $k . ".png";
break;
case 'weapp' :
$config = new ConfigModel();
$res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'WEAPP_CONFIG']]);
if (!empty($res[ 'data' ])) {
if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
$path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'message' ] = '未配置微信小程序';
} else {
$path[ $k ][ 'status' ] = 1;
$path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
}
} else {
$path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'message' ] = '未配置微信小程序';
}
break;
case 'wechat' :
$config = new ConfigModel();
$res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'WECHAT_CONFIG']]);
if (!empty($res[ 'data' ])) {
if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
$path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'message' ] = '未配置微信公众号';
} else {
$path[ $k ][ 'status' ] = 1;
$path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
}
} else {
$path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'message' ] = '未配置微信公众号';
}
break;
}
}
$return = [
'path' => $path,
'name' => $name,
];
return $this->success($return);
}
public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
{
$params = [
'site_id' => $site_id,
'data' => $qrcode_param,
'page' => $page,
'promotion_type' => $promotion_type,
'app_type' => $app_type,
'h5_path' => $page . '?id=' . $qrcode_param[ 'id' ],
'qrcode_path' => 'upload/qrcode/seckill',
'qrcode_name' => 'seckill_qrcode_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $site_id,
];
$solitaire = event('PromotionQrcode', $params, true);
return $this->success($solitaire);
}
/**
* 获取会员已购该商品数
* @param $goods_id
* @param $member_id
* @return float
*/
public function getGoodsPurchasedNum($sku_id, $member_id)
{
$join = [
['order o', 'o.order_id = og.order_id', 'left']
];
return model('order_goods')->getSum([
['og.member_id', '=', $member_id],
['og.sku_id', '=', $sku_id],
['o.order_status', '<>', Order::ORDER_CLOSE],
['o.promotion_type', '=', 'seckill'],
['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE]
], 'og.num', 'og', $join);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
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 orderClose($order_id)
{
$order_info = model('order')->getInfo([['order_id', '=', $order_id], ['promotion_type', '=', 'seckill'], ['order_status', '=', -1]], 'promotion_id');
if (!empty($order_info)) {
$condition = [
['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']
];
return 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);
}
}

View File

@@ -0,0 +1,311 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
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[ 'promotion_id' ] = $this->seckill_info['id'];
$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' ]);
// 增加销量 秒杀要用sale_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->batchDecOrderGoodsStock();
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', '', $this->order_id, $this->member_id);
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.form_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;
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
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,//分享内容
];
}
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\seckill\model\share;
use app\model\share\WeappShareBase;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WeappShare extends WeappShareBase
{
protected $config = [
[
'title' => '秒杀列表',
'config_key' => 'WEAPP_SHARE_CONFIG_SECKILL_LIST',
'path' => ['/pages_promotion/seckill/list'],
'method_prefix' => 'seckillList',
],
];
protected $sort = 9;
/**
* 秒杀列表
* @param $param
* @return array
*/
protected function seckillListShareData($param)
{
//获取和替换配置数据
$config_data = $this->seckillListShareConfig($param);
$title = $config_data['value']['title'];
$image_url = $config_data['value']['imageUrl'] ? img($config_data['value']['imageUrl']) : '';
$path = $this->getSharePath($param);
$data = [
'title' => $title,
'path' => $path,
'imageUrl' => $image_url,
];
return [
'permission' => [
'onShareAppMessage' => true,
'onShareTimeline' => true,
],
'data' => $data,//分享内容
];
}
/**
* 秒杀列表
* @param $param
* @return array
*/
protected function seckillListShareConfig($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' => '参与秒杀,优惠多多!',
'imageUrl' => '',
];
}
$variable = [];
return [
'value' => $data['value'],
'variable' => $variable,
];
}
}