100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\RefundCode;
|
|
use Hyperf\Database\Concerns\BuildsQueries;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $order_type
|
|
* @property int $order_id
|
|
* @property int $pay_id
|
|
* @property int $refund_status
|
|
* @property string $refund_money
|
|
* @property string $refund_time
|
|
* @property int $refund_type
|
|
* @property string $refund_order_sno
|
|
* @property string $alipay_transaction_id
|
|
* @property string $wx_transaction_id
|
|
* @property string $notify_json
|
|
* @property string $remark
|
|
* @property string $reason
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class RefundOrder extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'refund_order';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'order_type' => 'integer', 'order_id' => 'integer', 'pay_id' => 'integer', 'refund_status' => 'integer', 'refund_type' => 'integer'];
|
|
|
|
const string CREATED_AT = 'create_time';
|
|
const string UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* @param int $orderId
|
|
* @param int $type
|
|
* @return int|mixed|string
|
|
*/
|
|
public function getAllMoneyByOrderId(int $orderId, int $type): mixed
|
|
{
|
|
return $this
|
|
->where('order_id', $orderId)
|
|
->where('order_type', $type)
|
|
->whereIn('refund_status',[
|
|
RefundCode::WAIT_REFUND,
|
|
RefundCode::REFUND_SUCCESS
|
|
])->sum('refund_amount') ?? 0;
|
|
}
|
|
|
|
public function getSuccessMoneyByOrderId(int $orderId, int $type): mixed
|
|
{
|
|
return $this
|
|
->where('order_id', $orderId)
|
|
->where('order_type', $type)
|
|
->whereIn('refund_status',[
|
|
RefundCode::WAIT_REFUND,
|
|
RefundCode::REFUND_SUCCESS
|
|
])->sum('refund_amount') ?? 0;
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @param int $type
|
|
* @return \Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoByOrderIdAndTypeWaitRefund(int $id,int $type): \Hyperf\Database\Model\Model|null
|
|
{
|
|
return $this->where('order_id',$id)->where('order_type',$type)->where('refund_status',RefundCode::WAIT_REFUND)->first();
|
|
}
|
|
|
|
/**
|
|
* @param string $orderSno
|
|
* @param int $type
|
|
* @return \Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoByOrderSnoAndType(string $orderSno, int $type): \Hyperf\Database\Model\Model|null
|
|
{
|
|
return $this->where('order_sno',$orderSno)->where('order_type',$type)->first();
|
|
}
|
|
}
|