// +---------------------------------------------------------------------- namespace app\controller\admin\system; use app\common\repositories\store\DepositRepository; use app\validate\admin\DepositValidate; use crmeb\basic\BaseController; use FormBuilder\Exception\FormBuilderException; use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; /** * Class UserGroup * @package app\controller\admin\user * @author xaboy * @day 2020-05-07 */ class Deposit extends BaseController { /** * @var DepositRepository */ protected $repository; /** * UserGroup constructor. * @param App $app * @param DepositRepository $repository */ public function __construct(App $app, DepositRepository $repository) { parent::__construct($app); $this->repository = $repository; } /** * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020-05-07 */ public function lst() { [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->getList(['status' => 1], $page, $limit)); } /** * @return mixed * @throws FormBuilderException * @author xaboy * @day 2020-05-07 */ public function createForm() { return app('json')->success(formToData($this->repository->form())); } /** * @param DepositValidate $validate * @return mixed * @author xaboy * @day 2020-05-07 */ public function create(DepositValidate $validate) { $data = $this->checkParams($validate); $this->repository->create($data); return app('json')->success('添加成功'); } /** * @param $id * @return mixed * @throws DbException * @throws FormBuilderException * @throws DataNotFoundException * @throws ModelNotFoundException * @author xaboy * @day 2020-05-07 */ public function updateForm($id) { if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); return app('json')->success(formToData($this->repository->updateForm($id))); } /** * @param $id * @param DepositValidate $validate * @return mixed * @throws DbException * @author xaboy * @day 2020-05-07 */ public function update($id, DepositValidate $validate) { $data = $this->checkParams($validate); if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $this->repository->update($id, $data); return app('json')->success('编辑成功'); } /** * @param $id * @return mixed * @throws DbException * @author xaboy * @day 2020-05-07 */ public function delete($id) { if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $this->repository->update($id, array('status' => 0)); return app('json')->success('删除成功'); } /** * @param DepositValidate $validate * @return array * @author xaboy * @day 2020-05-07 */ protected function checkParams(DepositValidate $validate) { $data = $this->request->params(['count','cycle', 'diamond', 'diamond_max', 'money']); $validate->check($data); return $data; } }