UserController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: NODELOG
  5. * DateTime: 2017/3/8 10:09
  6. * Description:
  7. */
  8. namespace api\modules\v1\controllers;
  9. use abei2017\wx\Application;
  10. use abei2017\wx\mini\qrcode\Qrcode;
  11. use api\common\behaviors\QueryParamAuth;
  12. use api\common\controllers\Controller;
  13. use api\common\models\User;
  14. use api\modules\v1\models\Category;
  15. use api\modules\v1\models\UserEditForm;
  16. use common\enums\CodeEnum;
  17. use common\models\Store;
  18. use common\models\Voice;
  19. use common\modules\attachment\models\Attachment;
  20. use Yii;
  21. use yii\base\Exception;
  22. use yii\helpers\ArrayHelper;
  23. use yii\web\NotFoundHttpException;
  24. use yii\web\ServerErrorHttpException;
  25. class UserController extends Controller
  26. {
  27. public function behaviors()
  28. {
  29. return ArrayHelper::merge(parent::behaviors(), [
  30. [
  31. 'class' => QueryParamAuth::className(),
  32. 'tokenParam' => 'token',
  33. ]
  34. ]);
  35. }
  36. /**
  37. * 刷新用户信息
  38. * @return array
  39. * @author nodelog
  40. */
  41. public function actionRefresh()
  42. {
  43. // request()->setQueryParams(['expand' => 'profile,qrcode,count,countMenu']);
  44. return ['data' => User::findOne(Yii::$app->user->id)];
  45. }
  46. /**
  47. * 设置产业链
  48. * @return string[]
  49. * @throws ServerErrorHttpException
  50. * @author nodelog
  51. */
  52. public function actionSetChain()
  53. {
  54. $model = Yii::$app->user->identity;
  55. if (!empty($model->chain)) {
  56. return ['errcode' => CodeEnum::CODE_ERROR, 'errmsg' => '您已设置产业分类,无需重复设置'];
  57. }
  58. $chain = request('chain');
  59. $model->chain = $chain;
  60. $model->save();
  61. if ($model->hasErrors()) {
  62. throw new ServerErrorHttpException(current($model->getErrors())[0]);
  63. }
  64. return ['errmsg' => '设置成功'];
  65. }
  66. }