// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\console\model; use app\common\enum\order\refund\AuditStatus as AuditStatusEnum; use app\common\enum\order\refund\RefundType as RefundTypeEnum; use app\common\enum\order\refund\RefundStatus as RefundStatusEnum; use app\common\model\OrderRefund as OrderRefundModel; use app\console\model\user\CommissionsDetail; /** * 售后单模型 * Class OrderRefund * @package app\console\model */ class OrderRefund extends OrderRefundModel { /** * 查询截止时间确认收货待评价的订单列表 * @param int $storeId 商城ID * @param int $deadlineTime 截止时间 * @return \think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getOrderListByDelivery(int $storeId, int $deadlineTime) { // 查询条件 $filter = [ ['type', '=', RefundTypeEnum::RETURN], //退货退款类型 ['audit_status_zg', '=', AuditStatusEnum::REVIEWED], //主管审核通过 ['audit_status', '=', AuditStatusEnum::REVIEWED], //转院审核通过 ['approved_time', '<=', $deadlineTime], //超时了 ['is_user_send', '=', 0], //用户未发货 ['status', '=', RefundStatusEnum::NORMAL], //进行中状态 ]; // 查询列表记录 return $this->getList($storeId, $filter); } /** * 获取所有满足条件的超时未发货售后单列表 * @param int $storeId * @param array $filter * @param array $with * @return OrderRefund[]|array|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author: zjwhust * @Time: 2021/11/2 16:53 */ public function getList(int $storeId, $filter = [], $with = []) { return $this->with($with) ->where($filter) ->where('store_id', '=', $storeId) ->select(); } /** * 批量更新售后单单状态为超时未发货 * @param array $orderRefundIds * @return false|int */ public function onUpdateDelivery(array $orderRefundIds) { return $this->onBatchUpdate($orderRefundIds, [ 'status' => RefundStatusEnum::CLOSE, ]); } /** * 批量更新售后单 * @param $orderRefundIds * @param $data * @return false|int */ public function onBatchUpdate($orderRefundIds, $data) { return static::updateBase($data, [['order_refund_id', 'in', $orderRefundIds]]); } /** * 统计退款单数1.3.6 * @param $orderIds * @return int */ public static function getUserRefundCount36($orderIds) { return self::whereIn('order_id',$orderIds)->where('finance_refund',10) ->count('distinct order_id'); } /** * 计算退款销售额 * @param $orderGoodsIds * @return float|int */ public static function getRefundSaleVolume($orderGoodsIds){ if (!count($orderGoodsIds)) return 0; return OrderRefund::whereIn('order_goods_id',$orderGoodsIds)->where('finance_refund',10) ->sum('refund_money'); /* $a = OrderRefund::alias('od')->join('order_goods','od.order_goods_id=order_goods.order_goods_id','left') ->whereIn('od.order_goods_id',$orderGoodsIds) ->field('order_goods.goods_price,order_goods.distributor_goods_price,od.goods_num,od.type,od.finance_refund') ->select(); $sum = 0; if ($a){ foreach($a as $item){ $sum += ($item->goods_price - $item->distributor_goods_price)* $item->goods_num; } } return $sum;*/ } }