123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace app\controller\api\v1\system;
- use app\Request;
- use app\services\supplier\SystemSupplierServices;
- use app\services\system\SystemUserApplyServices;
- use app\validate\api\user\UserApplyValidate;
- use crmeb\services\CacheService;
- use think\exception\ValidateException;
- class UserApplyController
- {
- protected $services = NUll;
-
- public function __construct(SystemUserApplyServices $services)
- {
- $this->services = $services;
- }
-
- public function getInfo(Request $request, SystemSupplierServices $supplierServices, $id)
- {
- if (!$id) {
- return app('json')->fail('缺少参数');
- }
- $info = $this->services->get((int)$id);
- if (!$info || $info['uid'] != $request->uid()) {
- return app('json')->fail('数据不存在');
- }
- $info = $info->toArray();
- $data = ['url' => sys_config('site_url') . '/'. config('admin.supplier_prefix'), 'account' => '', 'pwd' => ''];
- if ($info['status'] == 1) {
- $data['account'] = $supplierServices->getAccount($info['phone']);
- $data['pwd'] = substr($info['phone'], -6);
- }
- $info = array_merge($info, $data);
- return app('json')->success($info);
- }
-
- public function userApply(Request $request, $id)
- {
- $data = $request->postMore([
- ['name', ''],
- ['phone', ''],
- ['system_name', ''],
- ['captcha', ''],
- ['images', []],
- ]);
-
- try {
- validate(UserApplyValidate::class)->check($data);
- } catch (ValidateException $e) {
- return app('json')->fail($e->getError());
- }
- $captcha = $data['captcha'];
- unset($data['captcha']);
-
- $verifyCode = CacheService::get('code_' . $data['phone']);
- if (!$verifyCode)
- return app('json')->fail('请先获取验证码');
- $verifyCode = substr($verifyCode, 0, 6);
- if ($verifyCode != $captcha) {
- return app('json')->fail('验证码错误');
- }
- $res = $this->services->saveApply((int)$id, (int)$request->uid(), $data);
- if ($res) {
- CacheService::delete('code_' . $data['phone']);
- return app('json')->successful('申请成功!', ['id' => $res]);
- }
- return app('json')->fail('申请失败!');
- }
-
- public function userApplyRecord(Request $request)
- {
- return app('json')->success($this->services->getUserApply((int)$request->uid()));
- }
- }
|