AccountController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <?php
  2. namespace backend\controllers;
  3. use backend\models\forms\CompleteMaterialForm;
  4. use backend\models\forms\IbOpenForm;
  5. use backend\models\forms\LoginForm;
  6. use backend\models\forms\OpenDemoForm;
  7. use backend\models\forms\OpenForm;
  8. use backend\models\forms\PwdForm;
  9. use backend\models\forms\RePwdForm;
  10. use backend\models\MailApi;
  11. use backend\models\MemberApi;
  12. use backend\models\SmsApi;
  13. use Yii;
  14. use yii\helpers\Html;
  15. use yii\web\Controller;
  16. use yii\web\UploadedFile;
  17. use backend\models\MemberIdentity;
  18. class AccountController extends Controller
  19. {
  20. public $enableCsrfValidation = false;
  21. /**
  22. * 真实账户申请界面
  23. * @return string
  24. */
  25. public function actionOpen()
  26. {
  27. $request = \Yii::$app->getRequest()->get();
  28. $login = isset($request['login']) ? trim($request['login']) : '';
  29. return $this->render('open', [
  30. 'login' => $login,
  31. ]);
  32. }
  33. /**
  34. * 真实账户提交
  35. * @return \yii\web\Response
  36. */
  37. public function actionOpensave()
  38. {
  39. $model = new OpenForm();
  40. if (Yii::$app->getRequest()->getIsPost()) {
  41. $data = Yii::$app->getRequest()->post();
  42. $data['card0'] = UploadedFile::getInstanceByName('card0');
  43. $data['card1'] = UploadedFile::getInstanceByName('card1');
  44. $model->setAttributes($data);
  45. if ($model->open()) {
  46. return $this->asJson([
  47. 'isSuccess' => true,
  48. 'msg' => '操作成功',
  49. ]);
  50. } else {
  51. return $this->asJson([
  52. 'isSuccess' => false,
  53. 'msg' => Html::errorSummary($model, ['header' => '']),
  54. ]);
  55. }
  56. }
  57. return $this->asJson([
  58. 'isSuccess' => false,
  59. 'msg' => 'invalid request',
  60. ]);
  61. }
  62. /**
  63. * 代理商(ib)开户页面
  64. */
  65. public function actionIbOpenIndex()
  66. {
  67. $this->layout = "pop.php";
  68. $request = \Yii::$app->getRequest()->get();
  69. $login = isset($request['login']) ? trim($request['login']) : '';
  70. $member = new MemberApi();
  71. $id = $member->getIdByLogin($login)['data'];
  72. $id = isset($id) ? intval($id) : '';
  73. return $this->render('ib-open-index', [
  74. 'login' => $login,
  75. 'id' => $id,
  76. ]);
  77. }
  78. /**
  79. * 代理商(ib)开户
  80. * @return \yii\web\Response
  81. */
  82. public function actionIbOpenSave()
  83. {
  84. $model = new IbOpenForm();
  85. if (Yii::$app->getRequest()->getIsPost()) {
  86. $data = Yii::$app->getRequest()->post();
  87. $data['card0'] = UploadedFile::getInstanceByName('card0');
  88. $data['card1'] = UploadedFile::getInstanceByName('card1');
  89. $model->bank_district = $data['bank_district'];
  90. $model->ref_id = $data['ref_id'];
  91. $model->setAttributes($data);
  92. if ($model->complete()) {
  93. return $this->asJson([
  94. 'isSuccess' => true,
  95. 'msg' => '操作成功',
  96. ]);
  97. } else {
  98. return $this->asJson([
  99. 'isSuccess' => false,
  100. 'msg' => Html::errorSummary($model, ['header' => '']),
  101. ]);
  102. }
  103. }
  104. return $this->asJson([
  105. 'isSuccess' => false,
  106. 'msg' => 'invalid request',
  107. ]);
  108. }
  109. /**
  110. * 模拟账户申请界面
  111. * @return string
  112. */
  113. public function actionOpendemo()
  114. {
  115. return $this->render('opendemo');
  116. }
  117. /**
  118. * 模拟账户提交
  119. * @return \yii\web\Response
  120. */
  121. public function actionOpendemosave()
  122. {
  123. $model = new OpenDemoForm();
  124. if (Yii::$app->getRequest()->getIsPost()) {
  125. $data = Yii::$app->getRequest()->post();
  126. $model->setAttributes($data);
  127. if ($model->openDemo()) {
  128. return $this->asJson([
  129. 'isSuccess' => true,
  130. 'msg' => '账户:' . $model->getLogin() . ', 密码:' . $model->getPassword(),
  131. ]);
  132. } else {
  133. return $this->asJson([
  134. 'isSuccess' => false,
  135. 'msg' => Html::errorSummary($model, ['header' => '']),
  136. ]);
  137. }
  138. }
  139. return $this->asJson([
  140. 'isSuccess' => false,
  141. 'msg' => 'invalid request',
  142. ]);
  143. }
  144. /**
  145. * 登录界面
  146. * @return string
  147. */
  148. public function actionLogin()
  149. {
  150. return $this->renderPartial('login');
  151. }
  152. /**
  153. * 登录验证函数
  154. * @return \yii\web\Response
  155. */
  156. public function actionLoginPost()
  157. {
  158. $model = new LoginForm();
  159. if (Yii::$app->getRequest()->getIsPost()) {
  160. $model->setAttributes(Yii::$app->getRequest()->post());
  161. $model->type = MemberIdentity::MEMBER_TYPE_USER;
  162. if ($model->login()) {
  163. return $this->asJson([
  164. 'isSuccess' => true,
  165. ]);
  166. }
  167. }
  168. return $this->asJson([
  169. 'isSuccess' => false,
  170. 'msg' => Html::errorSummary($model, ['header' => '']),
  171. ]);
  172. }
  173. /**
  174. * ibLogin页面
  175. * @return string
  176. */
  177. public function actionIblogin()
  178. {
  179. return $this->renderPartial('iblogin');
  180. }
  181. /**
  182. * ibLogin验证
  183. * @return \yii\web\Response
  184. */
  185. public function actionIbloginPost()
  186. {
  187. $model = new LoginForm();
  188. if (Yii::$app->getRequest()->getIsPost()) {
  189. $model->setAttributes(Yii::$app->getRequest()->post());
  190. $model->type = MemberIdentity::MEMBER_TYPE_IB;
  191. if ($model->login()) {
  192. return $this->asJson([
  193. 'isSuccess' => true,
  194. ]);
  195. }
  196. }
  197. return $this->asJson([
  198. 'isSuccess' => false,
  199. 'msg' => Html::errorSummary($model, ['header' => '']),
  200. ]);
  201. }
  202. /**
  203. * 不同忘记密码页面
  204. * @return string|\yii\web\Response
  205. */
  206. public function actionPwd()
  207. {
  208. $data = Yii::$app->getRequest()->get();
  209. $t = isset($data['type']) ? $data['type'] : '';
  210. if ($t == 1) {
  211. return $this->renderPartial('pwd-t-1');
  212. } elseif ($t == 2) {
  213. return $this->renderPartial('pwd-t-2');
  214. } else {
  215. return $this->asJson([
  216. 'isSuccess' => false,
  217. ]);
  218. }
  219. }
  220. /**
  221. * 发送邮件
  222. * @return \yii\web\Response
  223. */
  224. public function actionPwd1()
  225. {
  226. $pwdForm = new PwdForm();
  227. if (Yii::$app->getRequest()->getIsPost()) {
  228. $pwdForm->setAttributes(Yii::$app->getRequest()->post());
  229. if ($pwdForm->changePwd()) {
  230. return $this->asJson([
  231. 'isSuccess' => true,
  232. ]);
  233. }
  234. }
  235. return $this->asJson([
  236. 'isSuccess' => false,
  237. 'msg' => Html::errorSummary($pwdForm, ['header' => '']),
  238. ]);
  239. }
  240. /**
  241. * 修改密码页面
  242. * @return string
  243. */
  244. public function actionModifyPwd()
  245. {
  246. $request = Yii::$app->request;
  247. $username = $request->get('username');
  248. $type = $request->get('type');
  249. return $this->renderPartial('modify-pwd', [
  250. 'username' => $username,
  251. 'type' => $type,
  252. ]);
  253. }
  254. /**
  255. * 修改密码验证
  256. * @return \yii\web\Response
  257. */
  258. public function actionModifyPwd1()
  259. {
  260. $pwdForm = new RePwdForm();
  261. if (Yii::$app->getRequest()->getIsPost()) {
  262. $pwdForm->setAttributes(Yii::$app->getRequest()->post());
  263. if ($pwdForm->modifyPwd1()) {
  264. return $this->asJson([
  265. 'isSuccess' => true,
  266. ]);
  267. }
  268. }
  269. return $this->asJson([
  270. 'isSuccess' => false,
  271. 'msg' => Html::errorSummary($pwdForm, ['header' => '']),
  272. ]);
  273. }
  274. /**
  275. * 登出
  276. */
  277. public function actionLogout()
  278. {
  279. $redirectAction = 'login';
  280. $referrer = Yii::$app->request->referrer;
  281. if ($referrer) {
  282. $urlInfo = parse_url($referrer);
  283. if (!empty($urlInfo['path'])) {
  284. if (strpos($urlInfo['path'], '/ib') === 0) {
  285. Yii::$app->set('user', Yii::$app->get('userIb'));
  286. $redirectAction = 'iblogin';
  287. }
  288. }
  289. }
  290. Yii::$app->user->logout(false);
  291. $this->redirect([$redirectAction]);
  292. }
  293. /**
  294. * 检测邮箱是否已注册
  295. * @return \yii\web\Response
  296. */
  297. public function actionCheckemailexist()
  298. {
  299. $email = trim(Yii::$app->getRequest()->get('email'));
  300. if ($email == '') {
  301. return $this->asJson(false);
  302. }
  303. $api = new MemberApi();
  304. $result = $api->checkEmailExist($email);
  305. if ($result['code'] == 1) {
  306. return $this->asJson(true);
  307. } else {
  308. return $this->asJson(false);
  309. }
  310. }
  311. /**
  312. * 检测身份证是否已注册
  313. * @return \yii\web\Response
  314. */
  315. public function actionCheckidnoexist()
  316. {
  317. $idNo = trim(Yii::$app->getRequest()->get('id_card'));
  318. if ($idNo == '') {
  319. return $this->asJson(false);
  320. }
  321. $api = new MemberApi();
  322. $result = $api->checkIdNoExist($idNo);
  323. if ($result['code'] == 1) {
  324. return $this->asJson(true);
  325. } else {
  326. return $this->asJson(false);
  327. }
  328. }
  329. /**
  330. * 发送验证码
  331. * @return \yii\web\Response
  332. */
  333. public function actionSendsms()
  334. {
  335. $mobile = trim(Yii::$app->getRequest()->post('mobile'));
  336. if ($mobile == '') {
  337. return $this->asJson([
  338. 'isSuccess' => false,
  339. 'msg' => '请输入手机号码',
  340. ]);
  341. }
  342. $api = new SmsApi();
  343. $result = $api->sendCode($mobile);
  344. if ($result['code'] == 0) {
  345. return $this->asJson([
  346. 'isSuccess' => false,
  347. 'msg' => '太频繁,稍后',
  348. ]);
  349. }
  350. return $this->asJson([
  351. 'isSuccess' => true,
  352. 'msg' => '发送成功',
  353. ]);
  354. }
  355. /**
  356. * 发送验证码
  357. * @return \yii\web\Response
  358. */
  359. public function actionSendmail()
  360. {
  361. $email= trim(Yii::$app->getRequest()->post('email'));
  362. if ($email == '') {
  363. return $this->asJson([
  364. 'isSuccess' => false,
  365. 'msg' => '请输入电子邮箱',
  366. ]);
  367. }
  368. $api = new MemberApi();
  369. $result = $api->checkEmailExist($email);
  370. if ($result['code'] == 0) {
  371. return $this->asJson([
  372. 'isSuccess' => false,
  373. 'msg' => '邮箱已存在',
  374. ]);
  375. }
  376. $api = new MailApi();
  377. $result = $api->sendMailCode($email);
  378. if ($result['code'] == 0) {
  379. return $this->asJson([
  380. 'isSuccess' => false,
  381. 'msg' => '太频繁,稍后',
  382. ]);
  383. }
  384. return $this->asJson([
  385. 'isSuccess' => true,
  386. 'msg' => '发送成功',
  387. ]);
  388. }
  389. /**
  390. * 模拟账户申请 用户协议
  391. * @return string
  392. */
  393. public function actionAgreement()
  394. {
  395. return $this->render('agreement');
  396. }
  397. }