<?php

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api) {
    /*
   |--------------------------------------------------------------
   |  不需要token验证的接口
   |--------------------------------------------------------------
   */
    $api->group([
        'middleware' => ['throttle:120'], //代表1分钟内接口最高请求次数，超出返回 429: Too Many Attempts
    ], function ($api) {
        $api->get('setting/{tags?}', 'SettingsController@get'); //用户配置信息
        $api->post('setting', 'SettingsController@set'); //设置用户信息
        $api->post('sms/send', 'SmsController@send'); //发送手机验证码
        $api->post('email/send', 'EmailController@sendEmailCode'); //发送邮箱验证码
        $api->post('attachments/upload', 'AttachmentController@upload'); //上传附件
        $api->delete('attachments/{uid}', 'AttachmentController@delete'); //删除附件
        $api->post('reset_password', 'AuthController@forgetPassword');  //用户找回密码
        $api->post('find_id', 'AuthController@findId');  //用户找回ID

        $api->get('privacy', 'IndexController@privacyPolice'); //隐私政策
        $api->get('agreement', 'IndexController@userAgreement'); //用户协议
        $api->get('aboutus', 'IndexController@aboutus'); //关于我们

        $api->get('filter_type_list', 'ProductController@filterTypeList');  //产品类型(分类)
        $api->get('upload_type_list', 'ProductController@uploadTypeList');  //产品类型(上传)

    });

    $api->group(['prefix' => 'auth'], function ($api) {
        $api->post('register', 'AuthController@register'); //注册
        $api->post('login', 'AuthController@login');  //账号密码登录
        $api->post('smslogin', 'AuthController@loginBySmsCode'); //短信验证码登录
        $api->get('forget_password', 'AuthController@forgetPassword'); //忘记密码

        $api->post('oplogin', 'AuthController@authLogin'); //APP第三方授权登录(微信)
        $api->post('decrypt_phone', 'AuthController@decryptPhone'); //微信小程序获取手机号
        $api->post('mnplogin', 'AuthController@miniProgram'); //微信小程序登录(微信)
        $api->post('oalogin', 'AuthController@h5Oauth'); //H5授权登录[未实现]
        $api->get('minicode', 'AuthController@miniCode'); //获取微信小程序code[未实现]

    });

    $api->group(['prefix' => 'index'], function ($api) {
        $api->get('all_region', 'RegionController@allRegion'); //全国省市区
        $api->get('helps', 'ArticleController@helpList'); //帮助类型
        $api->get('answer', 'ArticleController@answer'); //问题答案
        $api->get('product_list', 'ProductController@productList'); //首页产品列表
    });

    // 系统设置
    $api->group(['prefix' => 'settings'], function ($api) {
        $api->get('notice_policy', 'SettingsController@noticePolicy'); //公告|政策
    });


    /*
     |--------------------------------------------------------------
     |  需要 token 验证的接口 'middleware' => ['api.auth'] 读取的 config/api.php  'auth' => ['jwt' => 'Dingo\Api\Auth\Provider\JWT'], 所以 在 Kernel.php 找不到这个中间件
     |--------------------------------------------------------------
     */
    $api->group([
        'middleware' => ['api.auth', 'throttle:120'],
    ], function ($api) {

        $api->get('logout', 'AuthController@logout')->name('logout');  //退出登录
        $api->post('auth/forget_password', 'AuthController@forgetPassword'); //忘记密码

        $api->group(['prefix' => 'users'], function($api){
            //restful实例
            $api->get('/', 'UserController@index'); //获取用户列表数据
            $api->get('show', 'UserController@show'); //根据用户id查询用户数据
            $api->post('/', 'UserController@create'); //新增用户
            $api->post('up_user_info', 'UserController@upUserInfo'); //修改用户信息
            $api->delete('/{id}', 'UserController@destroy'); //删除用户信息
            $api->post('avatar', 'UserController@avatar');  //上传头像接口
            $api->get('add_follow', 'UserController@addFollow');  //添加关注


            //[未实现:h5绑定、h5解绑;小程序绑定、小程序解绑]
            $api->post('bind_mobile', 'UserController@bindMobile'); //手机号绑定
            $api->post('rebind_mobile', 'UserController@bindMobile'); //手机号解绑
            $api->get('group_by_initial', 'UserController@groupByInitial'); //用户列表按照首字母分组排序，类似手机通讯录 ?
            $api->post('feedback', 'UserController@feedback'); //问题反馈 意见反馈
        });
        // 常见问题
        $api->group(['prefix' => 'questions'], function($api){
            $api->get('question_list', 'QuestionController@questionList');  //常见问题列表
            $api->get('question_detail', 'QuestionController@questionDetail');  //常见问题详情
        });

        // 产品
        $api->group(['prefix' => 'product'], function($api){
            $api->post('add_product', 'ProductController@addProduct');  //添加产品
            $api->get('user_product_list', 'ProductController@userProductList');  //我的产品列表
            $api->get('product_detail', 'ProductController@productDetail');  //产品详情
            $api->get('add_collect', 'ProductController@addCollect');  //添加收藏
            $api->get('add_like', 'ProductController@addLike');  //喜欢产品
            $api->get('collect_list', 'ProductController@collectList');  //收藏列表
            $api->post('report', 'ProductController@report');  //举报图片
        });

        // 会员
        $api->group(['prefix' => 'member'], function($api){
            $api->get('member_list', 'MemberController@memberList');  //会员价格
            $api->post('join_member', 'MemberController@joinMember');  //加入会员
        });

        // 文件夹
        $api->group(['prefix' => 'folder'], function($api){
            $api->post('add_folder', 'UserFolderController@addFolder');  //新建文件夹
            $api->get('folder_list', 'UserFolderController@folderList');  //文件夹列表
            $api->get('folder_detail', 'UserFolderController@folderDetail');  //文件夹详情
            $api->post('edit_folder', 'UserFolderController@editFolder');  //编辑文件夹
            $api->post('move_file', 'UserFolderController@moveFile');  //移动文件
            $api->get('image_list', 'UserFolderController@imageList');  //图片列表
        });

        // 支付
        $api->group(['prefix' => 'pay'], function($api){
            $api->get('payment', 'PayController@payment');  //会员价格
        });

    });

    $api->post('pay/alipay_notify', 'PayController@alipayNotify'); //支付宝支付回调
    $api->post('pay/wechatpay/notify', 'PayController@wechatpayNotify'); //微信支付回调
});
