response->format = Response::FORMAT_JSON; $out = [ 'results' => [ 'id' => '', 'text' => '' ] ]; $defaultCondition = ['like', 'mobile', $q]; $condition = ['merchant_id' => Yii::$app->services->merchant->getNotNullId()]; if (Yii::$app->services->devPattern->isB2B2C()) { $condition = []; } $field == 'id' && $defaultCondition = ['like', 'id', $q]; $field == 'nickname' && $defaultCondition = ['like', 'nickname', $q]; if (!is_null($q)) { $data = Member::find() ->select('id, nickname as text') ->where($defaultCondition) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['type' => MemberTypeEnum::MEMBER]) ->andFilterWhere($condition) ->limit(10) ->asArray() ->all(); $out['results'] = array_values($data); array_unshift($out['results'], [ 'id' => 0, 'text' => '不选择' ]); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => Member::findOne($id)->mobile]; } return $out; } }