<hr> </p> <?php echo Html::a('增加一行', '#', ['id' => 'add-tr']); ?> <?php $supplier = ""; $warehouse = ""; $isNewbill = false; //是否为新单据 if ($addnum == "") { $isNewbill = true; $num = date("Ymd", time()); $count = 0; $sql = "SELECT * FROM tbl_add WHERE uid=" . Yii::$app->user->id . " AND left(addnum,8)=" . $num . " order by id desc"; $add = Add::findBySql($sql)->one(); if ($add) { $addnum = $add->getAttribute('addnum'); $addnum += 1; } else { $addnum = $num . "01"; } } else { $add = Add::find()->where(['uid' => Yii::$app->user->id, 'addnum' => $addnum, 'status' => 0])->all(); foreach ($add as $item) { $supplier = $item->getAttribute('supplier'); $warehouse = $item->getAttribute('warehouse'); break; } } ?>
/** * AJAX匹配查询产品 */ public function actionSearchproduct() { if (isset($_POST['product'])) { $product = $_POST['product']; } if ($product != null) { $sql = "SELECT * FROM tbl_add WHERE uid=" . Yii::$app->user->id . " AND brand LIKE '%" . $product . "%' or model LIKE '%" . $product . "%'"; $add = Add::findBySql($sql)->all(); if ($add) { $json['return_code'] = 1; $count = 0; $barcodeArray = array(); $productArray = array(); $priceArray = array(); $colorArray = array(); $numArray = array(); $supplierArray = array(); $warehouseArray = array(); $pidArray = array(); foreach ($add as $item) { $brand = $item->getAttribute('brand'); $model = $item->getAttribute('model'); if ($model == "") { $myProduct = $brand; } else { $myProduct = $brand . "-" . $model; } $barcode = $item->getAttribute('barcode'); if (strlen($barcode) > 0) { $codeArray = explode(",", $barcode); for ($i = 0; $i < count($codeArray); $i++) { $barcodeModel = Barcode::find()->where(['uid' => Yii::$app->user->id, 'barcode' => $codeArray[$i], 'status' => 0])->one(); if ($barcodeModel) { $count++; $barcodeArray[] = $codeArray[$i]; $productArray[] = $myProduct; $priceArray[] = $item->getAttribute('price'); $colorArray[] = $item->getAttribute('color'); $numArray[] = $item->getAttribute('addnum'); $supplierArray[] = $item->getAttribute('supplier'); $warehouseArray[] = $item->getAttribute('warehouse'); $pidArray[] = $item->getAttribute('pid'); } } } else { if ($item->getAttribute('imeilen') == 0) { $count++; $barcodeArray[] = "无"; $productArray[] = $myProduct; $priceArray[] = $item->getAttribute('price'); $colorArray[] = $item->getAttribute('color'); $numArray[] = $item->getAttribute('addnum'); $supplierArray[] = $item->getAttribute('supplier'); $warehouseArray[] = $item->getAttribute('warehouse'); $pidArray[] = $item->getAttribute('pid'); } } } $json['barcodeArray'] = $barcodeArray; $json['productArray'] = $productArray; $json['priceArray'] = $priceArray; $json['colorArray'] = $colorArray; $json['numArray'] = $numArray; $json['supplierArray'] = $supplierArray; $json['warehouseArray'] = $warehouseArray; $json['pidArray'] = $pidArray; $json['count'] = $count; } else { $json['return_code'] = 0; } echo json_encode($json); } }
/** * AJAX监测条码输入格式是否正确 */ public function actionBarcode() { if (isset($_POST['brand'])) { $brand = $_POST['brand']; } if (isset($_POST['model'])) { $model = $_POST['model']; } if (isset($_POST['barcode'])) { $barcode = $_POST['barcode']; } if ($brand != null && $model != null) { if ($model == "无") { $products = Products::find()->where(['brand' => $brand])->one(); } else { $products = Products::find()->where(['brand' => $brand, 'model' => $model])->one(); } if (count($products)) { $len = $products->getAttribute('imeilen'); $json = ['return_code' => 1, 'imeilen' => $len]; if ($barcode != null && $barcode != "无") { $strs = explode("\n", $barcode); $index = 0; foreach ($strs as $item) { $strlen = strlen($item); if ($strlen > 0 && $strlen == $len) { $index++; $sql = "SELECT * FROM tbl_add WHERE barcode LIKE '%" . $item . "%'"; $add = Add::findBySql($sql)->one(); if ($add) { $json['index'] = $index; break; } } } } } else { $json = ['return_code' => 2]; } } else { $json = ['return_code' => 0]; } echo json_encode($json); }