<?php

use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;

Route::group([
    'prefix'    => 'mall',
    'namespace' => 'Api',
], function (Router $router) {

    /**
     * 轮播图
     */
    $router->get('banners', 'BannerController@index');
    /**
     * 商品分类
     */
    $router->get('categories', 'CategoryController@index');
    /**
     * 商品分类
     */
    $router->get('tags', 'TagController@index');
    /**
     * 店铺列表
     */
    $router->get('shops', 'ShopController@index');
    $router->get('shops/{shop}', 'ShopController@show')->where('shop', '[0-9]+');
    $router->get('shops/{shop}/categories', 'ShopExtendController@categories');
    $router->get('shops/{shop}/tags', 'ShopExtendController@tags');
    $router->get('shops/{shop}/brands', 'ShopExtendController@brands');
    $router->get('shops/{shop}/expresses', 'ShopExtendController@expresses');
    $router->get('shops/{shop}/banners', 'ShopExtendController@banners');
    /**
     * 商品管理
     */
    $router->get('goods', 'GoodsController@index');
});

Route::group([
    'prefix'     => 'mall',
    'namespace'  => 'Api',
    'middleware' => config('api.route.middleware_guess'),
], function (Router $router) {
    /**
     * 商城的首页
     */
    $router->get('', 'IndexController@index');
    $router->get('carts/count', 'CartController@count');
    $router->get('goods/{goods}', 'GoodsController@show');
    /**
     * 活动接口
     */
    $router->get('activities', 'ActivityController@index');
    $router->get('activities/{activity}', 'ActivityController@show');

});

Route::group([
    'prefix'     => 'mall',
    'namespace'  => 'Api',
    'middleware' => config('api.route.middleware_auth'),
], function (Router $router) {
    /**
     * 店铺操作
     */
    $router->get('shops/create', 'ShopController@create');
    $router->post('shops', 'ShopController@store');
    $router->get('shops/edit', 'ShopController@edit');
    $router->put('shops', 'ShopController@update');
    /**
     * 购物车
     */
    $router->get('carts', 'CartController@index');
    $router->post('carts', 'CartController@store');
    $router->put('carts/{cart}', 'CartController@update');
    $router->delete('carts/{cart}', 'CartController@destroy');
    /**
     * 订单管理
     */
    $router->get('orders/counts', 'OrderController@counts');
    $router->get('orders', 'OrderController@index');
    // 订单详情 可以通过 order_no 来查询
    $router->get('orders/{order}', 'OrderController@show')->where(['order' => '[0-9]+']);
    // 创建订单
    $router->get('buy/goods', 'OrderBuyController@goodsCreate');//商品确认订单
    $router->post('buy/goods', 'OrderBuyController@goodsBuy');  //商品购买
    $router->get('buy/carts', 'OrderBuyController@cartsCreate');//购物车确认订单
    $router->post('buy/carts', 'OrderBuyController@cartsBuy');  //购物车购买

    $router->get('buy/samples', 'OrderBuyController@sampleCreate');//试用商品
    $router->post('buy/samples', 'OrderBuyController@sampleBuy');  //试用商品购买

    // 更新订单，地址或其他信息
    $router->put('orders/{order}', 'OrderController@update')->where(['order' => '[0-9]+']);
    // 查看物流
    $router->get('orders/{order}/logistic', 'OrderController@logistic')->where(['order' => '[0-9]+']);
    // 签收订单
    $router->put('orders/{order}/sign', 'OrderController@sign')->where(['order' => '[0-9]+']);
    // 取消订单
    $router->put('orders/{order}/cancel', 'OrderController@cancel')->where(['order' => '[0-9]+']);
    // 删除订单
    $router->delete('orders/{order}', 'OrderController@destroy')->where(['order' => '[0-9]+']);
    //退款
    $router->get('orders/{order}/refund', 'OrderController@goods')->where(['order' => '[0-9]+']);
    $router->post('orders/{order}/refund', 'OrderController@refund')->where(['order' => '[0-9]+']);
    //订单支付
    $router->get('pay/{order}/wechat', 'PayController@wechat')->where(['order' => '[0-9]+']);
    $router->get('pay/{order}/alipay', 'PayController@alipay')->where(['order' => '[0-9]+']);
    $router->post('pay/{order}/score', 'PayController@score')->where(['order' => '[0-9]+']);
    //退货
    $router->post('refunds/{refund}/deliver', 'RefundController@deliver')->where(['refund' => '[0-9]+']);

    //退款售后
    $router->get('refunds', 'RefundController@index');
    $router->get('refunds/{refund}', 'RefundController@show')->where(['refund' => '[0-9]+']);
    $router->get('refunds/{refund}/logs', 'RefundController@logs')->where(['refund' => '[0-9]+']);

    /**
     * 收货地址
     */
    $router->post('addresses/{address}/default', 'AddressController@setDefault');
    $router->resource('addresses', 'AddressController');

});
