// +---------------------------------------------------------------------- namespace app\controller\admin\system; use app\common\repositories\store\LotteryRepository; use app\validate\admin\DepositValidate; use crmeb\basic\BaseController; use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use think\facade\Request; class Lottery extends BaseController { /** * @var LotteryRepository */ protected $repository; /** * CacheRepository constructor. * @param App $app */ public function __construct(App $app, LotteryRepository $repository) { parent::__construct($app); $this->repository = $repository; } /** * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020-05-07 */ public function lst() { return app('json')->success($this->repository->getList([])); } /** * @param $id * @param DepositValidate $validate * @return mixed * @throws DbException * @author xaboy * @day 2020-05-07 */ public function save() { $data = Request::post(); if(count($data) != 8){ return app('json')->fail('参数错误'); } $total = array_sum(array_column($data, 'rate')); if($total != 100) return app('json')->fail('总概率不等于100'); foreach ($data as $item){ $this->repository->update($item['id'], array('type' => $item['type'], 'value' => $item['value'], 'rate' => $item['rate'])); } return app('json')->success('保存成功'); } }