| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\ValetOrder\api\modules\v1\controllers;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\ValetOrder\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * 搜索手机号
- *
- * @return void
- */
- public function actionSearchMobile()
- {
- $mobile = $this->request->get('mobile');
- $user_id = $this->request->get('user_id');
- $type = $this->request->get('type'); // 0搜id 1搜手机号
- if (!isset($type)) {
- $this->success();
- return;
- }
- if (!$type && (!$user_id || $user_id < 1)) {
- $this->success();
- return;
- }
- // 小于6位不能搜
- if ($type && (!$mobile || mb_strlen($mobile) < 6)) {
- $this->success();
- return;
- }
- $where = [
- ['status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id]
- ];
- if (!$type) {
- $where[] = ['=', 'id', $user_id];
- } else {
- $where[] = ['like', 'mobile', $mobile];
- }
- $userFind = User::find();
- User::paramPack(
- [
- 'where' => $where,
- 'select' => 'id, mobile, nickname'
- ],
- $userFind
- );
- $this->success(
- 'success',
- $userFind->asArray()->all()
- );
- }
- }
|