public function actionSearch() { $type = 'static'; if (XUtils::method() == 'POST') { // var_dump($_POST); if (isset($_POST['type'])) { $type = $_POST['type']; } if ($type == 'static') { $data = AsAsset::model()->findByPk($_POST['RFID']); } else { $data = AsConsume::model()->findByPk($_POST['assetID']); } $data = json_decode(CJSON::encode($data), TRUE); // is_array ( $data ) ? null : $data = array (); // 防止空数组 // $this->render ( 'search', array ( // 'data' => $data // ) ); } $this->render('search', array('data' => $data, 'type' => $type)); }
public function actionAdd($sign, $condition) { //向日志文件中写入删除信息 $time = date('Y-m-d', time()); $logName = $time . '.log'; $logHandle = fopen('log/' . $logName, 'a'); //根据当前日期获取文件名 $time = date('Y-m-d', time()); $fileName = 'log/' . $time . '.txt'; if ($sign == 'RFID') { //获取该RFID的整条信息 $data = file_get_contents($fileName); $data = json_decode($data, true); $flag = 0; //标示该RFID所在数组中的下标 for ($i = 0; $i < count($data); $i++) { if ($data[$i]['RFID'] == $condition) { $flag = $i; break; } } $value = $data[$flag]; //插入数据库 $asset = new AsAsset(); // 资产数据库表 $asset->RFID = $value['RFID']; // 提交页面的RFID的值 $asset->assetName = $value['assetName']; $asset->specification = $value['specification']; $asset->state = 'in'; //$asset->state = $value['state']; $asset->Price = $value['Price']; $asset->storageId = $value['storageId']; $asset->inTime = 1; //需要有 $asset->outPrm = $value['outPrm']; $asset->brwPhone = $value['brwPhone']; if ($asset->save() > 0) { // 数据库表类的函数save(),存储是否成功,来自yii框架 //更改文件中该RFID的信息标志 $data[$flag]['flag'] = '正常'; //重新写入文件 $handle = fopen($fileName, "w"); fwrite($handle, json_encode($data)); //转化为json字符串写入文件 //向日志中写入添加信息 fwrite($logHandle, '向数据库中添加:RFID为' . $condition . '的信息' . "\r\n"); //$this->actionIndex();//刷新存在问题 echo "<script language=\"JavaScript\">alert(\"添加成功\");parent.location.href='/cms_new/index.php?r=asset/assetCheck/index';</script>"; //$this->redirect('/cms_new/index.php?r=asset/assetCheck/index'); } else { echo "<script language=\"JavaScript\">alert(\"添加失败\");</script>"; } } else { //向assetId内添加信息 //获取该条assetId的整条信息 $data = file_get_contents($fileName); $data = json_decode($data, true); $flag = 0; //标示该RFID所在数组中的下标 for ($i = 0; $i < count($data); $i++) { if ($data[$i]['assetId'] == $condition) { $flag = $i; break; } } $value = $data[$flag]; //插入数据库 $consume = new AsConsume(); // 资产数据库表 $consume->assetId = $value['assetId']; // 提交页面的RFID的值 $consume->assetName = $value['assetName']; $consume->specification = $value['specification']; $consume->state = $value['state']; $consume->Price = $value['Price']; $consume->storageId = $value['storageId']; $consume->inTime = 1; $consume->outPrm = $value['outPrm']; $consume->brwPhone = $value['brwPhone']; if ($consume->save() > 0) { // 数据库表类的函数save(),存储是否成功,来自yii框架 //更改文件中该RFID的信息标志 $data[$flag]['flag'] = '正常'; //重新写入文件 $handle = fopen($fileName, "w"); fwrite($handle, json_encode($data)); //转化为json字符串写入文件 //向日志中写入添加信息 fwrite($logHandle, '向数据库中添加:assetId为' . $condition . '的信息' . "\r\n"); echo "<script language=\"JavaScript\">alert(\"添加成功\");parent.location.href='/cms_new/index.php?r=asset/assetCheck/index';</script>"; } else { echo "<script language=\"JavaScript\">alert(\"添加失败\");</script>"; } } }