<?php

namespace App\Http\Controllers\QuickApp\User;


use App\Http\Controllers\QuickApp\BaseController;
use Illuminate\Http\Request;
use Log;
use DB;
class ShortcutController extends BaseController
{

    /**
     * @apiDefine Shortcut 快捷方式
     */

    /**
     * @apiVersion 1.0.0
     * @apiDescription 删除快捷方式
     * @api {get} shortcut/delete 删除快捷方式
     * @apiParam {String}  [token]  token
     * @apiHeader {String} [Authorization]  token 两个token任选其一
     * @apiGroup Shortcut
     * @apiName deleteShortCut
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {object}      data 结果集
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       code: 0,
     *       msg: "",
     *       data: {
     *
     *       }
     */

    function delete(Request $request){
        $res = DB::table('quickapp_shortcuts')->where('uid',$this->uid);
        if($res->first()){
            $res->update(['status'=>0,'updated_at'=>date("Y-m-d H:i:s")]);
        }else{
            $data = [
                'uid'=>$this->uid,
                'status'=>0,
                'created_at'=>date("Y-m-d H:i:s"),
                'updated_at'=>date("Y-m-d H:i:s"),

            ];
            $res = DB::table('quickapp_shortcuts')->insert($data);
        }
        return response()->success();
    }

    /**
     * @apiVersion 1.0.0
     * @apiDescription 快捷方式
     * @api {get} shortcut/add 添加快捷方式
     * @apiParam {String}  [token]  token
     * @apiHeader {String} [Authorization]  token 两个token任选其一
     * @apiGroup Shortcut
     * @apiName addShortCut
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {object}      data 结果集
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *       code: 0,
     *       msg: "",
     *       data: {
     *
     *       }
     */


    function add(Request $request)
    {
        $res = DB::table('quickapp_shortcuts')->where('uid', $this->uid);
        if ($res->first()) {
            $res->update(['status' => 1,'updated_at'=>date("Y-m-d H:i:s")]);
        } else {
            $data = [
                'uid' => $this->uid,
                'status' => 1,
                'created_at' => date("Y-m-d H:i:s"),
                'updated_at' => date("Y-m-d H:i:s"),

            ];
            $res = DB::table('quickapp_shortcuts')->insert($data);
        }
        return response()->success();
    }
}