<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace Applications\sample\api\controller\order;

use app\api\controller\BaseApiController;
use Applications\sample\modules\order\service\api\OrderService;
use Applications\sample\modules\order\validate\api\OrderValidator;
use Applications\sample\modules\order\validate\domain\OrderDomainValidator;
use think\Request;

/**
 * Order
 * @package Applications\sample\api\controller\order
 */
class Order extends BaseApiController
{
    /**
     * 订单列表
     */
    public function list(Request $request)
    {
        $uid = (int)$request->uid;
        return json($this->app->make(OrderService::class)->list($uid, $request));
    }

    /**
     * 创建订单
     */
    public function create(Request $request)
    {
        $uid = (int)$request->uid;
        $params = $request->param();
        $params['user_id'] = $uid;

        $this->validate($params, OrderValidator::class . '.create');
        $this->validateDomain($this->app->make(OrderDomainValidator::class), $params, 'create');

        return json($this->app->make(OrderService::class)->create($uid, (int)$params['article_id']));
    }
}
