MerchantAdmin.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-04-17
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\system\merchant;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\system\merchant\MerchantAdminRepository;
  13. use app\validate\admin\AdminValidate;
  14. use FormBuilder\Exception\FormBuilderException;
  15. use think\App;
  16. use think\db\exception\DbException;
  17. /**
  18. * Class MerchantAdmin
  19. * @package app\controller\admin\system\merchant
  20. * @author xaboy
  21. * @day 2020-04-17
  22. */
  23. class MerchantAdmin extends BaseController
  24. {
  25. /**
  26. * @var MerchantAdminRepository
  27. */
  28. protected $repository;
  29. /**
  30. * MerchantAdmin constructor.
  31. * @param App $app
  32. * @param MerchantAdminRepository $repository
  33. */
  34. public function __construct(App $app, MerchantAdminRepository $repository)
  35. {
  36. parent::__construct($app);
  37. $this->repository = $repository;
  38. }
  39. /**
  40. * @param int $id
  41. * @return mixed
  42. * @throws FormBuilderException
  43. * @author xaboy
  44. * @day 2020-04-17
  45. */
  46. public function passwordForm($id)
  47. {
  48. return app('json')->success(formToData($this->repository->passwordForm($id, 1)));
  49. }
  50. /**
  51. * @param int $id
  52. * @param AdminValidate $validate
  53. * @return mixed
  54. * @throws DbException
  55. * @author xaboy
  56. * @day 2020-04-17
  57. */
  58. public function password($id, AdminValidate $validate)
  59. {
  60. $data = $this->request->params(['pwd', 'againPassword']);
  61. $validate->isPassword()->check($data);
  62. if ($data['pwd'] !== $data['againPassword'])
  63. return app('json')->fail('两次密码输入不一致');
  64. $adminId = $this->repository->merchantIdByTopAdminId($id);
  65. if (!$adminId)
  66. return app('json')->fail('商户不存在');
  67. $data['pwd'] = $this->repository->passwordEncode($data['pwd']);
  68. unset($data['againPassword']);
  69. $this->repository->update($adminId, $data);
  70. return app('json')->success('修改密码成功');
  71. }
  72. }