zx/app/controller/admin/system/serve/Config.php

90 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\serve;
use app\common\repositories\system\serve\ServeMealRepository;
use app\validate\admin\MealValidata;
use crmeb\basic\BaseController;
use think\App;
/**
* 一号通套餐
*/
class Config extends BaseController
{
protected $repository;
public function __construct(App $app, ServeMealRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['status', 'type']);
$data = $this->repository->getList($where, $page, $limit);
return app('json')->success($data);
}
public function createForm()
{
return app('json')->success(formToData($this->repository->form()));
}
public function create(MealValidata $validata)
{
$data = $this->request->params(['name', 'price', 'num', 'type', 'status', 'sort']);
$validata->scene('create')->check($data);
$this->repository->create($data);
return app('json')->success('添加成功');
}
public function detail($id)
{
$data = $this->repository->get($id);
if (!$data) return app('json')->fail('数据不存在');
return app('json')->success($data);
}
public function updateForm($id)
{
return app('json')->success(formToData($this->repository->updateForm($id)));
}
public function update($id, MealValidata $validata)
{
$data = $this->request->params(['name', 'price', 'num', 'type', 'status', 'sort']);
$validata->scene('create')->check($data);
$this->repository->update($id, $data);
return app('json')->success('编辑成功');
}
public function detele($id)
{
$this->repository->delete($id);
return app('json')->success('删除成功');
}
public function switchStatus($id)
{
$status = $this->request->param('status', 1) == 1 ?: 0;
$this->repository->update($id, ['status' => $status]);
return app('json')->success('修改成功');
}
}