|
|
|
@ -2,8 +2,24 @@ |
|
|
|
|
|
|
|
namespace App\Controller\v3; |
|
|
|
|
|
|
|
use App\Constants\v3\OrderState; |
|
|
|
use App\Controller\BaseController; |
|
|
|
use App\Exception\BusinessException; |
|
|
|
use App\Model\v3\CcbPayment; |
|
|
|
use App\Model\v3\Order; |
|
|
|
use App\Service\v3\CcbPaymentService; |
|
|
|
use App\Service\v3\Interfaces\BadgeServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\CouponRebateServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\DeviceServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\FeiePrintServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\MiniprogramServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\MqttServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; |
|
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
|
use Hyperf\Logger\LoggerFactory; |
|
|
|
use Hyperf\Utils\ApplicationContext; |
|
|
|
|
|
|
|
class CcbNotifyController extends BaseController |
|
|
|
{ |
|
|
|
@ -12,6 +28,60 @@ class CcbNotifyController extends BaseController |
|
|
|
*/ |
|
|
|
private $logger; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var MqttServiceInterface |
|
|
|
*/ |
|
|
|
protected $mqttService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var DeviceServiceInterface |
|
|
|
*/ |
|
|
|
protected $deviceService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var MiniprogramServiceInterface |
|
|
|
*/ |
|
|
|
protected $miniprogramService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var FeiePrintServiceInterface |
|
|
|
*/ |
|
|
|
protected $feiePrintService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var CouponRebateServiceInterface |
|
|
|
*/ |
|
|
|
protected $couponRebateService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var OrderOnlineServiceInterface |
|
|
|
*/ |
|
|
|
protected $orderOnlineService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var SeparateAccountsServiceInterface |
|
|
|
*/ |
|
|
|
protected $separateAccountsService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var BadgeServiceInterface |
|
|
|
*/ |
|
|
|
protected $badgeService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var OrderStatisticsServiceInterface |
|
|
|
*/ |
|
|
|
protected $orderStatisticsService; |
|
|
|
|
|
|
|
public function __construct(LoggerFactory $loggerFactory) |
|
|
|
{ |
|
|
|
parent::__construct(); |
|
|
|
@ -25,10 +95,85 @@ class CcbNotifyController extends BaseController |
|
|
|
|
|
|
|
public function pay() |
|
|
|
{ |
|
|
|
$this->saveLog(__FUNCTION__, $this->request->getBody()->getContents()); |
|
|
|
return $this->response->json([ |
|
|
|
'Svc_Rsp_St' => '00', |
|
|
|
]); |
|
|
|
try { |
|
|
|
$this->saveLog(__FUNCTION__, $this->request->getBody()->getContents()); |
|
|
|
|
|
|
|
$data = $this->request->all(); |
|
|
|
if (!isset($data['Main_Ordr_No'], $data['Sign_Inf'])) { |
|
|
|
throw new BusinessException(500, '缺少参数'); |
|
|
|
} |
|
|
|
|
|
|
|
$ccb = ApplicationContext::getContainer()->get(CcbPaymentService::class); |
|
|
|
|
|
|
|
if (!$ccb->verifySign($ccb->createSign($data), $data['Sign_Inf'])) { |
|
|
|
throw new BusinessException(500, '验签失败'); |
|
|
|
} |
|
|
|
|
|
|
|
$model = CcbPayment::where('main_ordr_no', $data['Main_Ordr_No'])->first(); |
|
|
|
if (!$model) { |
|
|
|
throw new BusinessException(500, '下单记录不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
$payResult = $ccb->gatherEnquireOrder($data['Main_Ordr_No']); |
|
|
|
if ($payResult['Ordr_Stcd'] != $data['Ordr_Stcd']) { |
|
|
|
throw new BusinessException(500, '订单状态不一致'); |
|
|
|
} |
|
|
|
|
|
|
|
// 状态已同步
|
|
|
|
if ($model->ordr_stcd == $data['Ordr_Stcd']) { |
|
|
|
return $this->response->json([ |
|
|
|
'Svc_Rsp_St' => '00', |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
$model->ordr_stcd = $data['Ordr_Stcd']; |
|
|
|
$model->pay_time = $data['Pay_Time']; |
|
|
|
$model->pay_type = $data['TYPE']; |
|
|
|
$model->pay_channel = $data['PAY_CHANNEL']; |
|
|
|
$model->debit_credit_type = $data['DEBIT_CREDIT_TYPE']; |
|
|
|
$model->save(); |
|
|
|
|
|
|
|
if ($payResult['Ordr_Stcd'] == '2') { |
|
|
|
$orderMain = $model->orderMain; |
|
|
|
|
|
|
|
if ($orderMain->state != OrderState::UNPAID) { |
|
|
|
throw new BusinessException(500, '订单状态异常'); |
|
|
|
} |
|
|
|
|
|
|
|
$this->orderOnlineService->doByPaid($orderMain->global_order_id); |
|
|
|
$this->separateAccountsService->orderOnlinePaid($orderMain->global_order_id); |
|
|
|
|
|
|
|
//记录当前市场的当天外卖订单数
|
|
|
|
$this->orderStatisticsService->setForMarket($orderMain->market_id); |
|
|
|
|
|
|
|
// 优惠券返券
|
|
|
|
$this->couponRebateService->couponRebateInTask($orderMain->global_order_id); |
|
|
|
|
|
|
|
// 喇叭通知,兼容旧音响,MQTT+IOT
|
|
|
|
$res = $this->mqttService->speakToStore($orderMain->global_order_id); |
|
|
|
$res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->global_order_id); |
|
|
|
|
|
|
|
// 打印订单,自动打印
|
|
|
|
$res = $this->feiePrintService->feiePrint($orderMain->global_order_id); |
|
|
|
|
|
|
|
// 记录badge
|
|
|
|
$orderChildIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('store_id'); |
|
|
|
$this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::PAID); |
|
|
|
|
|
|
|
// 公众号模板消息
|
|
|
|
$res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->response->json([ |
|
|
|
'Svc_Rsp_St' => '00', |
|
|
|
]); |
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
return $this->response->json([ |
|
|
|
'Svc_Rsp_St' => '01', |
|
|
|
'Rsp_Inf' => $e instanceof BusinessException ? $e->getMessage() : '内部错误' |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function refund() |
|
|
|
|