<?php

namespace app\api\model\wholesaler;

use app\api\service\User as UserService;
use app\common\service\Order as OrderService;
use cores\exception\BaseException;

class Order extends \app\common\model\wholesaler\Order
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'create_time',
        'update_time',
        'store_id',
    ];

    /**
     * @notes:创建订单
     * @param array $data
     * @return bool
     * @throws BaseException
     * @author: wanghousheng
     */
    public function createOrder(array $data): bool
    {
        $arr = [
            'user_id' => UserService::getCurrentLoginUserId(),
            'order_no' => OrderService::createOrderNo(),
            'store_id' => self::$storeId,
        ];
        $data = array_merge($arr, $data);
        return $this->save($data);
    }

    /**
     * 获取订单详情 (待付款状态)
     * @param string $orderNo 订单号
     * @return \app\common\model\wholesaler\Order|array|null
     */
    public static function getPayDetail(string $orderNo)
    {
        return self::detail(['order_no' => $orderNo]);
    }
}