123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\api\v1;
- use app\jobs\system\CapitalFlowJob;
- use app\Request;
- use app\services\user\UserExtractServices;
- use app\services\user\UserServices;
- use crmeb\basic\BaseController;
- use crmeb\services\WithdrawService;
- /**
- * 公共类
- * Class PublicController
- * @package app\controller\api
- */
- class WithdrawController extends BaseController
- {
- public function notify(Request $request)
- {
- $data = $request->post();
- if (!isset($data['sign'])) {
- @file_put_contents('notify.txt', '未接受到签名' . json_encode($data) . PHP_EOL, FILE_APPEND);
- echo 'FAIL';
- return;
- }
- $sign = $data['sign'];
- unset($data['sign']);
- /** @var UserExtractServices $extract_service */
- $extract_service = app()->make(UserExtractServices::class);
- if (WithdrawService::init()::checkSign($data, $sign)) {
- switch ($data['type']) {
- case 'create_batch_order':
- if ($data['return_code'] == 'SUCCESS') {
- $info = WithdrawService::init()::decode($data['resoult']);
- @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
- $list = $extract_service->getList(['trade_number' => $info['trade_number'], 'status' => 2]);
- if ($info['data'][0]['result_code'] != 'SUCCESS') {
- foreach ($list as $v) {
- $extract_service->update($v['id'], ['status' => 0, 'mark' => '业务处理失败']);
- }
- } else {
- foreach ($list as $v) {
- $extract_service->update($v['id'], ['enterprise_order_id' => $info['data'][0]['enterprise_order_id']]);
- }
- }
- }
- break;
- case 'refuse_order':
- if ($data['return_code'] == 'SUCCESS') {
- $info = WithdrawService::init()::decode($data['resoult']);
- @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
- $list = $extract_service->getList(['enterprise_order_id' => $info['enterprise_order_id'], 'status' => 2]);
- foreach ($list as $v) {
- $extract_service->refuse($v['id'], $info['remarks']);
- }
- }
- break;
- case 'payment_resout':
- if ($data['return_code'] == 'SUCCESS') {
- $info = WithdrawService::init()::decode($data['resoult']);
- @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
- $id = explode('_', $info['request_no'])[1] ?? 0;
- if ($id) {
- $list = $extract_service->getList(['id' => $id, 'status' => 2]);
- foreach ($list as $v) {
- if ($info['payment_status'] == 2) {
- $extract_service->update($v['id'], ['status' => 0, 'mark' => '失败']);
- }
- if ($info['payment_status'] == 4) {
- $extract_service->update($v['id'], ['status' => 1, 'mark' => '成功']);
- /** @var UserServices $userServices */
- $userServices = app()->make(UserServices::class);
- $userType = $userServices->value(['uid' => $v['uid']], 'user_type');
- $nickname = $userServices->value(['uid' => $v['uid']], 'nickname');
- $phone = $userServices->value(['uid' => $v['uid']], 'phone');
- switch ($v['extract_type']) {
- case 'bank':
- $order_id = $v['bank_code'];
- break;
- case 'weixin':
- $order_id = $v['wechat'];
- break;
- case 'alipay':
- $order_id = $v['alipay_code'];
- break;
- default:
- $order_id = '';
- break;
- }
- //记录资金流水队列
- CapitalFlowJob::dispatch([['order_id' => $order_id, 'store_id' => 0, 'uid' => $v['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $v['extract_price'], 'pay_type' => $v['extract_type']], 'extract']);
- //消息推送
- event('notice.notice', [['uid' => $v['uid'], 'userType' => strtolower($userType), 'extractNumber' => $v['extract_price'], 'nickname' => $nickname], 'user_extract']);
- }
- }
- }
- }
- break;
- default:
- $info = WithdrawService::init()::decode($data['resoult']);
- @file_put_contents('notify.txt', $data['type'] . json_encode($info) . PHP_EOL, FILE_APPEND);
- break;
- }
- echo 'SUCCESS';
- } else {
- @file_put_contents('notify.txt', '签名校验失败' . PHP_EOL, FILE_APPEND);
- echo 'FAIL';
- }
- }
- }
|