10 changed files with 252 additions and 68 deletions
-
5app/Constants/LogLabel.php
-
107app/Controller/NotifyPayRefundController.php
-
9app/Model/CouponRec.php
-
18app/Model/CouponUserRec.php
-
3app/Model/FinancialRecord.php
-
48app/Service/CouponService.php
-
1app/Service/CouponServiceInterface.php
-
106app/Service/OrderService.php
-
21app/Service/WxRefundService.php
-
2app/Service/WxRefundServiceInterface.php
@ -0,0 +1,107 @@ |
|||
<?php |
|||
|
|||
namespace App\Controller; |
|||
|
|||
use App\Constants\LogLabel; |
|||
|
|||
use App\Model\OrderMain; |
|||
|
|||
use App\Model\Users; |
|||
use App\Service\CouponRebateServiceInterface; |
|||
use App\Service\DeviceServiceInterface; |
|||
use App\Service\FeiePrintServiceInterface; |
|||
use App\Service\MiniprogramServiceInterface; |
|||
use App\Service\MqttServiceInterface; |
|||
use App\Service\OrderServiceInterface; |
|||
use App\Service\SeparateAccountsServiceInterface; |
|||
use App\Service\UserServiceInterface; |
|||
use EasyWeChat\Factory; |
|||
use Hyperf\DbConnection\Db; |
|||
use Hyperf\Guzzle\CoroutineHandler; |
|||
use Exception; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
use Hyperf\HttpMessage\Stream\SwooleStream; |
|||
use Symfony\Component\HttpFoundation\Request; |
|||
|
|||
class NotifyPayRefundController extends BaseController |
|||
{ |
|||
|
|||
const AWARD_LIMIT_AMOUNT = 3; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var UserServiceInterface |
|||
*/ |
|||
protected $userService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var CouponRebateServiceInterface |
|||
*/ |
|||
protected $couponRebateService; |
|||
|
|||
/** |
|||
* @Inject |
|||
* @var OrderServiceInterface |
|||
*/ |
|||
protected $orderService; |
|||
|
|||
/** |
|||
* 微信退款回调 |
|||
*/ |
|||
public function wxPayRefund() |
|||
{ |
|||
$config = config('wxpay'); |
|||
$app = Factory::payment($config); |
|||
$app['guzzle_handler'] = CoroutineHandler::class; |
|||
|
|||
$get = $this->request->getQueryParams(); |
|||
$post = $this->request->getParsedBody(); |
|||
$cookie = $this->request->getCookieParams(); |
|||
$files = $this->request->getUploadedFiles(); |
|||
$server = $this->request->getServerParams(); |
|||
$xml = $this->request->getBody()->getContents(); |
|||
|
|||
$app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml); |
|||
|
|||
/* 通知回调,进行业务处理 */ |
|||
$response = $app->handleRefundedNotify(function ($message, $fail) use ($app) { |
|||
|
|||
try { |
|||
/* --- 退款失败 --- */ |
|||
if ( |
|||
empty($message) |
|||
|| !isset($message['result_code']) |
|||
|| $message['result_code'] != 'SUCCESS' |
|||
) { |
|||
// 错误日志
|
|||
$this->log->event( |
|||
LogLabel::PAY_NOTIFY_REFUND, |
|||
$message |
|||
); |
|||
$fail('Unknown error but FAIL'); |
|||
} |
|||
|
|||
/* --- 退款成功 --- */ |
|||
// 退款返还优惠券
|
|||
$this->couponService->orderRefundCoupon($message['out_trade_no']); |
|||
// 添加用户的流水
|
|||
$orderMain = OrderMain::select('id','global_order_id')->where('code',$message['out_trade_no'])->first(); |
|||
|
|||
|
|||
} catch (Exception $e) { |
|||
|
|||
$this->log->event( |
|||
LogLabel::PAY_NOTIFY_REFUND, |
|||
['exception_fail' => $e->getMessage()] |
|||
); |
|||
$fail('Exception'); |
|||
} |
|||
}); |
|||
|
|||
return $this->response |
|||
->withHeader('Content-Type', 'text/xml') |
|||
->withStatus(200) |
|||
->withBody(new SwooleStream($response->getContent())); |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Model; |
|||
|
|||
|
|||
class CouponUserRec extends Model |
|||
{ |
|||
/* 状态 */ |
|||
// 未使用
|
|||
const STATE_UNUSED = 0; |
|||
// 使用部分
|
|||
const STATE_SOME = 1; |
|||
// 已用完
|
|||
const STATE_FINISH = 2; |
|||
|
|||
protected $table = 'ims_system_coupon_user_receive'; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue