Files
hyperf_service/app/Service/Api/Order/BaseOrderService.php
2025-03-24 16:38:37 +08:00

205 lines
4.3 KiB
PHP

<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Api\Order;
use App\Cache\Redis\Common\ConfigCache;
use App\Cache\Redis\RedisCache;
use App\Model\CouponTemplate;
use App\Model\UserCoupon;
use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Admin\Catering\PrintTrait;
use App\Service\ServiceTrait\Api\OrderTrait;
use App\Service\ServiceTrait\Common\CycleTrait;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
abstract class BaseOrderService extends BaseService
{
use CycleTrait,OrderTrait,PrintTrait;
/**
* @var int 周期id
*/
protected int $cycleId;
/**
* @var array
*/
protected array $goodIds = [];
/**
* @var string 库存key
*/
protected string $stockKey;
/**
* @var RedisCache $redis
*/
#[Inject]
protected RedisCache $redis;
/**
* @var ConfigCache
*/
#[Inject]
protected ConfigCache $configCache;
/**
* @var UserCoupon
*/
#[Inject]
protected UserCoupon $userCouponModel;
/**
* @var CouponTemplate
*/
#[Inject]
protected CouponTemplate $couponTemplateModel;
/**
* @var array
*/
protected array $cartSecondData;
/**
* @var array
*/
protected array $cartFirstData;
/**
* @var int
*/
protected int $copies;
/**
* @var array
*/
protected array $skuArr;
/**
* @var array
*/
protected array $skuImageArr;
/**
* 订单结果
* @var array
*/
protected array $orderRes = [];
/**
* 优惠券id
* @var int
*/
protected int $couponId;
/**
* 地点id
* @var int
*/
protected int $siteId;
/**
* @var int
*/
protected int $orderId;
/**
* @var int 订单类型 (参考 SpuCode)
*/
protected int $orderType;
/**
* @var int 自动选择优惠券 (确认订单需要,下单不需要,用子类重置该值)
*/
protected int $isAutoSelectCoupon = 2;
/**
* 构造方法
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct()
{
parent::__construct();
$this->cycleId = (int)$this->initTodayCycleId();
$this->cartFirstData = [];
$this->cartSecondData = [];
$this->skuArr = [];
$this->goodIds = [];
$this->copies = 0;
$this->couponId = 0;
$this->siteId = 0;
$this->orderType = 0;
$this->orderRes = [
'total_price' => '0.00', //总价
'total_good_price' => '0.00', //商品总价
'favorable_good_price' => '0.00', //商品优惠价格
'good_after_discount_price' => '0.00', //商品优惠后价格
'total_sundry_price' => '0.00', //服务总费用
'sundry_price' => '0.00', //服务费单价
'sundry_num' => 0, //服务费数量
'favorable_sundry_price' => '0.00', //服务费优惠价格
'sundry_after_discount_price' => '0.00', //服务费优惠后价格
'actual_price' => '0.00', //实际支付价格
'coupon_id' => 0,
'coupon' => [],
'site_id' => 0,
'site' => [],
'good_ids' => [],
'good' => [],
'copies' => 0,
// 'meal_copies' => 0,
];
}
/**
* 检测
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function check(): void
{
$this->checkTodayCutOffTime();
$kitchenId = $this->checkSite($this->siteId);
$this->getGoodInfo($kitchenId);
$this->buildCartData($this->request->input('cart'));
$this->checkGood();
$this->checkStock();
}
/**
* 计算
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function compute(): void
{
$this->computePrice();
$this->computeSundryPrice();
// $this->computeFavorable();
$this->computeFinallyPrice();
}
}