UserInfo.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace app\person\controller;
  3. use app\person\common\PersonController;
  4. use app\common\model\Person as PersonModel;
  5. use app\common\api\UserApi;
  6. use think\facade\Db;
  7. /**
  8. * Description of UserInfo
  9. *
  10. * @author sgq
  11. */
  12. class UserInfo extends PersonController {
  13. public function index() {
  14. return view();
  15. }
  16. public function changeBasic() {
  17. $uid = $this->user["uid"];
  18. $response_object = new \StdClass();
  19. $response_object->code = 500;
  20. $data = [
  21. //'name' => \StrUtil::getRequestDecodeParam($this->request, 'name'),
  22. //'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'idCard'),
  23. //'sex' => \StrUtil::getRequestDecodeParam($this->request, 'sex'),
  24. //'email' => \StrUtil::getRequestDecodeParam($this->request, 'email'),
  25. 'address' => \StrUtil::getRequestDecodeParam($this->request, 'address')
  26. ];
  27. try {
  28. validate(\app\common\validate\Person::class)->batch(true)->scene('basic')->check($data);
  29. $data["id"] = $uid;
  30. $data["updateUser"] = $uid;
  31. $data["updateTime"] = date("Y-m-d H:i:s");
  32. PersonModel::update($data);
  33. $user = new UserApi($this->user["account"], "", 3);
  34. $user->setSession();
  35. $response_object->code = 200;
  36. $response_object->msg = "修改完成!";
  37. return json($response_object);
  38. } catch (\Exception $ex) {
  39. $response_object->msg = $ex->getMessage();
  40. return json($response_object);
  41. }
  42. }
  43. public function changePwd() {
  44. $uid = $this->user["uid"];
  45. $response_object = new \StdClass();
  46. $response_object->code = 500;
  47. $params = [
  48. 'password' => \StrUtil::getRequestDecodeParam($this->request, 'password'),
  49. 'newPassword' => \StrUtil::getRequestDecodeParam($this->request, 'newPassword'),
  50. 'newRePassword' => \StrUtil::getRequestDecodeParam($this->request, 'newRePassword')
  51. ];
  52. //新密码 与 原始密码不能为空
  53. if (!$params["password"]) {
  54. $response_object->msg = "请填写原密码!";
  55. return json($response_object);
  56. }
  57. if (!$params["newPassword"]) {
  58. $response_object->msg = "请填写新密码!";
  59. return json($response_object);
  60. }
  61. if (!$params["newRePassword"]) {
  62. $response_object->msg = "请填写重复新密码!";
  63. return json($response_object);
  64. }
  65. if ($params["newPassword"] != $params["newRePassword"]) {
  66. $response_object->msg = "两次输入的新密码不一致!";
  67. return json($response_object);
  68. }
  69. if (!preg_match("/^(?=.*\\d)(?=.*[A-Za-z]).{8,}$/", $params["newPassword"])) {
  70. $response_object->msg = "密码必须包含字母、数字、特殊符号且长度超过8位!";
  71. return json($response_object);
  72. }
  73. $userInfo = PersonModel::where("id", $uid)->find();
  74. if ($userInfo["password"] != md5($params ["password"])) {
  75. $response_object->msg = "原密码错误!";
  76. return json($response_object);
  77. }
  78. try {
  79. $data["id"] = $uid;
  80. $data["password"] = md5($params["newPassword"]);
  81. $data["updateTime"] = date("Y-m-d H:i:s");
  82. PersonModel::update($data);
  83. $user = new UserApi($userInfo["username"], "", 3);
  84. $user->setSession();
  85. $response_object->code = 200;
  86. $response_object->msg = "修改成功!";
  87. return json($response_object);
  88. } catch (\Exception $e) {
  89. $response_object->msg = $ex->getMessage();
  90. return json($response_object);
  91. }
  92. }
  93. public function changePhone() {
  94. $uid = $this->user["uid"];
  95. $response_object = new \StdClass();
  96. $response_object->code = 500;
  97. $params = [
  98. 'phone' => \StrUtil::getRequestDecodeParam($this->request, 'phone'),
  99. 'verificationCode' => \StrUtil::getRequestDecodeParam($this->request, 'verificationCode'),
  100. 'newPhone' => \StrUtil::getRequestDecodeParam($this->request, 'newPhone')
  101. ];
  102. //当前号码、验证码、新号码不能为空
  103. if (!$params["phone"]) {
  104. $response_object->msg = "当前号码不能为空!";
  105. return json($response_object);
  106. }
  107. if (!$params["verificationCode"]) {
  108. $response_object->msg = "请填写验证码!";
  109. return json($response_object);
  110. }
  111. if (!$params["newPhone"]) {
  112. $response_object->msg = "请填写新号码!";
  113. return json($response_object);
  114. }
  115. //新号码格式必须正确
  116. if (!preg_match("/^1\\d{10}$/", $params["newPhone"])) {
  117. $response_object->msg = "新号码格式有误!";
  118. return json($response_object);
  119. }
  120. //验证码验证
  121. $codeVerify = \app\common\api\MessageRecordApi::checkVerificationCode($params["phone"], $params["verificationCode"]);
  122. if ($codeVerify->code != 200) {
  123. $response_object->msg = $codeVerify->msg;
  124. return json($response_object);
  125. }
  126. try {
  127. $userInfo = PersonModel::where("id", $uid)->find();
  128. $where = [];
  129. $where[] = ["card_number", "=", $userInfo["idCard"]];
  130. $where[] = ["checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  131. $talentInfo = \app\enterprise\model\Talent::where($where)->order("createTime desc")->find();
  132. $oldWhere = [];
  133. $oldWhere[] = ["idCard", "=", $userInfo['idCard']];
  134. $oldWhere[] = ["checkState", "=", \app\common\state\MainState::PASS];
  135. $oldWhere[] = ["isPublic", "=", 6];
  136. $oldWhere[] = ["isEffect", "=", 1];
  137. $oldTalentInfo = Db::table("un_talent_info")->where($oldWhere)->find();
  138. //查询该证件号码和手机号是否在库
  139. $phone = $talentInfo ? $talentInfo["phone"] : $oldTalentInfo["phone"];
  140. if (!$talentInfo && !$oldTalentInfo) {
  141. $response_object->msg = "人才库中不存在该证件号码,修改失败!";
  142. return json($response_object);
  143. }
  144. if ($phone != $params["newPhone"]) {
  145. $response_object->msg = "手机号码必须与人才库中一致,可联系企业经办人修改人才库手机号码后再行修改";
  146. return json($response_object);
  147. }
  148. $data["id"] = $uid;
  149. $data["phone"] = $params["newPhone"];
  150. $data["updateUser"] = $uid;
  151. $data["updateTime"] = date("Y-m-d H:i:s");
  152. PersonModel::update($data);
  153. $user = new UserApi($userInfo["username"], "", 3);
  154. $user->setSession();
  155. $response_object->code = 200;
  156. $response_object->msg = "修改成功!";
  157. return json($response_object);
  158. } catch (\Exception $e) {
  159. $response_object->msg = $e->getMessage();
  160. return json($response_object);
  161. }
  162. }
  163. public function gotoChangeHeadPortraitPage() {
  164. $uid = $this->user["uid"];
  165. $userInfo = PersonModel::where("id", $uid)->find();
  166. return view("person_change_head", ["headPortrait" => $userInfo["headPortrait"]]);
  167. }
  168. public function changeHeadPortrait() {
  169. $response = new \stdClass();
  170. $response->code = 500;
  171. $uid = $this->user["uid"];
  172. $userInfo = PersonModel::where("id", $uid)->find();
  173. if ($this->request->file()) {
  174. $headPortrait = $this->request->file("headPortrait");
  175. $upload = new \app\common\api\UploadApi();
  176. $result = $upload->uploadOne($headPortrait, "image", "person/photo");
  177. if ($result->code != 200) {
  178. $response->msg = $result->msg;
  179. return \StrUtil::back($response, "ech.callback");
  180. }
  181. if ($userInfo["headPortrait"]) {
  182. //如果新照片符合像素要求,则删除旧照片
  183. $old_head_url = "storage/" . $userInfo ["headPortrait"];
  184. //if (file_exists($old_head_url))
  185. //@unlink($old_head_url);
  186. }
  187. $data["id"] = $uid;
  188. $data["headPortrait"] = $result->filepath;
  189. $data["updateUser"] = $uid;
  190. $data["updateTime"] = date("Y-m-d H:i:s");
  191. PersonModel::update($data);
  192. $user = new UserApi($userInfo["username"], "", 3);
  193. $user->setSession();
  194. $response->code = 200;
  195. $response->msg = "修改成功!";
  196. $response->url = getStoragePath($result->filepath);
  197. return \StrUtil::back($response, "ech.callback");
  198. } else {
  199. $response->msg = "没有上传新头像";
  200. return \StrUtil::back($response, "ech.callback");
  201. }
  202. }
  203. }