<?php

namespace Modules\Mall\Models\Traits;

use Illuminate\Database\Eloquent\Builder;
use Modules\Mall\Models\Order;

trait OrderScopes
{

    /**
     * Notes   : 未支付
     *
     * @Date   : 2021/5/17 10:59 上午
     * @Author : < Jason.C >
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeUnPay(Builder $query): Builder
    {
        return $query->where('state', self::STATUS_INIT);
    }

    /**
     * Notes   : 已支付，待发货
     *
     * @Date   : 2021/5/17 11:00 上午
     * @Author : < Jason.C >
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopePaid(Builder $query): Builder
    {
        return $query->where('state', self::STATUS_PAID);
    }

    /**
     * Notes   : 已发货，代签收
     *
     * @Date   : 2021/5/17 11:03 上午
     * @Author : < Jason.C >
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeDelivered(Builder $query): Builder
    {
        return $query->where('state', self::STATUS_DELIVERED);
    }

    /**
     * Notes   : 已签收
     *
     * @Date   : 2021/5/17 11:04 上午
     * @Author : < Jason.C >
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeSigned(Builder $query): Builder
    {
        return $query->where('state', self::STATUS_SIGNED);
    }

    /**
     * Notes   : 已完成的订单
     *
     * @Date   : 2021/5/17 11:04 上午
     * @Author : < Jason.C >
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeCompleted(Builder $query): Builder
    {
        return $query->where('state', self::STATUS_COMPLETED);
    }

    /**
     * Notes   : 订单列表排除退款部分
     *
     * @Date   : 2021/5/18 9:50
     * @Author : Mr.wang
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeCommon(Builder $query): Builder
    {
        return $query->whereIn('state', [
            self::STATUS_INIT,
            self::STATUS_CANCEL,
            self::STATUS_PAID,
            self::STATUS_DELIVERED,
            self::STATUS_SIGNED,
            self::STATUS_COMPLETED,
        ]);
    }

    /**
     * Notes: 签收和发货
     *
     * @Author: 玄尘
     * @Date: 2022/8/30 8:33
     * @param  Builder  $query
     * @return Builder
     */
    public function scopeDeliveredAndSigned(Builder $query): Builder
    {
        return $query->whereIn('state', [
            self::STATUS_DELIVERED,
            self::STATUS_SIGNED,
        ]);
    }

    /**
     * Notes: 积分兑换订单
     *
     * @Author: 玄尘
     * @Date: 2022/9/19 14:40
     * @param  Builder  $query
     * @return Builder
     */
    public function scopeTypeScore(Builder $query): Builder
    {
        return $query->where('type', Order::TYPE_SCORE);
    }

    /**
     * Notes: 提货订单
     *
     * @Author: 玄尘
     * @Date: 2022/9/19 14:40
     * @param  Builder  $query
     * @return Builder
     */
    public function scopeTypeSample(Builder $query): Builder
    {
        return $query->where('type', Order::TYPE_SAMPLE);
    }

}
