diff --git a/app/common/dao/store/order/StoreCartDao.php b/app/common/dao/store/order/StoreCartDao.php index c76760fd..145c0c26 100644 --- a/app/common/dao/store/order/StoreCartDao.php +++ b/app/common/dao/store/order/StoreCartDao.php @@ -114,7 +114,7 @@ class StoreCartDao extends BaseDao } }, 'productAttr' => function (Relation $query) { - $query->field('image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price') + $query->field('image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price,procure_price') ->append(['bc_extension_one', 'bc_extension_two']); }, 'merchant' => function (Relation $query) use ($uid) { diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 09a89555..933500ab 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -107,28 +107,28 @@ class StoreOrderCreateRepository extends StoreOrderRepository } } } - if (($order_type == 98 || $order_type == 99) && count($merchantCartList) > 1) { - throw new ValidateException('采购、委托商品不支持跨店购买'); - } + // if (($order_type == 98 || $order_type == 99) && count($merchantCartList) > 1) { + // throw new ValidateException('采购、委托商品不支持跨店购买'); + // } $community = []; - if ($order_type == 98) { - $sourceIdArray = []; - foreach($merchantCart['list'] as $prod){ - if ($prod['source_id'] > 0) { - $sourceIdArray[] = $prod['source_id']; - } - } - if (count($sourceIdArray)) { - if (count(array_unique($sourceIdArray)) > 1) { - throw new ValidateException('转售商品数据异常'); - } - $community = Db::name('Community')->where('community_id', $sourceIdArray[0] ?? 0)->field('community_id, title, image')->fetchSql(false)->find(); - if ($community) { - $deliverMethod = Db::name('resale')->where('community_id', $sourceIdArray[0] ?? 0)->value('deliver_method'); - $deliverMethodArray = explode(',', $deliverMethod); - } - } - } + // if ($order_type == 98) { + // $sourceIdArray = []; + // foreach($merchantCart['list'] as $prod){ + // if ($prod['source_id'] > 0) { + // $sourceIdArray[] = $prod['source_id']; + // } + // } + // if (count($sourceIdArray)) { + // if (count(array_unique($sourceIdArray)) > 1) { + // throw new ValidateException('转售商品数据异常'); + // } + // $community = Db::name('Community')->where('community_id', $sourceIdArray[0] ?? 0)->field('community_id, title, image')->fetchSql(false)->find(); + // if ($community) { + // $deliverMethod = Db::name('resale')->where('community_id', $sourceIdArray[0] ?? 0)->value('deliver_method'); + // $deliverMethodArray = explode(',', $deliverMethod); + // } + // } + // } unset($merchantCart, $cart); $order_price = 0; $total_true_price = 0; @@ -182,9 +182,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository $product_cart = []; foreach ($merchantCart['list'] as $k => $cart) { - if ($order_type == 98) { - $merchantCart['list'][$k]['product']['delivery_way'] = $cart['product']['delivery_way'] = $deliverMethod ?? ''; - } //获取订单类型, 活动商品单次只能购买一个 if ($cart['product']['delivery_way']) { $delivery_way = explode(',', $cart['product']['delivery_way']); @@ -233,7 +230,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository } $svip_discount = 0; $realPrice = $this->cartByPrice($cart); - if ($cart['product_type'] == 98 || $cart['product_type'] == 99) { + if ($source == StoreCartDao::SOURCE_PROCURE) { + if($realPrice==0){ + throw new ValidateException('价格必须大于0'); + } $cart['product']['price'] = $realPrice; $cart['productAttr']['price'] = $realPrice; $cart['productAttr']['stock'] = $cart['cart_num']; @@ -394,105 +394,14 @@ class StoreOrderCreateRepository extends StoreOrderRepository }); } - //过滤不可用店铺优惠券 - foreach ($merchantCart['coupon'] as &$coupon) { - if (!$coupon['coupon']['type']) continue; - - $coupon['disabled'] = false; - $coupon['checked'] = false; - - if (count(array_intersect(array_column($coupon['product'], 'product_id'), array_keys($product_price))) == 0) { - $coupon['disabled'] = true; - continue; - } - if($svip_coupon_merge != '1' && $use_svip){ - $coupon['disabled'] = true; - continue; - } - $flag = false; - foreach ($coupon['product'] as $_product) { - if (isset($product_price[$_product['product_id']]) && $product_price[$_product['product_id']] >= $coupon['use_min_price']) { - $flag = true; - break; - } - } - if (!$flag) { - $coupon['disabled'] = true; - } -// if (!$coupon['disabled']) { -// $all_coupon_product[] = $coupon['coupon_user_id']; -// } - } - - unset($coupon); - - //if ($useCouponFlag && count(array_diff($all_coupon_product, $use_coupon_product))) { - // throw new ValidateException('请选择有效的商品券'); - //} - //计算商品券金额 - foreach ($merchantCart['coupon'] as &$coupon) { - if (!$coupon['coupon']['type']) continue; - if ($coupon['disabled']) continue; - - foreach ($coupon['product'] as $_product) { - if (isset($product_price[$_product['product_id']]) && $product_price[$_product['product_id']] >= $coupon['use_min_price']) { - if ($useCouponFlag) { - if (!in_array($coupon['coupon_user_id'], $merCouponIds) || isset($use_coupon_product[$_product['product_id']])) { - continue; - } - } else if (isset($use_coupon_product[$_product['product_id']])) { - continue; - } - $coupon_price = bcadd($coupon_price, $coupon['coupon_price'], 2); - $use_coupon_product[$_product['product_id']] = $coupon; - $coupon['checked'] = true; - break; - } - } - unset($_product); - } - unset($coupon); $pay_price = max(bcsub($valid_total_price, $coupon_price, 2), 0); $_pay_price = $pay_price; - //计算店铺券 - foreach ($merchantCart['coupon'] as &$coupon) { - if ($coupon['coupon']['type']) continue; - $coupon['checked'] = false; - $coupon['disabled'] = $pay_price <= 0; - if ($use_store_coupon || $pay_price <= 0) continue; - if($svip_coupon_merge != '1' && $use_svip){ - $coupon['disabled'] = true; - continue; - } - //店铺券 - if ($valid_total_price >= $coupon['use_min_price']) { - if ($useCouponFlag) { - if (!in_array($coupon['coupon_user_id'], $merCouponIds)) { - continue; - } - } - $use_store_coupon = $coupon; - $coupon_price = bcadd($coupon_price, $coupon['coupon_price'], 2); - $_pay_price = bcsub($_pay_price, $coupon['coupon_price'], 2); - $coupon['checked'] = true; - } else { - $coupon['disabled'] = true; - } - } - unset($coupon); + $productCouponRate = []; $storeCouponRate = null; $useCouponIds = []; - //计算优惠占比 - foreach ($use_coupon_product as $productId => $coupon) { - $productCouponRate[$productId] = [ - 'rate' => $product_price[$productId] > 0 ? bcdiv($coupon['coupon_price'], $product_price[$productId], 4) : 1, - 'coupon_price' => $coupon['coupon_price'], - 'price' => $product_price[$productId] - ]; - $useCouponIds[] = $coupon['coupon_user_id']; - } + if ($use_store_coupon) { $storeCouponRate = [ @@ -507,39 +416,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository foreach ($merchantCart['list'] as $_k => &$cart) { $cartTotalPrice = bcmul($this->cartByPrice($cart), $cart['cart_num'], 2); $_cartTotalPrice = $cartTotalPrice; - if (!$cart['product_type'] && $cartTotalPrice > 0) { - if (isset($productCouponRate[$cart['product_id']])) { - //计算每个商品优惠金额(商品券) - if ($productCouponRate[$cart['product_id']]['rate'] >= 1) { - $cartTotalPrice = 0; - } else { - array_pop($product_cart); - if (!count($product_cart)) { - $cartTotalPrice = bcsub($cartTotalPrice, $productCouponRate[$cart['product_id']]['coupon_price'], 2); - $productCouponRate[$cart['product_id']]['coupon_price'] = 0; - } else { - $couponPrice = bcmul($cartTotalPrice, $productCouponRate[$cart['product_id']]['rate'], 2); - $cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2); - $productCouponRate[$cart['product_id']]['coupon_price'] = bcsub($productCouponRate[$cart['product_id']]['coupon_price'], $couponPrice, 2); - } - } - } - - //(店铺券) - if ($storeCouponRate && $cartTotalPrice > 0) { - if ($storeCouponRate['rate'] >= 1) { - $cartTotalPrice = 0; - } else { - if (count($merchantCart['list']) == $_k + 1) { - $cartTotalPrice = bcsub($cartTotalPrice, $storeCouponRate['coupon_price'], 2); - } else { - $couponPrice = bcmul($cartTotalPrice, $storeCouponRate['rate'], 2); - $cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2); - $storeCouponRate['coupon_price'] = bcsub($storeCouponRate['coupon_price'], $couponPrice, 2); - } - } - } - } //单个商品实际支付金额 $cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2); @@ -578,8 +454,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository } unset($merchantCart); - $usePlatformCouponId = $useCoupon[0] ?? 0; - $usePlatformCouponId = is_array($usePlatformCouponId) ? array_pop($usePlatformCouponId) : $usePlatformCouponId; + $usePlatformCouponId = 0; + $total_platform_coupon_price = 0; $usePlatformCouponFlag = isset($useCoupon[0]); foreach ($merchantCartList as &$merchantCart) { @@ -601,154 +477,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository } unset($merchantCart); - //计算平台券优惠金额 -// if ($total_true_price > 0) { - $StoreCouponUser = app()->make(StoreCouponUserRepository::class); - $platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid); - if ($enabledPlatformCoupon && count($platformCoupon)) { - - $catePriceLst = []; - $storePriceLst = []; - $_cartNum = 0; - - foreach ($merchantCartList as &$merchantCart) { - if ($merchantCart['order']['true_price'] <= 0) continue; - foreach ($merchantCart['list'] as &$cart) { - $_cartNum++; - if ($cart['product']['cate_id']) { - if (!isset($catePriceLst[$cart['product']['cate_id']])) { - $catePriceLst[$cart['product']['cate_id']] = ['price' => 0, 'cart' => []]; - } - $catePriceLst[$cart['product']['cate_id']]['price'] = bcadd($catePriceLst[$cart['product']['cate_id']]['price'], $cart['true_price']); - $catePriceLst[$cart['product']['cate_id']]['cart'][] = &$cart; - } - } - unset($cart); - $storePriceLst[$merchantCart['mer_id']] = [ - 'price' => $merchantCart['order']['true_price'], - 'num' => count($merchantCart['list']) - ]; - } - unset($merchantCart); - $flag = false; - $platformCouponRate = null; - - foreach ($platformCoupon as &$coupon) { - $coupon['checked'] = false; - //通用券 - if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_ALL) { - $coupon['disabled'] = $total_true_price <= 0 || $coupon['use_min_price'] > $total_true_price; - if (!$platformCouponRate && !$coupon['disabled'] && !$flag && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) { - $platformCouponRate = [ - 'id' => $coupon['coupon_user_id'], - 'type' => $coupon['coupon']['type'], - 'price' => $total_true_price, - 'coupon_price' => $coupon['coupon_price'], - 'use_count' => $_cartNum, - 'check' => function ($cart) { - return true; - } - ]; - $coupon['checked'] = true; - $flag = true; - } - //品类券 - } else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_CATE) { - $_price = 0; - $_use_count = 0; - $cateIds = $coupon['product']->column('product_id'); - $allCateIds = array_unique(array_merge(app()->make(StoreCategoryRepository::class)->allChildren($cateIds), $cateIds)); - $flag2 = true; - foreach ($allCateIds as $cateId) { - if (isset($catePriceLst[$cateId])) { - $_price = bcadd($catePriceLst[$cateId]['price'], $_price, 2); - $_use_count += count($catePriceLst[$cateId]['cart']); - $flag2 = false; - } - } - $coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price; - //品类券可用 - if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) { - $platformCouponRate = [ - 'id' => $coupon['coupon_user_id'], - 'type' => $coupon['coupon']['type'], - 'price' => $_price, - 'use_cate' => $allCateIds, - 'coupon_price' => $coupon['coupon_price'], - 'use_count' => $_use_count, - 'check' => function ($cart) use ($allCateIds) { - return in_array($cart['product']['cate_id'], $allCateIds); - } - ]; - $coupon['checked'] = true; - $flag = true; - } - //跨店券 - } else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_STORE) { - $_price = 0; - $_use_count = 0; - $flag2 = true; - foreach ($coupon['product'] as $item) { - $merId = $item['product_id']; - if (isset($storePriceLst[$merId])) { - $_price = bcadd($storePriceLst[$merId]['price'], $_price, 2); - $_use_count += $storePriceLst[$merId]['num']; - $flag2 = false; - } - } - $coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price; - //店铺券可用 - if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) { - $_merIds = $coupon['product']->column('product_id'); - $platformCouponRate = [ - 'id' => $coupon['coupon_user_id'], - 'type' => $coupon['coupon']['type'], - 'price' => $_price, - 'use_store' => $_merIds, - 'coupon_price' => $coupon['coupon_price'], - 'use_count' => $_use_count, - 'check' => function ($cart) use ($_merIds) { - return in_array($cart['mer_id'], $_merIds); - } - ]; - $coupon['checked'] = true; - $flag = true; - } - } - } - unset($coupon); - } -// } - $usePlatformCouponId = 0; $total_platform_coupon_price = 0; - //计算平台优惠券 - if (isset($platformCouponRate)) { - $_coupon_price = $platformCouponRate['coupon_price']; - foreach ($merchantCartList as &$merchantCart) { - $_price = 0; - foreach ($merchantCart['list'] as &$cart) { - if ($cart['true_price'] <= 0 || !$platformCouponRate['check']($cart)) continue; - - if ($platformCouponRate['use_count'] === 1) { - $couponPrice = min($platformCouponRate['coupon_price'], $cart['true_price']); - } else { - $couponPrice = min(bcmul($_coupon_price, bcdiv($cart['true_price'], $platformCouponRate['price'], 3), 2), $cart['true_price']); - } - $platformCouponRate['coupon_price'] = bcsub($platformCouponRate['coupon_price'], $couponPrice, 2); - $cart['true_price'] = bcsub($cart['true_price'], $couponPrice, 2); - $cart['platform_coupon_price'] = $couponPrice; - $platformCouponRate['use_count']--; - $_price = bcadd($couponPrice, $_price, 2); - } - unset($cart); - $merchantCart['order']['platform_coupon_price'] = $_price; - $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], $_price, 2); - $total_platform_coupon_price = bcadd($total_platform_coupon_price, $_price, 2); - } - $usePlatformCouponId = $platformCouponRate['id']; - unset($merchantCart); - } //积分配置 $sysIntegralConfig = systemConfig(['integral_money', 'integral_status', 'integral_order_rate']); @@ -775,49 +505,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merIntegralFlag = $merIntegralFlag || ((bool)$merIntegralConfig['mer_integral_status']); $integralFlag = $useIntegral && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0 && $merIntegralConfig['mer_integral_status']; - //计算积分抵扣 - foreach ($merchantCart['list'] as &$cart) { - //只有普通商品可以抵扣 - if ($cart['product_type'] == 0 && $integralFlag && $userIntegral > 0 && $merchantCart['order']['true_price'] > 0) { - $integralRate = $cart['product']['integral_rate']; - if ($integralRate < 0) { - $integralRate = $merIntegralConfig['mer_integral_rate']; - } else if($integralRate > 0){ - $integralRate = min(bcdiv($integralRate, 100, 4), 1); - } - if ($integralRate > 0) { - $productIntegralPrice = min(bcmul(bcmul($this->cartByPrice($cart), $cart['cart_num'], 2), $integralRate, 2), $cart['true_price']); - if ($productIntegralPrice > 0) { - $productIntegral = ceil(bcdiv($productIntegralPrice, $sysIntegralConfig['integral_money'], 3)); - if ($productIntegral <= $userIntegral) { - $userIntegral = bcsub($userIntegral, $productIntegral, 0); - //使用多少积分抵扣了多少金额 - $cart['integral'] = [ - 'use' => $productIntegral, - 'price' => $productIntegralPrice - ]; - } else { - $productIntegralPrice = bcmul($userIntegral, $sysIntegralConfig['integral_money'], 2); - //使用多少积分抵扣了多少金额 - $cart['integral'] = [ - 'use' => $userIntegral, - 'price' => $productIntegralPrice - ]; - $userIntegral = 0; - } - - $cart['true_price'] = bcsub($cart['true_price'], $cart['integral']['price'], 2); - $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], $cart['integral']['price'], 2); - - $total_integral_price = bcadd($total_integral_price, $cart['integral']['price'], 2); - $total_integral = bcadd($total_integral, $cart['integral']['use'], 0); - continue; - } - } - } - $cart['integral'] = null; - } - unset($cart); $order_total_integral = bcadd($order_total_integral, $total_integral, 0); $order_total_integral_price = bcadd($order_total_integral_price, $total_integral_price, 2); @@ -848,14 +535,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository $giveIntegralFlag = $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_order_rate'] > 0; $total_give_integral = 0; - //计算赠送积分, 只有普通商品赠送积分 - if ($giveIntegralFlag && !$order_type && $pay_price > 0) { - $total_give_integral = floor(bcmul($pay_price, $sysIntegralConfig['integral_order_rate'], 0)); - if ($total_give_integral > 0 && $svip_status && $svip_integral_rate > 0) { - $total_give_integral = bcmul($svip_integral_rate, $total_give_integral, 0); - } - } - $order_total_give_integral = bcadd($total_give_integral, $order_total_give_integral, 0); foreach ($fn as $callback) { $callback(); @@ -901,7 +580,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'order_price', 'total_price', 'community', - 'platformCoupon', 'enabledPlatformCoupon', 'usePlatformCouponId', 'order_total_integral', diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 55d842a0..15d9250f 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -557,17 +557,22 @@ class StoreOrderRepository extends BaseRepository return $cart['activeSku']['active_price']; // 更新调货价格 } else if ($cart['product_type'] == '98') { - if ($cart['source_id'] > 0) { - $resale_find = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->find(); - if ($resale_find &&$resale_find['status']==0) { - return $resale_find['price']; - }else if($resale_find['status']==1){ - throw new ValidateException('商品已转售'); - } - else { - throw new ValidateException('转售商品数据异常'); - } - } else { + // if ($cart['source_id'] > 0) { + // $resale_find = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->find(); + // if ($resale_find &&$resale_find['status']==0) { + // return $resale_find['price']; + // }else if($resale_find['status']==1){ + // throw new ValidateException('商品已转售'); + // } + // else { + // throw new ValidateException('转售商品数据异常'); + // } + // } else { + // return $cart['productAttr']['price']; + // } + if($cart['source']== StoreCartDao::SOURCE_PROCURE){ + return $cart['productAttr']['procure_price']; + }else{ return $cart['productAttr']['price']; } // 更新委托价格 diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index ffa2d9bb..66df1327 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -286,10 +286,10 @@ class ProductRepository extends BaseRepository $spuData['mer_labels'] = $data['mer_labels']; Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$product,$spuData,$merId) { $this->save($id, $settleParams, $content, $product, $productType); - if ($productType == 1) { //秒杀商品 - $dat = $this->setSeckillProduct($data); - app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); - } + // if ($productType == 1) { //秒杀商品 + // $dat = $this->setSeckillProduct($data); + // app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); + // } if ($productType == 0) { $make = app()->make(ParameterValueRepository::class); $make->clear($id, 'product_id'); @@ -595,7 +595,7 @@ class ProductRepository extends BaseRepository $_svip_price = $value['svip_price']; $svip_price = !$svip_price ? $value['svip_price'] : (($svip_price > $value['svip_price']) ? $value['svip_price'] : $svip_price); } - + $procure_price=$value['procure_price']??0.00; $cost = !$cost ? $value['cost'] : (($cost > $value['cost']) ?$cost: $value['cost']); $price = !$price ? $sprice : (($price > $sprice) ? $sprice : $price); $ot_price = !$ot_price ? $ot_price_ : (($ot_price > $ot_price_) ? $ot_price : $ot_price_); @@ -620,6 +620,7 @@ class ProductRepository extends BaseRepository 'sales' => $isUpdate ? ($oldSku[$sku]['sales'] ?? 0) : 0, 'svip_price' => $_svip_price, 'mer_id' => $merId, + 'procure_price' => $procure_price ]; $stock = $stock + intval($value['stock']); } @@ -629,6 +630,7 @@ class ProductRepository extends BaseRepository 'ot_price' => $ot_price, 'cost' => $cost, 'svip_price' => $svip_price, + 'procure_price' => $procure_price, ]; } catch (\Exception $exception) { throw new ValidateException('规格错误 :'.$exception->getMessage()); diff --git a/app/controller/api/server/StoreOrder.php.bak b/app/controller/api/server/StoreOrder.php.bak deleted file mode 100644 index f956034f..00000000 --- a/app/controller/api/server/StoreOrder.php.bak +++ /dev/null @@ -1,336 +0,0 @@ - -// +---------------------------------------------------------------------- - - -namespace app\controller\api\server; - - -use app\common\repositories\delivery\DeliveryStationRepository; -use app\common\repositories\store\order\StoreOrderRepository; -use app\common\repositories\store\order\StoreRefundOrderRepository; -use app\common\repositories\store\service\StoreServiceRepository; -use app\controller\merchant\Common; -use crmeb\basic\BaseController; -use think\App; -use think\exception\HttpResponseException; -use think\exception\ValidateException; -use think\facade\Db; -use think\response\Json; - -class StoreOrder extends BaseController -{ - public function __construct(App $app) - { - parent::__construct($app); - } - - public function orderStatistics($merId, StoreOrderRepository $repository) - { - $order = $repository->OrderTitleNumber($merId, null); - $order['refund'] = app()->make(StoreRefundOrderRepository::class)->getWhereCount(['is_system_del' => 0, 'mer_id' => $merId]); - $common = app()->make(Common::class); - $data = []; - $data['today'] = $common->mainGroup('today', $merId); - $data['yesterday'] = $common->mainGroup('yesterday', $merId); - $data['month'] = $common->mainGroup('month', $merId); - return app('json')->success(compact('order', 'data')); - } - - public function orderDetail($merId, StoreOrderRepository $repository) - { - [$page, $limit] = $this->getPage(); - list($start, $stop) = $this->request->params([ - ['start', strtotime(date('Y-m'))], - ['stop', time()], - ], true); - if ($start == $stop) return app('json')->fail('参数有误'); - if ($start > $stop) { - $middle = $stop; - $stop = $start; - $start = $middle; - } - $where = $this->request->has('start') ? ['dateRange' => compact('start', 'stop')] : []; - $list = $repository->orderGroupNumPage($where, $page, $limit, $merId); - return app('json')->success($list); - } - - public function orderList($merId, StoreOrderRepository $repository) - { - [$page, $limit] = $this->getPage(); - $where['status'] = $this->request->param('status'); - $where['is_verify'] = $this->request->param('is_verify'); - $where['search'] = $this->request->param('store_name'); - $where['mer_id'] = $merId; - $where['is_del'] = 0; - if($where['status'] == 2) $where['order_type'] = 0; - return app('json')->success($repository->merchantGetList($where, $page, $limit)); - } - - public function order($merId, $id, StoreOrderRepository $repository) - { - $detail = $repository->getDetail($id); - if (!$detail) - return app('json')->fail('订单不存在'); - if ($detail['mer_id'] != $merId) - return app('json')->fail('没有权限'); - return app('json')->success($detail->toArray()); - } - - - protected function checkOrderAuth($merId, $id) - { - if (!app()->make(StoreOrderRepository::class)->existsWhere(['mer_id' => $merId, 'order_id' => $id])) - throw new ValidateException('没有权限'); - } - - public function mark($merId, $id, StoreOrderRepository $repository) - { - $this->checkOrderAuth($merId, $id); - $data = $this->request->params(['remark']); - $repository->update($id, $data); - return app('json')->success('备注成功'); - } - - public function price($merId, $id, StoreOrderRepository $repository) - { - $this->checkOrderAuth($merId, $id); - - $data = $this->request->params(['total_price', 'pay_postage']); - - if ($data['total_price'] < 0 || $data['pay_postage'] < 0) - return app('json')->fail('金额不可未负数'); - if (!$repository->merStatusExists((int)$id, $merId)) - return app('json')->fail('订单信息或状态错误'); - $repository->eidt($id, $data); - return app('json')->success('修改成功'); - } - - /** - * TODO 发货操作 - * @param $merId - * @param $id - * @param StoreOrderRepository $repository - * @return Json - * @author Qinii - * @day 6/1/22 - */ - public function delivery($merId, $id, StoreOrderRepository $repository) - { - $this->checkOrderAuth($merId, $id); - $type = $this->request->param('delivery_type'); - $split = $this->request->params(['is_split',['split',[]]]); - if (!$repository->merDeliveryExists($id, $merId)) - return app('json')->fail('订单信息或状态错误'); - switch ($type) - { - case 3: //虚拟发货 - $data = $this->request->params([ - 'delivery_type', - 'remark', - ]); - $data['delivery_name'] = ''; - $data['delivery_id'] = ''; - $method = 'delivery'; - break; - case 4: //电子面单 - if (!systemConfig('crmeb_serve_dump')) - return app('json')->fail('电子面单功能未开启'); - $data = $this->request->params([ - 'delivery_type', - 'delivery_name', - 'from_name', - 'from_tel', - 'from_addr', - 'temp_id', - 'remark', - ]); - if (!$data['from_name'] || - !$data['delivery_name'] || - !$data['from_tel'] || - !$data['from_addr'] || - !$data['temp_id'] - ) - return app('json')->fail('填写配送信息'); - $method = 'dump'; - break; - case 5: //同城配送 - if (systemConfig('delivery_status') != 1) - return app('json')->fail('未开启同城配送'); - $data = $this->request->params([ - 'delivery_type', - 'station_id', - 'mark', - ['cargo_weight',0], - 'remark', - ]); - if ($data['cargo_weight'] < 0) return app('json')->fail('包裹重量能为负数'); - if (!$data['station_id']) return app('json')->fail('请选择门店'); - $method = 'cityDelivery'; - break; - default: //快递 - $data = $this->request->params([ - 'delivery_type', - 'delivery_type', - 'delivery_name', - 'delivery_id', - 'remark', - ]); - if (!$data['delivery_type'] || !$data['delivery_name'] || !$data['delivery_id']) - return app('json')->fail('填写配送信息'); - - $method = 'delivery'; - break; - } - $repository->runDelivery($id,$merId, $data, $split, $method, $this->request->serviceInfo()->service_id); - return app('json')->success('发货成功'); - } - - public function payPrice($merId, StoreOrderRepository $repository) - { - list($start, $stop, $month) = $this->request->params([ - ['start', strtotime(date('Y-m'))], - ['stop', time()], - 'month' - ], true); - - if ($month) { - $start = date('Y/m/d', strtotime(getStartModelTime('month'))); - $stop = date('Y/m/d H:i:s', strtotime('+ 1day')); - $front = date('Y/m/d', strtotime('first Day of this month', strtotime('-1 day', strtotime('first Day of this month')))); - $end = date('Y/m/d H:i:s', strtotime($start . ' -1 second')); - } else { - if ($start == $stop) return app('json')->fail('参数有误'); - if ($start > $stop) { - $middle = $stop; - $stop = $start; - $start = $middle; - } - $space = bcsub($stop, $start, 0);//间隔时间段 - $front = bcsub($start, $space, 0);//第一个时间段 - - $front = date('Y/m/d H:i:s', $front); - $start = date('Y/m/d H:i:s', $start); - $stop = date('Y/m/d H:i:s', $stop); - $end = date('Y/m/d H:i:s', strtotime($start . ' -1 second')); - } - $frontPrice = $repository->dateOrderPrice($front . '-' . $end, $merId); - $afterPrice = $repository->dateOrderPrice($start . '-' . date('Y/m/d H:i:s', strtotime($stop . '-1 second')), $merId); - $chartInfo = $repository->chartTimePrice($start, date('Y/m/d H:i:s', strtotime($stop . '-1 second')), $merId); - $data['chart'] = $chartInfo;//营业额图表数据 - $data['time'] = $afterPrice;//时间区间营业额 - $increase = (float)bcsub((string)$afterPrice, (string)$frontPrice, 2); //同比上个时间区间增长营业额 - $growthRate = abs($increase); - if ($growthRate == 0) $data['growth_rate'] = 0; - else if ($frontPrice == 0) $data['growth_rate'] = bcmul($growthRate, 100, 0); - else $data['growth_rate'] = (int)bcmul((string)bcdiv((string)$growthRate, (string)$frontPrice, 2), '100', 0);//时间区间增长率 - $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额 - $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2 - - return app('json')->success($data); - } - - /** - * @param StoreOrderRepository $repository - * @return Json - * @author xaboy - * @day 2020/8/27 - */ - public function payNumber($merId, StoreOrderRepository $repository) - { - list($start, $stop, $month) = $this->request->params([ - ['start', strtotime(date('Y-m'))], - ['stop', time()], - 'month' - ], true); - - if ($month) { - $start = date('Y/m/d', strtotime(getStartModelTime('month'))); - $stop = date('Y/m/d H:i:s', strtotime('+ 1day')); - $front = date('Y/m/d', strtotime('first Day of this month', strtotime('-1 day', strtotime('first Day of this month')))); - $end = date('Y/m/d H:i:s', strtotime($start . ' -1 second')); - } else { - if ($start == $stop) return app('json')->fail('参数有误'); - if ($start > $stop) { - $middle = $stop; - $stop = $start; - $start = $middle; - } - $space = bcsub($stop, $start, 0);//间隔时间段 - $front = bcsub($start, $space, 0);//第一个时间段 - - $front = date('Y/m/d H:i:s', $front); - $start = date('Y/m/d H:i:s', $start); - $stop = date('Y/m/d H:i:s', $stop); - $end = date('Y/m/d H:i:s', strtotime($start . ' -1 second')); - } - $frontNumber = $repository->dateOrderNum($front . '-' . $end, $merId); - $afterNumber = $repository->dateOrderNum($start . '-' . date('Y/m/d H:i:s', strtotime($stop . '-1 second')), $merId); - $chartInfo = $repository->chartTimeNum($start . '-' . date('Y/m/d H:i:s', strtotime($stop . '-1 second')), $merId); - $data['chart'] = $chartInfo;//订单数图表数据 - $data['time'] = $afterNumber;//时间区间订单数 - $increase = $afterNumber - $frontNumber; //同比上个时间区间增长订单数 - $growthRate = abs($increase); - if ($growthRate == 0) $data['growth_rate'] = 0; - else if ($frontNumber == 0) $data['growth_rate'] = bcmul($growthRate, 100, 0); - else $data['growth_rate'] = (int)bcmul((string)bcdiv((string)$growthRate, (string)$frontNumber, 2), '100', 0);//时间区间增长率 - $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额 - $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2 - - return app('json')->success($data); - } - - public function getFormData($merId) - { - $config = [ - 'mer_from_com', - 'mer_from_name', - 'mer_from_tel', - 'mer_from_addr', - 'mer_config_siid', - 'mer_config_temp_id' - ]; - $data = merchantConfig($merId,$config); - return app('json')->success($data); - } - - public function getDeliveryConfig() - { - $data = systemConfig(['crmeb_serve_dump','delivery_status']); - return app('json')->success($data); - } - - public function getDeliveryOptions($merId, DeliveryStationRepository $repository) - { - if (!systemConfig('delivery_status')) { - return app('json')->success([]); - } - $where = [ - 'status' => 1, - 'mer_id' => $merId, - 'type' => systemConfig('delivery_type'), - ]; - $data = $repository->getOptions($where)->toArray(); - $type = systemConfig('delivery_type') == 1 ? 'UU' : '达达'; - if (empty($data)) return app('json')->fail('请前往商户后台添加'.$type.'发货点'); - return app('json')->success($data); - } - - public function verify($merId,$id,StoreOrderRepository $orderRepository) - { - $order = $orderRepository->getWhere(['order_id' => $id,'mer_id' => $merId]); - if (!$order) return app('json')->fail('数据不存在'); - $data = $this->request->params(['verify_code','data']); - $orderRepository->verifyOrder($order->verify_code, $merId, $data, $this->request->serviceInfo()->service_id); - return app('json')->success('订单核销成功'); - } - -} diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 75f83709..0a3ef2e2 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -90,7 +90,7 @@ class StoreProduct extends BaseController $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1; $data['rate'] = 3; $typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code'); - // if ($merchant['type_id']==12){ + if ($merchant['type_id']==12){ if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){ $product_type=98;//供应链 }else{ @@ -104,7 +104,7 @@ class StoreProduct extends BaseController // 'unique' => $unique, // 'number' => $stockNum, // ]); - // } + } return app('json')->success('添加成功'); } diff --git a/app/controller/api/server/StoreProduct.php.bak b/app/controller/api/server/StoreProduct.php.bak deleted file mode 100644 index d39a5ffd..00000000 --- a/app/controller/api/server/StoreProduct.php.bak +++ /dev/null @@ -1,206 +0,0 @@ - -// +---------------------------------------------------------------------- -namespace app\controller\api\server; - -use app\common\repositories\store\order\StoreCartRepository; -use app\common\repositories\store\product\ProductLabelRepository; -use app\common\repositories\store\product\ProductRepository; -use app\common\repositories\store\service\StoreServiceRepository; -use app\common\repositories\system\merchant\MerchantRepository; -use app\validate\merchant\StoreProductValidate; -use crmeb\basic\BaseController; -use crmeb\services\UploadService; -use think\App; -use think\exception\HttpResponseException; -use think\exception\ValidateException; - -class StoreProduct extends BaseController -{ - protected $merId; - protected $repository; - - public function __construct(App $app, ProductRepository $repository) - { - parent::__construct($app); - $this->repository = $repository; - $this->merId = $this->request->route('merId'); - } - - /** - * TODO 头部统计 - * @param $merId - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function title($merId) - { - return app('json')->success($this->repository->getFilter($merId, '', 0)); - } - - /** - * TODO 列表 - * @param $merId - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function lst($merId) - { - [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id', 'keyword', ['type',20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels',['order','sort']]); - $where = array_merge($where, $this->repository->switchType($where['type'], $merId, 0)); - return app('json')->success($this->repository->getList($merId, $where, $page, $limit)); - } - - /** - * TODO 添加 - * @param $merId - * @param StoreProductValidate $validate - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function create($merId, StoreProductValidate $validate) - { - $res = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($res,$merId); - $data['mer_id'] = $merId; - $data['is_gift_bag'] = 0; - $merchant = app()->make(MerchantRepository::class)->get($merId); - $data['status'] = $merchant->is_audit ? 0 : 1; - $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1; - $data['rate'] = 3; - $this->repository->create($data, 0, 1); - return app('json')->success('添加成功'); - } - - /** - * TODO 编辑 - * @param $merId - * @param $id - * @param StoreProductValidate $validate - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function update($merId, $id, StoreProductValidate $validate) - { - $res = $this->request->params($this->repository::CREATE_PARAMS); - $data = $this->repository->checkParams($res,$merId,$id); - - $merchant = app()->make(MerchantRepository::class)->get($merId); - if (!$this->repository->merExists($merId, $id)) - return app('json')->fail('数据不存在'); - $pro = $this->repository->getWhere(['product_id' => $id]); - if ($pro->status == -2) { - $data['status'] = 0; - } else { - $data['status'] = $merchant->is_audit ? 0 : 1; - } - $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1; - $data['mer_id'] = $merId; - $this->repository->edit($id, $data, $merId, 0, 1); - return app('json')->success('编辑成功'); - } - - /** - * TODO 详情 - * @param $merId - * @param $id - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function detail($merId, $id) - { - if (!$this->repository->merExists($merId, $id)) - return app('json')->fail('数据不存在'); - return app('json')->success($this->repository->getAdminOneProduct($id, 0, 1)); - } - - /** - * TODO 修改状态 - * @param $merId - * @param $id - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function switchStatus($merId, $id) - { - $status = $this->request->param('status', 0) == 1 ? 1 : 0; - if (!$this->repository->merExists($merId, $id)) - return app('json')->fail('数据不存在'); - $this->repository->switchShow($id,$status, 'is_show',$merId); - return app('json')->success('修改成功'); - } - - /** - * TODO 加入回收站 - * @param $merId - * @param $id - * @return \think\response\Json - * @author Qinii - * @day 8/24/21 - */ - public function delete($merId, $id) - { - if (!$this->repository->merExists($merId, $id)) - return app('json')->fail('数据不存在'); - if ($this->repository->getWhereCount(['product_id' => $id, 'is_show' => 1, 'status' => 1])) - return app('json')->fail('商品上架中'); - $this->repository->delete($id); - return app('json')->success('转入回收站'); - } - - public function config($merId) - { - $data['extension_status'] = systemConfig('extension_status'); - $data['integral_status'] = 0; - $data['integral_rate'] = 0; - if(systemConfig('integral_status') && merchantConfig($merId,'mer_integral_status')) { - $data['integral_status'] = 1; - $data['integral_rate'] = merchantConfig($merId,'mer_integral_rate'); - } - $merchant = app()->make(MerchantRepository::class)->get($merId); - $data['delivery_way'] = $merchant->delivery_way; - return app('json')->success($data); - } - - public function restore($id) - { - if (!$this->repository->merDeleteExists($this->merId, $id)) - return app('json')->fail('只能删除回收站的商品'); - $this->repository->restore($id); - return app('json')->success('商品已恢复'); - } - - public function destory($id) - { - if (!$this->repository->merDeleteExists($this->merId, $id)) - return app('json')->fail('只能删除回收站的商品'); - if (app()->make(StoreCartRepository::class)->getProductById($id)) - return app('json')->fail('商品有被加入购物车不可删除'); - $this->repository->destory($id); - return app('json')->success('删除成功'); - } - - public function updateGood($id) - { - $is_good = $this->request->param('is_good', 0) == 1 ? 1 : 0; - if (!$this->repository->merExists($this->merId, $id)) - return app('json')->fail('数据不存在'); - - $this->repository->update($id, ['is_good' => $is_good]); - return app('json')->success('修改成功'); - } -}