diff --git a/modules/User/Http/Controllers/Admin/Actions/Pay.php b/modules/User/Http/Controllers/Admin/Actions/Pay.php index 21c25fd..67202a8 100644 --- a/modules/User/Http/Controllers/Admin/Actions/Pay.php +++ b/modules/User/Http/Controllers/Admin/Actions/Pay.php @@ -9,7 +9,7 @@ use Modules\User\Models\Order; class Pay extends RowAction { - public $name = '支付测试-正式版本移除'; + public $name = '通过'; public function handle(Order $order): Response { diff --git a/modules/User/Http/Controllers/Admin/OrderController.php b/modules/User/Http/Controllers/Admin/OrderController.php index 49f4b25..da1d825 100644 --- a/modules/User/Http/Controllers/Admin/OrderController.php +++ b/modules/User/Http/Controllers/Admin/OrderController.php @@ -8,6 +8,7 @@ use Encore\Admin\Grid; use Exception; use Modules\User\Http\Controllers\Admin\Actions\Pay; use Modules\User\Http\Controllers\Admin\Actions\Refund; +use Modules\User\Http\Controllers\Admin\Actions\Reject; use Modules\User\Models\Identity; use Modules\User\Models\Order; @@ -38,6 +39,9 @@ class OrderController extends AdminController if ($actions->row->canPay()) { $actions->add(new Pay()); } + if ($actions->row->canPay()) { + $actions->add(new Reject()); + } if ($actions->row->canRefund()) { $actions->add(new Refund()); diff --git a/modules/User/Http/Resources/UserIdentityResource.php b/modules/User/Http/Resources/UserIdentityResource.php index cf14503..5695adc 100644 --- a/modules/User/Http/Resources/UserIdentityResource.php +++ b/modules/User/Http/Resources/UserIdentityResource.php @@ -10,13 +10,15 @@ class UserIdentityResource extends JsonResource { public function toArray($request): array { - $user = Api::user(); - $open = $renew = false; - $text = '立即开通'; - $price = $this->getCondition('price', '0'); - $cost = $this->getCondition('cost', '0'); - $identityName = $this->name; - $coupon_price = 0; + $user = Api::user(); + $open = $renew = false; + $text = '立即开通'; + $price = $this->getCondition('price', '0'); + $cost = $this->getCondition('cost', '0'); + $identityName = $this->name; + $coupon_price = 0; + $reopen = false;//是否需要重新提交凭证 + $identityOrder = ''; if ($user) { $identity = $user->identityFirst(); @@ -30,10 +32,13 @@ class UserIdentityResource extends JsonResource } else { $identityOrder = Order::ByUser($user) ->where('identity_id', $this->id) - ->where('state', Order::STATE_INIT) ->first(); - if ($identityOrder) { + + if ($identityOrder && $identityOrder->state == Order::STATE_INIT) { $text = '等待审核'; + } elseif ($identityOrder && $identityOrder->state == Order::STATE_REJECT) { + $text = '驳回申请'; + $reopen = true; } else { $open = true; } @@ -45,11 +50,11 @@ class UserIdentityResource extends JsonResource } return [ - 'identity_id' => $this->id, - 'name' => $identityName, - 'stock' => $this->stock, - 'years' => $this->years, - 'times' => $this->when($user && $this->id == $user->identityFirst()->id, function () use ($user) { + 'identity_id' => $this->id, + 'name' => $identityName, + 'stock' => $this->stock, + 'years' => $this->years, + 'times' => $this->when($user && $this->id == $user->identityFirst()->id, function () use ($user) { return new IdentityMiddleResource($user->identityMiddle()->first()); }, [ 'name' => '---', @@ -57,22 +62,26 @@ class UserIdentityResource extends JsonResource 'started_at' => '---', 'ended_at' => '---', ]), - 'cover' => $this->cover_url, - 'order' => $this->order, - 'description' => $this->description ?? "", - 'coupon_price' => floatval($coupon_price),//开通金额 - 'cost' => floatval($cost),//开通金额 - 'price' => floatval($price),//开通金额 - 'can' => [ - 'buy' => (bool) $this->can_buy, - 'open' => $this->can_buy ? $open : false,//开通 - 'renew' => $this->can_buy ? $renew : false,//续费 + 'cover' => $this->cover_url, + 'order' => $this->order, + 'description' => $this->description ?? "", + 'coupon_price' => floatval($coupon_price),//开通金额 + 'cost' => floatval($cost),//开通金额 + 'price' => floatval($price),//开通金额 + 'can' => [ + 'buy' => (bool) $this->can_buy, + 'open' => $this->can_buy ? $open : false,//开通 + 'renew' => $this->can_buy ? $renew : false,//续费 + 're_open' => $reopen, ], - 'buttonText' => $text, - 'rights' => $this->rights, - 'rules' => $this->getRules(), - 'not_rules' => $this->getNotRules(), - 'is_open' => $user && $this->id == $user->identityFirst()->id + 'identity_order' => $this->when($identityOrder, function () use ($identityOrder) { + return new UserOrderResource($identityOrder); + }), + 'buttonText' => $text, + 'rights' => $this->rights, + 'rules' => $this->getRules(), + 'not_rules' => $this->getNotRules(), + 'is_open' => $user && $this->id == $user->identityFirst()->id ]; } diff --git a/modules/User/Models/Order.php b/modules/User/Models/Order.php index cbb7189..0b7dbda 100644 --- a/modules/User/Models/Order.php +++ b/modules/User/Models/Order.php @@ -3,6 +3,8 @@ namespace Modules\User\Models; use App\Models\Model; +use App\Traits\HasClicks; +use App\Traits\HasCovers; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Modules\Payment\Traits\WithPayments; use Modules\User\Events\UserOrderPaid; @@ -14,17 +16,20 @@ class Order extends Model use WithPayments, OrderActions, + HasCovers, BelongsToUser; protected $table = 'user_orders'; const STATE_INIT = 'INIT'; const STATE_SUCCESS = 'SUCCESS'; - const STATE_REFUND = 'refund'; + const STATE_REFUND = 'REFUND'; + const STATE_REJECT = 'REJECT'; const STATES = [ self::STATE_INIT => '待审核', self::STATE_SUCCESS => '已支付', + self::STATE_REJECT => '已驳回', self::STATE_REFUND => '已退款', ]; @@ -57,6 +62,7 @@ class Order extends Model /** * Notes: 设置订单支付 + * * @Author: 玄尘 * @Date : 2020/11/12 11:19 */ @@ -68,8 +74,26 @@ class Order extends Model event(new UserOrderPaid($this)); } + + /** + * Notes: 驳回理由 + * + * @Author: 玄尘 + * @Date: 2023/3/21 15:21 + * @param string $reason + * @return bool + */ + public function reject(string $reason): bool + { + $this->state = self::STATE_REJECT; + $this->reject_reason = $reason; + + return $this->save(); + } + /** * Notes: 是否可以支付 + * * @Author: 玄尘 * @Date : 2021/6/4 10:19 * @return bool @@ -91,7 +115,5 @@ class Order extends Model return $this->isPay(); } - - } diff --git a/modules/User/Routes/api.php b/modules/User/Routes/api.php index dd5e8d2..2398018 100644 --- a/modules/User/Routes/api.php +++ b/modules/User/Routes/api.php @@ -77,6 +77,9 @@ Route::group([ //获取支付数据 $router->get('pay/{order}/wechat', 'IndexController@wechat'); $router->get('pay/{order}/alipay', 'IndexController@alipay'); + + $router->get('order/{order}', 'OrderController@show');//编辑信息 + $router->post('order/{order}', 'OrderController@edit');//编辑信息 }); Route::group([ 'namespace' => 'Identity',