SiteController.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. namespace frontend\controllers;
  3. use common\models\common\Attachment;
  4. use frontend\models\ResendVerificationEmailForm;
  5. use frontend\models\VerifyEmailForm;
  6. use services\common\AttachmentService;
  7. use Yii;
  8. use yii\base\InvalidArgumentException;
  9. use yii\db\Exception;
  10. use yii\web\BadRequestHttpException;
  11. use yii\web\Controller;
  12. use yii\filters\VerbFilter;
  13. use yii\filters\AccessControl;
  14. use common\models\LoginForm;
  15. use frontend\models\PasswordResetRequestForm;
  16. use frontend\models\ResetPasswordForm;
  17. use frontend\models\SignupForm;
  18. use frontend\models\ContactForm;
  19. use common\models\common\AttachmentStorageConfig;
  20. use common\helpers\ResultHelper;
  21. use ReflectionMethod;
  22. use common\enums\PayTypeEnum;
  23. use common\helpers\Url;
  24. /**
  25. * Site controller
  26. */
  27. class SiteController extends Controller
  28. {
  29. public $enableCsrfValidation = false;
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function behaviors()
  34. {
  35. return [
  36. 'access' => [
  37. 'class' => AccessControl::class,
  38. 'only' => ['logout', 'signup'],
  39. 'rules' => [
  40. [
  41. 'actions' => ['signup'],
  42. 'allow' => true,
  43. 'roles' => ['?'],
  44. ],
  45. [
  46. 'actions' => ['logout'],
  47. 'allow' => true,
  48. 'roles' => ['@'],
  49. ],
  50. ],
  51. ],
  52. 'verbs' => [
  53. 'class' => VerbFilter::class,
  54. 'actions' => [
  55. 'logout' => ['post'],
  56. ],
  57. ],
  58. ];
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function actions()
  64. {
  65. return [
  66. 'error' => [
  67. 'class' => 'yii\web\ErrorAction',
  68. ],
  69. 'captcha' => [
  70. 'class' => 'yii\captcha\CaptchaAction',
  71. 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  72. ],
  73. ];
  74. }
  75. /**
  76. * Displays homepage.
  77. *
  78. * @return mixed
  79. */
  80. public function actionIndex()
  81. {
  82. return $this->render('index');
  83. }
  84. /**
  85. * Logs in a user.
  86. *
  87. * @return mixed
  88. */
  89. public function actionLogin()
  90. {
  91. if (!Yii::$app->user->isGuest) {
  92. return $this->goHome();
  93. }
  94. $model = new LoginForm();
  95. if ($model->load(Yii::$app->request->post()) && $model->login()) {
  96. return $this->goBack();
  97. } else {
  98. $model->password = '';
  99. return $this->render('login', [
  100. 'model' => $model,
  101. ]);
  102. }
  103. }
  104. /**
  105. * Logs out the current user.
  106. *
  107. * @return mixed
  108. */
  109. public function actionLogout()
  110. {
  111. Yii::$app->user->logout();
  112. return $this->goHome();
  113. }
  114. /**
  115. * Displays contact page.
  116. *
  117. * @return mixed
  118. */
  119. public function actionContact()
  120. {
  121. $model = new ContactForm();
  122. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  123. if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
  124. Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
  125. } else {
  126. Yii::$app->session->setFlash('error', 'There was an error sending your message.');
  127. }
  128. return $this->refresh();
  129. } else {
  130. return $this->render('contact', [
  131. 'model' => $model,
  132. ]);
  133. }
  134. }
  135. /**
  136. * Displays about page.
  137. *
  138. * @return mixed
  139. */
  140. public function actionAbout()
  141. {
  142. return $this->render('about');
  143. }
  144. /**
  145. * Signs user up.
  146. *
  147. * @return mixed
  148. */
  149. public function actionSignup()
  150. {
  151. $model = new SignupForm();
  152. if ($model->load(Yii::$app->request->post()) && $model->signup()) {
  153. Yii::$app->session->setFlash('success', 'Thank you for registration. Please check your inbox for verification email.');
  154. return $this->goHome();
  155. }
  156. return $this->render('signup', [
  157. 'model' => $model,
  158. ]);
  159. }
  160. /**
  161. * Requests password reset.
  162. *
  163. * @return mixed
  164. */
  165. public function actionRequestPasswordReset()
  166. {
  167. $model = new PasswordResetRequestForm();
  168. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  169. if ($model->sendEmail()) {
  170. Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
  171. return $this->goHome();
  172. } else {
  173. Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for the provided email address.');
  174. }
  175. }
  176. return $this->render('requestPasswordResetToken', [
  177. 'model' => $model,
  178. ]);
  179. }
  180. /**
  181. * Resets password.
  182. *
  183. * @param string $token
  184. * @return mixed
  185. * @throws BadRequestHttpException
  186. */
  187. public function actionResetPassword($token)
  188. {
  189. try {
  190. $model = new ResetPasswordForm($token);
  191. } catch (InvalidArgumentException $e) {
  192. throw new BadRequestHttpException($e->getMessage());
  193. }
  194. if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
  195. Yii::$app->session->setFlash('success', 'New password saved.');
  196. return $this->goHome();
  197. }
  198. return $this->render('resetPassword', [
  199. 'model' => $model,
  200. ]);
  201. }
  202. /**
  203. * Verify email address
  204. *
  205. * @param string $token
  206. * @throws BadRequestHttpException
  207. * @return yii\web\Response
  208. */
  209. public function actionVerifyEmail($token)
  210. {
  211. try {
  212. $model = new VerifyEmailForm($token);
  213. } catch (InvalidArgumentException $e) {
  214. throw new BadRequestHttpException($e->getMessage());
  215. }
  216. if ($user = $model->verifyEmail()) {
  217. if (Yii::$app->user->login($user)) {
  218. Yii::$app->session->setFlash('success', 'Your email has been confirmed!');
  219. return $this->goHome();
  220. }
  221. }
  222. Yii::$app->session->setFlash('error', 'Sorry, we are unable to verify your account with provided token.');
  223. return $this->goHome();
  224. }
  225. /**
  226. * Resend verification email
  227. *
  228. * @return mixed
  229. */
  230. public function actionResendVerificationEmail()
  231. {
  232. $model = new ResendVerificationEmailForm();
  233. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  234. if ($model->sendEmail()) {
  235. Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
  236. return $this->goHome();
  237. }
  238. Yii::$app->session->setFlash('error', 'Sorry, we are unable to resend verification email for the provided email address.');
  239. }
  240. return $this->render('resendVerificationEmail', [
  241. 'model' => $model
  242. ]);
  243. }
  244. /**
  245. * 图片上传
  246. *
  247. * @return array
  248. * @throws \yii\web\NotFoundHttpException
  249. */
  250. public function actionImages()
  251. {
  252. try {
  253. // $config = [
  254. // 'storage_aliyun_accesskeyid' => 'LTAIMdIIcLvoF64t',
  255. // 'storage_aliyun_accesskeysecret' => 'obKaqmVGQj9BLrUSajkg3gmpTXJhWM',
  256. // 'storage_aliyun_bucket' => 'shuzixiangdao',
  257. // 'storage_aliyun_endpoint' => 'oss-cn-guangzhou.aliyuncs.com',
  258. // 'storage_aliyun_user_url' => 'shuzixiangdao.oss-cn-guangzhou.aliyuncs.com',
  259. // 'storage_aliyun_transport_protocols' => 'https'
  260. // ];
  261. // //$res = AttachmentStorageConfig::saveConfig(5,'oss',$config);
  262. //
  263. //
  264. // $attach_config = AttachmentStorageConfig::getConfig(5);
  265. //
  266. // print_r($attach_config);
  267. $res = Yii::$app->services->rabbitMq->connect();
  268. var_dump($res);
  269. exit;
  270. $post = Yii::$app->request->post();
  271. $type = $post['upload_type'];
  272. if(!isset(Attachment::$uploadTypeExplain[$type])){
  273. throw new Exception('上传类型有误');
  274. }
  275. // $config = [
  276. // 'drive' => 'local',
  277. // 'writeTable' => true,
  278. // 'thumb' => [
  279. // [
  280. // 'path' => 'thumb/',// 图片创建路径
  281. // 'width' => 200,
  282. // 'height' => 200
  283. // ]
  284. // ]
  285. // ];
  286. $config = AttachmentStorageConfig::getConfig(5);
  287. $upload = new \common\helpers\UploadHelper($config, $type);
  288. $upload->verifyFile();
  289. $upload->save();
  290. return ResultHelper::json(200, '上传成功', $upload->getBaseInfo());
  291. } catch (\Exception $e) {
  292. echo $e->getMessage();
  293. exit;
  294. }
  295. }
  296. public function actionConsume()
  297. {
  298. $url = Url::toFront( ['site/' . PayTypeEnum::action(PayTypeEnum::JOINPAY)],TRUE);
  299. echo $url;
  300. exit;
  301. $service = Yii::$app->services->pay;
  302. $orders[] = [
  303. 'order_no' => '123456789',
  304. 'amount' => 100.00,
  305. 'title' => 'test goods',
  306. 'notify_class' => '',
  307. 'order_type' => 'goods'
  308. ];
  309. $orders[] = [
  310. 'order_no' => '222555666',
  311. 'amount' => 100.111,
  312. 'title' => 'test goods2',
  313. 'notify_class' => '',
  314. 'order_type' => 'goods'
  315. ];
  316. $res = $service->createTrade(5,10,$orders);
  317. var_dump($res);
  318. }
  319. }