/** * 获取产品型号 */ public function actionProduct() { if (isset($_POST['product'])) { $product = $_POST['product']; } if ($product != null) { $uid = Yii::$app->user->id; $sql = "SELECT id,brand,model,imeilen from tbl_products WHERE uid=" . $uid . " and brand like '" . $product . "%' or model like '" . $product . "%' or concat(brand,model) like '%" . $product . "' or concat(brand,model) like '" . $product . "%'"; $model = Products::findBySql($sql)->all(); $json = array(); if ($model) { $infoArray = array(); $lenArray = array(); $pidArray = array(); $json['return_code'] = 1; foreach ($model as $item) { $brand = $item->getAttribute('brand'); $model = $item->getAttribute('model'); if ($model == null) { $infoArray[] = $brand; } else { $infoArray[] = $brand . "-" . $model; } $lenArray[] = $item->getAttribute('imeilen'); $pidArray[] = $item->getAttribute('id'); } $json['infoArray'] = $infoArray; $json['lenArray'] = $lenArray; $json['pidArray'] = $pidArray; } else { $json['return_code'] = 0; } echo json_encode($json); } }