UserFields.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\controller\admin\user;
  3. use app\common\repositories\user\UserFieldsRepository;
  4. use crmeb\basic\BaseController;
  5. use think\App;
  6. /**
  7. * Class UserFields
  8. * app\controller\admin\user
  9. * 用户扩展字段
  10. */
  11. class UserFields extends BaseController
  12. {
  13. /**
  14. * @var UserFieldsRepository
  15. */
  16. protected $repository;
  17. public function __construct(App $app, UserFieldsRepository $repository)
  18. {
  19. parent::__construct($app);
  20. $this->repository = $repository;
  21. }
  22. /**
  23. * 保存用户扩展字段表单
  24. * @param $uid
  25. * @return \think\response\Json
  26. * @author yyw
  27. */
  28. public function saveForm($uid)
  29. {
  30. return app('json')->success(formToData($this->repository->extendInfoForm((int)$uid)));
  31. }
  32. /**
  33. * 保存或修改
  34. * @return \think\response\Json
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. *
  39. * @date 2023/09/26
  40. * @author yyw
  41. */
  42. public function save($uid)
  43. {
  44. $data = $this->request->param();
  45. $save_data = [];
  46. // 组合数据
  47. foreach ($data as $key => $item) {
  48. $save_data[] = [
  49. 'field' => $key,
  50. 'value' => $item,
  51. ];
  52. }
  53. $this->repository->save((int)$uid, $save_data);
  54. return app('json')->success('操作成功');
  55. }
  56. }