lqmac 9 months ago
parent 2392ce2015
commit 3ac982fc46
  1. 3
      app/api/model/Goods.php
  2. 3
      app/api/model/Order.php
  3. 3
      app/api/service/Cart.php
  4. 128
      app/api/service/Goods.php

@ -534,6 +534,7 @@ class Goods extends GoodsModel
{
// 判断是否登录
if (!UserService::isLogin()) {
$goods['line_price_min'] = $goods['goods_price_min'];
return;
}
$catService = new \app\store\model\GoodsCategoryRel();
@ -545,6 +546,7 @@ class Goods extends GoodsModel
// $price_list_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['goods_price_min']);
// }
$goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价
//价格判断
if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
@ -561,6 +563,7 @@ class Goods extends GoodsModel
$goods['goods_price_min'] = $priceArr['distributionPrice'];
//$goods['goods_price_min_dealer'] = min($price_list_dealer);
}
// 会员折扣价: 商品sku列表
if ($goods->getRelation('skuList')) {
foreach ($goods['skuList'] as &$skuItem) {

@ -90,8 +90,9 @@ class Order extends OrderModel
$item['skuInfo'] = GoodsModel::getSkuInfo($item, $goodsSkuId, false);
// 商品封面 (优先sku封面)
$item['goods_image'] = $item['skuInfo']['goods_image'] ?: $item['goods_image'];
// 商品单价
$item['goods_price'] = $item['skuInfo']['goods_price'];
$item['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']);
// 商品购买数量
$item['total_num'] = $goodsNum;
// 商品SKU索引

@ -80,7 +80,8 @@ class Cart extends BaseService
// 商品记录
$goods = $item['goods'];
// 商品单价
$goods['goods_price'] = $goods['skuInfo']['goods_price'];
$goods['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']);
//$goods['goods_price'] = $goods['skuInfo']['goods_price'];
// 商品购买数量
$goods['total_num'] = $item['goods_num'];
// 商品SKU索引

@ -222,6 +222,19 @@ class Goods extends GoodsService
province_id,city_id,region_id,shop_id,address,latitude,longitude,wechat_img_id,history1,history2,history3,remark,history,parking_name,parking_desc,parking_latitude,parking_longitude,shop_image_id,fuwu_hours,fuwu_num')->find()->toArray();
//todo wmc
$info['remark'] = json_decode($info['remark'],true);
$arr = explode(" ", $info['shop_hours']);
$arr = explode("-", $arr[1] ?? "");
$info['is_open'] = 0;
// if ($arr && count($arr) == 2) {
// $start = explode(":", $arr[0]);
// $end = explode(":", $arr[1]);
// $start_time = ($start[0] ?? 0)
// if ($start[0]) {
// // code...
// }
// $info['is_open'] = 0;
// }
// $info['is_open'] = $arr && $arr[]
// $info['fuwu_hours'] = 5;
// $info['fuwu_num'] = 15;
// $info['wechat'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240127/12bb1b1747e652d258443247a5c4777c.png';
@ -289,7 +302,19 @@ class Goods extends GoodsService
// return $list;
// }
public static function getGoodsPrice($goods_id, $price, $cost_price){
$catService = new \app\store\model\GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods_id])->column('category_id');
if (UserService::isstore()) {
$price = $cost_price;
} elseif (UserService::isPlusMember()) {
$price = \app\common\model\PriceSet::membershipPrice($price, $cost_price, $catIds);
} elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($price, $cost_price, $catIds);
$price = $priceArr['goods_price_min_dealer'];
}
return $price;
}
/**
* 格式化商品列表
* @param $goodsList
@ -297,56 +322,61 @@ class Goods extends GoodsService
*/
private function formatGoodsList($goodsList): array
{
$data = [];
foreach ($goodsList as $goods) {
$temp = [
'goods_id' => $goods['goods_id'],
'goods_name' => $goods['goods_name'],
'selling_point' => $goods['selling_point'],
'goods_image' => $goods['goods_image'],
'goods_price_min' => $goods['goods_price_min'],//商品价格
'goods_price_max' => $goods['goods_price_max'],
'line_price_min' => $goods['goods_price_min'],//划线价格等于市场价
'line_price_max' => $goods['line_price_max'],
'goods_sales' => $goods['goods_sales'],
'remaizhishu' => $goods['remaizhishu'],
];
if (UserService::isLogin()) {
$catService = new \app\store\model\GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods['goods_id']])->column('category_id');
// $price_list_plus = $price_list_dealer = [];
// foreach ($catIds as $k => $v) {
// $price_list_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['goods_price_min']);
// $price_list_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['goods_price_min']);
// }
// echo "<pre>";
// print_r($goodsList->toArray());
// exit();
// $data = [];
// foreach ($goodsList as $goods) {
// $temp = [
// 'goods_id' => $goods['goods_id'],
// 'goods_name' => $goods['goods_name'],
// 'selling_point' => $goods['selling_point'],
// 'goods_image' => $goods['goods_image'],
// 'goods_price_min' => $goods['goods_price_min'],//商品价格
// 'goods_price_max' => $goods['goods_price_max'],
// 'line_price_min' => $goods['goods_price_min'],//划线价格等于市场价
// 'line_price_max' => $goods['line_price_max'],
// 'goods_sales' => $goods['goods_sales'],
// 'remaizhishu' => $goods['remaizhishu'],
// ];
// var_dump($goods->toArray());
// var_dump($temp);
// exit();
// if (UserService::isLogin()) {
// $catService = new \app\store\model\GoodsCategoryRel();
// $catIds = $catService->where(['goods_id' => $goods['goods_id']])->column('category_id');
// // $price_list_plus = $price_list_dealer = [];
// // foreach ($catIds as $k => $v) {
// // $price_list_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['goods_price_min']);
// // $price_list_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['goods_price_min']);
// // }
//价格判断
if (UserService::isstore()) {
// //价格判断
// if (UserService::isstore()) {
//$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
// $temp['goods_price_min_plus'] = $priceArr['membershipPrice'];
// $temp['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$temp['goods_price_min'] = $goods['cost_price_min'];
// $temp['goods_price_min_plus'] = min($price_list_plus);
// $temp['goods_price_min_dealer'] = min($price_list_dealer);
} elseif (UserService::isPlusMember()) {
//$temp['goods_price_min_plus'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$temp['goods_price_min'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
// $temp['goods_price_min'] = $temp['goods_price_min_plus'];
// $temp['goods_price_max'] = $temp['goods_price_min_plus'];
//$temp['goods_price_min_plus'] = min($price_list_plus);
} elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
//$temp['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$temp['goods_price_min'] = $priceArr['goods_price_min_dealer'];
//$temp['goods_price_min_dealer'] = min($price_list_dealer);
}
}
$data[] = $temp;
}
return $data;
// //$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
// // $temp['goods_price_min_plus'] = $priceArr['membershipPrice'];
// // $temp['goods_price_min_dealer'] = $priceArr['distributionPrice'];
// $temp['goods_price_min'] = $goods['cost_price_min'];
// // $temp['goods_price_min_plus'] = min($price_list_plus);
// // $temp['goods_price_min_dealer'] = min($price_list_dealer);
// } elseif (UserService::isPlusMember()) {
// //$temp['goods_price_min_plus'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
// $temp['goods_price_min'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
// // $temp['goods_price_min'] = $temp['goods_price_min_plus'];
// // $temp['goods_price_max'] = $temp['goods_price_min_plus'];
// //$temp['goods_price_min_plus'] = min($price_list_plus);
// } elseif (UserService::isDealerMember()) {
// $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
// //$temp['goods_price_min_dealer'] = $priceArr['distributionPrice'];
// $temp['goods_price_min'] = $priceArr['goods_price_min_dealer'];
// //$temp['goods_price_min_dealer'] = min($price_list_dealer);
// }
// }
// $data[] = $temp;
// }
return is_array($goodsList) ? $goodsList : $goodsList->toArray();
}

Loading…
Cancel
Save