order price
parent
8a2f2fb3e6
commit
eea0c744c0
15
README.md
15
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
|
||||
|
|
|
|||
|
|
@ -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('支付方式');
|
||||
|
|
|
|||
|
|
@ -40,5 +40,6 @@ return [
|
|||
'user_get_profit' => '用户获得积分',
|
||||
'scene' => '订单类别',
|
||||
'ship_money' => '配送费',
|
||||
'discount_price' => '改价优惠',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Order\Action;
|
||||
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
use Peidikeji\Order\Form\PriceForm;
|
||||
|
||||
class ShowPrice extends AbstractTool
|
||||
{
|
||||
protected $style = 'btn btn-sm btn-danger';
|
||||
|
||||
protected $title = '订单改价';
|
||||
|
||||
public function html()
|
||||
{
|
||||
$model = $this->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('<button type="button" class="'.$this->style.'">'.$this->title.'</button>');
|
||||
}
|
||||
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.orders.price');
|
||||
}
|
||||
|
||||
public function allowed()
|
||||
{
|
||||
$model = $this->parent->model();
|
||||
|
||||
return $model->canPay();
|
||||
}
|
||||
}
|
||||
|
|
@ -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('<button type="button" class="'.$this->style.'">'.$this->title.'</button>');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Order\Form;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Peidikeji\Order\Models\Order;
|
||||
|
||||
class PriceForm extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
protected $buttons = ['reset' => 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']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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 '<span>'.$value.'</span>' . ($this->discount_price > 0 ? '(<span class="text-danger">-'.$this->discount_price.'</span>)' : '');
|
||||
})->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());
|
||||
});
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue