private function mainTreeRender(Tree &$tree, $selectedKey) { $li = new Li(); $mainDiv = new Div(); $mainDiv->addStyleClasses(["expand", "text_non_select", "tree_text_node", "input_hover"]); $table = new Table(); $tr = new Tr(); $nodeIcon = new Td(); $nodeText = new Td(); $nodeText->addStyleClass("tree_text"); $nodeSearchCount = new Td(); $nodeSearchCount->addStyleClass("tree_search_count"); if (count($tree->childrens) > 0) { $nodeIcon->addStyleClasses(["tree_btn"]); $icon = new Img(); $icon->addAttribute("style", "top: 2px; position: relative; margin: 0 5px;"); $icon->addAttribute("src", $this->treeLevel <= $this->DEFAULT_TREE_LEVEL_TO_SHOW || $tree->show ? "images/arrow90.png" : "images/arrow00.png"); $nodeIcon->addChild($icon); } else { $nodeIcon->addStyleClass("tree_empty"); } $link = new A(); $link->addAttribute("href", URLBuilder::getCatalogLinkForTree($tree->key)); $link->addChild($tree->value); $link->addStyleClass("input_hover"); $nodeSelected = new Div(); $nodeSelected->addStyleClass($tree->key == $selectedKey ? 'selected' : 'tree_empty'); $link->addChild($nodeSelected); $nodeText->addChild($link); return $li->addChild($mainDiv->addChild($table->addChild($tr->addChildList([$nodeIcon, $nodeText, $nodeSearchCount])))); }
public function putBoothDesc($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $desc = Input::get('desc', ''); $title = Input::get('title', ''); $img_token = Input::get('img_token', ''); try { $user = User::chkUserByToken($token, $u_id); $booth = Booth::find($id); if (empty($booth->b_id) || $booth->u_id != $u_id) { throw new Exception("无法获取到请求的店铺", 7001); } $booth->b_desc = $desc; $booth->b_title = $title; if ($img_token) { $imgObj = new Img('booth', $img_token); $booth->b_imgs = $imgObj->getSavedImg($booth->b_id, $booth->b_imgs); } $booth->save(); $re = ['result' => 2000, 'data' => [], 'info' => '更新店铺成功']; } catch (Exception $e) { $code = 7001; if ($e->getCode() > 2000) { $code = $e->getCode(); } $re = ['result' => $code, 'data' => [], 'info' => '更新店铺失败:' . $e->getMessage()]; } return Response::json($re); }
/** * @covers Xoops\Html\Img::render * @todo Implement testRender(). */ public function testRender() { $output = $this->object->render(); $this->assertStringStartsWith('<img ', $output); $this->assertStringEndsWith(' />', $output); $this->assertGreaterThanOrEqual(4, strpos($output, 'src="image.png" ')); $this->assertGreaterThanOrEqual(4, strpos($output, 'class="image" ')); }
public function run() { $faker = Faker::create(); for ($i = 1; $i <= 200; $i++) { $img = new Img(); $img->img = $faker->imageUrl($width = 640, $height = 480, $category = 'animals'); $img->description = $faker->sentence($nbWords = 4); $img->user_id = User::all()->random(1)->id; $img->save(); } }
/** * add new post * @author Kydz 2015-06-17 */ public function addPost($imgToken) { $this->created_at = date('Y-m-d H:i:s'); $this->p_status = 1; $this->baseValidate(); if (!$this->save()) { throw new Exception("添加帖子失败", 1); } if ($imgToken) { $img = new Img('post', $imgToken); $this->p_content = $img->getSavedImg($this->p_id, $this->p_content); $this->save(); } return true; }
public function saveCroppedImage(Request $request, $slider_title = "") { $file = $request->file('slider_img'); if ($file && isset($_FILES["slider_img"]["tmp_name"])) { try { $slider_img_x = $_POST['x']; $slider_img_y = $_POST['y']; $slider_img_w = $_POST['w']; $slider_img_h = $_POST['h']; $display_w = $_POST['display_w']; $file_path = $file->getPathname(); $orig_w = getimagesize($_FILES["slider_img"]["tmp_name"])[0]; $ratio = $orig_w / $display_w; $fileUploadDir = 'files/uploads/'; $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); if (File::exists($fileUploadDir . $fileName)) { $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); } $img = \Img::make($file_path)->crop((int) ($slider_img_w * $ratio), (int) ($slider_img_h * $ratio), (int) ($slider_img_x * $ratio), (int) ($slider_img_y * $ratio)); $img = $img->resize(300, 300); $tmpFile = $fileUploadDir . "tmp_slider_img" . time(); $img->save($tmpFile); //merge two images to one $this->merge('img/deze.png', $tmpFile, $fileUploadDir . $fileName, $slider_title, $request); //delete tmp file File::delete($tmpFile); return $fileName; } catch (Exception $e) { return false; } } return false; }
public function showDetail() { $data = []; $data['id'] = $this->a_id; $data['sub_title'] = $this->a_sub_title; $data['win_username'] = $this->a_win_username; $data['win_price'] = $this->a_win_price; $data['status'] = $this->a_status; $data['cost'] = $this->a_cost; $data['current_time'] = Tools::getNow(); if (empty($this->eventItem)) { $data['title'] = ''; $data['start_at'] = ''; $data['end_at'] = ''; $data['url'] = ''; $data['cover_img'] = []; $data['detail_content_img'] = []; $data['detail_header_img'] = []; } else { $data['title'] = $this->eventItem->e_title; $data['start_at'] = $this->eventItem->e_start_at; $data['end_at'] = $this->eventItem->e_end_at; $data['url'] = $this->eventItem->url; $data['cover_img'] = Img::filterKey('cover_img', Img::toArray($this->eventItem->cover_img)); $data['detail_content_img'] = Img::filterKey('detail_content_img', Img::toArray($this->eventItem->cover_img)); $data['detail_header_img'] = Img::filterKey('detail_header_img', Img::toArray($this->eventItem->cover_img)); } return $data; }
public function saveThumbnailImage(Request $request) { $file = $request->file('product_thumbnail_img'); if ($file && $_FILES["product_thumbnail_img"]["tmp_name"]) { try { $preview_img_x = $_POST['x_thumbnail']; $preview_img_y = $_POST['y_thumbnail']; $preview_img_w = $_POST['w_thumbnail']; $preview_img_h = $_POST['h_thumbnail']; $display_w = $_POST['display_w_thumbnail']; $file_path = $file->getPathname(); $orig_w = getimagesize($_FILES["product_thumbnail_img"]["tmp_name"])[0]; $ratio = $orig_w / $display_w; $fileUploadDir = 'files/uploads/'; $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); if (File::exists($fileUploadDir . $fileName)) { $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); } $img = \Img::make($file_path)->crop((int) ($preview_img_w * $ratio), (int) ($preview_img_h * $ratio), (int) ($preview_img_x * $ratio), (int) ($preview_img_y * $ratio)); $img->resize(300, 167); $img->save($fileUploadDir . $fileName); return $fileName; } catch (Exception $e) { return false; } } return false; }
public function showDetail() { $data = []; $data['title'] = $this->e_title; $data['cover_img'] = Img::toArray($this->cover_img); $data['url'] = $this->url; $data['range'] = $this->e_range; if (count($this->positions) > 0) { $positions = []; foreach ($this->positions as $position) { $positions[] = $position->showInList(); } $data['positions'] = $positions; } else { $data['positions'] = null; } if (count($this->ranges) > 0) { $ranges = []; foreach ($this->ranges as $range) { $ranges[] = $range->showInList(); } $data['ranges'] = $ranges; } $data['start_at'] = $this->e_start_at; $data['end_at'] = $this->e_end_at; return $data; }
public function showInList() { $data = []; $data['id'] = $this->ad_id; $data['status'] = $this->ad_status; $date = new DateTime($this->created_at); $data['created_at'] = $date->format('Y-m-d H:i:s'); $data['created_at_timestamps'] = strtotime($data['created_at']); if (empty($this->eventItem)) { $this->load('eventItem'); } if (empty($this->eventItem)) { $data['title'] = ''; $data['cover_img'] = null; $data['url'] = ''; $data['brief'] = ''; $data['active_at'] = ''; } else { $data['title'] = $this->eventItem->e_title; $data['cover_img'] = Img::filterKey('cover_img', Img::toArray($this->eventItem->cover_img)); $data['url'] = $this->eventItem->url; $data['brief'] = $this->eventItem->e_brief; $data['active_at'] = $this->eventItem->e_start_at; } return $data; }
public function showDetail() { $data = []; $this->load('school'); $data['school'] = empty($this->school) ? null : $this->school->showInList(); $data['student_img'] = Img::toArray($this->u_student_imgs, true); $data['student_number'] = $this->u_student_number; $data['student_verified'] = $this->u_is_student_verified; $data['identity_number'] = $this->u_id_number; $data['identity_img'] = Img::toArray($this->u_id_imgs, true); $data['identity_verified'] = $this->u_is_id_verified; $data['entry_year'] = $this->u_entry_year; $data['major'] = $this->u_major; $data['emergency_phone'] = $this->em_contact_phone; $data['emergency_name'] = $this->em_contact_name; $data['home_adress'] = $this->u_home_adress; $data['father_name'] = $this->u_father_name; $data['father_telephone'] = $this->u_father_phone; $data['mother_name'] = $this->u_mother_name; $data['mother_telephone'] = $this->u_mother_phone; $data['apartment'] = $this->u_apartment_no; $data['status'] = $this->u_status; if ($this->u_status == 2) { $data['remark'] = $this->remark; } return $data; }
/** * Creates and renders a new version of a specific image. * @param integer $id the image id. * @param string $version the name of the image version. * @throws CHttpException if the requested version is not defined. */ public function actionCreate($id, $version) { $versions = Yii::app()->image->versions; if (isset($versions[$version])) { $thumb = Yii::app()->image->createImageVersion($id, $version); $thumb->render(); } else { throw new CHttpException(404, Img::t('error', 'Failed to create image! Version is unknown.')); } }
public function confirmDraw($id) { $confirm = Input::get('confirm', 0); $comment = Input::get('comment', ''); $img_token = Input::get('img_token', ''); DB::beginTransaction(); try { $draw = UsersDraw::find($id); if (empty($draw)) { throw new Exception("请求的数据不存在", 10001); } $balance = UsersWalletBalances::find($draw->u_id); if (empty($balance)) { $balance = new UsersWalletBalances(); $balance->u_id = $draw->u_id; } if ($confirm == 1) { $balance->deFreez($draw->d_amount); $draw->d_status = 1; $balance->getOut($draw->d_amount); } elseif ($confirm == 0) { $draw->d_status = 2; } else { throw new Exception("只有确认提现/不确认提现", 10001); } $draw->confirm($comment); if ($img_token) { $imgObj = new Img('draw', $img_token); $imgs = $imgObj->getSavedImg($draw->d_id); $draw->imgs = $imgs; $draw->save(); } $re = Tools::reTrue('确认提现成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '确认提现失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
public function allocateRepayment($id) { $comment = Input::get('comment', ''); $img_token = Input::get('img_token', ''); DB::beginTransaction(); try { $repay = Repayment::find($id); if (empty($repay)) { throw new Exception("没有找到放款明细", 10001); } $repay->allocate($comment); if ($img_token) { $imgObj = new Img('loan', $img_token); $imgs = $imgObj->getSavedImg($repay->t_id); $repay->imgs = $imgs; $repay->save(); } $fund = Fund::find($repay->f_id); if (empty($fund)) { throw new Exception("没有找到相关的基金", 1); } $fund->load('loans'); if ($fund->chkLoansAlloc()) { $fund->t_status = 5; } $fund->t_status = 4; $fund->save(); $msg = new MessageDispatcher($fund->u_id); $msg->fireTextToUser('您申请的基金第' . $repay->f_schema . '次已放款, 金额:' . $repay->f_re_money); $re = Tools::reTrue('放款成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '放款失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
public function showDetail() { $data = []; $this->load('school'); $data['school'] = empty($this->school) ? null : $this->school->showInList(); $data['student_img'] = Img::toArray($this->u_student_imgs, true); $data['student_number'] = $this->u_student_number; $data['identity_number'] = $this->u_id_number; $data['identity_img'] = Img::toArray($this->u_id_imgs, true); $data['entry_year'] = $this->u_entry_year; $data['major'] = $this->u_major; $data['emergency_phone'] = $this->em_contact_phone; $data['status'] = $this->u_status; return $data; }
public function showDetail() { $data = []; $data['identity_number'] = $this->u_identity_number; $data['identity_imgs'] = Img::toArray($this->u_identity_img, true); $data['home_adress'] = $this->u_home_adress; $data['father_name'] = $this->u_father_name; $data['father_telephone'] = $this->u_father_telephone; $data['mother_name'] = $this->u_mother_name; $data['mother_telephone'] = $this->u_mother_telephone; $data['status'] = $this->u_status; if ($this->u_status == 2) { $data['remark'] = $this->remark; } return $data; }
public function beforeUpdate($id, $data) { //print_r($data); if (isset($data['pass']) && $data['pass'] != '') { unset($data['repass']); $data['pass'] = Hash::make($data['pass']); } else { unset($data['pass']); unset($data['repass']); } $data['fullname'] = $data['firstname'] . ' ' . $data['lastname']; $photo = Img::getPictures($data['id']); $avatar = Img::getAvatarUrl($data['id']); $data['photo'] = $photo; $data['avatar'] = $avatar; //die(); return $data; }
/** * Генерация шаблона из одного символа * @param resource $img * @param int $width * @param int $height * @return string */ public static function generateTemplateChar($img, $width = 15, $height = 16) { if (imagesx($img) != $width || imagesy($img) != $height) { $img = Img::resize($img, $width, $height); } $colorIndexes = Divider::getColorsIndexTextAndBackground($img); $colorTextIndexes = array_flip($colorIndexes['text']); $line = ''; for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { if (isset($colorTextIndexes[$colorIndexes['pix'][$x][$y]])) { $line .= '1'; } else { $line .= '0'; } } } return $line; }
public function showDetail() { $data = []; $data['title'] = $this->c_title; $data['brief'] = $this->c_brief; $data['official_url'] = $this->c_official_url; $data['imgs'] = Img::toArray($this->c_imgs); if (empty($data['imgs']['club_proof_img'])) { $data['imgs']['club_proof_img'] = null; } $data['status'] = $this->c_status; $data['remark'] = $this->remark; if (!empty($this->school)) { $data['school'] = $this->school->showInList(); } if (!empty($this->user)) { $data['user'] = $this->user->showInList(); } return $data; }
/** * Execute the job. * * @param Request $request * @return string */ public function handle(Request $request) { $file = $request->file('slider_img'); if ($file && isset($_FILES["slider_img"]["tmp_name"])) { try { $preview_img_x = $_POST['x_texture']; $preview_img_y = $_POST['y_texture']; $preview_img_w = $_POST['w_texture']; $preview_img_h = $_POST['h_texture']; $display_w = $_POST['display_w_texture']; $file_path = $file->getPathname(); $orig_w = getimagesize($_FILES["slider_img"]["tmp_name"])[0]; $ratio = $orig_w / $display_w; $fileUploadDir = 'files/uploads/'; $img = \Img::make($file_path)->crop((int) ($preview_img_w * $ratio), (int) ($preview_img_h * $ratio), (int) ($preview_img_x * $ratio), (int) ($preview_img_y * $ratio)); $img->resize(300, 143); $img->save($fileUploadDir . $this->fileName); } catch (Exception $e) { } } }
public function actionIndex() { $focusmap = Yii::app()->cache->get('aboutusfocusmap'); if($focusmap == false){ $focusmap = Img::model()->find(array( 'select'=>'path', 'condition'=>'typeid=5', 'order'=>'createtime desc', 'limit'=>'1', )); Yii::app()->cache->set('aboutusfocusmap',$focusmap,3600*24*30); } $aModel = new Article; //查询5条最新的莱斯新闻 $news = $aModel->findAll(array( 'select'=>'id,title', 'order'=>'sort desc,updatetime desc', 'limit'=>10, )); //根据ID 查询当前文章内容 $nid = isset($_GET['id'])?intval($_GET['id']):0; if($nid!=0){ $onenews = $aModel->find(array( 'select'=>'operator,title,content,updatetime', 'condition'=>"id=$nid", )); }else{ $this->render('404',array('msg'=>'你没有选择具体的新闻!')); exit; } $this->render('index',array( 'news'=>$news, 'focusmap'=>$focusmap, 'onenews'=>$onenews, )); }
public function showDetail() { $data = []; $this->load('school'); $data['school'] = $this->school->showInList(); $data['student_img'] = Img::toArray($this->u_student_img, true); $data['student_number'] = $this->u_student_number; $data['teacher_name'] = $this->u_teacher_name; $data['teacher_phone'] = $this->u_teacher_telephone; $data['frend_name1'] = $this->u_frend_name1; $data['frend_telephone1'] = $this->u_frend_telephone1; $data['frend_name2'] = $this->u_frend_name2; $data['frend_telephone2'] = $this->u_frend_telephone2; $data['profession'] = $this->u_prof; $data['degree'] = $this->u_degree; $data['entry_year'] = $this->u_entry_year; $data['status'] = $this->u_status; if ($this->u_status == 2) { $data['remark'] = $this->remark; } return $data; }
/** * Run the migrations. * * @return void */ public function up() { set_time_limit(0); Schema::table('crowd_fundings', function ($table) { $table->integer('e_id'); }); $list = CrowdFunding::get(); foreach ($list as $key => $funding) { // handle event $event = new EventItem(); $event->e_title = $funding->c_title; $imgs = Img::toArray($funding->c_imgs); if (empty($imgs['cover_img'])) { $cover = ''; } else { $cover = $imgs['cover_img']; unset($imgs['cover_img']); } $event->cover_img = $cover; $event->e_brief = $funding->c_brief; $event->e_range = 0; $event->e_start_at = $funding->active_at; $event->e_end_at = $funding->end_at; $event->created_at = $funding->created_at; $event->e_status = 1; $event->save(); // handle ranges $range = new EventRange(); $range->e_id = $event->e_id; $range->s_id = $funding->s_id; $range->c_id = $funding->c_id; $range->p_id = $funding->pv_id; $range->save(); // handle imgs $funding->c_imgs = implode(',', $imgs); $funding->e_id = $event->e_id; $funding->save(); } }
public function actionIndex() { //分配焦点图 $focusmap = Yii::app()->cache->get('aboutusfocusmap'); if($focusmap == false){ $focusmap = Img::model()->find(array( 'select'=>'path', 'condition'=>'typeid=4', 'order'=>'createtime desc', 'limit'=>'1', )); Yii::app()->cache->set('aboutusfocusmap',$focusmap,3600*24*30); } //分配文章 isset($_GET['id'])?$id = intval($_GET['id']):$id=1; $model = Yii::app()->cache->get('Articles'.$id); if($model == false){ $model = $this->loadModel($id); Yii::app()->cache->set('Articles'.$id,$model,3600*24*30); } //分配文章项 $items = Yii::app()->cache->get('Articleitems'); if($items == false){ $items = News::model()->findAll(array( 'select'=>'id,title', 'condition'=>'id <> 1', )); Yii::app()->cache->set('Articleitems',$items,3600*24*30); } $this->render('index',array( 'model'=>$model, 'items'=>$items, 'focusmap'=>$focusmap, )); }
public function saveCroppedImage(Request $request, $i) { $file = $request->file('product_preview_img_' . $i); if ($file && isset($_FILES["product_preview_img_" . $i]["tmp_name"])) { if ($_POST['w_' . $i] != "") { try { $preview_img_x = $_POST['x_' . $i]; $preview_img_y = $_POST['y_' . $i]; $preview_img_w = $_POST['w_' . $i]; $preview_img_h = $_POST['h_' . $i]; $display_w = $_POST['display_w_' . $i]; $file_path = $file->getPathname(); $orig_w = getimagesize($_FILES["product_preview_img_" . $i]["tmp_name"])[0]; $ratio = $orig_w / $display_w; $fileUploadDir = 'files/uploads/'; $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); $origFileName = $file->getFilename() . time() . "_orig." . $file->getClientOriginalExtension(); if (File::exists($fileUploadDir . $fileName)) { $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); } $img = \Img::make($file_path)->crop((int) ($preview_img_w * $ratio), (int) ($preview_img_h * $ratio), (int) ($preview_img_x * $ratio), (int) ($preview_img_y * $ratio)); $img->resize(300, 300); $img->save($fileUploadDir . $fileName); //save orig image $orig_img = \Img::make($file_path); $orig_img->save($fileUploadDir . $origFileName); return [$fileName, $origFileName]; } catch (Exception $e) { return false; } } else { return false; } } return false; }
public function loadProduct() { if (!$this->p_id || !$this->c_quantity) { throw new Exception("购买数量不能为0", 7001); } $product = Product::find($this->p_id); if (empty($product->p_id)) { throw new Exception("没有获取到产品", 7001); } // caculate quantity $product->load('quantity'); if (empty($product->quantity->q_id)) { throw new Exception("没有获取到产品库存信息", 7001); } $total = $product->quantity->q_total; $sold = $product->quantity->q_sold; $inCart = Cart::where('c_status', '=', 1)->where('p_id', '=', $this->p_id)->sum('c_quantity'); $remain = (int) $total - (int) $sold - (int) $inCart + $this->_quntityOri; if ($this->c_quantity > $remain) { throw new Exception("产品库存不足", 7006); } $product->quantity->q_cart = $inCart + $this->c_quantity - $this->_quntityOri; $product->quantity->save(); $this->c_price_origin = $product->p_price_origin; $this->c_discount = $product->p_discount; $this->c_price = $this->c_price_origin * $this->c_discount / 100; $this->c_amount_origin = $this->c_price_origin * $this->c_quantity; $this->c_amount = $this->c_amount_origin * $this->c_discount / 100; $this->p_name = $product->p_title; $imgs = Img::toArray($product->p_imgs); $this->p_img = array_pop($imgs); }
<div id="imgInstaller"> <h1><?php echo Img::t('install', 'Error'); ?> </h1> <p class="notice"><?php echo Img::t('install', 'An error occurred while installing the Image module.'); ?> </p> <p><?php echo Img::t('install', 'Please try again or consult the documentation.'); ?> </p> <p class="last"><?php echo CHtml::link(Img::t('install', 'Continue »'), Yii::app()->homeUrl); ?> </p> </div>
<?php /** * This is a view for home. * * @author Arsess Vakilpour * @version 1.0 * @package Peris24-Testprojekt */ $home = new Home(); $home->par = $this; $home->page_title = 'Preis24-Testprojekt'; $main_image = new Img(); $main_image->Src = ROOT_DIR . APPLICATION_DIR . IMAGES_DIR . 'smartphone-tariff.jpg'; $main_image->Id = 'main_image'; $home->content = '<br />' . $main_image->Display(); include_once 'view/javascripts/' . $this->get_values['Page'] . '.javascript.php'; $home->Display();
while ($f = readdir($d)) { if (preg_match('/\\.(jpe?g|gif|png)$/i', $f)) { if (!strstr($f, "-after.")) { $files[] = "{$dir}/{$f}"; } } } closedir($d); if ($nth !== null) { return $files[$nth]; } return $files; } $DIR = @$_GET['dir'] ? safedir($_GET['dir']) : 'images'; $IMG = @$_GET['img'] ? $_GET['img'] : list_images($DIR, 0); $old = new Img($IMG); ?> <h1>imgmin: lossless + intelligent lossy JPEG compression</h1> <div style="display:table"> <div class="r"> <?php $classify = array(array('Small', 200, array()), array('Medium', 400, array()), array('Large', INF, array())); # partition images $li = list_images($DIR); asort($li); foreach ($li as $img) { list($width, $height, $type, $attr) = getimagesize($img); for ($i = 0; $i < count($classify); $i++) {
public function putFlea($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $mobile = Input::get('mobile', ''); $prodName = Input::get('prod_name', ''); $prodDesc = Input::get('content', ''); $prodBrief = Input::get('prod_brief', ''); $price = Input::get('price', ''); $publish = Input::get('publish', 1); $product_cate = Input::get('cate', 7); $active_at = Input::get('active_at'); $open_file = Input::get('open_file', 0); if (empty($active_at)) { $active_at = Tools::getNow(); } $img_token = Input::get('img_token', ''); $prodDesc = urldecode($prodDesc); $modified_img = Input::get('modified_img', ''); $modified_img_index = Input::get('modified_img_index', ''); if ($modified_img) { $modified_img = explode(',', $modified_img); } try { $user = User::chkUserByToken($token, $u_id); $product = Product::find($id); if (empty($product) || $product->u_id != $u_id) { throw new Exception("没有找到请求的产品", 1); } $product->p_title = $prodName; $product->p_desc = $prodDesc; $product->sort = 1; $product->p_cate = $product_cate; $product->p_brief = $prodBrief; $product->p_status = $publish == 1 ? 1 : 2; $product->p_price_origin = $price; $product->p_price = $price; $product->active_at = $active_at; $product->p_mobile = $mobile; $product->open_file = $open_file; $old_imgs = Img::toArray($product->p_imgs); if (empty($old_imgs['cover_img'])) { $cover_img = ''; } else { $cover_img = $old_imgs['cover_img']; unset($old_imgs['cover_img']); } if (is_numeric($modified_img_index)) { $imgObj = new Img('product', $img_token); $new_paths = []; if (!empty($modified_img)) { foreach ($modified_img as $old_path) { $new_path = $imgObj->reindexImg($id, $modified_img_index, $old_path); $new_paths[] = $new_path; $modified_img_index++; } foreach ($old_imgs as $obj) { if (!in_array($obj, $new_paths)) { $imgObj->remove($id, $obj); } } $new_paths = Img::attachHost($new_paths); $product->p_imgs = implode(',', $new_paths); } } if ($cover_img) { if ($product->p_imgs) { $product->p_imgs .= ',' . $cover_img; } else { $product->p_imgs = $cover_img; } } if ($img_token) { $imgObj = new Img('product', $img_token); $imgs = $imgObj->getSavedImg($id, $product->p_imgs, true); if (!empty($modified_img)) { foreach ($modified_img as $del) { if (array_key_exists($del, $imgs)) { unset($imgs[$del]); } } } $product->p_imgs = implode(',', $imgs); } $product->save(); $re = Tools::reTrue('更新产品成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '更新产品失败:' . $e->getMessage()); } return Response::json($re); }