OrderRefund.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\common\model\order;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 售后管理模型
  6. */
  7. class OrderRefund extends BaseModel
  8. {
  9. protected $name = 'order_refund';
  10. protected $pk = 'order_refund_id';
  11. /**
  12. * 关联用户表
  13. */
  14. public function user()
  15. {
  16. return $this->belongsTo('app\\common\\model\\user\\User');
  17. }
  18. /**
  19. * 关联订单主表
  20. */
  21. public function orderMaster()
  22. {
  23. return $this->belongsTo('app\\common\\model\\order\\Order');
  24. }
  25. /**
  26. * 关联订单商品表
  27. */
  28. public function orderproduct()
  29. {
  30. return $this->belongsTo('app\\common\\model\\order\\OrderProduct', 'order_product_id', 'order_product_id');
  31. }
  32. /**
  33. * 关联图片记录表
  34. */
  35. public function image()
  36. {
  37. return $this->hasMany('app\\common\\model\\order\\OrderRefundImage');
  38. }
  39. /**
  40. * 关联物流公司表
  41. */
  42. public function express()
  43. {
  44. return $this->belongsTo('app\\api\\model\\settings\\Express');
  45. }
  46. /**
  47. * 关联用户表
  48. */
  49. public function address()
  50. {
  51. return $this->hasOne('app\\api\\model\\order\\OrderRefundAddress');
  52. }
  53. /**
  54. * 关联供应商表
  55. */
  56. public function supplier()
  57. {
  58. return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id');
  59. }
  60. /**
  61. * 售后类型
  62. */
  63. public function getTypeAttr($value)
  64. {
  65. $status = [10 => '退货退款', 20 => '换货', 30 => '仅退款'];
  66. return ['text' => $status[$value], 'value' => $value];
  67. }
  68. /**
  69. * 售后类型
  70. */
  71. public function getPlateStatusAttr($value)
  72. {
  73. $status = [0 => '未申请', 10 => '待审核',20 => '已同意', 30 => '已拒绝'];
  74. return ['text' => $status[$value], 'value' => $value];
  75. }
  76. /**
  77. * 商家是否同意售后
  78. */
  79. public function getIsAgreeAttr($value)
  80. {
  81. $status = [0 => '待审核', 10 => '已同意', 20 => '已拒绝'];
  82. return ['text' => $status[$value], 'value' => $value];
  83. }
  84. /**
  85. * 售后单状态
  86. */
  87. public function getStatusAttr($value)
  88. {
  89. $status = [0 => '进行中', 10 => '已拒绝', 20 => '已完成', 30 => '已取消'];
  90. return ['text' => $status[$value], 'value' => $value];
  91. }
  92. /**
  93. * 售后单详情
  94. */
  95. public static function detail($where)
  96. {
  97. is_array($where) ? $filter = $where : $filter['order_refund_id'] = (int)$where;
  98. return (new static())->with(['order_master', 'image.file', 'orderproduct.image', 'express', 'address', 'user'])->where($filter)->find();
  99. }
  100. /**
  101. * 获取退款订单总数 (可指定某天)
  102. * 已同意的退款
  103. */
  104. public function getOrderRefundData($startDate = null, $endDate = null, $type, $shop_supplier_id)
  105. {
  106. $model = $this;
  107. $model = $model->where('create_time', '>=', strtotime($startDate));
  108. if(is_null($endDate)){
  109. $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
  110. }else{
  111. $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
  112. }
  113. if($shop_supplier_id > 0){
  114. $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
  115. }
  116. $model = $model->where('is_agree', '=', 10);
  117. if($type == 'order_refund_money'){
  118. // 退款金额
  119. return $model->sum('refund_money');
  120. }else if($type == 'order_refund_total'){
  121. // 退款数量
  122. return $model->count();
  123. }
  124. return 0;
  125. }
  126. }