<?php

namespace app\controller\admin\system;

use app\common\repositories\system\CacheRepository;
use ln\basic\BaseController;
use ln\services\YunxinSmsService;
use think\App;

class Cache extends BaseController
{
    /**
     * @var CacheRepository
     */
    protected $repository;

    /**
     * CacheRepository constructor.
     * @param App $app
     */
    public function __construct(App $app, CacheRepository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }


    /**
     * @Author:Qinii
     * @Date: 2020/9/15
     * @return mixed
     */
    public function getAgree($key)
    {
        $allow = [
            'sys_integral_rule',
            'sys_intention_agree',
            'sys_product_presell_agree',
            'sys_user_agree',
            'wechat_menus',
            'sys_receipt_agree',
            'sys_extension_agree',
            'sys_merchant_type',
            'sys_brokerage',
            ];
        if (!in_array($key, $allow)) return app('json')->fail('数据不存在');
        $make = app()->make(CacheRepository::class);
        $data[$key] = $make->getResult($key);
        return app('json')->success($data);
    }


    /**
     * @Author:Qinii
     * @Date: 2020/9/15
     * @return mixed
     */
    public function saveAgree($key)
    {
        /**
         * sys_integral_rule 分销
         * sys_intention_agree 积分
         * sys_product_presell_agree 预售
         * sys_user_agree 用户
         * wechat_menus
         * sys_extension_agree
         *
         */
        $allow = [
            'sys_integral_rule',
            'sys_intention_agree',
            'sys_product_presell_agree',
            'sys_user_agree',
            'wechat_menus',
            'sys_receipt_agree',
            'sys_extension_agree',
            'sys_merchant_type',
            'sys_brokerage',
        ];
        if (!in_array($key, $allow)) return app('json')->fail('KEY不存在');

        $value = $this->request->param('agree');
        app()->make(CacheRepository::class)->save($key, $value);
        return app('json')->success('保存成功');
    }
}
