<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\PayCenter\Admin\Controller; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Log; use ModStart\Admin\Auth\AdminPermission; use ModStart\Admin\Concern\HasAdminQuickCRUD; use ModStart\Admin\Layout\AdminCRUDBuilder; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Exception\BizException; use ModStart\Core\Input\Response; use ModStart\Core\Util\CRUDUtil; use ModStart\Core\Util\EventUtil; use ModStart\Grid\Displayer\ItemOperate; use ModStart\Grid\GridFilter; use ModStart\Repository\Filter\RepositoryFilter; use ModStart\Support\Concern\HasFields; use ModStart\Widget\TextAjaxRequest; use Module\PayCenter\Biz\PayCenterBiz; use Module\PayCenter\Events\OrderPayedEvent; use Module\PayCenter\Type\PayOrderStatus; use Module\PayCenter\Type\PayType; class PayOrderController extends Controller { use HasAdminQuickCRUD; protected function crud(AdminCRUDBuilder $A2Tuf) { $A2Tuf->init('pay_order')->field(function ($A2Tuf) { $A2Tuf->id('id', '结算ID'); $A2Tuf->select('biz', '业务')->options(PayCenterBiz::allMap()); $A2Tuf->text('bizId', '业务订单ID'); $A2Tuf->type('status', '状态')->type(PayOrderStatus::class); $A2Tuf->type('payType', '支付类型')->type(PayType::class); $A2Tuf->currency('feeTotal', '金额'); $A2Tuf->text('body', '内容'); $A2Tuf->display('created_at', L('Created At')); $A2Tuf->display('updated_at', L('Updated At'))->listable(false); })->gridFilter(function (GridFilter $cbHm3) { $cbHm3->eq('id', '结算ID'); $cbHm3->eq('biz', '业务')->select(PayCenterBiz::allMap()); $cbHm3->eq('status', '状态')->select(PayOrderStatus::class); $cbHm3->eq('payType', '支付类型')->select(PayType::class); })->operateFixed('right')->hookItemOperateRendering(function (ItemOperate $i3KYf) { $vPOhn = $i3KYf->item(); switch ($vPOhn->status) { case PayOrderStatus::PAYED: goto Lly2R; Lly2R: $i3KYf->push(TextAjaxRequest::danger('退款', action('\\' . __CLASS__ . '@refund', array('_id' => $vPOhn->id)), '确定标记退款？<br />标记退款后，需要手动在支付宝/微信等三方支付平台人工处理退款')); goto uxmuD; G2PIM: break; goto G5vip; uxmuD: if (!$vPOhn->eventNotified) { $i3KYf->push(TextAjaxRequest::danger('重新触发事件', action('\\' . __CLASS__ . '@fireEvent', array('_id' => $vPOhn->id)), '确定重新触发支付？')); } goto G2PIM; G5vip: } })->disableCUD()->title('全部订单'); } public function refund() { goto ITNNV; Jr6GY: ModelUtil::update('pay_order', $MZHZc['id'], array('status' => PayOrderStatus::REFUND_SUCCESS)); goto QzChI; QzChI: return Response::redirect(CRUDUtil::jsGridRefresh()); goto VUW3a; ffAhI: $pNLgg = CRUDUtil::id(); goto euT2U; euT2U: $MZHZc = ModelUtil::get('pay_order', $pNLgg); goto a8OTr; ITNNV: AdminPermission::demoCheck(); goto ffAhI; a8OTr: BizException::throwsIfEmpty('订单不存在', $MZHZc); goto Ftk8G; Ftk8G: BizException::throwsIf('订单状态错误', $MZHZc['status'] != PayOrderStatus::PAYED); goto Jr6GY; VUW3a: } public function fireEvent() { goto mS23I; jCUGm: BizException::throwsIfEmpty('订单不存在', $MZHZc); goto GhPwy; fKgbA: $Z8J51->order = $MZHZc; goto RYRFa; RYRFa: EventUtil::fire($Z8J51); goto NkJCD; N2XND: $Z8J51 = new OrderPayedEvent(); goto sXHpg; NkJCD: Log::info('PayCenter.FireEventFromAdmin.OrderPayedEvent - ' . json_encode($Z8J51, JSON_UNESCAPED_UNICODE)); goto T_ABo; TNjnB: $Z8J51->bizId = $MZHZc['bizId']; goto fKgbA; T_ABo: ModelUtil::update('pay_order', $MZHZc['id'], array('eventNotified' => true)); goto u2l0z; GhPwy: BizException::throwsIf('订单状态错误', $MZHZc['status'] != PayOrderStatus::PAYED); goto N2XND; mS23I: AdminPermission::demoCheck(); goto G4i0l; DFJCB: $MZHZc = ModelUtil::get('pay_order', $pNLgg); goto jCUGm; G4i0l: $pNLgg = CRUDUtil::id(); goto DFJCB; u2l0z: return Response::redirect(CRUDUtil::jsGridRefresh()); goto ZuppB; sXHpg: $Z8J51->biz = $MZHZc['biz']; goto TNjnB; ZuppB: } }