优化更新

main
fengxinyhyl 6 months ago
parent f64d4cd91f
commit 43cdb752e6
  1. 24
      app/controller/admin/user/User.php

@ -201,21 +201,21 @@ class User extends BaseController
*/ */
public function update($id, UserValidate $validate, UserLabelRepository $labelRepository, UserGroupRepository $groupRepository) public function update($id, UserValidate $validate, UserLabelRepository $labelRepository, UserGroupRepository $groupRepository)
{ {
$data = $this->request->params(['real_name', 'phone', 'birthday', 'card_id', 'addres', 'mark', 'group_id', ['label_id', []], ['is_promoter', 0], ['status', 0]]); $data = $this->request->params(['real_name', 'phone', 'birthday', 'card_id', 'addres', 'mark']);
$validate->check($data); $validate->check($data);
if (!$this->repository->exists($id)) if (!$this->repository->exists($id))
return app('json')->fail('数据不存在'); return app('json')->fail('数据不存在');
if ($data['group_id'] && !$groupRepository->exists($data['group_id'])) // if ($data['group_id'] && !$groupRepository->exists($data['group_id']))
return app('json')->fail('分组不存在'); // return app('json')->fail('分组不存在');
$label_id = (array)$data['label_id']; // $label_id = (array)$data['label_id'];
foreach ($label_id as $k => $value) { // foreach ($label_id as $k => $value) {
$label_id[$k] = (int)$value; // $label_id[$k] = (int)$value;
if (!$labelRepository->exists((int)$value)) // if (!$labelRepository->exists((int)$value))
return app('json')->fail('标签不存在'); // return app('json')->fail('标签不存在');
} // }
$data['label_id'] = implode(',', $label_id); // $data['label_id'] = implode(',', $label_id);
if ($data['is_promoter']) // if ($data['is_promoter'])
$data['promoter_time'] = date('Y-m-d H:i:s'); // $data['promoter_time'] = date('Y-m-d H:i:s');
if(!$data['birthday']) unset($data['birthday']); if(!$data['birthday']) unset($data['birthday']);
$this->repository->update($id, $data); $this->repository->update($id, $data);

Loading…
Cancel
Save