DefaultController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\ValetOrder\api\modules\v1\controllers;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. use api\controllers\OnAuthController;
  7. /**
  8. * 默认控制器
  9. *
  10. * Class DefaultController
  11. * @package addons\ValetOrder\api\modules\v1\controllers
  12. */
  13. class DefaultController extends OnAuthController
  14. {
  15. public $modelClass = '';
  16. /**
  17. * 不用进行登录验证的方法
  18. *
  19. * 例如: ['index', 'update', 'create', 'view', 'delete']
  20. * 默认全部需要验证
  21. *
  22. * @var array
  23. */
  24. protected $authOptional = ['index'];
  25. /**
  26. * 首页
  27. *
  28. * @return string
  29. */
  30. public function actionIndex()
  31. {
  32. return 'Hello world';
  33. }
  34. /**
  35. * 搜索手机号
  36. *
  37. * @return void
  38. */
  39. public function actionSearchMobile()
  40. {
  41. $mobile = $this->request->get('mobile');
  42. $user_id = $this->request->get('user_id');
  43. $type = $this->request->get('type'); // 0搜id 1搜手机号
  44. if (!isset($type)) {
  45. $this->success();
  46. return;
  47. }
  48. if (!$type && (!$user_id || $user_id < 1)) {
  49. $this->success();
  50. return;
  51. }
  52. // 小于6位不能搜
  53. if ($type && (!$mobile || mb_strlen($mobile) < 6)) {
  54. $this->success();
  55. return;
  56. }
  57. $where = [
  58. ['status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id]
  59. ];
  60. if (!$type) {
  61. $where[] = ['=', 'id', $user_id];
  62. } else {
  63. $where[] = ['like', 'mobile', $mobile];
  64. }
  65. $userFind = User::find();
  66. User::paramPack(
  67. [
  68. 'where' => $where,
  69. 'select' => 'id, mobile, nickname'
  70. ],
  71. $userFind
  72. );
  73. $this->success(
  74. 'success',
  75. $userFind->asArray()->all()
  76. );
  77. }
  78. }