OrderRefund.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\console\model;
  13. use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
  14. use app\common\enum\order\refund\RefundType as RefundTypeEnum;
  15. use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
  16. use app\common\model\OrderRefund as OrderRefundModel;
  17. use app\console\model\user\CommissionsDetail;
  18. /**
  19. * 售后单模型
  20. * Class OrderRefund
  21. * @package app\console\model
  22. */
  23. class OrderRefund extends OrderRefundModel
  24. {
  25. /**
  26. * 查询截止时间确认收货待评价的订单列表
  27. * @param int $storeId 商城ID
  28. * @param int $deadlineTime 截止时间
  29. * @return \think\Collection
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function getOrderListByDelivery(int $storeId, int $deadlineTime)
  35. {
  36. // 查询条件
  37. $filter = [
  38. ['type', '=', RefundTypeEnum::RETURN], //退货退款类型
  39. ['audit_status_zg', '=', AuditStatusEnum::REVIEWED], //主管审核通过
  40. ['audit_status', '=', AuditStatusEnum::REVIEWED], //转院审核通过
  41. ['approved_time', '<=', $deadlineTime], //超时了
  42. ['is_user_send', '=', 0], //用户未发货
  43. ['status', '=', RefundStatusEnum::NORMAL], //进行中状态
  44. ];
  45. // 查询列表记录
  46. return $this->getList($storeId, $filter);
  47. }
  48. /**
  49. * 获取所有满足条件的超时未发货售后单列表
  50. * @param int $storeId
  51. * @param array $filter
  52. * @param array $with
  53. * @return OrderRefund[]|array|\think\Collection
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @author: zjwhust
  58. * @Time: 2021/11/2 16:53
  59. */
  60. public function getList(int $storeId, $filter = [], $with = [])
  61. {
  62. return $this->with($with)
  63. ->where($filter)
  64. ->where('store_id', '=', $storeId)
  65. ->select();
  66. }
  67. /**
  68. * 批量更新售后单单状态为超时未发货
  69. * @param array $orderRefundIds
  70. * @return false|int
  71. */
  72. public function onUpdateDelivery(array $orderRefundIds)
  73. {
  74. return $this->onBatchUpdate($orderRefundIds, [
  75. 'status' => RefundStatusEnum::CLOSE,
  76. ]);
  77. }
  78. /**
  79. * 批量更新售后单
  80. * @param $orderRefundIds
  81. * @param $data
  82. * @return false|int
  83. */
  84. public function onBatchUpdate($orderRefundIds, $data)
  85. {
  86. return static::updateBase($data, [['order_refund_id', 'in', $orderRefundIds]]);
  87. }
  88. /**
  89. * 统计退款单数1.3.6
  90. * @param $orderIds
  91. * @return int
  92. */
  93. public static function getUserRefundCount36($orderIds)
  94. {
  95. return self::whereIn('order_id',$orderIds)->where('finance_refund',10)
  96. ->count('distinct order_id');
  97. }
  98. /**
  99. * 计算退款销售额
  100. * @param $orderGoodsIds
  101. * @return float|int
  102. */
  103. public static function getRefundSaleVolume($orderGoodsIds){
  104. if (!count($orderGoodsIds)) return 0;
  105. return OrderRefund::whereIn('order_goods_id',$orderGoodsIds)->where('finance_refund',10)
  106. ->sum('refund_money');
  107. /* $a = OrderRefund::alias('od')->join('order_goods','od.order_goods_id=order_goods.order_goods_id','left')
  108. ->whereIn('od.order_goods_id',$orderGoodsIds)
  109. ->field('order_goods.goods_price,order_goods.distributor_goods_price,od.goods_num,od.type,od.finance_refund')
  110. ->select();
  111. $sum = 0;
  112. if ($a){
  113. foreach($a as $item){
  114. $sum += ($item->goods_price - $item->distributor_goods_price)* $item->goods_num;
  115. }
  116. }
  117. return $sum;*/
  118. }
  119. }