AccountController.php 12 KB

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