feat : spu
This commit is contained in:
61
app/Amqp/Consumer/Pay/GoodOrderPayFinishConsumer.php
Normal file
61
app/Amqp/Consumer/Pay/GoodOrderPayFinishConsumer.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Amqp\Consumer\Pay;
|
||||||
|
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Lib\Log;
|
||||||
|
use App\Service\Amqp\Pay\PayGoodOrderFinishService;
|
||||||
|
use Exception;
|
||||||
|
use Hyperf\Amqp\Message\Type;
|
||||||
|
use Hyperf\Amqp\Result;
|
||||||
|
use Hyperf\Amqp\Annotation\Consumer;
|
||||||
|
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||||
|
use PhpAmqpLib\Message\AMQPMessage;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
|
#[Consumer(exchange: 'GoodOrderPayFinish', routingKey: 'GoodOrderPayFinish', queue: 'GoodOrderPayFinish.pay', name: "GoodOrderPayFinishConsumer", nums: 1)]
|
||||||
|
class GoodOrderPayFinishConsumer extends ConsumerMessage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Type|string 消息类型
|
||||||
|
*/
|
||||||
|
protected Type|string $type = Type::DIRECT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Log
|
||||||
|
*/
|
||||||
|
protected Log $log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @param AMQPMessage $message
|
||||||
|
* @return Result
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function consumeMessage($data, AMQPMessage $message): Result
|
||||||
|
{
|
||||||
|
if (!$data['order_sno'] || !$data['pay_type']) {
|
||||||
|
$this->log->error('GoodOrderPayFinishConsumer:error:NoData:'.json_encode($data));
|
||||||
|
return Result::ACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->log->callbackLog('GoodOrderPayFinishConsumer:success:'.json_encode($data));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$service = new PayGoodOrderFinishService();
|
||||||
|
|
||||||
|
$service->orderSno = $data['order_sno'];
|
||||||
|
$service->payType = (int)$data['pay_type'];
|
||||||
|
|
||||||
|
$service->handle();
|
||||||
|
} catch (Exception|ErrException $e) {
|
||||||
|
$this->log->error('GoodOrderPayFinishConsumer:error:'.$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result::ACK;
|
||||||
|
}
|
||||||
|
}
|
||||||
62
app/Amqp/Consumer/Refund/GoodOrderRefundFinishConsumer.php
Normal file
62
app/Amqp/Consumer/Refund/GoodOrderRefundFinishConsumer.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Amqp\Consumer\Refund;
|
||||||
|
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Lib\Log;
|
||||||
|
use App\Service\Amqp\Refund\RefundGoodOrderFinishService;
|
||||||
|
use Exception;
|
||||||
|
use Hyperf\Amqp\Message\Type;
|
||||||
|
use Hyperf\Amqp\Result;
|
||||||
|
use Hyperf\Amqp\Annotation\Consumer;
|
||||||
|
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||||
|
use PhpAmqpLib\Message\AMQPMessage;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
|
#[Consumer(exchange: 'GoodOrderRefundFinish', routingKey: 'GoodOrderRefundFinish', queue: 'GoodOrderRefundFinish.refund', name: "GoodOrderRefundFinishConsumer", nums: 1)]
|
||||||
|
class GoodOrderRefundFinishConsumer extends ConsumerMessage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Type|string 消息类型
|
||||||
|
*/
|
||||||
|
protected Type|string $type = Type::DIRECT;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Log
|
||||||
|
*/
|
||||||
|
protected Log $log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @param AMQPMessage $message
|
||||||
|
* @return Result
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function consumeMessage($data, AMQPMessage $message): Result
|
||||||
|
{
|
||||||
|
if (!$data['refund_order_sno'] || !$data['pay_type']) {
|
||||||
|
$this->log->error('GoodOrderRefundFinishConsumer:error:NoData:'.json_encode($data));
|
||||||
|
return Result::ACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->log->callbackLog('GoodOrderRefundFinishConsumer:success:'.json_encode($data));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$service = new RefundGoodOrderFinishService();
|
||||||
|
|
||||||
|
$service->orderSno = $data['order_sno'];
|
||||||
|
$service->payType = (int)$data['pay_type'];
|
||||||
|
|
||||||
|
$service->handle();
|
||||||
|
} catch (Exception|ErrException $e) {
|
||||||
|
$this->log->error('GoodOrderRefundFinishConsumer:error:'.$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result::ACK;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Amqp/Producer/Pay/GoodOrderPayFinishProducer.php
Normal file
26
app/Amqp/Producer/Pay/GoodOrderPayFinishProducer.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Amqp\Producer\Pay;
|
||||||
|
|
||||||
|
use Hyperf\Amqp\Annotation\Producer;
|
||||||
|
use Hyperf\Amqp\Message\ProducerMessage;
|
||||||
|
use Hyperf\Amqp\Message\Type;
|
||||||
|
|
||||||
|
#[Producer(exchange: 'GoodOrderPayFinish', routingKey: 'GoodOrderPayFinish')]
|
||||||
|
class GoodOrderPayFinishProducer extends ProducerMessage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Type|string 消息类型
|
||||||
|
*/
|
||||||
|
protected Type|string $type = Type::DIRECT;
|
||||||
|
|
||||||
|
public function __construct($data)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* $data string array => {"order_sno":"out_trade_no","pay_type":"PayType"}
|
||||||
|
*/
|
||||||
|
$this->payload = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Amqp/Producer/Refund/GoodOrderRefundFinishProducer.php
Normal file
26
app/Amqp/Producer/Refund/GoodOrderRefundFinishProducer.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Amqp\Producer\Refund;
|
||||||
|
|
||||||
|
use Hyperf\Amqp\Annotation\Producer;
|
||||||
|
use Hyperf\Amqp\Message\ProducerMessage;
|
||||||
|
use Hyperf\Amqp\Message\Type;
|
||||||
|
|
||||||
|
#[Producer(exchange: 'GoodOrderRefundFinish', routingKey: 'GoodOrderRefundFinish')]
|
||||||
|
class GoodOrderRefundFinishProducer extends ProducerMessage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Type|string 消息类型
|
||||||
|
*/
|
||||||
|
protected Type|string $type = Type::DIRECT;
|
||||||
|
|
||||||
|
public function __construct($data)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* $data string array => {"refund_order_sno":"out_trade_no","pay_type":"PayType"}
|
||||||
|
*/
|
||||||
|
$this->payload = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
app/Controller/Api/DriverController.php
Normal file
27
app/Controller/Api/DriverController.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
|
use App\Controller\AbstractController;
|
||||||
|
use App\Middleware\Api\JwtAuthMiddleware;
|
||||||
|
use App\Service\Api\Driver\GetSiteListService;
|
||||||
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
|
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||||
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
use Hyperf\Validation\Annotation\Scene;
|
||||||
|
|
||||||
|
#[Controller(prefix: 'api/driver')]
|
||||||
|
#[Middlewares([
|
||||||
|
JwtAuthMiddleware::class,
|
||||||
|
])]
|
||||||
|
class DriverController extends AbstractController
|
||||||
|
{
|
||||||
|
#[RequestMapping(path: 'get_site_list',methods: 'GET')]
|
||||||
|
#[Scene(scene: 'get_site_list')]
|
||||||
|
public function get_site_list()
|
||||||
|
{
|
||||||
|
return (new GetSiteListService)->handle();
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
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\OrderCode;
|
||||||
use App\Constants\Common\PayCode;
|
use App\Constants\Common\PayCode;
|
||||||
use App\Constants\Common\RefundCode;
|
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\PayFinishTrait;
|
||||||
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
||||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||||
|
use Hyperf\Amqp\Producer;
|
||||||
use Hyperf\DbConnection\Db;
|
use Hyperf\DbConnection\Db;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
@@ -68,6 +72,12 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
|||||||
*/
|
*/
|
||||||
protected bool $isCatering = true;
|
protected bool $isCatering = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Producer
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Producer $producer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
@@ -80,18 +90,25 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
|||||||
|
|
||||||
$this->checkWxCallBackOrder();
|
$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();
|
// Db::transaction(function (){
|
||||||
});
|
// $this->manageOrder();
|
||||||
|
//
|
||||||
//已经截单 自动退款
|
// $this->manageWxOrder();
|
||||||
if (!$this->isCatering) $this->joinRefundQueue($this->orderId,RefundCode::FULL_GOOD_REFUND,'已截单,系统自动退款');
|
////
|
||||||
|
// $this->isCatering = $this->manageAddCateringLog();
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// //已经截单 自动退款
|
||||||
|
// if (!$this->isCatering) $this->joinRefundQueue($this->orderId,RefundCode::FULL_GOOD_REFUND,'已截单,系统自动退款');
|
||||||
|
|
||||||
//todo 发送订阅通知
|
//todo 发送订阅通知
|
||||||
// $this->sendGainCoinMsg();
|
// $this->sendGainCoinMsg();
|
||||||
@@ -118,19 +135,25 @@ class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
|||||||
|
|
||||||
$this->checkWxRefundCallBackOrder();
|
$this->checkWxRefundCallBackOrder();
|
||||||
|
|
||||||
$this->checkRefundOrder();
|
$message = new GoodOrderRefundFinishProducer([
|
||||||
|
'refund_order_sno' => $this->orderNo,
|
||||||
|
'pay_type' => self::PayType,
|
||||||
|
]);
|
||||||
|
$this->producer->produce($message);
|
||||||
|
|
||||||
Db::transaction(function (){
|
// $this->checkRefundOrder();
|
||||||
$this->manageRefundOrder();
|
//
|
||||||
|
// Db::transaction(function (){
|
||||||
$this->manageOrderByRefund();
|
// $this->manageRefundOrder();
|
||||||
|
//
|
||||||
$this->manageSubCateringLog();
|
// $this->manageOrderByRefund();
|
||||||
|
//
|
||||||
if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
|
// $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->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||||
|
|
||||||
return $this->returnSuccess();
|
return $this->returnSuccess();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ trait GoodOrderTrait
|
|||||||
protected function checkCallBackOrder(): void
|
protected function checkCallBackOrder(): void
|
||||||
{
|
{
|
||||||
$this->orderInfo = $this->orderModel->getInfoByOrderSno($this->orderNo);
|
$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)) {
|
if (empty($this->orderInfo) || empty($this->payInfo)) {
|
||||||
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
|
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ trait RefundOrderTrait
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
*/
|
||||||
protected function checkRefundOrder(): void
|
protected function checkRefundOrder(): void
|
||||||
{
|
{
|
||||||
@@ -23,26 +21,15 @@ trait RefundOrderTrait
|
|||||||
$this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id);
|
$this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id);
|
||||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
|
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
|
||||||
|
|
||||||
if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) {
|
if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) throw new ErrException('订单不存在');
|
||||||
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
|
|
||||||
throw new ErrException('订单不存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->refundInfo->refund_status != RefundCode::WAIT_BY_PAY_TOOL) {
|
if ($this->refundInfo->refund_status != RefundCode::WAIT_BY_PAY_TOOL) throw new ErrException('订单已退款成功');
|
||||||
$this->log->debug(__CLASS__.':订单已退款成功,订单信息:'.json_encode($this->refundInfo->toArray()));
|
|
||||||
throw new ErrException('订单已退款成功');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->refundInfo->refund_type != PayCode::WECHAT_PAY) {
|
if ($this->refundInfo->refund_type != PayCode::WECHAT_PAY) throw new ErrException('订单退款渠道错误');
|
||||||
$this->log->debug(__CLASS__.':订单退款渠道错误,订单信息:'.json_encode($this->refundInfo->toArray()));
|
|
||||||
throw new ErrException('订单退款渠道错误');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
*/
|
||||||
protected function manageRefundOrder(): void
|
protected function manageRefundOrder(): void
|
||||||
{
|
{
|
||||||
@@ -56,8 +43,8 @@ trait RefundOrderTrait
|
|||||||
if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败');
|
if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败');
|
||||||
|
|
||||||
}catch (Exception $e) {
|
}catch (Exception $e) {
|
||||||
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
// $this->log->error('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||||
throw new ErrException($e->getMessage());
|
throw new ErrException('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +71,7 @@ trait RefundOrderTrait
|
|||||||
|
|
||||||
}catch (Exception $e) {
|
}catch (Exception $e) {
|
||||||
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
$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