123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\common\model;
- use think\Model;
- /**
- * 短信验证码
- */
- class Refund Extends Model
- {
- protected $name='order_info_refund';
- const REFUND_ING=10;
- const REFUND_PASS=20;
- const REFUND_REJECT=30;
- const REFUND_CANCEL=40;
- public static $refundStatus=[
- self::REFUND_ING=>'申请处理中',
- self::REFUND_PASS=>'申请通过',
- self::REFUND_REJECT=>'申请驳回',
- self::REFUND_CANCEL=>'已取消',
- ];
- /**
- * @return string[]
- */
- public static function getRefundStatus(): array
- {
- return self::$refundStatus;
- }
- const REFUND_TYPE_MONEY=1;
- const REFUND_TYPE_ALL=2;
- const REFUND_TYPE_GOODS=3;
- public static $refundTypes=[
- self::REFUND_TYPE_MONEY=>'仅退款',
- self::REFUND_TYPE_ALL=>'退款退货',
- self::REFUND_TYPE_GOODS=>'仅退货',
- ];
- public static $refundTypeGoods=[self::REFUND_TYPE_ALL,self::REFUND_TYPE_GOODS];
- /**
- * @return string[]
- */
- public static function getRefundTypes(): array
- {
- return self::$refundTypes;
- }
- /**
- * @return int[]
- */
- public static function getRefundTypeGoods(): array
- {
- return self::$refundTypeGoods;
- }
- protected $autoWriteTimestamp=true;
- public function orderInfo(){
- return $this->belongsTo(OrderInfo::class);
- }
- public function allowCancel(){
- return in_array($this['refund_status'],[
- self::REFUND_ING,
- ]);
- }
- public function makeCancel(){
- $this['refund_status']=self::REFUND_CANCEL;
- $this->save();
- OrderInfo::where('id',$this['order_info_id'])->update([
- 'refund_id'=>null,
- ]);
- }
- public function allowAudit(){
- return $this['refund_status']==self::REFUND_ING;
- }
- public function makeAudit($pass){
- $this['refund_status']=$pass?self::REFUND_PASS:self::REFUND_REJECT;
- if($pass){
- #如果退货
- if(in_array($this['refund_type'],self::getRefundTypeGoods())){
- $this->orderInfo()->update(['is_return_goods'=>1]);
- }
- }else{
- }
- $this->save();
- }
- protected static function init()
- {
- self::beforeInsert(function (self $refund){
- $refund['refund_status']=self::REFUND_ING;
- });
- }
- }
|