فهرست منبع

增加注册功能

sandm 2 سال پیش
والد
کامیت
7723edb451
4فایلهای تغییر یافته به همراه147 افزوده شده و 27 حذف شده
  1. 28 5
      app/common/api/UploadApi.php
  2. 77 22
      app/common/controller/Auth.php
  3. 16 0
      app/common/model/TalentChecklog.php
  4. 26 0
      app/common/validate/Upload.php

+ 28 - 5
app/common/api/UploadApi.php

@@ -2,6 +2,8 @@
 
 namespace app\common\api;
 
+use app\common\validate\Upload;
+
 /**
  * Description of UploadApi
  *
@@ -41,16 +43,37 @@ class UploadApi {
     /**
      * 单个文件上传
      * @param type $file
+     * @param type $type 图片 => image 文件 => file 其他 => hybrid
      * @return type
      */
-    public function uploadOne($file, $path = "uploadfiles") {
+    public function uploadOne($file, $type, $path = "uploadfiles") {
+        $upload_result = new \StdClass();
         try {
-            validate(['image' => ["sileSize" => $this->fileSize, "fileExt" => $this->fileExt, "fileMime" => $this->fileMime]])
-                    ->check([$file]);
+            switch ($type){
+                case 'image':
+                    $check = ['image' => $file];
+                    break;
+                case 'file':
+                    $check = ['file' => $file];
+                    break;
+                case 'hybrid':
+                    $check = ['file' => $file];
+                    break;
+                default:
+                    $upload_result->code = 500;
+                    $upload_result->msg = "不支持的上传类型";
+                    return $upload_result;
+            }
+
+            validate(Upload::class)->check($check);
             $savename = \think\facade\Filesystem::disk("public")->putFile($path, $file);
-            return $savename;
+            $upload_result->code = 200;
+            $upload_result->filepath = $savename;
+            return $upload_result;
         } catch (\think\exception\ValidateException $e) {
-            echo $e->getMessage();
+            $upload_result->code = 500;
+            $upload_result->msg = $e->getMessage();
+            return $upload_result;
         }
     }
 

+ 77 - 22
app/common/controller/Auth.php

@@ -5,10 +5,12 @@ namespace app\common\controller;
 use app\BaseController;
 use app\common\api\ChuanglanSmsApi;
 use app\common\model\MessageRecord;
+use app\common\model\TalentChecklog;
 use think\Facade\Cache;
 use app\common\validate\Enterprise;
 use think\exception\ValidateException;
 use think\facade\Request;
+use app\common\api\UploadApi;
 
 class Auth extends BaseController
 {
@@ -17,31 +19,84 @@ class Auth extends BaseController
         $msg = "";
         if($this->request->isPost()){
             $source = intval($this->request['source']);
+            $response_object = new \StdClass();
+            $data = [
+                'username' => \StrUtil::getRequestDecodeParam($this->request,'username'),
+                'password' => \StrUtil::getRequestDecodeParam($this->request,'password'),
+                're_password' => \StrUtil::getRequestDecodeParam($this->request,'re_password'),
+                'name' => \StrUtil::getRequestDecodeParam($this->request,'name'),
+                'idCard' => \StrUtil::getRequestDecodeParam($this->request,'idCard'),
+                'agentName' => \StrUtil::getRequestDecodeParam($this->request,'agentName'),
+                'agentPhone' => \StrUtil::getRequestDecodeParam($this->request,'agentPhone'),
+                'verificationCode' => \StrUtil::getRequestDecodeParam($this->request,'verificationCode'),
+                'legal' => \StrUtil::getRequestDecodeParam($this->request,'legal'),
+                'street' => \StrUtil::getRequestDecodeParam($this->request,'street'),
+                'address' => \StrUtil::getRequestDecodeParam($this->request,'address'),
+                'type' => intval($this->request['type']),
+                'talentType' => \StrUtil::getRequestDecodeParam($this->request,'talentType'),
+                'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'agentEmail'),
+                'ephone' => \StrUtil::getRequestDecodeParam($this->request,'ephone'),
+                'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew'),
+                'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld'),
+                'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'bankCard'),
+                'bank' => \StrUtil::getRequestDecodeParam($this->request,'bank'),
+                'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'bankNetwork')
+            ];
             try {
-                $result = validate(Enterprise::class)->batch(true)->scene('add')->check(Request::post());
+                $result = validate(Enterprise::class)->batch(true)->scene('add')->check($data);
+                //检验验证码
+                $codeResult = MessageRecord::where('smsType',1)->where('phone',$data['agentPhone'])->find();
+                if(!$codeResult){
+                    $response_object->code = 500;
+                    $response_object->msg = '请先发送验证码';
+                    return \StrUtil::back($response_object,"Register.epCallBack");
+                }
+
+                if(time() - strtotime($codeResult['createTime']) > 300){
+                    $response_object->code = 500;
+                    $response_object->msg = '验证码过期,请重新发送';
+                    return \StrUtil::back($response_object,"Register.epCallBack");
+                }
+                //检验附件
+                $uploadapi = new UploadApi();
+                $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'),'image');
+                if($upload_result->code == 500){
+                    return \StrUtil::back($upload_result,"Register.epCallBack");
+                }
+                $data['id'] = getStringId();
+                $data['password'] = simple_hash($data['password']);
+                $data['source'] = $source;
+                $data['imgurl'] = $upload_result->filepath;
+                $data['createTime'] = date("Y-m-d H:i:s",time());
+                $data['updateTime'] = date("Y-m-d H:i:s",time());
+                $data['active'] = 1;
+                $data['checkState'] = 1;
+                \app\common\model\Enterprise::create($data);
+
+                TalentChecklog::create([
+                    'id' => getStringId(),
+                    'mainId' => $data['id'],
+                    'type' => 10,
+                    'typeField' => null,
+                    'active' => 1,
+                    'state' => 1,
+                    'step' => 100,
+                    'stateChange' => '用户提交',
+                    'description' => '用户注册',
+                    'createTime' => date("Y-m-d H:i:s",time()),
+                    'createUser' => '用户'
+                ]);
+
+                $response_object->code = 200;
+                $response_object->msg = '注册成功';
+                return \StrUtil::back($response_object,"Register.epCallBack");
             } catch (ValidateException $e){
-                dd($e->getError());
+                $error = $e->getError();
+                $response_object->code = 500;
+                $response_object->msg = array_pop($error);
+                return \StrUtil::back($response_object,"Register.epCallBack");
             }
-            dd($result);
-            $username = \StrUtil::getRequestDecodeParam($this->request,'username');
-            $password = \StrUtil::getRequestDecodeParam($this->request,'password');
-            $name = \StrUtil::getRequestDecodeParam($this->request,'name');
-            $idCard = \StrUtil::getRequestDecodeParam($this->request,'idCard');
-            $agentName = \StrUtil::getRequestDecodeParam($this->request,'agentName');
-            $agentPhone = \StrUtil::getRequestDecodeParam($this->request,'agentPhone');
-            $verificationCode = \StrUtil::getRequestDecodeParam($this->request,'verificationCode');
-            $legal = \StrUtil::getRequestDecodeParam($this->request,'legal');
-            $street = \StrUtil::getRequestDecodeParam($this->request,'street');
-            $address = \StrUtil::getRequestDecodeParam($this->request,'address');
-            $type = intval($this->request['type']);
-            $talentType = \StrUtil::getRequestDecodeParam($this->request,'talentType');
-            $agentEmail = \StrUtil::getRequestDecodeParam($this->request,'agentEmail');
-            $ephone = \StrUtil::getRequestDecodeParam($this->request,'ephone');
-            $industryFieldNew = \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew');
-            $industryFieldOld = \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld');
-            $bankCard = \StrUtil::getRequestDecodeParam($this->request,'bankCard');
-            $bank = \StrUtil::getRequestDecodeParam($this->request,'bank');
-            $bankNetwork = \StrUtil::getRequestDecodeParam($this->request,'bankNetwork');
+
 
         }
         return view("", ["msg" => $msg]);

+ 16 - 0
app/common/model/TalentChecklog.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * Description of Batch
+ *
+ * @author sgq
+ */
+class TalentChecklog extends Model {
+
+    protected $table = "new_talent_checklog";
+
+}

+ 26 - 0
app/common/validate/Upload.php

@@ -0,0 +1,26 @@
+<?php
+namespace app\common\validate;
+
+use think\Validate;
+
+class Upload extends Validate
+{
+    protected $rule = [
+        'image' => ['fileExt' => 'jpg,png,gif,jpeg', 'fileSize' => 5 * 1024 * 1024, 'fileMime' => 'image/jpg,image/png,image/gif,image/jpeg'],
+        'file' => ['fileExt' => 'pdf,doc,docx,xlsx,xls,csv', 'fileSize' => 10 * 1024 * 1024,'fileMime' => 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
+        'hybrid' => ['fileExt' => 'zip,rar,7z', 'fileSize' => 50 * 1024 * 1024, 'fileMime' => 'application/zip,application/x-rar-compressed,application/x-7z-compressed']
+
+    ];
+
+    protected $message = [
+        'image.fileExt' => '图片的格式仅支持:png,jpg,jpeg,gif',
+        'image.fileSize' => '图片大小不能大于5兆',
+        'image.fileMime' => '图片的文件类型不正确',
+        'file.fileExt' => '文件的格式支持:pdf,doc,docx,xlsx,xls,csv',
+        'file.fileSize' => '文件大小不能大于10兆',
+        'file.fileMime' => '文件类型不支持',
+        'hybrid.fileExt'=> '文件的格式支持:zip,rar,7z',
+        'hybrid.fileSize' => '文件大小不能大于50兆',
+        'hybrid.fileMime' => '文件类型不支持'
+    ];
+}