UserApplyController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\api\v1\system;
  12. use app\Request;
  13. use app\services\supplier\SystemSupplierServices;
  14. use app\services\system\SystemUserApplyServices;
  15. use app\validate\api\user\UserApplyValidate;
  16. use crmeb\services\CacheService;
  17. use think\exception\ValidateException;
  18. /**
  19. * 用户申请类
  20. * Class UserApplyController
  21. * @package app\controller\api\v1\system
  22. */
  23. class UserApplyController
  24. {
  25. protected $services = NUll;
  26. /**
  27. * UserExtractController constructor.
  28. * @param SystemUserApplyServices $services
  29. */
  30. public function __construct(SystemUserApplyServices $services)
  31. {
  32. $this->services = $services;
  33. }
  34. /**
  35. * 获取单个申请详情
  36. * @param Request $request
  37. * @param SystemSupplierServices $supplierServices
  38. * @param $id
  39. * @return \think\Response
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function getInfo(Request $request, SystemSupplierServices $supplierServices, $id)
  45. {
  46. if (!$id) {
  47. return app('json')->fail('缺少参数');
  48. }
  49. $info = $this->services->get((int)$id);
  50. if (!$info || $info['uid'] != $request->uid()) {
  51. return app('json')->fail('数据不存在');
  52. }
  53. $info = $info->toArray();
  54. $data = ['url' => sys_config('site_url') . '/'. config('admin.supplier_prefix'), 'account' => '', 'pwd' => ''];
  55. if ($info['status'] == 1) {//审核通过
  56. $data['account'] = $supplierServices->getAccount($info['phone']);
  57. $data['pwd'] = substr($info['phone'], -6);
  58. }
  59. $info = array_merge($info, $data);
  60. return app('json')->success($info);
  61. }
  62. /**
  63. * 申请供应商
  64. * @param Request $request
  65. * @param $id
  66. * @return \think\Response
  67. */
  68. public function userApply(Request $request, $id)
  69. {
  70. $data = $request->postMore([
  71. ['name', ''],
  72. ['phone', ''],
  73. ['system_name', ''],
  74. ['captcha', ''],
  75. ['images', []],
  76. ]);
  77. //验证手机号
  78. try {
  79. validate(UserApplyValidate::class)->check($data);
  80. } catch (ValidateException $e) {
  81. return app('json')->fail($e->getError());
  82. }
  83. $captcha = $data['captcha'];
  84. unset($data['captcha']);
  85. //验证验证码
  86. $verifyCode = CacheService::get('code_' . $data['phone']);
  87. if (!$verifyCode)
  88. return app('json')->fail('请先获取验证码');
  89. $verifyCode = substr($verifyCode, 0, 6);
  90. if ($verifyCode != $captcha) {
  91. return app('json')->fail('验证码错误');
  92. }
  93. $res = $this->services->saveApply((int)$id, (int)$request->uid(), $data);
  94. if ($res) {
  95. CacheService::delete('code_' . $data['phone']);
  96. return app('json')->successful('申请成功!', ['id' => $res]);
  97. }
  98. return app('json')->fail('申请失败!');
  99. }
  100. /**
  101. * 获取申请记录
  102. * @param Request $request
  103. * @return \think\Response
  104. */
  105. public function userApplyRecord(Request $request)
  106. {
  107. return app('json')->success($this->services->getUserApply((int)$request->uid()));
  108. }
  109. }