diff --git a/README.md b/README.md index ddefc8e..4df62a0 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,21 @@ - `composer require peidikeji/dcat-admin-order:dev-develop` - `php artisan migrate` +## 权限 + +````php +$permissions = [ + 'orders' => ['name' => '订单列表', 'curd' => ['index', 'show', 'destroy'], 'children' => [ + 'pay' => '支付订单', + 'cancel' => '取消订单', + 'ship' => '发货', + 'receive' => '收货', + 'price' => '订单改价', + ]], +]; + +```` + ## 配置 ### dcat-admin-user\src\Models\User.php diff --git a/database/2022_08_15_083640_create_orders_table.php b/database/2022_08_15_083640_create_orders_table.php index 6e889f1..892943d 100644 --- a/database/2022_08_15_083640_create_orders_table.php +++ b/database/2022_08_15_083640_create_orders_table.php @@ -23,6 +23,8 @@ return new class extends Migration $table->decimal('score_discount_amount')->default(0)->comment('使用积分数量'); $table->decimal('score_discount_ratio')->default(0)->comment('积分抵扣比例'); + $table->decimal('discount_price')->default(0)->comment('改价优惠'); + $table->decimal('pay_money', 12, 2)->default(0)->comment('支付金额'); $table->dateTime('pay_at')->nullable()->comment('支付时间'); $table->unsignedInteger('pay_way')->nullable()->comment('支付方式'); diff --git a/lang/zh_CN/order.php b/lang/zh_CN/order.php index 99476d2..ffac47d 100644 --- a/lang/zh_CN/order.php +++ b/lang/zh_CN/order.php @@ -40,5 +40,6 @@ return [ 'user_get_profit' => '用户获得积分', 'scene' => '订单类别', 'ship_money' => '配送费', + 'discount_price' => '改价优惠', ] ]; diff --git a/src/Action/ShowPrice.php b/src/Action/ShowPrice.php new file mode 100644 index 0000000..c1b24c6 --- /dev/null +++ b/src/Action/ShowPrice.php @@ -0,0 +1,39 @@ +parent->model(); + + $money = $model->total_money - $model->score_discount_money + $model->ship_money; + + return Modal::make() + ->lg() + ->title($this->title) + ->body(PriceForm::make()->payload(['id' => $model->id, 'pay_money' => $model->pay_money, 'origin_money' => $money])) + ->button(''); + } + + protected function authorize($user): bool + { + return $user->can('dcat.admin.orders.price'); + } + + public function allowed() + { + $model = $this->parent->model(); + + return $model->canPay(); + } +} diff --git a/src/Action/ShowShip.php b/src/Action/ShowShip.php index 35dd7d6..a8fbce7 100644 --- a/src/Action/ShowShip.php +++ b/src/Action/ShowShip.php @@ -17,7 +17,7 @@ class ShowShip extends AbstractTool $model = $this->parent->model(); return Modal::make() ->xl() - ->title($this->title()) + ->title($this->title) ->body(ShipForm::make()->payload(['id' => $model->id, 'ship_way' => $model->ship_way])) ->button(''); } diff --git a/src/Form/PriceForm.php b/src/Form/PriceForm.php new file mode 100644 index 0000000..197e1c8 --- /dev/null +++ b/src/Form/PriceForm.php @@ -0,0 +1,57 @@ + false, 'submit' => true]; + + public function handle(array $input) + { + $id = $this->payload['id']; + $order = Order::findOrFail($id); + $money = $input['money']; + $oldMoney = $this->payload['origin_money']; + $order->update([ + 'pay_money' => $money, + 'discount_price' => $oldMoney - $money, + ]); + + $admin = Admin::user(); + $order->options()->create([ + 'user_type' => $admin->getMorphClass(), + 'user_id' => $admin->id, + 'description' => '管理员: '.$admin->name.' 订单改价为: ' . $money, + 'attribute' => [ + 'old_money' => $oldMoney, + 'money' => $money, + ], + ]); + + return $this->response()->success('操作成功')->refresh(); + } + + public function form() + { + $this->display('origin_money', '原价'); + $this->display('pay_money', '现价'); + $this->currency('money', '修改为')->symbol('¥')->required(); + } + + public function default() + { + return [ + 'origin_money' => $this->payload['origin_money'], + 'pay_money' => $this->payload['pay_money'], + 'money' => $this->payload['pay_money'] + ]; + } +} diff --git a/src/Http/Admin/OrderController.php b/src/Http/Admin/OrderController.php index 9287e42..2a3d0fb 100644 --- a/src/Http/Admin/OrderController.php +++ b/src/Http/Admin/OrderController.php @@ -19,6 +19,7 @@ use Peidikeji\Order\Action\ShowCancel; use Peidikeji\Order\Action\ShowDelete; use Peidikeji\Order\Action\ShowPay; use Peidikeji\Order\Action\ShowPayQuery; +use Peidikeji\Order\Action\ShowPrice; use Peidikeji\Order\Action\ShowReceive; use Peidikeji\Order\Action\ShowRemarks; use Peidikeji\Order\Action\ShowShip; @@ -99,21 +100,22 @@ class OrderController extends AdminController $show->row(function (Show\Row $show) { $show->width(6)->field('score_discount_money'); $show->width(6)->field('score_discount_amount'); - // $show->width(6)->field('score_discount_ratio'); }); $show->row(function (Show\Row $show) use ($info) { - // $show->width(6)->field('pay_status')->as(fn() => $this->pay_status->label())->unescape(); + $show->width(6)->field('pay_money')->as(function ($value) { + return ''.$value.'' . ($this->discount_price > 0 ? '(-'.$this->discount_price.')' : ''); + })->unescape(); $show->width(6)->field('pay_way')->as(fn() => $this->pay_way?->label())->unescape(); - $show->width(6)->field('pay_money'); if ($info->pay_status === PayStatus::Success) { $show->width(6)->field('pay_at'); $show->width(6)->field('pay_no'); } }); + $show->row(function (Show\Row $show) use ($info) { // $show->width(6)->field('ship_status')->as(fn() => $this->ship_status->label())->unescape(); - $show->width(6)->field('ship_address')->as(fn($v) => $v ? implode(',', Arr::only($v, ['name', 'phone', 'address'])) : ''); $show->width(6)->field('ship_money'); + $show->width(6)->field('ship_address')->as(fn($v) => $v ? implode(',', Arr::only($v, ['name', 'phone', 'address'])) : ''); $show->width(6)->field('ship_way')->as(fn() => $this->ship_way?->label())->unescape(); $show->width(6)->field('ship_at'); }); @@ -127,6 +129,7 @@ class OrderController extends AdminController $tools->append(new ShowShip()); $tools->append(new ShowReceive()); $tools->append(new ShowDelete()); + $tools->append(new ShowPrice()); $tools->append(new ShowRemarks()); }); })); diff --git a/src/Models/Order.php b/src/Models/Order.php index db9d2b3..34a089e 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -24,7 +24,7 @@ class Order extends Model 'sn', 'total_money', 'user_id', 'ship_address', 'ship_at', 'ship_money', 'ship_status', 'ship_way', 'receive_at', 'score_discount_amount', 'score_discount_money', 'score_discount_ratio', - 'pay_at', 'pay_money', 'pay_no', 'pay_status', 'pay_way', + 'pay_at', 'pay_money', 'pay_no', 'pay_status', 'pay_way', 'discount_price', 'auto_close_at', 'extra', 'is_closed', 'refund_status', 'remarks', 'review_at', 'user_remarks' ];