|
|
|
@ -180,20 +180,22 @@ class OrderService implements OrderServiceInterface |
|
|
|
|
|
|
|
$goodsItem['combination_id'] = intval($goodsItem['combination_id']); |
|
|
|
|
|
|
|
// 存在规格,则去规格处查库存,整个接口还有很多别的问题,目前
|
|
|
|
$goods = (object)[]; |
|
|
|
// 存在规格,则去规格处查库存
|
|
|
|
$goods = []; |
|
|
|
if ($goodsItem['combination_id'] > 0) { |
|
|
|
|
|
|
|
$goods = SpecCombination::query() |
|
|
|
->with(['goods' => function($query){ |
|
|
|
$query->select(['name', 'is_max']); |
|
|
|
}]) |
|
|
|
->select(['id', 'number AS inventory']) |
|
|
|
$combination = SpecCombination::query() |
|
|
|
->select(['good_id AS id', 'number AS inventory']) |
|
|
|
->where(['id' => $goodsItem['combination_id']]) |
|
|
|
->first() |
|
|
|
->toArray(); |
|
|
|
$goods->name = $goods->goods->name; |
|
|
|
$goods->is_max = $goods->goods->is_max; |
|
|
|
|
|
|
|
$goods = Goods::query() |
|
|
|
->select(['id', 'name', 'is_max']) |
|
|
|
->where(['id' => $combination['id']]) |
|
|
|
->first() |
|
|
|
->toArray(); |
|
|
|
$goods['inventory'] = $combination['inventory']; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
@ -205,13 +207,12 @@ class OrderService implements OrderServiceInterface |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var_dump('$goods', $goods); |
|
|
|
if (!$goods) { |
|
|
|
Db::rollBack(); |
|
|
|
return '缺少商品'; |
|
|
|
} |
|
|
|
|
|
|
|
if($goodsItem['num'] > $goods->inventory && $goods->is_max != Goods::INVENTORY_NOLIMIT){ |
|
|
|
if($goodsItem['num'] > $goods['inventory'] && $goods['is_max'] != Goods::INVENTORY_NOLIMIT){ |
|
|
|
Db::rollBack(); |
|
|
|
return '商品 '.$goods->name.' 库存不足!'; |
|
|
|
} |
|
|
|
@ -241,21 +242,21 @@ class OrderService implements OrderServiceInterface |
|
|
|
$tempGoods = $orderGoods; |
|
|
|
$orderGoods = []; |
|
|
|
foreach ($tempGoods as $key => &$value) { |
|
|
|
$goods['good_id'] = $value['good_id']; |
|
|
|
$goods['img'] = $value['logo']; |
|
|
|
$goods['number'] = $value['num']; |
|
|
|
$goods['order_id'] = $value['order_id']; |
|
|
|
$goods['name'] = $value['name']; |
|
|
|
$goods['money'] = $value['money']; |
|
|
|
$goods['dishes_id'] = $value['dishes_id']; |
|
|
|
$goods['spec'] = $value['spec']; |
|
|
|
$goods['is_qg'] = $value['is_qg']; |
|
|
|
$goods['good_unit'] = $value['good_unit']; |
|
|
|
$goods['uniacid'] = $value['uniacid']; |
|
|
|
$goods['combination_id'] = $value['combination_id']; |
|
|
|
$orderGoods[] = $goods; |
|
|
|
$goodsTemp['good_id'] = $value['good_id']; |
|
|
|
$goodsTemp['img'] = $value['logo']; |
|
|
|
$goodsTemp['number'] = $value['num']; |
|
|
|
$goodsTemp['order_id'] = $value['order_id']; |
|
|
|
$goodsTemp['name'] = $value['name']; |
|
|
|
$goodsTemp['money'] = $value['money']; |
|
|
|
$goodsTemp['dishes_id'] = $value['dishes_id']; |
|
|
|
$goodsTemp['spec'] = $value['spec']; |
|
|
|
$goodsTemp['is_qg'] = $value['is_qg']; |
|
|
|
$goodsTemp['good_unit'] = $value['good_unit']; |
|
|
|
$goodsTemp['uniacid'] = $value['uniacid']; |
|
|
|
$goodsTemp['combination_id'] = $value['combination_id']; |
|
|
|
$orderGoods[] = $goodsTemp; |
|
|
|
} |
|
|
|
var_dump('$orderGoods', $orderGoods); |
|
|
|
|
|
|
|
$addOrderGoods = OrderGoods::query()->insert($orderGoods); |
|
|
|
if (!$addOrderGoods) { |
|
|
|
Db::rollBack(); |
|
|
|
@ -290,9 +291,9 @@ class OrderService implements OrderServiceInterface |
|
|
|
# 使用记录、更新当前优惠券
|
|
|
|
foreach ($canUseConpons as $key => &$coupon) { |
|
|
|
$couponUse = [ |
|
|
|
'user_id' => $coupon['user_id'], |
|
|
|
'user_receive_id' => $coupon['id'], |
|
|
|
'system_coupon_id' => $coupon['system_coupon_user_id'], |
|
|
|
'user_id' => $coupon->user_id, |
|
|
|
'user_receive_id' => $coupon->id, |
|
|
|
'system_coupon_id' => $coupon->system_coupon_user_id, |
|
|
|
'order_main_id' => $orderMainId, |
|
|
|
'use_time' => $currentTime, |
|
|
|
'return_time' => 0, |
|
|
|
@ -304,16 +305,16 @@ class OrderService implements OrderServiceInterface |
|
|
|
$insertRes = CouponUserUse::query()->insert($couponUse); |
|
|
|
|
|
|
|
if ($insertRes) { |
|
|
|
$numberRemain = $coupon['number_remain'] - 1; |
|
|
|
$numberRemain = $coupon->number_remain - 1; |
|
|
|
if ($numberRemain == 0) { |
|
|
|
$status = 2; |
|
|
|
} elseif ($numberRemain > 0 && $numberRemain < $coupon['number']) { |
|
|
|
} elseif ($numberRemain > 0 && $numberRemain < $coupon->number) { |
|
|
|
$status = 1; |
|
|
|
} elseif ($numberRemain == $coupon['number']) { |
|
|
|
} elseif ($numberRemain == $coupon->number) { |
|
|
|
$status = 0; |
|
|
|
} |
|
|
|
|
|
|
|
$upRes = CouponUserRec::query()->where(['id' => $coupon['id']])->update(['number_remain' => $numberRemain, 'status' => $status]); |
|
|
|
$upRes = CouponUserRec::query()->where(['id' => $coupon->id])->update(['number_remain' => $numberRemain, 'status' => $status]); |
|
|
|
|
|
|
|
if (!$upRes) { |
|
|
|
Db::rollBack(); |
|
|
|
@ -321,7 +322,7 @@ class OrderService implements OrderServiceInterface |
|
|
|
} |
|
|
|
|
|
|
|
// 缓存使用记录
|
|
|
|
$usedRes = $this->couponService->cacheTodayCouponUsed($coupon['user_id'], $coupon['system_coupon_user_id'], $coupon['id']); |
|
|
|
$usedRes = $this->couponService->cacheTodayCouponUsed($coupon->user_id, $coupon->system_coupon_user_id, $coupon->id); |
|
|
|
if (!$usedRes) { |
|
|
|
Db::rollBack(); |
|
|
|
return '优惠券使用失败'; |
|
|
|
|