$item["name"]]); if (!empty($findProductionModel)) { return -1; } $productionModel = Yii::createObject(ProductionModel::className()); $productionModel->production_no = self::getProductionNo(); $productionModel->name = $item["name"]; // 生产日期 $saveResult = $productionModel->save(); return $saveResult; } catch (Exception $e) { return false; } } /** * 更新生产日期 * @param $id * @param $item * @return null|static */ static function update($id, $item) { $productionModel = ProductionModel::findOne($id); if (empty($productionModel)) { return false; } if (isset($item['name']) && $productionModel->name != $item['name']) { $findProductionModel = ProductionModel::findOne(['name' => $item["name"]]); if (!empty($findProductionModel)) { return -1; } } if (isset($item['name']) && !empty($item['name'])) { $productionModel->name = $item['name']; } $resultSave = $productionModel->save(); return $resultSave; } /** * 删除生产日期 * @param $id * @param $item * @return null|static */ public static function delete($id) { $productionModel = ProductionModel::findOne($id); if (empty($productionModel)) { return false; } return ProductionModel::deleteAll(["id" => $id]); } /** * 获取十六进制生产日期编号 */ private static function getProductionNo() { $findProduction = ProductionModel::find()->orderBy("id desc")->asArray()->one(); if (empty($findProduction)) { return "0001"; } $dataNo = hexdec($findProduction['production_no']) + 1; $dataNo = (string) dechex($dataNo); if (strlen($dataNo) == 1) { $dataNo = "000" . $dataNo; } else if (strlen($dataNo) == 2) { $dataNo = "00" . $dataNo; } else if (strlen($dataNo) == 3) { $dataNo = "0" . $dataNo; } return $dataNo; } }