109 lines
3.6 KiB
PHP
109 lines
3.6 KiB
PHP
<?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\common\model\goods;
|
||
|
||
|
||
use app\admin\validate\SeckillTime;
|
||
use app\api\logic\SeckillLogic;
|
||
use app\common\basics\Models;
|
||
use app\common\enum\OrderEnum;
|
||
use app\api\logic\OrderLogic;
|
||
use app\common\model\seckill\SeckillGoods;
|
||
use app\common\model\seckill\SeckillTime as SeckillTimeModel;
|
||
use app\common\server\UrlServer;
|
||
|
||
|
||
/**
|
||
* 商品规格
|
||
* Class GoodsItem
|
||
* @package app\common\model\goods
|
||
*/
|
||
class GoodsItem extends Models
|
||
{
|
||
/**
|
||
* 根据goods_id,num和item_id计算价格
|
||
*/
|
||
public function sumGoodsPrice($goods_id, $item_id, $num,$discount)
|
||
{
|
||
$goods_price = $this
|
||
->where([
|
||
['goods_id', '=', $goods_id],
|
||
['id', '=', $item_id],
|
||
])
|
||
->value('price');
|
||
$seckill_goods_price = self::isSeckill($item_id);
|
||
if($seckill_goods_price != 0){
|
||
$goods_price = $seckill_goods_price;
|
||
OrderLogic::$order_type = OrderEnum::SECKILL_ORDER;
|
||
}
|
||
$is_member = Goods::where('id',$goods_id)->value('is_member');
|
||
|
||
if ($is_member === 0 || empty($is_member)){//不参与会员价
|
||
$price = round($goods_price*$num,2);
|
||
}
|
||
if ($is_member == 1){
|
||
$price = round($goods_price*$num*$discount/10,2);
|
||
}
|
||
return $price;
|
||
}
|
||
|
||
public function sumMemberPrice($goods_id, $item_id, $num,$discount)
|
||
{
|
||
$goods_price = $this
|
||
->where([
|
||
['goods_id', '=', $goods_id],
|
||
['id', '=', $item_id],
|
||
])
|
||
->value('price');
|
||
$seckill_goods_price = self::isSeckill($item_id);
|
||
if($seckill_goods_price != 0){
|
||
$goods_price = $seckill_goods_price;
|
||
OrderLogic::$order_type = OrderEnum::SECKILL_ORDER;
|
||
}
|
||
$is_member = Goods::where('id',$goods_id)->value('is_member');
|
||
|
||
if ($is_member === 0 || empty($is_member)){//不参与会员价
|
||
$price = 0;
|
||
}
|
||
if ($is_member == 1){
|
||
$price = round($goods_price*$num*(1-$discount/10),2);
|
||
}
|
||
return $price;
|
||
}
|
||
/***
|
||
*
|
||
*是否为秒杀商品
|
||
*
|
||
***/
|
||
public static function isSeckill($item_id){
|
||
|
||
//当前时段秒杀商品
|
||
$seckill = SeckillLogic::getSeckillGoods();
|
||
$seckill_goods = $seckill['seckill_goods'];
|
||
|
||
//当前商品规格是否为秒杀商品
|
||
if (isset($seckill_goods[$item_id])) {
|
||
return $seckill_goods[$item_id]['price'];
|
||
}else{
|
||
return 0;
|
||
}
|
||
}
|
||
} |