public function delAction() { $p = $_REQUEST; $pId = empty($p['id']) ? die('ID不能为空') : floatval($p['id']); $tMO = new FoodModel(); $tRow = $tMO->field('large_img,thumb_img')->where('id = ' . $pId)->fRow(); $tSql = 'delete from ' . $tMO->table . ' where id=' . $pId; if (!$tMO->exec($tSql)) { Tool_Fnc::ajaxMsg('删除失败'); } if (!empty($tRow['large_img'])) { unlink(APPLICATION_PATH . '/public' . $tRow['large_img']); } if (!empty($tRow['thumb_img'])) { unlink(APPLICATION_PATH . '/public' . $tRow['thumb_img']); } $tFT = new FoodtagModel(); $tSql = "delete from " . $tFT->table . " where fid =" . $pId; $tFT->exec($tSql); Tool_Fnc::ajaxMsg('删除成功', 1); }
public function indexAction() { exit; #$db = new SQLite3('/home/zhangyueru/data/www/dakang_www/shell/foods.db'); #$res = $db->query('select * from foods'); #$data = $db->fetchArray($res); #print_r($data); # header('Content-type:text/html;charset=utf-8'); $tFMO = new FoodModel(); $tFUMO = new FoodunitsModel(); $tFTMO = new FoodtagModel(); $tSqlite = new Orm_Sqlite('/home/zhangyueru/data/www/dakang_www/shell/food.db'); $res = $tSqlite->query('select a.*,s.name ctitle from (select fd.thumb_image_url,fd.large_image_url,fd.ingredient,lights,cate_id,fd.name,fd.units from foods f, food_detail fd where f.id = fd.parent_id) a,categories s where a.cate_id = s.id'); $ii = 0; while ($tRow = $res->fetchArray()) { $tTime = time(); $ii++; $large_image_url = ''; $thumb_image_url = ''; if (!empty($tRow['thumb_image_url']) && $tRow['thumb_image_url'] != 'null') { $thumb_image_url = '/foodimg/small/' . $tTime . '_' . rand(1000, 99999) . '.jpg'; $this->saveimg($tRow['thumb_image_url'], $thumb_image_url); echo 'thumb'; } if (!empty($tRow['large_image_url']) && $tRow['large_image_url'] != 'null') { $large_image_url = '/foodimg/' . $tTime . '_' . rand(1000, 99999) . '.jpg'; $this->saveimg($tRow['large_image_url'], $large_image_url); echo 'large'; } $i = json_decode($tRow['ingredient'], true); $l = json_decode($tRow['lights'], true); $tTag = array(); foreach ($l as $tKey => $tVal) { if (empty($tVal)) { continue; } $tTag[$tKey] = $tVal; } $tTag = implode('|', $tTag); $i['calcium'] = empty($i['calcium']) ? 0 : $i['calcium']; $i['vitamin_a'] = empty($i['vitamin_a']) ? 0 : $i['vitamin_a']; $i['zinc'] = empty($i['zinc']) ? 0 : $i['zinc']; $i['magnesium'] = empty($i['magnesium']) ? 0 : $i['magnesium']; $i['vitamin_c'] = empty($i['vitamin_c']) ? 0 : $i['vitamin_c']; $i['fiber_dietary'] = empty($i['fiber_dietary']) ? 0 : $i['fiber_dietary']; $i['selenium'] = empty($i['selenium']) ? 0 : $i['selenium']; $i['copper'] = empty($i['copper']) ? 0 : $i['copper']; $i['carbohydrate'] = empty($i['carbohydrate']) ? 0 : $i['carbohydrate']; $i['phosphor'] = empty($i['phosphor']) ? 0 : $i['phosphor']; $i['fat'] = empty($i['fat']) ? 0 : $i['fat']; $i['niacin'] = empty($i['niacin']) ? 0 : $i['niacin']; $i['vitamin_e'] = empty($i['vitamin_e']) ? 0 : $i['vitamin_e']; $i['manganese'] = empty($i['manganese']) ? 0 : $i['manganese']; $i['cholesterol'] = empty($i['cholesterol']) ? 0 : $i['cholesterol']; $i['iron'] = empty($i['iron']) ? 0 : $i['iron']; $i['kalium'] = empty($i['kalium']) ? 0 : $i['kalium']; $i['natrium'] = empty($i['natrium']) ? 0 : $i['natrium']; $i['thiamine'] = empty($i['thiamine']) ? 0 : $i['thiamine']; $i['protein'] = empty($i['protein']) ? 0 : $i['protein']; $i['lactoflavin'] = empty($i['lactoflavin']) ? 0 : $i['lactoflavin']; $i['calory'] = empty($i['calory']) ? 0 : $i['calory']; $i['carotene'] = empty($i['carotene']) ? 0 : $i['carotene']; $tSql = 'insert into food values("%s","%s",%d,%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"%s","%s",%s,"%s","%s")'; $tSql = sprintf($tSql, '', $tRow['name'], $tTime, 0, $i['calcium'], $i['vitamin_a'], $i['zinc'], $i['magnesium'], $i['vitamin_c'], $i['fiber_dietary'], $i['selenium'], $i['copper'], $i['carbohydrate'], $i['phosphor'], $i['fat'], $i['niacin'], $i['vitamin_e'], $i['manganese'], $i['cholesterol'], $i['iron'], $i['kalium'], $i['natrium'], $i['thiamine'], $i['protein'], $i['lactoflavin'], $i['calory'], $i['carotene'], $tTag, $thumb_image_url, $tRow['cate_id'], $tRow['ctitle'], $large_image_url); $tFid = $tFMO->exec($tSql); foreach ($l as $tKey => $tVal) { if (empty($tVal)) { continue; } $tData = array('title' => $tKey, 'fid' => $tFid, 'flag' => $tVal); $tFTMO->insert($tData); } $tUnitsArr = json_decode($tRow['units'], true); foreach ($tUnitsArr as $tURow) { $tData = array('amount' => $tURow['amount'], 'unit' => $tURow['unit'], 'fid' => $tFid, 'calory' => $tURow['calory'], 'weight' => $tURow['weight']); $tFUMO->insert($tData); } echo $ii . "\r\n"; } die; }