UserCenterRegister.Class.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * 用户中心注册管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/01
  7. * Time: 14:00
  8. */
  9. namespace JinDouYun\Controller\UserCenter;
  10. use http\Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Cache\SmsVerification;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\UserCenter\MUserCenterRegister;
  16. use JinDouYun\Model\Enterprise\MEnterprise;
  17. class UserCenterRegister extends BaseController
  18. {
  19. private $objMUserCenterRegister;
  20. private $objMEnterprise;
  21. private $SmsVerification;
  22. public function __construct($isCheckAcl = false, $isMustLogin = false, $checkToken=false)
  23. {
  24. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  25. $this->objMUserCenterRegister = new MUserCenterRegister();
  26. $this->objMEnterprise = new MEnterprise();
  27. $this->SmsVerification = new SmsVerification();
  28. }
  29. /**
  30. * 获取参数
  31. * @param bool $verifyEnterprise
  32. * @return array
  33. */
  34. public function commonFieldFilter($verifyEnterprise = false)
  35. {
  36. //接收参数
  37. $params = $this->request->getRawJson();
  38. //映射参数
  39. $UserCenterData = [
  40. "mobile" => isset($params['mobile']) ? $params['mobile'] : '',
  41. "password" => isset($params['password']) ? $params['password'] : '',
  42. "repeatPassword" => isset($params['repeatPassword']) ? $params['repeatPassword'] : '',
  43. "smsCode" => isset($params['smsCode']) ? $params['smsCode'] : '',
  44. ];
  45. if($verifyEnterprise) {
  46. $UserCenterData["enterpriseId"] = isset($params['enterpriseId']) ? $params['enterpriseId'] : '';
  47. }
  48. //校验参数
  49. foreach ($UserCenterData as $key => $value) {
  50. if (empty($value) && $value !== 0) {
  51. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  52. }
  53. }
  54. //校验两次密码
  55. if($UserCenterData['password'] != $UserCenterData['repeatPassword']){
  56. parent::sendOutput('两次输入密码不一致', ErrorCode::$paramError);
  57. }
  58. unset($UserCenterData['repeatPassword']);
  59. //固定参数
  60. $UserCenterData['source'] = isset($params['source']) ? $params['source'] : StatusCode::$source['manage'];
  61. $UserCenterData['updateTime'] = time();
  62. //校验手机号格式
  63. $this->checkMobile($UserCenterData['mobile']);
  64. return $UserCenterData;
  65. }
  66. /**
  67. * 用户中心添加 / 后台用户注册
  68. * @throws \Exception
  69. */
  70. public function addUserCenter()
  71. {
  72. exit;
  73. $UserCenterData = $this->commonFieldFilter();
  74. //校验redis短信验证码
  75. // $this->VerifyMobileCode($UserCenterData['mobile'], $UserCenterData['smsCode']);
  76. unset($UserCenterData['smsCode']);
  77. //格式化密码
  78. $UserCenterData['password'] = password_hash($UserCenterData['password'], PASSWORD_DEFAULT );
  79. //来源标识
  80. $UserCenterData['source'] = StatusCode::$source['manage'];
  81. $UserCenterData['createTime'] = time();
  82. $UserCenterData['updateTime'] = time();
  83. $result = $this->objMUserCenterRegister->addUserCenter($UserCenterData);
  84. if ($result->isSuccess()) {
  85. parent::sendOutput($result->getData());
  86. } else {
  87. parent::sendOutput($result->getData(), $result->getErrorCode());
  88. }
  89. }
  90. /**
  91. * 修改手机号(账号)
  92. */
  93. public function updateUserMobile()
  94. {
  95. $params = $this->request->getRawJson();
  96. if(empty($params)){
  97. parent::sendOutput('参数为空', ErrorCode::$paramError);
  98. }
  99. $data['mobile'] = isset($params['mobile']) ? $params['mobile'] : '';
  100. $data['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : '';
  101. $data['password'] = isset($params['password']) ? $params['password'] : '';
  102. foreach($data as $key => $value){
  103. if(empty($value)){
  104. parent::sendOutput($key.'参数为空', ErrorCode::$paramError);
  105. }
  106. }
  107. $result = $this->objMUserCenterRegister->updateUserMobile($data);
  108. if ($result->isSuccess()) {
  109. parent::sendOutput($result->getData());
  110. } else {
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. }
  114. /**
  115. * 用户中心删除
  116. */
  117. public function deleteUserCenter()
  118. {
  119. $params['id'] = $this->request->param('request_id');
  120. if (empty($params)) {
  121. parent::sendOutput('参数为空', ErrorCode::$paramError);
  122. }
  123. $result = $this->objMUserCenterRegister->deleteUserCenter($params);
  124. if ($result->isSuccess()) {
  125. parent::sendOutput($result->getData());
  126. } else {
  127. parent::sendOutput($result->getData(), $result->getErrorCode());
  128. }
  129. }
  130. /**
  131. * 用户中心修改
  132. */
  133. public function updateUserCenter()
  134. {
  135. $params['id'] = $this->request->param('request_id');
  136. if (empty($params)) {
  137. parent::sendOutput('参数为空', ErrorCode::$paramError);
  138. }
  139. $UserCenterData = $this->commonFieldFilter();
  140. $result = $this->objMUserCenterRegister->updateUserCenter($UserCenterData, $params);
  141. if ($result->isSuccess()) {
  142. parent::sendOutput($result->getData());
  143. } else {
  144. parent::sendOutput($result->getData(), $result->getErrorCode());
  145. }
  146. }
  147. /**
  148. * 后台用户中心忘记密码
  149. * @throws \Exception
  150. */
  151. public function forgetPassword()
  152. {
  153. $UserCenterData = $this->commonFieldFilter();
  154. //检验手机号是否存在
  155. $mobileResult = $this->objMUserCenterRegister->mobileIsRegister($UserCenterData['mobile']);
  156. if(!$mobileResult){
  157. parent::sendOutput('手机号不存在', ErrorCode::$mobileishaved);
  158. }
  159. //校验redis短信验证码
  160. $this->VerifyMobileCode($UserCenterData['mobile'], $UserCenterData['smsCode']);
  161. //格式化密码
  162. $password = password_hash($UserCenterData['password'], PASSWORD_DEFAULT );
  163. $where['mobile'] = $UserCenterData['mobile'];
  164. $result = $this->objMUserCenterRegister->updateUserCenterPassword($password, $where);
  165. if ($result->isSuccess()) {
  166. parent::sendOutput($result->getData());
  167. } else {
  168. parent::sendOutput($result->getData(), $result->getErrorCode());
  169. }
  170. }
  171. /**
  172. * 用户中心列表
  173. */
  174. public function getAllUserCenter()
  175. {
  176. $params = $this->request->getRawJson();
  177. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  178. $selectParams['limit'] = $pageParams['limit'];
  179. $selectParams['offset'] = $pageParams['offset'];
  180. $result = $this->objMUserCenterRegister->getAllUserCenter($selectParams);
  181. if ($result->isSuccess()) {
  182. $returnData = $result->getData();
  183. $pageData = [
  184. 'pageIndex' => $params['page'],
  185. 'pageSize' => $params['pageSize'],
  186. 'pageTotal' => $returnData['total'],
  187. ];
  188. parent::sendOutput($returnData['data'], 0, $pageData);
  189. } else {
  190. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  191. }
  192. }
  193. /**
  194. * 用户中心详情
  195. */
  196. public function getUserCenterInfo()
  197. {
  198. $params['id'] = $this->request->param('request_id');
  199. if (empty($params['id'])) {
  200. parent::sendOutput('参数为空', ErrorCode::$paramError);
  201. }
  202. $result = $this->objMUserCenterRegister->getUserCenterInfo($params);
  203. if ($result->isSuccess()) {
  204. parent::sendOutput($result->getData());
  205. } else {
  206. parent::sendOutput($result->getData(), $result->getErrorCode());
  207. }
  208. }
  209. /**
  210. * 公用方法
  211. */
  212. /**
  213. * 验证短信验证码
  214. *
  215. * @param $mobile
  216. * @param $mobileCode
  217. * @return void
  218. * @throws \Exception
  219. */
  220. public function VerifyMobileCode($mobile, $mobileCode)
  221. {
  222. // $cacheMobileCode = $this->SmsVerification->getMobileCode($mobile);
  223. // if( $mobileCode != $cacheMobileCode ){
  224. // parent::sendOutput('验证码有误', ErrorCode::$mobileCodeFail);
  225. // }
  226. }
  227. /**
  228. * 验证手机号是否存在(注册)
  229. */
  230. public function mobileIsRegister()
  231. {
  232. $mobile = $this->request->param('request_id');
  233. if( !$mobile ){
  234. parent::sendOutput('手机号为空', ErrorCode::$paramError);
  235. }
  236. $this->checkMobile($mobile);
  237. $result = $this->objMUserCenterRegister->mobileIsRegister($mobile);
  238. if ($result) {
  239. parent::sendOutput(true); //已注册
  240. }
  241. parent::sendOutput( false);//未注册
  242. }
  243. }