添加:总平台订单下单流程兼容

This commit is contained in:
wuhui_zzw 2024-04-11 15:07:10 +08:00
parent 4ae8ae8a6e
commit 60f58e2e9c
8 changed files with 89 additions and 62 deletions

View File

@ -154,7 +154,7 @@ class StoreCartDao extends BaseDao
}
])
->whereIn('cart_id',$ids)
->order('product_type DESC,cart_id DESC')
->order('product_type DESC,mer_id ASC,cart_id DESC')
->select();
}

View File

@ -6,6 +6,8 @@ use app\common\model\BaseModel;
class Point extends BaseModel{
public $hidden = ['is_del'];
public static function tablePk(): string{
return 'id';
}

View File

@ -77,7 +77,22 @@ class PointRepository extends BaseRepository{
}
/**
* Common: 移动端获取总平台提货点配置信息
* Author: wu-hui
* Time: 2024/04/11 10:14
* @param int $useId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUseInfo(int $useId = 0):array{
$list = $this->getSearchModel([])->withoutField('create_time,update_time')->select()->toArray();
$config = $useId > 0 ? (array_column($list, null, 'id')[$useId] ?? []) : [];
return compact('list', 'config');
}

View File

@ -11,6 +11,7 @@ use app\common\model\store\product\Product;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\coupon\StoreCouponProductRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\PointRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\user\MemberinterestsRepository;
use think\exception\ValidateException;
@ -48,7 +49,7 @@ class StoreCartRepository extends BaseRepository
return $this->checkCartList($res, $user->uid, $user);
}
public function checkCartList($res, $hasCoupon = 0, $user = null)
public function checkCartList($res, $hasCoupon = 0, $user = null,$points = [])
{
$arr = $fail = [];
$product_make = app()->make(ProductRepository::class);
@ -60,14 +61,24 @@ class StoreCartRepository extends BaseRepository
} else {
//商户信息
if ($item['merchant']){
// 商户存在 购买商户商品
$merchantData = $item['merchant']->append(['openReceipt'])->toArray();
} else {
// 商户不存在 购买总平台商品
$merchantData = [
'mer_id' => 0,
'delivery_way' => [1,2]
'delivery_way' => $product_make->getPlatformDeliveryWay(),
];
// 总平台 允许自提时 提货点信息处理
if(in_array(1, $merchantData['delivery_way'])){
$pointId = $points[$merchantData['mer_id']] ?? 0;
$deliveryWayInfo = app()->make(PointRepository::class)->getUseInfo((int)$pointId);
$merchantData['delivery_way_list'] = $deliveryWayInfo['list'];
$merchantData['config'] = $deliveryWayInfo['config'];
}
}
unset($item['merchant']);
$coupon_make = app()->make(StoreCouponRepository::class);
if (!isset($arr[$item['mer_id']])) {
@ -89,6 +100,7 @@ class StoreCartRepository extends BaseRepository
}
}
$list = array_values($arr);
return compact('list', 'fail');
}

View File

@ -38,7 +38,7 @@ use think\facade\{Cache,Db,Log,Queue};
class StoreOrderCreateRepository extends StoreOrderRepository{
/****** 原始版本 ************************************/
public function v2CartIdByOrderInfo($user,array $cartId,array $takes = NULL,array $useCoupon = NULL,bool $useIntegral = FALSE,int $addressId = NULL,array $withGoods = [],$createOrder = FALSE){
public function v2CartIdByOrderInfo($user,array $cartId,array $takes = NULL,array $points = NULL,array $useCoupon = NULL,bool $useIntegral = FALSE,int $addressId = NULL,array $withGoods = [],$createOrder = FALSE){
$uid = $user->uid;
$userIntegral = $user->integral;
$exchangeIntegral = $user->exchange_integral ?? 0;// 持有可用酒水卡积分
@ -57,7 +57,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
//获取购物车信息
if($isWithGoods) $cartIbByData = $storeCartRepository->cartIbByData($cartId,0,$address,$withGoods);
else $cartIbByData = $storeCartRepository->cartIbByData($cartId,$uid,$address);
$res = $storeCartRepository->checkCartList($cartIbByData,0,$user);
$res = $storeCartRepository->checkCartList($cartIbByData,0,$user,$points);
$merchantCartList = $res['list'];
$fail = $res['fail'];
@ -70,9 +70,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
throw new ValidateException('[已失效]'.mb_substr($fail[0]['product']['store_name'],0,10).'...');
}
$svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1';
$svip_integral_rate = $svip_status ? app()
->make(MemberinterestsRepository::class)
->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0;
$svip_integral_rate = $svip_status ? app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0;
//订单活动类型
$order_type = 0;
//虚拟订单
@ -148,22 +146,20 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$order_refund_switch = 0;
//是否自提
$isTake = in_array($merchantCart['mer_id'],$takes ?? []);
$merTake = in_array('1',$merchantCart['delivery_way'],TRUE);
$merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2',$merchantCart['delivery_way'],TRUE));
$merTake = in_array('1',$merchantCart['delivery_way']);
$merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2',$merchantCart['delivery_way']));
$_merTake = $merTake;
$_merDelivery = $merDelivery;
$deliveryStatus = TRUE;
if($createOrder && $isTake && !$merTake){
$deliveryStatus = FALSE;
}
if($createOrder && $isTake && !$merTake) $deliveryStatus = FALSE;
$product_cart = [];
foreach($merchantCart['list'] as $k => $cart){
//获取订单类型, 活动商品单次只能购买一个
if($cart['product']['delivery_way']){
$delivery_way = explode(',',$cart['product']['delivery_way']);
$proTake = in_array('1',$delivery_way,TRUE);
$proTake = in_array('1',$delivery_way);
$merTake = $merTake && $proTake;
$proDelivery = (!count($delivery_way) || in_array('2',$delivery_way,TRUE));
$proDelivery = (!count($delivery_way) || in_array('2',$delivery_way));
$merDelivery = $merDelivery && $proDelivery;
$merchantCart['list'][$k]['allow_take'] = $proTake;
$merchantCart['list'][$k]['allow_delivery'] = $proDelivery;
@ -172,16 +168,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$merchantCart['list'][$k]['allow_take'] = $_merTake;
$merchantCart['list'][$k]['allow_delivery'] = $_merDelivery;
}
if($createOrder && $isTake && !$merTake){
$deliveryStatus = FALSE;
}
}
if(!$merDelivery && !$merTake){
$deliveryStatus = FALSE;
}
if($deliveryStatus && !$isTake && ($merDelivery || $merTake)){
$isTake = $merDelivery ? 0 : 1;
if($createOrder && $isTake && !$merTake) $deliveryStatus = FALSE;
}
if(!$merDelivery && !$merTake) $deliveryStatus = FALSE;
if($deliveryStatus && !$isTake && ($merDelivery || $merTake)) $isTake = $merDelivery ? 0 : 1;
//加载商品数据
foreach($merchantCart['list'] as $cart){
//预售订单
@ -514,9 +506,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
}
unset($cart,$_k);
$total_true_price = bcadd($_pay_price,$total_true_price,2);
if(count($merchantCartList) > 1 || count($merchantCart['list']) > 1){
$orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus;
}
if(count($merchantCartList) > 1 || count($merchantCart['list']) > 1) $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus;
$merchantCart['order'] = [
'true_price' => $_pay_price,
'platform_coupon_price' => 0,
@ -741,8 +731,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
'mer_integral_status' => 0,
];
$allow_no_address = $allow_no_address && $merchantCart['order']['isTake'];
foreach($merchantCart['config'] as $config){
$merchantCart['take'][$config['config_key']] = $config['value'];
// 提货点 总平台和商户兼容处理
if($merchantCart['mer_id'] > 0){
// 商户
foreach($merchantCart['config'] as $config){
$merchantCart['take'][$config['config_key']] = $config['value'];
}
}else{
// 总平台
$merchantCart['take'] = array_merge($merchantCart['take'], ($merchantCart['config'] ?? []));
}
$merIntegralConfig = $merchantCart['take'];
unset($merchantCart['config']);
@ -962,17 +959,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$uid = $user->uid;
// $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true);
$orderInfo = Cache::get('order_create_cache'.$uid.'_'.$key);
if(!$orderInfo) throw new ValidateException('订单操作超时,请刷新页面');
$order_model = $orderInfo['order_model'];
$order_extend = $orderInfo['order_extend'];
if(!$orderInfo['order_delivery_status']){
throw new ValidateException('部分商品配送方式不一致,请单独下单');
}
if($orderInfo['order_price'] > 1000000){
throw new ValidateException('支付金额超出最大限制');
}
if(!$orderInfo['order_delivery_status']) throw new ValidateException('部分商品配送方式不一致,请单独下单');
if($orderInfo['order_price'] > 1000000) throw new ValidateException('支付金额超出最大限制');
if($orderInfo['status'] == 'noDeliver') throw new ValidateException('部分商品不支持该区域');
if($orderInfo['status'] == 'noAddress') throw new ValidateException('请选择地址');
if(!$order_model && $orderInfo['allow_address']){
@ -981,9 +972,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$extend = [];
}
elseif(count($order_extend)){
$extend = app()
->make(OrderVirtualFieldValidate::class)
->load($order_extend,$extend);
$extend = app()->make(OrderVirtualFieldValidate::class)->load($order_extend,$extend);
}
else{
$extend = [];
@ -998,9 +987,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$cartSpread = 0;
$hasTake = FALSE;
foreach($merchantCartList as $merchantCart){
if($merchantCart['order']['isTake']){
$hasTake = TRUE;
}
//检查发票状态
if(isset($receipt_data[$merchantCart['mer_id']]) && !$merchantCart['openReceipt']) throw new ValidateException('该店铺不支持开发票');
foreach($merchantCart['list'] as $cart){
@ -1008,18 +994,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$cartSpread = $cart['spread_id'];
}
}
// 判断:订单配送方式为自提时 判断是否存在自提信息
if($merchantCart['order']['isTake']) {
$hasTake = TRUE;
if(empty($merchantCart['take']['mer_take_name'])) throw new ValidateException('请选择有效的提货点!');
}
}
if($hasTake){
app()
->make(UserAddressValidate::class)
->scene('take')
->check($post);
}
if($cartSpread){
app()
->make(UserRepository::class)
->bindSpread($user,$cartSpread);
}
if($hasTake) app()->make(UserAddressValidate::class)->scene('take')->check($post);
if($cartSpread) app()->make(UserRepository::class)->bindSpread($user,$cartSpread);
$isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0;
if($isSelfBuy){
$spreadUser = $user;
@ -1042,6 +1025,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
$cartIds = [];
$orderList = [];
foreach($merchantCartList as $k => $merchantCart){
// 数据补齐 总平台商品订单可能存在部分数据不存在
$merchantCart['commission_rate'] = $merchantCart['commission_rate'] ?? 0;
$cost = 0;
$total_extension_one = 0;
$total_extension_two = 0;
@ -1118,12 +1105,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
}
unset($cart);
$rate = 0;
if($merchantCart['commission_rate'] > 0){
$rate = $merchantCart['commission_rate'];
}
elseif(isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0){
$rate = bcmul($merchantCart['merchantCategory']['commission_rate'],100,4);
}
if($merchantCart['commission_rate'] > 0) $rate = $merchantCart['commission_rate'];
elseif(isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) $rate = bcmul($merchantCart['merchantCategory']['commission_rate'],100,4);
$user_address = isset($address) ? ($address['province'].$address['city'].$address['district'].$address['street'].$address['detail']) : '';
//整理订单数据
$_order = [

View File

@ -17,6 +17,7 @@ use app\common\repositories\store\order\StoreCartRepository;
use app\common\repositories\store\order\StoreOrderProductRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\parameter\ParameterValueRepository;
use app\common\repositories\store\PointRepository;
use app\common\repositories\store\StoreActivityRepository;
use app\common\repositories\store\StoreSeckillActiveRepository;
use app\common\repositories\store\StoreSeckillTimeRepository;
@ -2627,6 +2628,18 @@ class ProductRepository extends BaseRepository
return compact('count', 'list');
}
/**
* Common: 获取总平台允许送货方式
* Author: wu-hui
* Time: 2024/04/11 9:29
* @return int[]
*/
public function getPlatformDeliveryWay():array{
// 存在提货点 则允许自提和快递 不存在则仅允许快递
$pointCount = (int)app()->make(PointRepository::class)->getSearchModel([])->count();
if($pointCount > 0) return [1,2];
else return [2];
}

View File

@ -4,6 +4,7 @@
namespace app\controller\admin\store;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\product\SpuRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use think\App;
@ -310,7 +311,7 @@ class StoreProduct extends BaseController
// $data['delivery_way'] = $this->request->merchant()->delivery_way ? $this->request->merchant()->delivery_way : [2];
// $data['is_audit'] = $this->request->merchant()->is_audit;
$data['is_audit'] = 0;
$data['delivery_way'] = [1,2];
$data['delivery_way'] = app()->make(ProductRepository::class)->getPlatformDeliveryWay();
return app('json')->success($data);
}

View File

@ -54,6 +54,7 @@ class StoreOrder extends BaseController
$addressId = (int)$this->request->param('address_id');
$couponIds = (array)$this->request->param('use_coupon', []);
$takes = (array)$this->request->param('takes', []);
$points = (array)$this->request->param('points', []);
// $usePlatformIntegral = (bool)$this->request->param('use_platform_integral', false);
// $useMerIntegral = (bool)$this->request->param('use_mer_integral', false);
$useIntegral = (bool)$this->request->param('use_integral', false);
@ -71,7 +72,7 @@ class StoreOrder extends BaseController
if (!($count = count($cartId)) || $count != $cartCount) return app('json')->fail('数据无效');
// $orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $couponIds, $usePlatformIntegral,$useMerIntegral, $addressId);
$orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $couponIds, $useIntegral, $addressId, $withGoods);
$orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $points, $couponIds, $useIntegral, $addressId, $withGoods);
return app('json')->success($orderInfo);
}