UserInfo.php 8.4 KB

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