feat: place Order
This commit is contained in:
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Order;
|
||||
|
||||
use App\Cache\Redis\Common\ConfigCache;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\OrderTrait;
|
||||
@@ -43,6 +44,12 @@ abstract class BaseOrderService extends BaseService
|
||||
#[Inject]
|
||||
protected RedisCache $redis;
|
||||
|
||||
/**
|
||||
* @var ConfigCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected ConfigCache $configCache;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -86,6 +93,11 @@ abstract class BaseOrderService extends BaseService
|
||||
*/
|
||||
protected int $orderId;
|
||||
|
||||
/**
|
||||
* @var int 自动选择优惠券 (确认订单需要,下单不需要,用子类重置该值)
|
||||
*/
|
||||
protected int $isAutoSelectCoupon = 2;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -147,6 +159,8 @@ abstract class BaseOrderService extends BaseService
|
||||
/**
|
||||
* 计算
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function compute(): void
|
||||
{
|
||||
|
||||
@@ -15,6 +15,13 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class ConfirmationOrderService extends BaseOrderService
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->isAutoSelectCoupon = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
|
||||
@@ -27,6 +27,13 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class PlaceOrderService extends BaseOrderService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->isAutoSelectCoupon = 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 统一下单逻辑
|
||||
* @return array
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Cache\Redis\Api\SiteCache;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\ApiCode;
|
||||
use App\Constants\Common\GoodCode;
|
||||
use App\Constants\ConfigCode;
|
||||
use App\Exception\ErrException;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
@@ -204,11 +205,19 @@ trait OrderTrait
|
||||
/**
|
||||
* 计算服务费
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function computeSundryPrice(): void
|
||||
{
|
||||
$this->orderRes['sundry_num'] = $this->orderRes['optional_copies'];
|
||||
$this->orderRes['sundry_price'] = '1.00'; //todo 设置
|
||||
$this->orderRes['sundry_num'] = match ($this->configCache->getConfigValue(ConfigCode::SUNDRY_PRICE_COMPUTE_TYPE))
|
||||
{
|
||||
1 => $this->orderRes['optional_copies'],
|
||||
2 => $this->orderRes['meal_copies'],
|
||||
3 => $this->copies,
|
||||
};
|
||||
|
||||
$this->orderRes['sundry_price'] = $this->configCache->getConfigValue(ConfigCode::SUNDRY_UNIT_PRICE);
|
||||
$this->orderRes['total_sundry_price'] = bcmul($this->orderRes['sundry_price'],$this->orderRes['sundry_num'],2);
|
||||
}
|
||||
|
||||
@@ -218,11 +227,15 @@ trait OrderTrait
|
||||
*/
|
||||
protected function computeFavorable(): void
|
||||
{
|
||||
if ($this->couponId <= 0) {
|
||||
if ($this->couponId <= 0 && $this->isAutoSelectCoupon == 1) {
|
||||
$this->couponId = $this->getAutoCouponId();
|
||||
}
|
||||
|
||||
if ($this->couponId <= 0) {
|
||||
$this->orderRes['coupon_id'] = 0;
|
||||
$this->orderRes['coupon'] = [];
|
||||
$this->orderRes['favorable_good_price'] = '0';
|
||||
$this->orderRes['favorable_sundry_price'] = '0';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user