1.提交缺失的东西
This commit is contained in:
@ -114,50 +114,51 @@ class GoodsLogic{
|
||||
}
|
||||
//商品详情
|
||||
public static function getGoodsDetail($user_id,$id){
|
||||
$goods =Goods::find(['id'=>$id,'status'=>1])->with(['goods_image', 'goods_item']);
|
||||
// $goods = Goods::where(['id'=>$id,'status'=>1])->with(['goods_image','goods_item']);
|
||||
|
||||
$goods = Goods::where(['id'=>$id,'status'=>1])->with(['goods_image','goods_item']);
|
||||
if(empty($goods)){
|
||||
return [];
|
||||
}
|
||||
|
||||
//点击量
|
||||
$goods->click_count = $goods->click_count + 1;
|
||||
$goods->save();
|
||||
$goods->sales_sum += $goods->virtual_sales_sum;
|
||||
$goods->is_collect = 0;
|
||||
$goods->member_price = 0;
|
||||
$goods->append(['order_give_integral', 'commission_price']);
|
||||
$goods['click_count'] = $data['click_count'] = $goods['click_count'] + 1;
|
||||
Goods::where(['id'=>$id,'status'=>1])->update($data);
|
||||
$goods['sales_sum'] += $goods['virtual_sales_sum'];
|
||||
$goods['is_collect'] = 0;
|
||||
$goods['member_price'] = 0;
|
||||
$goods['order_give_integral'] = "";
|
||||
$goods['commission_price'] = "";
|
||||
|
||||
//检查商品是否整在参加活动,如果正在参加活动替换商品的价格为活动价
|
||||
$goods = self::checkActivity($goods);
|
||||
if($user_id) {
|
||||
//是否收藏
|
||||
$collect = Db::name('goods_collect')->where(['user_id'=>$user_id,'goods_id'=>$id])->find();
|
||||
$goods->is_collect= $collect ? 1 : 0;
|
||||
$goods['is_collect']= $collect ? 1 : 0;
|
||||
|
||||
//会员折扣
|
||||
$member_discount = Db::name('user_level l')
|
||||
$member_discount = Db::name('user_level')->alias('l')
|
||||
->join('user u', 'u.level = l.id')
|
||||
->where(['u.id' => $user_id])
|
||||
->value('discount');
|
||||
$price_array = [];
|
||||
//处理会员折扣价格
|
||||
if ($goods->is_member > 0 && $member_discount > 0) {
|
||||
if ($goods['is_member'] > 0 && $member_discount > 0) {
|
||||
//会员价格
|
||||
foreach ($goods->goods_item as $item => $value){
|
||||
$goods->goods_item[$item]['member_price'] = 0;
|
||||
foreach ($goods['goods_item'] as $item => $value){
|
||||
$goods['goods_item'][$item]['member_price'] = 0;
|
||||
if($member_discount){
|
||||
$member_price = round($value['price'] * $member_discount / 10,2);
|
||||
$goods->goods_item[$item]['member_price'] = $member_price;
|
||||
$goods['goods_item'][$item]['member_price'] = $member_price;
|
||||
$price_array[] = $member_price;
|
||||
}
|
||||
}
|
||||
$price_array && $goods->member_price = min($price_array);
|
||||
$price_array && $goods['member_price'] = min($price_array);
|
||||
}
|
||||
//多规格,按最高的价格计算积分
|
||||
if($price_array && 2 === $goods->give_integral_type){
|
||||
$price = $price_array ? max($price_array) : $goods->max_price;
|
||||
$goods->order_give_integral = intval($price * $goods->give_integral / 100);
|
||||
if($price_array && 2 === $goods['give_integral_type']){
|
||||
$price = $price_array ? max($price_array) : $goods['max_price'];
|
||||
$goods['order_give_integral'] = intval($price * $goods['give_integral'] / 100);
|
||||
}
|
||||
}
|
||||
//猜你喜欢
|
||||
@ -169,15 +170,15 @@ class GoodsLogic{
|
||||
'click_count','min_price','max_price','market_price','is_collect','goods_spec','goods_image',
|
||||
'goods_item','activity','member_price','is_express','is_selffetch','market_price']);
|
||||
|
||||
$market_price_array = array_column($goods->goods_item->toarray(),'market_price');
|
||||
$goods->market_price = max($market_price_array);
|
||||
$price_array = array_column($goods->goods_item->toarray(),'price');
|
||||
$goods->min_price = min($price_array);
|
||||
$goods->max_price = max($price_array);
|
||||
$market_price_array = array_column($goods['goods_item']->toarray(),'market_price');
|
||||
$goods['market_price'] = max($market_price_array);
|
||||
$price_array = array_column($goods['goods_item']->toarray(),'price');
|
||||
$goods['min_price'] = min($price_array);
|
||||
$goods['max_price'] = max($price_array);
|
||||
|
||||
$goods->poster = !empty($goods->poster) ? UrlServer::getFileUrl($goods->poster) : '';
|
||||
$goods['poster'] = !empty($goods['poster']) ? UrlServer::getFileUrl($goods['poster']) : '';
|
||||
// 商品虚拟浏览量
|
||||
$goods->click_count += $goods->virtual_click;
|
||||
$goods['click_count'] += $goods['virtual_click'];
|
||||
//判断是否开启了拼团
|
||||
if ($goods['is_team']) {
|
||||
$resTeam = self::getTeam($goods);
|
||||
|
||||
134
app/api/logic/SeckillLogic.php
Normal file
134
app/api/logic/SeckillLogic.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\logic;
|
||||
use app\common\service\ConfigServer;
|
||||
use app\common\service\UrlServer;
|
||||
use think\facade\Db;
|
||||
|
||||
class SeckillLogic{
|
||||
|
||||
public static function seckillTime(){
|
||||
$time_list = Db::name('seckill_time')
|
||||
->where(['del'=>0])
|
||||
->order('start_time asc')
|
||||
->field('id,start_time,end_time')
|
||||
->select();
|
||||
$now = time();
|
||||
foreach ($time_list as &$item){
|
||||
$item['status'] = 2;
|
||||
$item['tips'] = '';
|
||||
$start_time = strtotime(date('Y-m-d'.$item['start_time']));
|
||||
$end_time = strtotime(date('Y-m-d'.$item['end_time']));
|
||||
if($now >= $end_time ){
|
||||
$item['tips'] = '已结束';
|
||||
}
|
||||
if($start_time <= $now && $now < $end_time){
|
||||
$item['status'] = 1;
|
||||
$item['tips'] = '抢购中';
|
||||
}
|
||||
if($start_time >= $now){
|
||||
$item['tips'] = '未开始';
|
||||
$item['status'] = 0;
|
||||
}
|
||||
}
|
||||
return $time_list;
|
||||
}
|
||||
|
||||
public static function seckillGoods($id,$page,$size){
|
||||
$where[] = ['g.del','=',0];
|
||||
$where[] = ['sg.del','=',0];
|
||||
$where[] = ['g.status','=',1];
|
||||
$where[] = ['sg.seckill_id','=',$id];
|
||||
|
||||
$goods_count = Db::name('goods g')
|
||||
->join('seckill_goods sg','g.id = sg.goods_id')
|
||||
->group('sg.goods_id')
|
||||
->order('sg.sales_sum desc')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$goods_list = Db::name('goods g')
|
||||
->join('seckill_goods sg','g.id = sg.goods_id')
|
||||
->where($where)
|
||||
->group('sg.goods_id')
|
||||
->order('sg.sales_sum,sg.id desc')
|
||||
->page($page,$size)
|
||||
->field('g.id,g.name,g.image,g.min_price,sg.price as seckill_price,sg.sales_sum')
|
||||
->select();
|
||||
|
||||
|
||||
$default_image = UrlServer::getFileUrl(ConfigServer::get('website', 'goods_image', ''));
|
||||
foreach ($goods_list as &$item){
|
||||
// 传入默认商品主图
|
||||
if(empty( $item['image'])) {
|
||||
$item['image'] = $default_image;
|
||||
}else{
|
||||
$item['image'] = UrlServer::getFileUrl($item['image']);
|
||||
}
|
||||
}
|
||||
|
||||
$more = is_more($goods_count,$page,$size); //是否有下一页
|
||||
|
||||
$data = [
|
||||
'list' => $goods_list,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'count' => $goods_count,
|
||||
'more' => $more
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
//获取当前的秒杀时段
|
||||
public static function getSeckill(){
|
||||
$seckill_time = Db::name('seckill_time')
|
||||
->where(['del'=>0])
|
||||
->order('start_time asc')
|
||||
->field('id,start_time,end_time')
|
||||
->select();
|
||||
$seckill = [];
|
||||
$now = time();
|
||||
|
||||
foreach ($seckill_time as $item){
|
||||
$start_time = strtotime(date('Y-m-d'.$item['start_time']));
|
||||
$end_time = strtotime(date('Y-m-d'.$item['end_time']));
|
||||
|
||||
if($start_time <= $now && $now < $end_time){
|
||||
$item['end_time'] = $end_time;
|
||||
$seckill = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $seckill;
|
||||
}
|
||||
//获取当前的秒杀信息和秒杀商品
|
||||
public static function getSeckillGoods(){
|
||||
|
||||
$seckill = self::getSeckill();
|
||||
$seckill_goods = [];
|
||||
if($seckill){
|
||||
$seckill_goods = Db::name('seckill_goods')
|
||||
->where(['seckill_id'=>$seckill['id'],'del'=>0])
|
||||
->column('id as seckill_goods_id,price,goods_id','item_id');
|
||||
}
|
||||
|
||||
return ['seckill'=>$seckill,'seckill_goods'=>$seckill_goods];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user