feat : spu
This commit is contained in:
81
app/Service/Amqp/Pay/PayGoodOrderFinishService.php
Normal file
81
app/Service/Amqp/Pay/PayGoodOrderFinishService.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Pay;
|
||||
|
||||
use App\Constants\Common\RefundCode;
|
||||
use App\Model\Order;
|
||||
use App\Model\PayOrder;
|
||||
use App\Service\ServiceTrait\Api\CateringTrait;
|
||||
use App\Service\ServiceTrait\Api\GoodOrderTrait;
|
||||
use App\Service\ServiceTrait\Api\PayFinishTrait;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class PayGoodOrderFinishService
|
||||
{
|
||||
use GoodOrderTrait;
|
||||
use PayFinishTrait;
|
||||
use CateringTrait;
|
||||
use OrderChangeStatusTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public string $orderSno;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $payType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $orderType;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
protected Order $orderInfo;
|
||||
|
||||
/**
|
||||
* @var PayOrder
|
||||
*/
|
||||
protected PayOrder $payInfo;
|
||||
|
||||
/**
|
||||
* @var bool 是否加入配餐数据
|
||||
*/
|
||||
protected bool $isCatering = true;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->checkCallBackOrder();
|
||||
|
||||
Db::transaction(function (){
|
||||
$this->manageOrder();
|
||||
|
||||
$this->manageWxOrder();
|
||||
//
|
||||
$this->isCatering = $this->manageAddCateringLog();
|
||||
});
|
||||
|
||||
//已经截单 自动退款
|
||||
if (!$this->isCatering) $this->joinRefundQueue($this->orderInfo->id,RefundCode::FULL_GOOD_REFUND,'已截单,系统自动退款');
|
||||
}
|
||||
}
|
||||
63
app/Service/Amqp/Refund/RefundGoodOrderFinishService.php
Normal file
63
app/Service/Amqp/Refund/RefundGoodOrderFinishService.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Service\ServiceTrait\Api\CateringTrait;
|
||||
use App\Service\ServiceTrait\Api\CouponTrait;
|
||||
use App\Service\ServiceTrait\Api\OrderTrait;
|
||||
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class RefundGoodOrderFinishService
|
||||
{
|
||||
use RefundOrderTrait;
|
||||
use CateringTrait;
|
||||
use CouponTrait;
|
||||
use OrderTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public string $orderSno;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $payType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $orderType;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->checkRefundOrder();
|
||||
|
||||
Db::transaction(function (){
|
||||
$this->manageRefundOrder();
|
||||
|
||||
$this->manageOrderByRefund();
|
||||
|
||||
$this->manageSubCateringLog();
|
||||
|
||||
if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
|
||||
});
|
||||
|
||||
// $this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
}
|
||||
}
|
||||
56
app/Service/Api/Driver/BaseDriverService.php
Normal file
56
app/Service/Api/Driver/BaseDriverService.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Driver;
|
||||
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminUser;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\CycleTrait;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\Database\Model\Model;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
abstract class BaseDriverService extends BaseService
|
||||
{
|
||||
use CycleTrait;
|
||||
|
||||
/**
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @var Builder|Model|AdminUser|null
|
||||
*/
|
||||
protected AdminUser|null|Builder|Model $adminInfo;
|
||||
|
||||
protected int $cycleId;
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->cycleId = $this->initTodayCycleId();
|
||||
|
||||
$this->adminInfo = $this->adminUserModel->getAdminInfoByBindUserId($this->userId);
|
||||
if ($this->adminInfo->role_id != RoleCode::DRIVER) throw new ErrException('暂无权限,请联系客服并提供相关信息绑定账号');
|
||||
}
|
||||
|
||||
abstract public function handle();
|
||||
}
|
||||
166
app/Service/Api/Driver/GetSiteListService.php
Normal file
166
app/Service/Api/Driver/GetSiteListService.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Driver;
|
||||
|
||||
use App\Constants\Admin\CateringCode;
|
||||
use App\Constants\Common\GoodCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\OrderMealCateringLog;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
use App\Model\Site;
|
||||
use App\Model\Sku;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class GetSiteListService extends BaseDriverService
|
||||
{
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected Site $siteModel;
|
||||
|
||||
/**
|
||||
* @var OrderMealCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderMealCateringLog $orderMealCateringLogModel;
|
||||
|
||||
/**
|
||||
* @var OrderOptionCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderOptionCateringLog $orderOptionCateringLogModel;
|
||||
|
||||
/**
|
||||
* @var Sku
|
||||
*/
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $siteIds;
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function setCache()
|
||||
{
|
||||
$siteArr = $this->siteModel
|
||||
->where('delivered_id',$this->adminInfo->id)
|
||||
->orderBy('sequence')
|
||||
->get();
|
||||
if ($siteArr->isEmpty()) throw new ErrException('该司机并未绑定站点');
|
||||
$siteArr = array_column($siteArr->toArray(),null,'id');
|
||||
$this->siteIds = array_keys($siteArr);
|
||||
|
||||
$optionArr = $this->getOptionData();
|
||||
|
||||
$mealArr = $this->getMealData();
|
||||
|
||||
$res = [];
|
||||
foreach ($siteArr as $site) {
|
||||
if (empty($res[$site['id']])) {
|
||||
$res[$site['id']] = [
|
||||
'site_id' => $site['id'],
|
||||
'site_name' => $site['name'],
|
||||
'name' => '',
|
||||
'meal_order_quantity' => 0,
|
||||
'meal_add_staple_food_num' => 0,
|
||||
'option_order_quantity' => 0,
|
||||
'option_add_staple_food_num' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getMealData(): array
|
||||
{
|
||||
$mealArr = $this->orderMealCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',CateringCode::CATERING_STATUS_FINISH)
|
||||
->whereIn('site_id', $this->siteIds)
|
||||
->select(['quantity','site_id','sku_id'])
|
||||
->get();
|
||||
if ($mealArr->isEmpty()) $mealArr = [];
|
||||
$mealArr = $mealArr->toArray();
|
||||
|
||||
$skuIds = array_column($mealArr, 'sku_id');
|
||||
$skuArr = $this->skuModel->getDataArrByIds($skuIds);
|
||||
$skuArr = array_column($skuArr,null,'id');
|
||||
|
||||
|
||||
$res = [];
|
||||
foreach ($mealArr as $oneLog) {
|
||||
if (empty($res[$oneLog['site_id']])) {
|
||||
$res[$oneLog['site_id']] = [
|
||||
'total_copies' => 0,
|
||||
'add_staple_food_num' => 0,
|
||||
'sku' => []
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($res[$oneLog['site_id']]['sku'][$oneLog['sku_id']])) {
|
||||
$res[$oneLog['site_id']]['sku'][$oneLog['sku_id']] = [
|
||||
'sku_id' => $oneLog['sku_id'],
|
||||
'sku_name' => $skuArr[$oneLog['sku_id']]['title'] ?? '',
|
||||
'quantity' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
if ($skuArr[$oneLog['sku_id']]['is_add_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) {
|
||||
$res[$oneLog['site_id']]['add_staple_food_num'] += $oneLog['quantity'];
|
||||
} else {
|
||||
$res[$oneLog['site_id']]['total_copies'] += $oneLog['quantity'];
|
||||
}
|
||||
|
||||
$res[$oneLog['site_id']]['sku'][$oneLog['sku_id']]['quantity'] += $oneLog['quantity'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getOptionData(): array
|
||||
{
|
||||
$optionArr = $this->orderOptionCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',CateringCode::CATERING_STATUS_FINISH)
|
||||
->whereIn('site_id', $this->siteIds)
|
||||
->select(['quantity','site_id','add_staple_food_num'])
|
||||
->get();
|
||||
if ($optionArr->isEmpty()) $optionArr = [];
|
||||
$optionArr = $optionArr->toArray();
|
||||
|
||||
$res = [];
|
||||
foreach ($optionArr as $oneSite) {
|
||||
if (empty($res[$oneSite['site_id']])) {
|
||||
$res[$oneSite['site_id']] = [
|
||||
'copies' => 0,
|
||||
'add_staple_food_num' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$res[$oneSite['site_id']]['copies'] = $oneSite['quantity'] + $res[$oneSite['site_id']]['copies'];
|
||||
$res[$oneSite['site_id']]['add_staple_food_num'] = $oneSite['add_staple_food_num'] + $res[$oneSite['site_id']]['add_staple_food_num'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Service\Common\Pay\Wx;
|
||||
|
||||
use App\Amqp\Producer\Pay\GoodOrderPayFinishProducer;
|
||||
use App\Amqp\Producer\Refund\GoodOrderRefundFinishProducer;
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Constants\Common\PayCode;
|
||||
use App\Constants\Common\RefundCode;
|
||||
@@ -13,7 +15,9 @@ use App\Service\ServiceTrait\Api\OrderTrait;
|
||||
use App\Service\ServiceTrait\Api\PayFinishTrait;
|
||||
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@@ -68,6 +72,12 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
*/
|
||||
protected bool $isCatering = true;
|
||||
|
||||
/**
|
||||
* @var Producer
|
||||
*/
|
||||
#[Inject]
|
||||
protected Producer $producer;
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -80,18 +90,25 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
|
||||
$this->checkWxCallBackOrder();
|
||||
|
||||
$this->checkCallBackOrder();
|
||||
$message = new GoodOrderPayFinishProducer([
|
||||
'order_sno' => $this->orderNo,
|
||||
'pay_type' => self::PayType,
|
||||
]);
|
||||
$this->producer->produce($message);
|
||||
|
||||
Db::transaction(function (){
|
||||
$this->manageOrder();
|
||||
|
||||
$this->manageWxOrder();
|
||||
// $this->checkCallBackOrder();
|
||||
//
|
||||
$this->isCatering = $this->manageAddCateringLog();
|
||||
});
|
||||
|
||||
//已经截单 自动退款
|
||||
if (!$this->isCatering) $this->joinRefundQueue($this->orderId,RefundCode::FULL_GOOD_REFUND,'已截单,系统自动退款');
|
||||
// Db::transaction(function (){
|
||||
// $this->manageOrder();
|
||||
//
|
||||
// $this->manageWxOrder();
|
||||
////
|
||||
// $this->isCatering = $this->manageAddCateringLog();
|
||||
// });
|
||||
//
|
||||
// //已经截单 自动退款
|
||||
// if (!$this->isCatering) $this->joinRefundQueue($this->orderId,RefundCode::FULL_GOOD_REFUND,'已截单,系统自动退款');
|
||||
|
||||
//todo 发送订阅通知
|
||||
// $this->sendGainCoinMsg();
|
||||
@@ -118,19 +135,25 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
||||
|
||||
$this->checkWxRefundCallBackOrder();
|
||||
|
||||
$this->checkRefundOrder();
|
||||
$message = new GoodOrderRefundFinishProducer([
|
||||
'refund_order_sno' => $this->orderNo,
|
||||
'pay_type' => self::PayType,
|
||||
]);
|
||||
$this->producer->produce($message);
|
||||
|
||||
Db::transaction(function (){
|
||||
$this->manageRefundOrder();
|
||||
|
||||
$this->manageOrderByRefund();
|
||||
|
||||
$this->manageSubCateringLog();
|
||||
|
||||
if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
|
||||
});
|
||||
|
||||
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
// $this->checkRefundOrder();
|
||||
//
|
||||
// Db::transaction(function (){
|
||||
// $this->manageRefundOrder();
|
||||
//
|
||||
// $this->manageOrderByRefund();
|
||||
//
|
||||
// $this->manageSubCateringLog();
|
||||
//
|
||||
// if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
|
||||
// });
|
||||
//
|
||||
// $this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
|
||||
return $this->returnSuccess();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ trait GoodOrderTrait
|
||||
protected function checkCallBackOrder(): void
|
||||
{
|
||||
$this->orderInfo = $this->orderModel->getInfoByOrderSno($this->orderNo);
|
||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
|
||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,$this->orderType,$this->payType);
|
||||
|
||||
if (empty($this->orderInfo) || empty($this->payInfo)) {
|
||||
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
|
||||
|
||||
@@ -14,8 +14,6 @@ trait RefundOrderTrait
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function checkRefundOrder(): void
|
||||
{
|
||||
@@ -23,26 +21,15 @@ trait RefundOrderTrait
|
||||
$this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id);
|
||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
|
||||
|
||||
if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) {
|
||||
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
|
||||
throw new ErrException('订单不存在');
|
||||
}
|
||||
if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) throw new ErrException('订单不存在');
|
||||
|
||||
if ($this->refundInfo->refund_status != RefundCode::WAIT_BY_PAY_TOOL) {
|
||||
$this->log->debug(__CLASS__.':订单已退款成功,订单信息:'.json_encode($this->refundInfo->toArray()));
|
||||
throw new ErrException('订单已退款成功');
|
||||
}
|
||||
if ($this->refundInfo->refund_status != RefundCode::WAIT_BY_PAY_TOOL) throw new ErrException('订单已退款成功');
|
||||
|
||||
if ($this->refundInfo->refund_type != PayCode::WECHAT_PAY) {
|
||||
$this->log->debug(__CLASS__.':订单退款渠道错误,订单信息:'.json_encode($this->refundInfo->toArray()));
|
||||
throw new ErrException('订单退款渠道错误');
|
||||
}
|
||||
if ($this->refundInfo->refund_type != PayCode::WECHAT_PAY) throw new ErrException('订单退款渠道错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function manageRefundOrder(): void
|
||||
{
|
||||
@@ -56,8 +43,8 @@ trait RefundOrderTrait
|
||||
if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败');
|
||||
|
||||
}catch (Exception $e) {
|
||||
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
throw new ErrException($e->getMessage());
|
||||
// $this->log->error('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
throw new ErrException('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +71,7 @@ trait RefundOrderTrait
|
||||
|
||||
}catch (Exception $e) {
|
||||
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
throw new ErrException($e->getMessage());
|
||||
throw new ErrException('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user