first commit
This commit is contained in:
116
app/Models/Order.php
Normal file
116
app/Models/Order.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\OrderCando;
|
||||
use App\Models\Traits\OrderHasActions;
|
||||
use App\Models\Traits\OrderHasAttributes;
|
||||
use App\Models\Traits\OrderHasScopes;
|
||||
use App\Utils\Helper;
|
||||
use Auth;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
use OrderCando, OrderHasActions, OrderHasAttributes, OrderHasScopes, SoftDeletes;
|
||||
|
||||
const ORDER_INIT = 'INIT'; // 订单初始化
|
||||
const ORDER_UNPAY = 'UNPAY'; // 待支付
|
||||
const ORDER_PAID = 'PAID'; // 已支付
|
||||
const ORDER_DELIVER = 'DELIVER'; // 发货处理中
|
||||
const ORDER_DELIVERED = 'DELIVERED'; // 已发货
|
||||
const ORDER_SIGNED = 'SIGNED'; // 已签收
|
||||
const REFUND_APPLY = 'REFUND_APPLY'; // 申请退款
|
||||
const REFUND_AGREE = 'REFUND_AGREE'; // 同意退款
|
||||
const REFUND_REFUSE = 'REFUND_REFUSE'; // 拒绝退款
|
||||
const REFUND_PROCESS = 'REFUND_PROCESS'; // 退款中
|
||||
const REFUND_COMPLETED = 'REFUND_COMPLETED'; // 退款完成
|
||||
const ORDER_CLOSED = 'CLOSED'; // 已关闭
|
||||
const ORDER_CANCEL = 'CANCEL'; // 取消
|
||||
const ORDER_COMPLETED = 'COMPLETED'; // 已完成
|
||||
|
||||
const CANCEL_USER = 2; // 买家取消
|
||||
const CANCEL_SELLER = 3; // 卖家取消
|
||||
const CANCEL_SYSTEM = 4; // 系统取消
|
||||
|
||||
protected $dates = [
|
||||
'paid_at',
|
||||
];
|
||||
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'orderid';
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($model) {
|
||||
$model->orderid = Helper::orderid(config('aslong_order.order_orderid.length'), config('aslong_order.order_orderid.prefix'));
|
||||
});
|
||||
|
||||
self::updated(function ($model) {
|
||||
$model->logs()->create([
|
||||
'user' => self::detectUser(),
|
||||
'status' => $model->getOriginal('status', '0000') . '|' . $model->status,
|
||||
'state' => $model->getOriginal('state') . '|' . $model->state,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 侦测当前操作用户
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-26T14:29:52+0800
|
||||
* @return Auth
|
||||
*/
|
||||
public static function detectUser()
|
||||
{
|
||||
return Auth::user() ?: Auth::guard(config('aslong_order.admin_guard'))->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联所属用户
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-19T14:05:42+0800
|
||||
* @return User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(config('aslong_order.user_model'))->withDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-19T10:35:55+0800
|
||||
* @return OrderDetail
|
||||
*/
|
||||
public function details()
|
||||
{
|
||||
return $this->hasMany(OrderDetail::class);
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
return $this->hasOne(OrderDetail::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单日志
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-19T10:36:11+0800
|
||||
* @return OrderLog
|
||||
*/
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(OrderLog::class);
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->hasOne(OrderPayment::class)->whereNotNull('transaction_id')->orderBy('id', 'desc')->withDefault();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user