Auth.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\api\ChuanglanSmsApi;
  5. use app\common\api\EnterpriseApi;
  6. use app\common\model\MessageRecord;
  7. use app\common\model\TalentChecklog;
  8. use think\facade\Cache;
  9. use app\common\validate\Enterprise;
  10. use think\exception\ValidateException;
  11. use think\facade\Request;
  12. use app\common\api\UploadApi;
  13. class Auth extends BaseController
  14. {
  15. public function register(){
  16. $msg = "";
  17. if($this->request->isPost()){
  18. $source = intval($this->request['source']);
  19. $response_object = new \StdClass();
  20. $special = \StrUtil::getRequestDecodeParam($this->request,'special');
  21. $data = [
  22. 'username' => \StrUtil::getRequestDecodeParam($this->request,'username'),
  23. 'password' => \StrUtil::getRequestDecodeParam($this->request,'password'),
  24. 're_password' => \StrUtil::getRequestDecodeParam($this->request,'re_password'),
  25. 'name' => \StrUtil::getRequestDecodeParam($this->request,'name'),
  26. 'idCard' => \StrUtil::getRequestDecodeParam($this->request,'idCard'),
  27. 'agentName' => \StrUtil::getRequestDecodeParam($this->request,'agentName'),
  28. 'agentPhone' => \StrUtil::getRequestDecodeParam($this->request,'agentPhone'),
  29. 'verificationCode' => \StrUtil::getRequestDecodeParam($this->request,'verificationCode'),
  30. 'legal' => \StrUtil::getRequestDecodeParam($this->request,'legal'),
  31. 'street' => \StrUtil::getRequestDecodeParam($this->request,'street'),
  32. 'address' => \StrUtil::getRequestDecodeParam($this->request,'address'),
  33. 'type' => intval($this->request['type']),
  34. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseTag'),
  35. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseType'),
  36. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'agentEmail'),
  37. 'ephone' => \StrUtil::getRequestDecodeParam($this->request,'ephone'),
  38. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew'),
  39. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld'),
  40. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'bankCard'),
  41. 'bank' => \StrUtil::getRequestDecodeParam($this->request,'bank'),
  42. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'bankNetwork')
  43. ];
  44. try {
  45. if($special == 'qiye'){
  46. if($data['type'] == 1){
  47. validate(Enterprise::class)->batch(true)->scene('add')->check($data);
  48. }else{
  49. validate(Enterprise::class)->batch(true)->scene('jc_add')->check($data);
  50. }
  51. $data['special'] = 0;
  52. }else{
  53. $data['type'] = 1;
  54. validate(Enterprise::class)->batch(true)->scene('sy_add')->check($data);
  55. $data['special'] = 1;
  56. }
  57. //检验验证码
  58. $codeResult = MessageRecord::where('smsType',1)->where('phone',$data['agentPhone'])->order('createTime','desc')->find();
  59. if(!$codeResult){
  60. $response_object->code = 500;
  61. $response_object->msg = '请先发送验证码';
  62. return \StrUtil::back($response_object,"Register.epCallBack");
  63. }
  64. if(time() - strtotime($codeResult['createTime']) > 300){
  65. $response_object->code = 500;
  66. $response_object->msg = '验证码过期,请重新发送';
  67. return \StrUtil::back($response_object,"Register.epCallBack");
  68. }
  69. $uploadapi = new UploadApi();
  70. $files = $this->request->file();
  71. //检验附件 营业执照
  72. if(array_key_exists('imgurl',$files)){
  73. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'),'image');
  74. if($upload_result->code == 500){
  75. return \StrUtil::back($upload_result,"Register.epCallBack");
  76. }
  77. $imgurl = $upload_result->filepath;
  78. }else{
  79. $imgurl = '';
  80. }
  81. //检验附件 开户许可证
  82. if(array_key_exists('bankImg',$files)){
  83. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'),'image');
  84. if($upload_result->code == 500){
  85. return \StrUtil::back($upload_result1,"Register.epCallBack");
  86. }
  87. $bankImg = $upload_result1->filepath;
  88. }else{
  89. $bankImg = '';
  90. }
  91. //检验附件 行业领域佐证材料
  92. if(array_key_exists('domainImg',$files)){
  93. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'),'image');
  94. if($upload_result2->code == 500){
  95. return \StrUtil::back($upload_result2,"Register.epCallBack");
  96. }
  97. $domainImg = $upload_result2->filepath;
  98. }else{
  99. $domainImg = '';
  100. }
  101. //检验附件 人才联络员备案表
  102. if(array_key_exists('beian',$files)){
  103. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'),'system');
  104. if($upload_result->code == 500){
  105. return \StrUtil::back($upload_result3,"Register.epCallBack");
  106. }
  107. $beian = $upload_result3->filepath;
  108. }else{
  109. $beian = '';
  110. }
  111. $data['id'] = getStringId();
  112. $data['password'] = hash('md5',$data['password']);
  113. $data['source'] = $source;
  114. $data['imgurl'] = $imgurl;
  115. $data['bankImg'] = $bankImg;
  116. $data['domainImg'] = $domainImg;
  117. $data['beian'] = $beian;
  118. $data['createTime'] = date("Y-m-d H:i:s",time());
  119. $data['updateTime'] = date("Y-m-d H:i:s",time());
  120. $data['active'] = 1;
  121. $data['checkState'] = 1;
  122. \app\common\model\Enterprise::create($data);
  123. TalentChecklog::create([
  124. 'id' => getStringId(),
  125. 'mainId' => $data['id'],
  126. 'type' => 10,
  127. 'typeField' => null,
  128. 'active' => 1,
  129. 'state' => 1,
  130. 'step' => 100,
  131. 'stateChange' => '用户提交',
  132. 'description' => '用户注册',
  133. 'createTime' => date("Y-m-d H:i:s",time()),
  134. 'createUser' => '用户'
  135. ]);
  136. $response_object->code = 200;
  137. $response_object->msg = '注册成功';
  138. return \StrUtil::back($response_object,"Register.epCallBack");
  139. } catch (ValidateException $e){
  140. $error = $e->getError();
  141. $response_object->code = 500;
  142. $response_object->msg = array_pop($error);
  143. return \StrUtil::back($response_object,"Register.epCallBack");
  144. }
  145. }
  146. return view("", ["msg" => $msg]);
  147. }
  148. public function enterprise_edit()
  149. {
  150. $temp = session('temp');
  151. if(empty($temp)){
  152. return redirect("/");
  153. }
  154. $ep = EnterpriseApi::getOne(session('temp')['uid']);
  155. if($this->request->isPost()){
  156. $response_object = new \StdClass();
  157. $data = [
  158. 'name' => \StrUtil::getRequestDecodeParam($this->request,'name'),//单位名称
  159. 'idCard' => \StrUtil::getRequestDecodeParam($this->request,'idCard'),//统一社会信用代码
  160. 'agentName' => \StrUtil::getRequestDecodeParam($this->request,'agentName'),//人才联络员
  161. 'legal' => \StrUtil::getRequestDecodeParam($this->request,'legal'),//法人
  162. 'street' => \StrUtil::getRequestDecodeParam($this->request,'street'),//镇街
  163. 'address' => \StrUtil::getRequestDecodeParam($this->request,'address'),//地址
  164. 'type' => intval($this->request['type']),
  165. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseTag'),//单位标签
  166. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseType'),//单位类型
  167. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'agentEmail'),//邮箱
  168. 'ephone' => \StrUtil::getRequestDecodeParam($this->request,'ephone'),//单位电话
  169. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew'),//产业领域
  170. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld'),//行业领域
  171. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'bankCard'),//银行
  172. 'bank' => \StrUtil::getRequestDecodeParam($this->request,'bank'),//开户行
  173. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'bankNetwork')//网点
  174. ];
  175. try {
  176. $data['id'] = $ep->id;
  177. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('check_common')->check($data);
  178. $data['checkState'] = 1;
  179. $ep->update($data);
  180. $response_object->code = 200;
  181. $response_object->msg = '修改成功';
  182. return \StrUtil::back($response_object,"Register.epCallBack");
  183. }catch (ValidateException $e){
  184. $error = $e->getError();
  185. $response_object->code = 500;
  186. $response_object->msg = array_pop($error);
  187. return \StrUtil::back($response_object,"Register.epCallBack");
  188. }
  189. }
  190. $msg = session('temp')['msg'];
  191. return view("",['msg' => $msg, 'ep' => $ep]);
  192. }
  193. public function verificationCode()
  194. {
  195. $phone = $this->request["phone"];
  196. $type = $this->request["type"];
  197. //校验手机号码是否为空
  198. if(\StrUtil::isEmpOrNull($phone)) {
  199. return json(["msg" => "请填写手机号码!"],500);
  200. }
  201. if (\StrUtil::isEmpOrNull($type)) {
  202. return json(["msg" => "请填写手机号码!"],500);
  203. }
  204. //校验手机号码格式是否正确
  205. if(\StrUtil::isMoblePhone($phone)) {
  206. return json(["msg" => "请填写正确的手机号码!"],500);
  207. }
  208. $record = Cache::get("verify_{$type}_{$phone}");
  209. if($record){
  210. $time = time();
  211. if($time - $record <= 60){
  212. return json(["msg" => "一分钟内请勿频繁发送短信!"],500);
  213. }
  214. }
  215. $code = '';
  216. for ($i = 1;$i <= 6;$i++){
  217. $code .= rand(0,9);
  218. }
  219. $code = 999999;
  220. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  221. $smsapi = new ChuanglanSmsApi();
  222. //$result = $smsapi->sendSMS($phone,$template);
  223. //测试
  224. $result = [
  225. 'code' => 0,
  226. 'errorMsg' => ''
  227. ];
  228. //$result = json_decode($result,true);
  229. $id = getStringId();
  230. $record_data = [
  231. 'id' => $id,
  232. 'bizId' => $id,
  233. 'type' => 2,
  234. 'smsType' => 1,
  235. 'phone' => $phone,
  236. 'params' => $code,
  237. 'templateCode' => $template,
  238. 'state' => $result['code'] == 0 ? 2 : 3,
  239. 'sendingDate' => date("Y-m-d H:i:s",time()),
  240. 'createTime' => date("Y-m-d H:i:s",time()),
  241. 'msg' => $result['errorMsg']
  242. ];
  243. MessageRecord::create($record_data);
  244. if($result['code'] == 0){
  245. Cache::set("verify_{$type}_{$phone}",time());
  246. return json(["msg" => '验证码发送成功'],200);
  247. }else{
  248. return json(["msg" => '验证码发送失败'],500);
  249. }
  250. }
  251. }