lqmac 3 months ago
parent 7de738bbfa
commit 82033e6813
  1. 4
      app/api/controller/Cart.php
  2. 5
      app/api/controller/Checkout.php
  3. 7
      app/api/controller/Goods.php
  4. 3
      app/api/model/Cart.php
  5. 40
      app/api/model/Goods.php
  6. 6
      app/api/model/Order.php
  7. 18
      app/api/service/Cart.php
  8. 2
      app/api/service/Goods.php
  9. 2
      app/api/service/cashier/Payment.php
  10. 13
      app/common/model/Goods.php

@ -37,7 +37,7 @@ class Cart extends Controller
{
// 购物车商品列表
$service = new CartService;
$list = $service->getList();
$list = $service->getList([], true, $this->storeInfo->toArray());
// 购物车商品总数量
$cartTotal = (new CartModel)->getCartTotal();
return $this->renderSuccess(compact('cartTotal', 'list'));
@ -68,6 +68,7 @@ class Cart extends Controller
*/
public function add(int $goodsId, string $goodsSkuId, int $goodsNum): Json
{
$model = new CartModel;
if (!$model->add($goodsId, $goodsSkuId, $goodsNum)) {
return $this->renderError($model->getError() ?: '加入购物车失败');
@ -90,6 +91,7 @@ class Cart extends Controller
*/
public function update(int $goodsId, string $goodsSkuId, int $goodsNum): Json
{
$model = new CartModel;
if (!$model->sUpdate($goodsId, $goodsSkuId, $goodsNum)) {
return $this->renderError($model->getError() ?: '更新失败');

@ -89,7 +89,8 @@ class Checkout extends Controller
$goodsList = $model->getOrderGoodsListByNow(
(int)$params['goodsId'],
(string)$params['goodsSkuId'],
(int)$params['goodsNum']
(int)$params['goodsNum'],
$this->storeInfo->toArray(),
);
$merchantId = 0;
//有上级商城的,商户ID都=0
@ -150,7 +151,7 @@ class Checkout extends Controller
// 商品结算信息
$CartModel = new CartService;
// 购物车商品列表
$goodsList = $CartModel->getOrderGoodsList($cartIds);
$goodsList = $CartModel->getOrderGoodsList($cartIds, $this->storeInfo->toArray());
// 获取订单结算信息
$orderInfo = $Checkout->onCheckout($goodsList);
if ($this->request->isGet()) {

@ -42,7 +42,8 @@ class Goods extends Controller
$param = $this->request->param();
//限制过滤条件-渠道
$param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : [];
$param['p_store_id'] = $this->storeInfo->p_store_id;
//$param['p_store_id'] = $this->storeInfo->p_store_id;
$param['storeInfo'] = $this->storeInfo;
//分类利润-利润率
$param['fliter_condition'] = $this->storeInfo['fliter_condition'];
if (isset($param['keyword']) && $param['keyword']) {
@ -73,7 +74,7 @@ class Goods extends Controller
{
// wmc商品详情
$model = new GoodsModel;
$goodsInfo = $model->getDetails($goodsId, $verifyStatus);
$goodsInfo = $model->getDetails($goodsId, $verifyStatus, $this->storeInfo->toArray());
if (!empty($goodsInfo['content'])) {
$goodsInfo['content'] = str_ireplace('onload="if(this.width>750){this.height=this.height*(750.0/this.width); this.width = 750;}', '', $goodsInfo['content']);
@ -372,7 +373,9 @@ class Goods extends Controller
*/
public function recommendedNew(): Json
{
$param = $this->request->param();
$param['storeInfo'] = $this->storeInfo;
$service = new GoodsService;
$goodsList = $service->recommendedNew($param);

@ -52,6 +52,7 @@ class Cart extends CartModel
*/
public function add(int $goodsId, string $goodsSkuId, int $goodsNum): bool
{
$storeId = self::$storeId;
// 判断是否已存在购物车记录
$detail = $this->getInfo($goodsId, $goodsSkuId, false);
// 如果已存在购物车记录, 则累计商品数量
@ -67,7 +68,7 @@ class Cart extends CartModel
'goods_sku_id' => $goodsSkuId,
'goods_num' => $goodsNum,
'user_id' => $userId,
'store_id' => self::$storeId,
'store_id' => $storeId,
]);
}

@ -433,7 +433,7 @@ class Goods extends GoodsModel
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDetails(int $goodsId, bool $verifyStatus = true)
public function getDetails(int $goodsId, bool $verifyStatus = true, array $storeInfo = [])
{
// 关联查询(商品图片、sku列表)
//$with = ['images.file', 'skuList.image', 'video', 'videoCover'];
@ -448,7 +448,7 @@ class Goods extends GoodsModel
$with = ['images.file', 'skuList.image', 'video', 'videoCover'];
}
// 获取商品记录
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus, $storeInfo);
//$this->dealGoodsImage($goodsInfo);
// 商品规格列表
@ -576,10 +576,14 @@ class Goods extends GoodsModel
* @return mixed
* @throws BaseException
*/
private function getGoodsMain(int $goodsId, array $with = [], bool $verifyStatus = true)
private function getGoodsMain(int $goodsId, array $with = [], bool $verifyStatus = true, array $storeInfo = [])
{
// 获取商品记录
$goodsInfo = static::detail($goodsId, $with);
//处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goodsInfo->cost_price_min = round($goodsInfo->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01));
}
//单规格和多规格处理不一致
$goodsInfo->skuList = $goodsInfo->skuList1 ? $goodsInfo->skuList1 : $goodsInfo->skuList;
@ -592,6 +596,10 @@ class Goods extends GoodsModel
if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other'] && $value->goods_id == $goodsId) {
$value->goods_sku_no = $goodsInfo['goods_no_other'];
}
if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$value->cost_price = round($value->cost_price / (1 - $storeInfo['markup_rate'] * 0.01));
}
}
//使用总后台的商品的图片作为商城商品的图片
@ -630,10 +638,17 @@ class Goods extends GoodsModel
* @param array $goodsIds
* @return mixed
*/
public function getListByIdsFromApi(array $goodsIds)
public function getListByIdsFromApi(array $goodsIds, array $storeInfo = [])
{
// 获取商品列表
$data = $this->getListByIds($goodsIds, GoodsStatusEnum::ON_SALE);
foreach ($data as $key => &$goods) {
//处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goods->cost_price_min = round($goods->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01));
}
}
// 整理列表数据并返回
return $this->setGoodsListDataFromApi($data);
}
@ -646,13 +661,18 @@ class Goods extends GoodsModel
* @return \app\common\model\GoodsSku|array|null
* @throws BaseException
*/
public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true)
public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true, array $storeInfo = [])
{
$goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId);
//处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goods->skuInfo->cost_price = round($goods->skuInfo->cost_price / (1 - $storeInfo['markup_rate'] * 0.01));
}
//$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo);
$catService = new GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
// $catService = new GoodsCategoryRel();
// $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
$catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id');
$currtime = time();
if ($goods->getAttr('skuInfo')) {
if (UserService::isPlusMember()) {
@ -715,10 +735,12 @@ class Goods extends GoodsModel
return;
}
$currtime = time();
$catService = new GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
// $catService = new GoodsCategoryRel();
// $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
$catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id');
$goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价
$goods['discount'] = 0.0;
//价格判断
if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);

@ -75,11 +75,11 @@ class Order extends OrderModel
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrderGoodsListByNow(int $goodsId, string $goodsSkuId, int $goodsNum)
public function getOrderGoodsListByNow(int $goodsId, string $goodsSkuId, int $goodsNum, array $storeInfo = [])
{
// 获取商品列表
$model = new GoodsModel;
$goodsList = $model->setEnableGradeMoney(false)->getListByIdsFromApi([$goodsId]);
$goodsList = $model->setEnableGradeMoney(false)->getListByIdsFromApi([$goodsId], $storeInfo);
if ($goodsList->isEmpty()) {
throwError('未找到商品信息');
@ -91,7 +91,7 @@ class Order extends OrderModel
$goodsList->hidden(GoodsModel::getHidden(['content', 'goods_images', 'images']));
foreach ($goodsList as &$item) {
// 商品sku信息
$item['skuInfo'] = GoodsModel::getSkuInfo($item, $goodsSkuId, false);
$item['skuInfo'] = GoodsModel::getSkuInfo($item, $goodsSkuId, false, $storeInfo);
// 商品封面 (优先sku封面)
$item['goods_image'] = $item['skuInfo']['goods_image'] ?: $item['goods_image'];

@ -37,7 +37,7 @@ class Cart extends BaseService
* @throws \think\db\exception\ModelNotFoundException
* @throws BaseException
*/
public function getList(array $cartIds = [], bool $enableGradeMoney = true)
public function getList(array $cartIds = [], bool $enableGradeMoney = true, array $storeInfo = [])
{
// 购物车列表
$cartList = $this->getCartList($cartIds);
@ -45,11 +45,11 @@ class Cart extends BaseService
$goodsIds = helper::getArrayColumn($cartList, 'goods_id');
if (empty($goodsIds)) return [];
// 获取商品列表
$goodsList = $this->getGoodsListByIds($goodsIds, $enableGradeMoney);
$goodsList = $this->getGoodsListByIds($goodsIds, $enableGradeMoney, $storeInfo);
// 整理购物车商品列表
foreach ($cartList as $cartIdx => $item) {
// 查找商品, 商品不存在则删除该购物车记录
$result = $this->findGoods($goodsList, $item, $enableGradeMoney);
$result = $this->findGoods($goodsList, $item, $enableGradeMoney, $storeInfo);
if ($result !== false) {
$cartList[$cartIdx]['goods'] = $result;
@ -80,10 +80,10 @@ class Cart extends BaseService
* @throws \think\db\exception\ModelNotFoundException
* @throws BaseException
*/
public function getOrderGoodsList(array $cartIds = []): array
public function getOrderGoodsList(array $cartIds = [], array $storeInfo = []): array
{
// 购物车列表
$cartList = $this->getList($cartIds, false);
$cartList = $this->getList($cartIds, false, $storeInfo);
// 订单商品列表
$goodsList = [];
foreach ($cartList as $item) {
@ -111,7 +111,7 @@ class Cart extends BaseService
* @return false|mixed
* @throws BaseException
*/
private function findGoods($goodsList, CartModel $item, bool $enableGradeMoney = true)
private function findGoods($goodsList, CartModel $item, bool $enableGradeMoney = true, array $storeInfo = [])
{
// 查找商品记录
$goodsInfo = helper::getArrayItemByColumn($goodsList, 'goods_id', $item['goods_id']);
@ -119,7 +119,7 @@ class Cart extends BaseService
return false;
}
// 获取当前选择的商品SKU信息
$goodsInfo['skuInfo'] = GoodsModel::getSkuInfo($goodsInfo, $item['goods_sku_id'], $enableGradeMoney);
$goodsInfo['skuInfo'] = GoodsModel::getSkuInfo($goodsInfo, $item['goods_sku_id'], $enableGradeMoney, $storeInfo);
// if (UserService::isPlusMember()) {
// $goodsInfo['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goodsInfo['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds);
@ -157,10 +157,10 @@ class Cart extends BaseService
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getGoodsListByIds(array $goodsIds, bool $enableGradeMoney = true)
private function getGoodsListByIds(array $goodsIds, bool $enableGradeMoney = true, array $storeInfo = [])
{
return (new GoodsModel)->setEnableGradeMoney($enableGradeMoney)
->getListByIdsFromApi($goodsIds)
->getListByIdsFromApi($goodsIds, $storeInfo)
->hidden(GoodsModel::getHidden(['goods_images']));
}

@ -193,6 +193,7 @@ class Goods extends GoodsService
'goodsIds' => implode(",",$setting['params']['goodsIds']),
'sortType' => "all",
'page' => $param['page'] ?? 1,
'storeInfo' => $param['storeInfo'] ?? [],
], 10);
} else {
// 数据来源:自动
@ -201,6 +202,7 @@ class Goods extends GoodsService
'categoryId' => is_array($setting['params']['auto']['category']) ? implode(',', $setting['params']['auto']['category']) : $setting['params']['auto']['category'],
'sortType' => $setting['params']['auto']['goodsSort'],
'page' => $param['page'] ?? 1,
'storeInfo' => $param['storeInfo'] ?? [],
], 10);
}

@ -278,7 +278,7 @@ class Payment extends BaseService
{
$PaymentModel = new PaymentModel;
//当前商户是系统自动创建的商户,自动读取商城主的支付配置
$model = \app\store\model\Merchant::detail($merchantId);
$model = \app\store\model\Merchant::withoutGlobalScope()->where('merchant_id', $merchantId)->find();
$merchantId = ($model && $model->channel_id > 0) ? 0 : $merchantId;
$templateInfo = $PaymentModel->getPaymentInfo($this->method, $this->client, $this->getStoreId(), $merchantId);
return $templateInfo['template']['config'][$this->method];

@ -28,6 +28,7 @@ use think\Paginator;
use app\store\model\GoodsImage as GoodsImageModel;
use app\store\model\UploadFile as UploadFileModel;
use app\common\model\Region;
use app\common\model\Store;
/**
* 商品模型
@ -382,8 +383,8 @@ class Goods extends BaseModel
}
}
$storeIds = [$storeId];
if (isset($param['p_store_id']) && $param['p_store_id']) {
$storeIds[] = $param['p_store_id'];
if (isset($param['storeInfo']['p_store_id']) && $param['storeInfo']['p_store_id']) {
$storeIds[] = $param['storeInfo']['p_store_id'];
}
//数据渠道过滤特殊处理
if (isset($param['fliter_condition']) && $param['fliter_condition']) {
@ -438,7 +439,7 @@ class Goods extends BaseModel
// 整理列表数据并返回
return $this->setGoodsListData($list);
return $this->setGoodsListData($list, null, $param['storeInfo'] ?? []);
}
/**
@ -711,7 +712,7 @@ class Goods extends BaseModel
* @param callable|null $callback 回调函数
* @return mixed
*/
protected function setGoodsListData($list, callable $callback = null)
protected function setGoodsListData($list, callable $callback = null, $storeInfo = [])
{
if ($list->isEmpty()) {
return $list;
@ -730,6 +731,10 @@ class Goods extends BaseModel
$goods->goods_no = $goodsList[$goods->origin_goods_id]['goods_no'] ?? "";
$goods->goods_name = $goodsList[$goods->origin_goods_id]['goods_name'] ?? "";
}
//处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goods->cost_price_min = round($goods->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01));
}
$goods = $this->setGoodsData($goods, $callback);
}

Loading…
Cancel
Save