feat : order
This commit is contained in:
@@ -60,4 +60,10 @@ class OrderCode
|
|||||||
*/
|
*/
|
||||||
const string ORDER_TYPE_GOOD_PREFIX = 'OG';
|
const string ORDER_TYPE_GOOD_PREFIX = 'OG';
|
||||||
const string ORDER_TYPE_BALANCE_PREFIX = 'OB';
|
const string ORDER_TYPE_BALANCE_PREFIX = 'OB';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int 1=自选 2=套餐
|
||||||
|
*/
|
||||||
|
CONST INT ORDER_TYPE_OPTIONAL = 1;
|
||||||
|
CONST INT ORDER_TYPE_MEAL = 2;
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ class ConfigCode
|
|||||||
const string TODAY_CUT_OFF_TIME_KEY = 'TodayCutOffTime'; // 当日下单截止时间
|
const string TODAY_CUT_OFF_TIME_KEY = 'TodayCutOffTime'; // 当日下单截止时间
|
||||||
const string ORDER_CANCEL_TIME_KEY = 'OrderCancelTime'; // 订单取消时间(下单后自动取消)
|
const string ORDER_CANCEL_TIME_KEY = 'OrderCancelTime'; // 订单取消时间(下单后自动取消)
|
||||||
const string SUNDRY_UNIT_PRICE = 'SundryUnitPrice'; // 附加费单价 (服务费)
|
const string SUNDRY_UNIT_PRICE = 'SundryUnitPrice'; // 附加费单价 (服务费)
|
||||||
const string SUNDRY_PRICE_COMPUTE_TYPE = 'SundryPriceComputeType'; // 附加费计算方式 1 仅自选计算(默认值) 2 仅套餐计算 3 套餐+自选计算
|
const string SUNDRY_PRICE_COMPUTE_TYPE = 'SundryPriceComputeType'; // 附加费计算方式 1 仅自选计算(默认值) 2 仅套餐计算 3 套餐自选都计算
|
||||||
const string NUMBER_OF_USER_ADDRESS_POOLS = 'NumberOfUserAddressPools'; // 用户可以设置的送达地址的数量
|
const string NUMBER_OF_USER_ADDRESS_POOLS = 'NumberOfUserAddressPools'; // 用户可以设置的送达地址的数量
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ use Hyperf\DbConnection\Model\Model;
|
|||||||
* @property int $site_id
|
* @property int $site_id
|
||||||
* @property int $city_id
|
* @property int $city_id
|
||||||
* @property int $coupon_id
|
* @property int $coupon_id
|
||||||
* @property int $meal_copies
|
* @property int $copies
|
||||||
* @property int $optional_copies
|
* @property int $type
|
||||||
* @property string $total_price
|
* @property string $total_price
|
||||||
* @property string $actual_price
|
* @property string $actual_price
|
||||||
* @property string $discount_price
|
* @property string $discount_price
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ abstract class BaseOrderService extends BaseService
|
|||||||
*/
|
*/
|
||||||
protected int $orderId;
|
protected int $orderId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int 订单类型 (参考 SpuCode)
|
||||||
|
*/
|
||||||
|
protected int $orderType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int 自动选择优惠券 (确认订单需要,下单不需要,用子类重置该值)
|
* @var int 自动选择优惠券 (确认订单需要,下单不需要,用子类重置该值)
|
||||||
*/
|
*/
|
||||||
@@ -133,6 +138,7 @@ abstract class BaseOrderService extends BaseService
|
|||||||
$this->copies = 0;
|
$this->copies = 0;
|
||||||
$this->couponId = 0;
|
$this->couponId = 0;
|
||||||
$this->siteId = 0;
|
$this->siteId = 0;
|
||||||
|
$this->orderType = 0;
|
||||||
|
|
||||||
$this->orderRes = [
|
$this->orderRes = [
|
||||||
'total_price' => '0.00', //总价
|
'total_price' => '0.00', //总价
|
||||||
@@ -151,8 +157,8 @@ abstract class BaseOrderService extends BaseService
|
|||||||
'site' => [],
|
'site' => [],
|
||||||
'good_ids' => [],
|
'good_ids' => [],
|
||||||
'good' => [],
|
'good' => [],
|
||||||
'optional_copies' => 0,
|
'copies' => 0,
|
||||||
'meal_copies' => 0,
|
// 'meal_copies' => 0,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +194,7 @@ abstract class BaseOrderService extends BaseService
|
|||||||
|
|
||||||
$this->computeSundryPrice();
|
$this->computeSundryPrice();
|
||||||
|
|
||||||
$this->computeFavorable();
|
// $this->computeFavorable();
|
||||||
|
|
||||||
$this->computeFinallyPrice();
|
$this->computeFinallyPrice();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class CheckCartService extends BaseOrderService
|
|||||||
public function handle(): array
|
public function handle(): array
|
||||||
{
|
{
|
||||||
$this->siteId = (int)$this->request->input('site_id');
|
$this->siteId = (int)$this->request->input('site_id');
|
||||||
|
$this->orderType = (int)$this->request->input('order_type');
|
||||||
|
|
||||||
$this->check();
|
$this->check();
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class ConfirmationOrderService extends BaseOrderService
|
|||||||
{
|
{
|
||||||
$this->siteId = (int)$this->request->input('site_id');
|
$this->siteId = (int)$this->request->input('site_id');
|
||||||
$this->couponId = (int)$this->request->input('coupon_id',0);
|
$this->couponId = (int)$this->request->input('coupon_id',0);
|
||||||
|
$this->orderType = (int)$this->request->input('order_type');
|
||||||
|
|
||||||
$this->check();
|
$this->check();
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class OrderInfoService extends BaseService
|
|||||||
$imageList = $this->getOssObjects($imageIds);
|
$imageList = $this->getOssObjects($imageIds);
|
||||||
|
|
||||||
$orderCopiesList = [];
|
$orderCopiesList = [];
|
||||||
for ($i = 1; $i <= ($orderInfo['meal_copies'] + $orderInfo['optional_copies']); $i++) {
|
for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) {
|
||||||
|
|
||||||
$oneCopiesInfo = [
|
$oneCopiesInfo = [
|
||||||
'total_price' => '0.00',
|
'total_price' => '0.00',
|
||||||
@@ -115,7 +115,7 @@ class OrderInfoService extends BaseService
|
|||||||
'sku_list' => [],
|
'sku_list' => [],
|
||||||
'image_list' => [],
|
'image_list' => [],
|
||||||
'take_food_code' => '', //todo 取餐码
|
'take_food_code' => '', //todo 取餐码
|
||||||
'copies_type' => 0,
|
// 'copies_type' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($newOrderSkuList[$i] as $item) {
|
foreach ($newOrderSkuList[$i] as $item) {
|
||||||
@@ -128,7 +128,7 @@ class OrderInfoService extends BaseService
|
|||||||
$oneCopiesInfo['sku_list'][] = $skuInfo;
|
$oneCopiesInfo['sku_list'][] = $skuInfo;
|
||||||
$oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
$oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
||||||
|
|
||||||
if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
|
// if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
|
||||||
}
|
}
|
||||||
// foreach ($newOrderSkuList as $item) {
|
// foreach ($newOrderSkuList as $item) {
|
||||||
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ class OrderListService extends BaseService
|
|||||||
'order_sno',
|
'order_sno',
|
||||||
'user_id',
|
'user_id',
|
||||||
'site_id',
|
'site_id',
|
||||||
'meal_copies',
|
'copies',
|
||||||
'optional_copies',
|
'type',
|
||||||
'actual_price',
|
'actual_price',
|
||||||
'total_price',
|
'total_price',
|
||||||
'status',
|
'status',
|
||||||
@@ -91,7 +91,6 @@ class OrderListService extends BaseService
|
|||||||
private function buildData(array &$orderList): void
|
private function buildData(array &$orderList): void
|
||||||
{
|
{
|
||||||
$orderIds = array_column($orderList, 'id');
|
$orderIds = array_column($orderList, 'id');
|
||||||
$siteIds = array_column($orderList, 'site_id');
|
|
||||||
|
|
||||||
$orderSkuList = $this->orderGoodModel->whereIn('order_id', $orderIds)->get()->toArray();
|
$orderSkuList = $this->orderGoodModel->whereIn('order_id', $orderIds)->get()->toArray();
|
||||||
$skuIds = [];
|
$skuIds = [];
|
||||||
@@ -123,7 +122,7 @@ class OrderListService extends BaseService
|
|||||||
|
|
||||||
foreach ($orderList as &$order) {
|
foreach ($orderList as &$order) {
|
||||||
$orderCopiesList = [];
|
$orderCopiesList = [];
|
||||||
for ($i = 1; $i <= ($order['meal_copies'] + $order['optional_copies']); $i++) {
|
for ($i = 1; $i <= ($order['copies'] ?? 0); $i++) {
|
||||||
|
|
||||||
$oneCopiesInfo = [
|
$oneCopiesInfo = [
|
||||||
'total_price' => '0.00',
|
'total_price' => '0.00',
|
||||||
@@ -131,7 +130,7 @@ class OrderListService extends BaseService
|
|||||||
// 'sku_list' => [],
|
// 'sku_list' => [],
|
||||||
'image_list' => [],
|
'image_list' => [],
|
||||||
'take_food_code' => [], //todo 取餐码
|
'take_food_code' => [], //todo 取餐码
|
||||||
'copies_type' => 0,
|
// 'copies_type' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($newOrderSkuList[$order['id']][$i] as $item) {
|
foreach ($newOrderSkuList[$order['id']][$i] as $item) {
|
||||||
@@ -144,7 +143,7 @@ class OrderListService extends BaseService
|
|||||||
// $oneCopiesInfo['sku_list'][] = [];
|
// $oneCopiesInfo['sku_list'][] = [];
|
||||||
$oneCopiesInfo['image_list'][] = $imageList[$imageId]['url'] ?? [];
|
$oneCopiesInfo['image_list'][] = $imageList[$imageId]['url'] ?? [];
|
||||||
|
|
||||||
if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
|
// if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
|
||||||
}
|
}
|
||||||
// foreach ($newOrderSkuList as $item) {
|
// foreach ($newOrderSkuList as $item) {
|
||||||
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class PlaceOrderService extends BaseOrderService
|
|||||||
|
|
||||||
$this->siteId = (int)$this->request->input('site_id');
|
$this->siteId = (int)$this->request->input('site_id');
|
||||||
$this->couponId = (int)$this->request->input('coupon_id',0);
|
$this->couponId = (int)$this->request->input('coupon_id',0);
|
||||||
|
$this->orderType = (int)$this->request->input('order_type');
|
||||||
|
|
||||||
// 生成购物车信息 , 检测商品和库存等
|
// 生成购物车信息 , 检测商品和库存等
|
||||||
$this->check();
|
$this->check();
|
||||||
@@ -191,8 +192,8 @@ class PlaceOrderService extends BaseOrderService
|
|||||||
$orderInsertModel->site_id = $this->siteId;
|
$orderInsertModel->site_id = $this->siteId;
|
||||||
$orderInsertModel->city_id = $this->orderRes['site_info']['city_id'];
|
$orderInsertModel->city_id = $this->orderRes['site_info']['city_id'];
|
||||||
$orderInsertModel->coupon_id = $this->couponId;
|
$orderInsertModel->coupon_id = $this->couponId;
|
||||||
$orderInsertModel->meal_copies = $this->orderRes['meal_copies'];
|
$orderInsertModel->copies = $this->orderRes['copies'];
|
||||||
$orderInsertModel->optional_copies = $this->orderRes['optional_copies'];
|
$orderInsertModel->type = $this->orderType;
|
||||||
$orderInsertModel->total_price = $this->orderRes['total_price'];
|
$orderInsertModel->total_price = $this->orderRes['total_price'];
|
||||||
$orderInsertModel->actual_price = $this->orderRes['actual_price'];
|
$orderInsertModel->actual_price = $this->orderRes['actual_price'];
|
||||||
$orderInsertModel->discount_price = $this->orderRes['favorable_sundry_price'] + $this->orderRes['favorable_good_price'];
|
$orderInsertModel->discount_price = $this->orderRes['favorable_sundry_price'] + $this->orderRes['favorable_good_price'];
|
||||||
|
|||||||
@@ -102,8 +102,10 @@ trait OrderTrait
|
|||||||
protected function checkGood(): void
|
protected function checkGood(): void
|
||||||
{
|
{
|
||||||
foreach ($this->cartFirstData as $key => $one) {
|
foreach ($this->cartFirstData as $key => $one) {
|
||||||
if (in_array($key, $this->goodIds)) continue;
|
if ($this->orderType == 0) $this->orderType = $this->skuArr[$key]['type'];
|
||||||
|
if ($this->skuArr[$key]['type'] != $this->orderType) throw new ErrException('自选菜品跟套餐菜品请分开订单下单');
|
||||||
|
|
||||||
|
if (in_array($key, $this->goodIds)) continue;
|
||||||
throw new ErrException('商品不存在',ApiCode::ORDER_GOOD_IN_EXISTENCE);
|
throw new ErrException('商品不存在',ApiCode::ORDER_GOOD_IN_EXISTENCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,21 +156,36 @@ trait OrderTrait
|
|||||||
protected function getGoodInfo(int $kitchenId): void
|
protected function getGoodInfo(int $kitchenId): void
|
||||||
{
|
{
|
||||||
$this->stockKey = ApiRedisKey::goodStockKey($this->cycleId,$kitchenId);
|
$this->stockKey = ApiRedisKey::goodStockKey($this->cycleId,$kitchenId);
|
||||||
$mealGoodKey = ApiRedisKey::mealGoodListKey($this->cycleId,$kitchenId);
|
|
||||||
$optionalGoodKey = ApiRedisKey::optionalGoodListKey($this->cycleId,$kitchenId);
|
|
||||||
|
|
||||||
$mealGood = $this->redis->get($mealGoodKey);
|
|
||||||
$optionalGood = $this->redis->get($optionalGoodKey);
|
|
||||||
|
|
||||||
if (empty($mealGood) || empty($optionalGood)) throw new ErrException('商品不存在');
|
|
||||||
|
|
||||||
if (!$this->redis->exists($this->stockKey)) throw new ErrException('库存不足');
|
if (!$this->redis->exists($this->stockKey)) throw new ErrException('库存不足');
|
||||||
|
|
||||||
$mealGood = json_decode($mealGood, true);
|
|
||||||
$optionalGood = json_decode($optionalGood, true);
|
|
||||||
|
|
||||||
$skuArr = [];
|
$skuArr = [];
|
||||||
$skuImageArr = [];
|
$skuImageArr = [];
|
||||||
|
switch ($this->orderType) {
|
||||||
|
case OrderCode::ORDER_TYPE_OPTIONAL:
|
||||||
|
$optionalGoodKey = ApiRedisKey::optionalGoodListKey($this->cycleId,$kitchenId);
|
||||||
|
$optionalGood = $this->redis->get($optionalGoodKey);
|
||||||
|
if (empty($optionalGood)) throw new ErrException('商品不存在');
|
||||||
|
|
||||||
|
$optionalGood = json_decode($optionalGood, true);
|
||||||
|
|
||||||
|
foreach ($optionalGood as $one){
|
||||||
|
$newSkuList = array_map(function($sku) use($one) {
|
||||||
|
$sku['spu_title'] = strtolower($one['title']);
|
||||||
|
$sku['type'] = GoodCode::SPU_TYPE_OPTIONAL;
|
||||||
|
return $sku;
|
||||||
|
}, $one['sku_list']);
|
||||||
|
|
||||||
|
$skuImageArr = array_merge($skuImageArr,$one['image_list']);
|
||||||
|
$skuArr = array_merge($skuArr,$newSkuList);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case OrderCode::ORDER_TYPE_MEAL:
|
||||||
|
$mealGoodKey = ApiRedisKey::mealGoodListKey($this->cycleId,$kitchenId);
|
||||||
|
$mealGood = $this->redis->get($mealGoodKey);
|
||||||
|
if (empty($mealGood)) throw new ErrException('商品不存在');
|
||||||
|
|
||||||
|
$mealGood = json_decode($mealGood, true);
|
||||||
|
|
||||||
foreach ($mealGood as $one){
|
foreach ($mealGood as $one){
|
||||||
$newSkuList = array_map(function($sku) use($one) {
|
$newSkuList = array_map(function($sku) use($one) {
|
||||||
@@ -181,15 +198,9 @@ trait OrderTrait
|
|||||||
$skuArr = array_merge($skuArr,$newSkuList);
|
$skuArr = array_merge($skuArr,$newSkuList);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($optionalGood as $one){
|
break;
|
||||||
$newSkuList = array_map(function($sku) use($one) {
|
default:
|
||||||
$sku['spu_title'] = strtolower($one['title']);
|
throw new ErrException('还不支持下单');
|
||||||
$sku['type'] = GoodCode::SPU_TYPE_OPTIONAL;
|
|
||||||
return $sku;
|
|
||||||
}, $one['sku_list']);
|
|
||||||
|
|
||||||
$skuImageArr = array_merge($skuImageArr,$one['image_list']);
|
|
||||||
$skuArr = array_merge($skuArr,$newSkuList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->skuArr = array_column($skuArr,null,'id');
|
$this->skuArr = array_column($skuArr,null,'id');
|
||||||
@@ -217,7 +228,7 @@ trait OrderTrait
|
|||||||
foreach ($this->cartSecondData as $oneCopies) {
|
foreach ($this->cartSecondData as $oneCopies) {
|
||||||
$oneCopiesTotalPrice = '0.00';
|
$oneCopiesTotalPrice = '0.00';
|
||||||
|
|
||||||
$copiesType = 1;
|
// $copiesType = 1;
|
||||||
|
|
||||||
$oneCopiesGoodInfo = [];
|
$oneCopiesGoodInfo = [];
|
||||||
|
|
||||||
@@ -238,9 +249,9 @@ trait OrderTrait
|
|||||||
|
|
||||||
$oneCopiesTotalPrice = bcadd($oneCopiesTotalPrice, bcmul($this->skuArr[$key]['price'],(string)$oneGood,2),2);
|
$oneCopiesTotalPrice = bcadd($oneCopiesTotalPrice, bcmul($this->skuArr[$key]['price'],(string)$oneGood,2),2);
|
||||||
|
|
||||||
if ($copiesType == 1 && $this->skuArr[$key]['type'] == GoodCode::SPU_TYPE_MEAL) {
|
// if ($copiesType == 1 && $this->skuArr[$key]['type'] == GoodCode::SPU_TYPE_MEAL) {
|
||||||
$copiesType = 2;
|
// $copiesType = 2;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->orderRes['good'][] = [
|
$this->orderRes['good'][] = [
|
||||||
@@ -248,11 +259,11 @@ trait OrderTrait
|
|||||||
'price' => $oneCopiesTotalPrice,
|
'price' => $oneCopiesTotalPrice,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($copiesType == 1) {
|
// if ($copiesType == 1) {
|
||||||
$this->orderRes['optional_copies']++;
|
// $this->orderRes['optional_copies']++;
|
||||||
} else {
|
// } else {
|
||||||
$this->orderRes['meal_copies']++;
|
$this->orderRes['copies']++;
|
||||||
}
|
// }
|
||||||
|
|
||||||
$this->orderRes['total_good_price'] = bcadd($this->orderRes['total_good_price'],$oneCopiesTotalPrice,2);
|
$this->orderRes['total_good_price'] = bcadd($this->orderRes['total_good_price'],$oneCopiesTotalPrice,2);
|
||||||
}
|
}
|
||||||
@@ -268,8 +279,8 @@ trait OrderTrait
|
|||||||
{
|
{
|
||||||
$this->orderRes['sundry_num'] = match ($this->configCache->getConfigValueByKey(ConfigCode::SUNDRY_PRICE_COMPUTE_TYPE))
|
$this->orderRes['sundry_num'] = match ($this->configCache->getConfigValueByKey(ConfigCode::SUNDRY_PRICE_COMPUTE_TYPE))
|
||||||
{
|
{
|
||||||
1 => $this->orderRes['optional_copies'],
|
1 => $this->orderType == OrderCode::ORDER_TYPE_OPTIONAL ? $this->copies : 0,
|
||||||
2 => $this->orderRes['meal_copies'],
|
2 => $this->orderType == OrderCode::ORDER_TYPE_MEAL ? $this->copies : 0,
|
||||||
3 => $this->copies,
|
3 => $this->copies,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user