<?php
/**
 * @package merchant
 *
 * @author xaboy
 * @day 2020-03-24
 *
 * 
 */

namespace app\controller\admin\system\config;


use crmeb\basic\BaseController;
use app\common\repositories\user\UserAwardRepository;
use FormBuilder\Exception\FormBuilderException;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

/**
 * Class Config
 * @package app\controller\admin\system\config
 * @author xaboy
 * @day 2020-03-27
 */
class Award extends BaseController
{
    /**
     * @var UserAwardRepository
     */
    protected $repository;

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

    /**
     * @return mixed
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     * @author xaboy
     * @day 2020-03-31
     */
    public function lst()
    {
        $where = $this->request->params(['keyword']);
        [$page, $limit] = $this->getPage();
        $lst = $this->repository->getList($where, $page, $limit);

        return app('json')->success($lst);
    }

    /**
     * @return mixed
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     * @throws FormBuilderException
     * @author xaboy
     * @day 2020-03-31
     */
    public function updateTable()
    {
        $data = $this->request->param();
        $form = $this->repository->updateForm($data);
        return app('json')->success(formToData($form));
    }

    /**
     * @param int $key
     * @return mixed
     * @throws DbException
     * @author xaboy
     * @day 2020-03-27
     */
    public function update($key)
    {
        $data = $this->request->param();
        $this->repository->updateAward($key,$data);
        return app('json')->success('修改成功');
    }

}
