<?php

namespace Modules\Mall\Traits;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Gout\Models\GoutCase;
use Modules\Mall\Models\GoodsSku;
use Modules\Mall\Models\Order;
use Modules\Mall\Models\Order as OrderModel;

trait HasOrders
{

    /**
     * Notes   : 用户的订单列表
     *
     * @Date   : 2021/4/19 10:28 上午
     * @Author : < Jason.C >
     * @return HasMany
     */
    public function orders(): HasMany
    {
        return $this->hasMany(Order::class);
    }

    /**
     * Notes: 是否可以申请提货
     *
     * @Author: 玄尘
     * @Date  : 2021/10/22 14:13
     * @return bool
     */
    public function canPick(): bool
    {
        return $this->case && $this->case->status == GoutCase::STATUS_PASS &&
            $this->identities()->where('order', '>', 1)->count() > 0 &&
            $this->userStock->stock > $this->userStock->hold;
    }

    /**
     * Notes: 提货
     *
     * @Author: 玄尘
     * @Date: 2022/7/27 16:18
     */
    public function pickGoods()
    {
        if (! $this->canPick()) {
            return '不可提货';
        }
    }

}