MerchantAdmin.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\system\merchant;
  12. use crmeb\basic\BaseController;
  13. use app\common\repositories\system\merchant\MerchantAdminRepository;
  14. use app\validate\admin\AdminValidate;
  15. use FormBuilder\Exception\FormBuilderException;
  16. use think\App;
  17. use think\db\exception\DbException;
  18. /**
  19. * Class MerchantAdmin
  20. * @package app\controller\admin\system\merchant
  21. * @author xaboy
  22. * @day 2020-04-17
  23. */
  24. class MerchantAdmin extends BaseController
  25. {
  26. /**
  27. * @var MerchantAdminRepository
  28. */
  29. protected $repository;
  30. /**
  31. * MerchantAdmin constructor.
  32. * @param App $app
  33. * @param MerchantAdminRepository $repository
  34. */
  35. public function __construct(App $app, MerchantAdminRepository $repository)
  36. {
  37. parent::__construct($app);
  38. $this->repository = $repository;
  39. }
  40. /**
  41. * @param int $id
  42. * @return mixed
  43. * @throws FormBuilderException
  44. * @author xaboy
  45. * @day 2020-04-17
  46. */
  47. public function passwordForm($id)
  48. {
  49. return app('json')->success(formToData($this->repository->passwordForm($id, 1)));
  50. }
  51. /**
  52. * @param int $id
  53. * @param AdminValidate $validate
  54. * @return mixed
  55. * @throws DbException
  56. * @author xaboy
  57. * @day 2020-04-17
  58. */
  59. public function password($id, AdminValidate $validate)
  60. {
  61. $data = $this->request->params(['pwd', 'againPassword']);
  62. $validate->isPassword()->check($data);
  63. if ($data['pwd'] !== $data['againPassword'])
  64. return app('json')->fail('两次密码输入不一致');
  65. $adminId = $this->repository->merchantIdByTopAdminId($id);
  66. if (!$adminId)
  67. return app('json')->fail('商户不存在');
  68. $data['pwd'] = $this->repository->passwordEncode($data['pwd']);
  69. unset($data['againPassword']);
  70. $this->repository->update($adminId, $data);
  71. return app('json')->success('修改密码成功');
  72. }
  73. }