repository = $repository; } /** * @param int $groupId * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author zfy * @day 2020-03-30 */ public function lst($groupId) { [$page, $limit] = $this->getPage(); $lst = $this->repository->getGroupDataLst($this->request->merId(), intval($groupId), $page, $limit); return app('json')->success($lst); } /** * @param int $groupId * @return mixed * @throws FormBuilderException * @author zfy * @day 2020-04-02 */ public function createTable($groupId) { if (!app()->make(GroupRepository::class)->exists($groupId)) return app('json')->fail('组合数据不存在!'); return app('json')->success(formToData($this->repository->form($groupId, null, $this->request->merId()))); } /** * @param $id * @return mixed * @throws DbException * @author zfy * @day 2020-05-13 */ public function changeStatus($id) { $status = $this->request->param('status', 0) == 1 ? 1 : 0; if (!$this->repository->merExists($this->request->merId(), $id)) return app('json')->fail('数据不存在'); $this->repository->update($id, compact('status')); return app('json')->success('修改成功'); } /** * @param int $groupId * @param int $id * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @throws FormBuilderException * @author zfy * @day 2020-04-02 */ public function updateTable($groupId, $id) { if (!app()->make(GroupRepository::class)->exists($groupId)) return app('json')->fail('组合数据不存在!'); if (!$this->repository->merExists($this->request->merId(), $id)) return app('json')->fail('数据不存在!'); return app('json')->success(formToData($this->repository->updateForm($groupId, $this->request->merId(), $id))); } /** * @param int $groupId * @param GroupDataValidate $validate * @param GroupRepository $groupRepository * @return mixed * @author zfy * @day 2020-04-02 */ public function create($groupId, GroupDataValidate $validate, GroupRepository $groupRepository) { $data = $this->request->params([['sort', 0], ['status', 0]]); $validate->check($data); if (!$groupRepository->exists($groupId)) return app('json')->fail('数据组不存在'); $fieldRule = $groupRepository->fields($groupId); $data['value'] = $this->request->params(array_column($fieldRule, 'field')); $data['group_id'] = $groupId; $this->repository->create($this->request->merId(), $data, $fieldRule); return app('json')->success('添加成功'); } /** * @param int $groupId * @param int $id * @param GroupDataValidate $validate * @param GroupRepository $groupRepository * @return mixed * @throws DbException * @author zfy * @day 2020-04-02 */ public function update($groupId, $id, GroupDataValidate $validate, GroupRepository $groupRepository) { $data = $this->request->params([['sort', 0], ['status', 0]]); $validate->check($data); if (!$groupRepository->exists($groupId)) return app('json')->fail('数据组不存在'); if (!$this->repository->merExists($this->request->merId(), $id)) return app('json')->fail('数据不存在!'); $fieldRule = $groupRepository->fields($groupId); $data['value'] = $this->request->params(array_column($fieldRule, 'field')); $this->repository->merUpdate($this->request->merId(), $id, $data, $fieldRule); return app('json')->success('修改成功'); } /** * @param int $id * @return mixed * @throws DbException * @author zfy * @day 2020-03-30 */ public function delete($id) { $this->repository->merDelete($this->request->merId(), $id); return app('json')->success('删除成功'); } }