|
|
@ -24,7 +24,6 @@ use app\common\model\Goods as GoodsModel; |
|
|
|
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel; |
|
|
|
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel; |
|
|
|
use app\common\model\GoodsImage as GoodsImageModel; |
|
|
|
use app\common\model\GoodsImage as GoodsImageModel; |
|
|
|
use app\common\model\UploadFile as UploadFileModel; |
|
|
|
use app\common\model\UploadFile as UploadFileModel; |
|
|
|
use app\store\model\goods\GoodsPrice as GoodsPriceModel; |
|
|
|
|
|
|
|
use cores\exception\BaseException; |
|
|
|
use cores\exception\BaseException; |
|
|
|
use think\db\exception\DataNotFoundException; |
|
|
|
use think\db\exception\DataNotFoundException; |
|
|
|
use think\db\exception\DbException; |
|
|
|
use think\db\exception\DbException; |
|
|
@ -45,8 +44,6 @@ class Goods extends GoodsModel |
|
|
|
'images', |
|
|
|
'images', |
|
|
|
'delivery', |
|
|
|
'delivery', |
|
|
|
'deduct_stock_type', |
|
|
|
'deduct_stock_type', |
|
|
|
'sales_initial', |
|
|
|
|
|
|
|
'sales_actual', |
|
|
|
|
|
|
|
'sort', |
|
|
|
'sort', |
|
|
|
'is_delete', |
|
|
|
'is_delete', |
|
|
|
'store_id', |
|
|
|
'store_id', |
|
|
@ -232,6 +229,43 @@ class Goods extends GoodsModel |
|
|
|
return $info; |
|
|
|
return $info; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function presaleGoodss(array $param): array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$list = []; |
|
|
|
|
|
|
|
$cate_goods_id = []; |
|
|
|
|
|
|
|
if (!empty($param['category_id'])) { |
|
|
|
|
|
|
|
$cate_model = new \app\store\model\GoodsCategoryRel(); |
|
|
|
|
|
|
|
$cate_goods_id = $cate_model |
|
|
|
|
|
|
|
->where(['category_id' => $param['category_id']]) |
|
|
|
|
|
|
|
->column('goods_id'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$model = new PreSale(); |
|
|
|
|
|
|
|
$info = $model->where(['is_change' => 0, 'status' => 1])->field('goods_list,p_time')->find(); |
|
|
|
|
|
|
|
if (!$info->isEmpty()) { |
|
|
|
|
|
|
|
$info = $info->toArray(); |
|
|
|
|
|
|
|
$goods_ids = explode(',', $info['goods_list']); |
|
|
|
|
|
|
|
if ($cate_goods_id) { |
|
|
|
|
|
|
|
$goods_ids = array_unique(array_values(array_intersect($cate_goods_id, $goods_ids))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$result = $this->getListByIds($goods_ids); |
|
|
|
|
|
|
|
if (!$result->isEmpty()) { |
|
|
|
|
|
|
|
$result = $result->toArray(); |
|
|
|
|
|
|
|
foreach ($result as $v) { |
|
|
|
|
|
|
|
$list[] = [ |
|
|
|
|
|
|
|
'goods_id' => $v['goods_id'], |
|
|
|
|
|
|
|
'goods_name' => $v['goods_name'], |
|
|
|
|
|
|
|
'goods_price_min' => $v['goods_price_min'], |
|
|
|
|
|
|
|
'sales_initial' => $v['sales_initial'], |
|
|
|
|
|
|
|
'sales_actual' => $v['sales_actual'], |
|
|
|
|
|
|
|
'image' => $v['goods_image'], |
|
|
|
|
|
|
|
'end_time' => strtotime($info['p_time']) - time() |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function presaleGoodsList() |
|
|
|
public function presaleGoodsList() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$info = PreSale::where([ |
|
|
|
$info = PreSale::where([ |
|
|
@ -318,13 +352,15 @@ class Goods extends GoodsModel |
|
|
|
|
|
|
|
|
|
|
|
return $info; |
|
|
|
return $info; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 商品主图、商品轮播图、商品详情处理 |
|
|
|
* 商品主图、商品轮播图、商品详情处理 |
|
|
|
* [dealGoodsImage description] |
|
|
|
* [dealGoodsImage description] |
|
|
|
* @param [type] &$goodsInfo [description] |
|
|
|
* @param [type] &$goodsInfo [description] |
|
|
|
* @return [type] [description] |
|
|
|
* @return [type] [description] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function dealGoodsImage(&$goodsInfo){ |
|
|
|
public function dealGoodsImage(&$goodsInfo) |
|
|
|
|
|
|
|
{ |
|
|
|
switch ($goodsInfo->channel) { |
|
|
|
switch ($goodsInfo->channel) { |
|
|
|
case 'jd': |
|
|
|
case 'jd': |
|
|
|
$jd = new \app\common\service\Jd(); |
|
|
|
$jd = new \app\common\service\Jd(); |
|
|
@ -364,6 +400,7 @@ class Goods extends GoodsModel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取商品详情 (详细数据用于页面展示) |
|
|
|
* 获取商品详情 (详细数据用于页面展示) |
|
|
|
* @param int $goodsId 商品ID |
|
|
|
* @param int $goodsId 商品ID |
|
|
@ -491,13 +528,13 @@ class Goods extends GoodsModel |
|
|
|
$goodsInfo = static::detail($goodsId, $with); |
|
|
|
$goodsInfo = static::detail($goodsId, $with); |
|
|
|
|
|
|
|
|
|
|
|
if ($goodsInfo->skuList) { |
|
|
|
if ($goodsInfo->skuList) { |
|
|
|
foreach ($goodsInfo->skuList as &$value) { |
|
|
|
foreach ($goodsInfo->skuList as &$value) { |
|
|
|
$goods_image = GoodsImage::where('goods_id', $value['goods_id'])->order("id asc")->find(); |
|
|
|
$goods_image = GoodsImage::where('goods_id', $value['goods_id'])->order("id asc")->find(); |
|
|
|
$file_path = UploadFile::where('file_id',$goods_image['image_id'] ?? 0)->find(); |
|
|
|
$file_path = UploadFile::where('file_id', $goods_image['image_id'] ?? 0)->find(); |
|
|
|
if ($file_path) { |
|
|
|
if ($file_path) { |
|
|
|
$value['image_url'] = getUrl($file_path['file_path'], $file_path['domain']); |
|
|
|
$value['image_url'] = getUrl($file_path['file_path'], $file_path['domain']); |
|
|
|
} |
|
|
|
} |
|
|
|
$goods = GoodsModel::where('goods_id',$value['goods_id'])->find(); |
|
|
|
$goods = GoodsModel::where('goods_id', $value['goods_id'])->find(); |
|
|
|
$value['stock_num'] = $goods['stock_total'] ?? 0; |
|
|
|
$value['stock_num'] = $goods['stock_total'] ?? 0; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -600,11 +637,11 @@ class Goods extends GoodsModel |
|
|
|
|
|
|
|
|
|
|
|
} elseif (UserService::isPlusMember()) { |
|
|
|
} elseif (UserService::isPlusMember()) { |
|
|
|
$membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); |
|
|
|
$membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); |
|
|
|
$goods['discount'] = bcdiv((string)($membershipPrice*10), (string)$goods['goods_price_min'], 1); |
|
|
|
$goods['discount'] = bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1); |
|
|
|
$goods['goods_price_min'] = $membershipPrice; |
|
|
|
$goods['goods_price_min'] = $membershipPrice; |
|
|
|
} elseif (UserService::isDealerMember()) { |
|
|
|
} elseif (UserService::isDealerMember()) { |
|
|
|
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); |
|
|
|
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); |
|
|
|
$goods['discount'] = bcdiv((string)($priceArr['distributionPrice']*10), (string)$goods['goods_price_min'], 1); |
|
|
|
$goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1); |
|
|
|
//$goods['goods_price_min'] = $membershipPrice; |
|
|
|
//$goods['goods_price_min'] = $membershipPrice; |
|
|
|
$goods['goods_price_min'] = $priceArr['distributionPrice']; |
|
|
|
$goods['goods_price_min'] = $priceArr['distributionPrice']; |
|
|
|
} |
|
|
|
} |
|
|
@ -709,7 +746,8 @@ class Goods extends GoodsModel |
|
|
|
* @throws DbException |
|
|
|
* @throws DbException |
|
|
|
* @throws ModelNotFoundException |
|
|
|
* @throws ModelNotFoundException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function editGoodsPrice($data) { |
|
|
|
public function editGoodsPrice($data) |
|
|
|
|
|
|
|
{ |
|
|
|
if (empty($data['goods_price']) || empty($data['cost_price']) || empty($data['id'])) { |
|
|
|
if (empty($data['goods_price']) || empty($data['cost_price']) || empty($data['id'])) { |
|
|
|
$this->error = "请补全信息"; |
|
|
|
$this->error = "请补全信息"; |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -743,11 +781,12 @@ class Goods extends GoodsModel |
|
|
|
$data['cost_price_min'] = $data['cost_price']; |
|
|
|
$data['cost_price_min'] = $data['cost_price']; |
|
|
|
$detail->save($data); |
|
|
|
$detail->save($data); |
|
|
|
//更新sku的价格 |
|
|
|
//更新sku的价格 |
|
|
|
GoodsSkuModel::where('goods_id', $data['id'])->update(['cost_price'=>$data['cost_price'], 'goods_price' => $data['goods_price']]); |
|
|
|
GoodsSkuModel::where('goods_id', $data['id'])->update(['cost_price' => $data['cost_price'], 'goods_price' => $data['goods_price']]); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function editGoodsSeckillPrice($data) { |
|
|
|
public function editGoodsSeckillPrice($data) |
|
|
|
|
|
|
|
{ |
|
|
|
if (empty($data['seckill_price']) || empty($data['is_limit']) || empty($data['limit_times']) || empty($data['goods_id'])) { |
|
|
|
if (empty($data['seckill_price']) || empty($data['is_limit']) || empty($data['limit_times']) || empty($data['goods_id'])) { |
|
|
|
$this->error = "请补全信息"; |
|
|
|
$this->error = "请补全信息"; |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -758,7 +797,7 @@ class Goods extends GoodsModel |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(empty($data['sku_id'])) { |
|
|
|
if (empty($data['sku_id'])) { |
|
|
|
$this->error = "请输入sku_id"; |
|
|
|
$this->error = "请输入sku_id"; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -766,18 +805,18 @@ class Goods extends GoodsModel |
|
|
|
// var_dump($data['sku_id']); |
|
|
|
// var_dump($data['sku_id']); |
|
|
|
$sku_id = $data['sku_id']; |
|
|
|
$sku_id = $data['sku_id']; |
|
|
|
// foreach ($sku_ids as $sku_id) { |
|
|
|
// foreach ($sku_ids as $sku_id) { |
|
|
|
$skuData = GoodsSkuModel::get(['id' => $sku_id,'goods_id' => $data['goods_id']]); |
|
|
|
$skuData = GoodsSkuModel::get(['id' => $sku_id, 'goods_id' => $data['goods_id']]); |
|
|
|
if ($skuData) { |
|
|
|
if ($skuData) { |
|
|
|
$up_data = [ |
|
|
|
$up_data = [ |
|
|
|
'seckill_price' => $data['seckill_price'], |
|
|
|
'seckill_price' => $data['seckill_price'], |
|
|
|
'is_limit' => $data['is_limit'], |
|
|
|
'is_limit' => $data['is_limit'], |
|
|
|
'limit_times' => $data['limit_times'], |
|
|
|
'limit_times' => $data['limit_times'], |
|
|
|
'sec_start_time' => $data['sec_start_time'], |
|
|
|
'sec_start_time' => $data['sec_start_time'], |
|
|
|
// 'sec_end_time' => $data['sec_end_time'], |
|
|
|
// 'sec_end_time' => $data['sec_end_time'], |
|
|
|
'sec_hour' => $data['sec_hour'], |
|
|
|
'sec_hour' => $data['sec_hour'], |
|
|
|
]; |
|
|
|
]; |
|
|
|
$skuData->save($up_data); |
|
|
|
$skuData->save($up_data); |
|
|
|
} |
|
|
|
} |
|
|
|
// } |
|
|
|
// } |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|