139 lines
4.2 KiB
PHP
139 lines
4.2 KiB
PHP
<?php
|
||
|
||
|
||
namespace Yunshop\MinApp\Backend\Controllers;
|
||
|
||
|
||
use app\common\components\BaseController;
|
||
use app\common\services\payment\WechatMinPay;
|
||
use Yunshop\MinApp\Common\Models\WechatMinAppPayOrder;
|
||
|
||
class PayManageOrderController extends BaseController
|
||
{
|
||
|
||
public function index()
|
||
{
|
||
|
||
return view('Yunshop\MinApp::pay-order-list', [])->render();
|
||
|
||
}
|
||
|
||
public function getList()
|
||
{
|
||
|
||
$search = request()->input('search');
|
||
|
||
$list = WechatMinAppPayOrder::getList($search)->paginate(15);
|
||
|
||
return $this->successJson('ok', $list);
|
||
}
|
||
|
||
/**
|
||
* @return \Illuminate\Http\JsonResponse
|
||
* @throws \app\common\exceptions\AppException
|
||
*/
|
||
public function divideAccount()
|
||
{
|
||
$id = intval(request()->input('id'));
|
||
|
||
$payOrder = WechatMinAppPayOrder::find($id);
|
||
if (!$payOrder) {
|
||
return $this->errorJson('支付记录不存在');
|
||
}
|
||
|
||
$sevenDays = 7 * 24 * 60 * 60;
|
||
$current_time = time();
|
||
//支付七天后才能分账
|
||
if ($payOrder->pay_time && (($payOrder->pay_time + $sevenDays) > $current_time)) {
|
||
return $this->errorJson('支付时间未超过七天,无法分账');
|
||
}
|
||
|
||
if (empty($payOrder->openid)) {
|
||
return $this->errorJson('会员微信openid标识为空,无法分账');
|
||
}
|
||
|
||
$result = (new WechatMinPay())->divideAccount($payOrder);
|
||
|
||
if ($result['errcode']) {
|
||
$payOrder->mark = $result;
|
||
$payOrder->error_msg = $result['errmsg'];
|
||
$payOrder->save();
|
||
return $this->errorJson($result['errmsg']);
|
||
}
|
||
|
||
$payOrder->fill(['mark'=> $result,'error_msg'=> $result['errmsg'],'status' => 2])->save();
|
||
|
||
return $this->successJson('分账成功');
|
||
}
|
||
|
||
public function bindOpenid()
|
||
{
|
||
$id = intval(request()->input('bind_order_id'));
|
||
$uid = intval(request()->input('bing_member_id'));
|
||
|
||
if (empty($id) || empty($uid)) {
|
||
return $this->errorJson('请输入会员ID');
|
||
}
|
||
|
||
|
||
$openid = \app\common\models\Member::getOpenIdForType($uid, 2);
|
||
if (!$openid) {
|
||
return $this->errorJson("该会员ID({$uid})不存在微信小程序openid");
|
||
}
|
||
|
||
$payOrder = WechatMinAppPayOrder::find($id);
|
||
|
||
$payOrder->openid = $openid;
|
||
$bool = $payOrder->save();
|
||
if ($bool) {
|
||
return $this->successJson('绑定成功');
|
||
}
|
||
|
||
return $this->errorJson('绑定失败');
|
||
}
|
||
|
||
public function fix()
|
||
{
|
||
$logs = \app\common\models\PayResponseDataLog::uniacid()->where('third_type', '微信小程序')->get();
|
||
|
||
if ($logs->isEmpty()) {
|
||
echo '没有微信小程序支付记录';
|
||
}
|
||
|
||
$success = $logs->unique('out_order_no')->map(function ($log) {
|
||
$payOrder = WechatMinAppPayOrder::where('trade_no', $log->out_order_no)->first();
|
||
|
||
if (!$payOrder) {
|
||
$message = json_decode($log->params, true);
|
||
$createData = [
|
||
'uniacid' => $log->uniacid,
|
||
'trade_no' => $message['order_info']['trade_no'],
|
||
'transaction_id' => $message['order_info']['transaction_id'],
|
||
'notice_params' => $message['order_info'],
|
||
'pay_time' => $message['CreateTime'],
|
||
'status' => 1,
|
||
];
|
||
|
||
$tag = substr($log->out_order_no, 0, 2);
|
||
if ('PN' == strtoupper($tag)) {
|
||
$orderPayLog = \app\common\models\OrderPay::where('pay_sn', $log->out_order_no)->first();
|
||
if ($orderPayLog->uid) {
|
||
$openid = \app\common\models\Member::getOpenIdForType($orderPayLog->uid, 2);
|
||
if ($openid) {
|
||
$createData['openid'] = $openid;
|
||
}
|
||
}
|
||
}
|
||
WechatMinAppPayOrder::create($createData);
|
||
|
||
return $log->out_order_no;
|
||
}
|
||
return null;
|
||
})->filter()->values()->toArray();
|
||
|
||
\Log::info('---微信小程序支付管旧数据修复---',$success);
|
||
|
||
echo '总共成功同步旧数据:'.count($success);
|
||
|
||
}
|
||
} |