|
@@ -2,10 +2,12 @@
|
|
|
|
|
|
namespace app\common\model;
|
|
|
|
|
|
+use app\common\service\OrderRefundService;
|
|
|
use think\Model;
|
|
|
|
|
|
/**
|
|
|
* 短信验证码
|
|
|
+ * @property Orders orders
|
|
|
*/
|
|
|
class Refund Extends Model
|
|
|
{
|
|
@@ -36,6 +38,7 @@ class Refund Extends Model
|
|
|
self::REFUND_TYPE_GOODS=>'仅退货',
|
|
|
];
|
|
|
public static $refundTypeGoods=[self::REFUND_TYPE_ALL,self::REFUND_TYPE_GOODS];
|
|
|
+ public static $refundTypeMoney=[self::REFUND_TYPE_MONEY,self::REFUND_TYPE_ALL];
|
|
|
|
|
|
/**
|
|
|
* @return string[]
|
|
@@ -52,10 +55,21 @@ class Refund Extends Model
|
|
|
{
|
|
|
return self::$refundTypeGoods;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return int[]
|
|
|
+ */
|
|
|
+ public static function getRefundTypeMoney(): array
|
|
|
+ {
|
|
|
+ return self::$refundTypeMoney;
|
|
|
+ }
|
|
|
protected $autoWriteTimestamp=true;
|
|
|
public function orderInfo(){
|
|
|
return $this->belongsTo(OrderInfo::class);
|
|
|
}
|
|
|
+ public function orders(){
|
|
|
+ return $this->belongsTo(Orders::class,'order_id');
|
|
|
+ }
|
|
|
public function allowCancel(){
|
|
|
return in_array($this['refund_status'],[
|
|
|
self::REFUND_ING,
|
|
@@ -71,17 +85,45 @@ class Refund Extends Model
|
|
|
public function allowAudit(){
|
|
|
return $this['refund_status']==self::REFUND_ING;
|
|
|
}
|
|
|
+ #退款相关
|
|
|
+ /**
|
|
|
+ * 退款金额
|
|
|
+ */
|
|
|
+ public function getRefundAmount(){
|
|
|
+ return $this['amount'];
|
|
|
+ }
|
|
|
+ public function refundResult($succ,$remark=''){
|
|
|
+ $this['pay_status']=$succ?1:2;
|
|
|
+ $this['pay_remark']=$remark;
|
|
|
+ $this->save();
|
|
|
+ }
|
|
|
+ #end
|
|
|
public function makeAudit($pass){
|
|
|
$this['refund_status']=$pass?self::REFUND_PASS:self::REFUND_REJECT;
|
|
|
+ $refundMoney=false;
|
|
|
if($pass){
|
|
|
#如果退货
|
|
|
if(in_array($this['refund_type'],self::getRefundTypeGoods())){
|
|
|
$this->orderInfo()->update(['is_return_goods'=>1]);
|
|
|
}
|
|
|
- }else{
|
|
|
-
|
|
|
+ #如果退款,执行退款
|
|
|
+ if(in_array($this['refund_type'],self::getRefundTypeMoney())){
|
|
|
+ $this['order_no']=order_no('TK');
|
|
|
+ $refundMoney=true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!$this->save()){
|
|
|
+ throw_user('保存失败');
|
|
|
+ }
|
|
|
+ if($refundMoney){
|
|
|
+ $payment=$this->orders->payment??null;
|
|
|
+ if($payment){
|
|
|
+ $refund=new OrderRefundService();
|
|
|
+ $refund->setPayment($payment);
|
|
|
+ $refund->setRefund($this);
|
|
|
+ $refund->pay();
|
|
|
+ }
|
|
|
}
|
|
|
- $this->save();
|
|
|
}
|
|
|
|
|
|
|