Refund.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 短信验证码
  6. */
  7. class Refund Extends Model
  8. {
  9. protected $name='order_info_refund';
  10. const REFUND_ING=10;
  11. const REFUND_PASS=20;
  12. const REFUND_REJECT=30;
  13. const REFUND_CANCEL=40;
  14. public static $refundStatus=[
  15. self::REFUND_ING=>'申请处理中',
  16. self::REFUND_PASS=>'申请通过',
  17. self::REFUND_REJECT=>'申请驳回',
  18. self::REFUND_CANCEL=>'已取消',
  19. ];
  20. /**
  21. * @return string[]
  22. */
  23. public static function getRefundStatus(): array
  24. {
  25. return self::$refundStatus;
  26. }
  27. const REFUND_TYPE_MONEY=1;
  28. const REFUND_TYPE_ALL=2;
  29. const REFUND_TYPE_GOODS=3;
  30. public static $refundTypes=[
  31. self::REFUND_TYPE_MONEY=>'仅退款',
  32. self::REFUND_TYPE_ALL=>'退款退货',
  33. self::REFUND_TYPE_GOODS=>'仅退货',
  34. ];
  35. public static $refundTypeGoods=[self::REFUND_TYPE_ALL,self::REFUND_TYPE_GOODS];
  36. /**
  37. * @return string[]
  38. */
  39. public static function getRefundTypes(): array
  40. {
  41. return self::$refundTypes;
  42. }
  43. /**
  44. * @return int[]
  45. */
  46. public static function getRefundTypeGoods(): array
  47. {
  48. return self::$refundTypeGoods;
  49. }
  50. protected $autoWriteTimestamp=true;
  51. public function orderInfo(){
  52. return $this->belongsTo(OrderInfo::class);
  53. }
  54. public function allowCancel(){
  55. return in_array($this['refund_status'],[
  56. self::REFUND_ING,
  57. ]);
  58. }
  59. public function makeCancel(){
  60. $this['refund_status']=self::REFUND_CANCEL;
  61. $this->save();
  62. OrderInfo::where('id',$this['order_info_id'])->update([
  63. 'refund_id'=>null,
  64. ]);
  65. }
  66. public function allowAudit(){
  67. return $this['refund_status']==self::REFUND_ING;
  68. }
  69. public function makeAudit($pass){
  70. $this['refund_status']=$pass?self::REFUND_PASS:self::REFUND_REJECT;
  71. if($pass){
  72. #如果退货
  73. if(in_array($this['refund_type'],self::getRefundTypeGoods())){
  74. $this->orderInfo()->update(['is_return_goods'=>1]);
  75. }
  76. }else{
  77. }
  78. $this->save();
  79. }
  80. protected static function init()
  81. {
  82. self::beforeInsert(function (self $refund){
  83. $refund['refund_status']=self::REFUND_ING;
  84. });
  85. }
  86. }