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();
     }
 }
 public function run($args)
 {
     date_default_timezone_set('Asia/Shanghai');
     //$date=date('Ymd');
     $date = '20150414';
     //echo $date;
     //echo date('Ymd',strtotime('-1 day'));
     $dir = DISK . 'npsite/tyrb/' . $date . '/';
     //echo $dir;
     if (is_dir($dir)) {
         //创建存放文件的文件夹
         $img_file = PC . '/epaper2/assets/article_img/' . $date;
         if (is_dir($img_file)) {
             echo 'exist ' . $date . ' epaper data';
         } else {
             if ($dh = opendir($dir)) {
                 // echo $img_file.'<bf>';
                 if (mkdir($img_file, 0777)) {
                     $filenames = scandir($dir);
                     $fl_array1 = preg_grep("/\\w*.xml/", $filenames);
                     $fl_array = preg_grep("/^((?!pages.xml).)*\$/", $fl_array1);
                     $xmlfile = array_values($fl_array);
                     //$xml=$xmlfile[0];
                     $pageCount = new Pagecount();
                     $pageCount->setAttributes(array('create_time' => $date, 'pageCount' => count($xmlfile)));
                     $pageCount->save(true);
                     foreach ($xmlfile as $xml) {
                         if (file_exists($dir . $xml)) {
                             $xml = simplexml_load_file($dir . $xml);
                             $PageNo = $xml->PageInfo[0]->attributes()[0];
                             $PageName = $xml->PageInfo[0]->attributes()[1];
                             $ppname = new Pname();
                             $ppname->setAttributes(array('create_time' => $date, 'pageNo' => $PageNo, 'pageName' => $PageName));
                             $ppname->save(true);
                             $ArticleList = $xml->children()[1];
                             foreach ($ArticleList->children() as $child) {
                                 //echo count($ArticleList->children());
                                 //$IntroTitle= $child->IntroTitle[0];
                                 $Title = $child->Title[0];
                                 //echo $Title;
                                 $Title = preg_replace('/(\\n)/', '', $Title);
                                 $SubTitle = $child->SubTitle[0];
                                 $SubTitle = preg_replace('/(\\n)/', '', $SubTitle);
                                 $Content = $child->Content[0];
                                 //$Content = preg_replace('/(\\n\s*){2,}/','',$Content);
                                 //$Content = preg_replace('/(\\n\s*){2,}/','',$Content);
                                 //$Content=nl2br($Content);
                                 $ImageList = $child->ImageList[0];
                                 $imageCount = count($ImageList->children());
                                 //$Image= $ImageList->Image[0]->attributes()[0];
                                 //echo $Title."<br>";
                                 $PointList = $child->PointList[0];
                                 $x1 = intval($PointList->Point[0]->attributes()[0]);
                                 $y1 = intval($PointList->Point[0]->attributes()[1]);
                                 $x2 = intval($PointList->Point[2]->attributes()[0]);
                                 $y2 = intval($PointList->Point[2]->attributes()[1]);
                                 //echo "x1=".$x1.",y1=".$y1."x2=".$x2.",y2=".$y2;
                                 $node = new stdClass();
                                 $node->title = $Title;
                                 $node->body['und'][0]['value'] = "<p>" . $Content . "</p>";
                                 $node->uid = 1;
                                 $node->type = '_xinwen';
                                 $node->language = 'zh-hans';
                                 $node->status = 1;
                                 //(1 or 0): published or not
                                 $node->promote = 0;
                                 //(1 or 0): promoted to front page
                                 $node->comment = 2;
                                 // 0 = comments disabled, 1 = read only, 2 = read/write
                                 $node->field_pageno['und'][0]['value'] = $PageNo;
                                 $node->field_pagename['und'][0]['value'] = $PageName;
                                 $SubTitle = str_replace(" ", "", $SubTitle);
                                 $node->field_subtitle['und'][0]['value'] = $SubTitle;
                                 $node->field_riq['und'][0]['value'] = $date;
                                 foreach ($ImageList->children() as $key => $image) {
                                     $imageUrl = $image->attributes()[0];
                                     $imageData = new Img();
                                     $imageData->setAttributes(array('url' => $imageUrl, 'article_id' => $article->id));
                                     $imageData->save(true);
                                     if (file_exists($dir . $imageUrl)) {
                                         $url = $dir . $imageUrl;
                                     } else {
                                         if (file_exists($dir . 'm_' . $imageUrl)) {
                                             $url = $dir . 'm_' . $imageUrl;
                                         }
                                     }
                                     Image::thumb($url, $img_file . '/s_' . $imageUrl, 137, 109);
                                     Image::thumb($url, $img_file . '/b_' . $imageUrl, 600, 400);
                                     //$htmlimg="<img  src=http://localhost/admin/assets/article_img/".$date.'/b_'.$imageUrl." style=\"width:100%\"/></a>";
                                     $htmlimg = "<p style=\"text-align: center;\"><img src=\"" . ImgRoot . $date . "/b_" . $imageUrl . " \" style=\"width: 100%;\"/></p>";
                                     //echo $htmlimg;
                                     $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value'];
                                     //if($key==1)
                                     $node->field_suoluetu['und'][0]['value'] = ImgRoot . $date . '/b_' . $imageUrl;
                                     //echo $imageUrl;
                                 }
                                 //存完图片
                                 $node = node_submit($node);
                                 // Prepare node for saving
                                 //print_r($node);
                                 node_save($node);
                                 $coor = new Coor();
                                 $coor->setAttributes(array('create_time' => $date, 'pageNo' => $PageNo, 'nid' => $node->nid, 'x1' => $x1, 'x2' => $x2, 'y1' => $y1, 'y2' => $y2));
                                 $coor->save(true);
                             }
                             //处理完一版的新闻
                         }
                     }
                     //foreach ($xmlfile as $xml)
                 }
             }
             //开始新建图片文件夹
         }
         //还未更新数据
     }
     //电子报数据存在
 }
Exemple #3
0
 /**
  * 修改店铺
  *
  * @return Response
  */
 public function postModify()
 {
     //获取表达提交数据
     $data = Input::all();
     $userID = Auth::id();
     $shopID = base64_decode(Input::get('shop_id'));
     $shopInfoType = Input::get('shop_info_type');
     switch ($shopInfoType) {
         case SHOP_BASIC_INFO:
             //建立验证规则
             $rules = array('shop_phone' => 'digits:11', 'shop_longitude' => 'required', 'shop_latitude' => 'required', 'shop_addr' => 'max:255', 'shop_keywords' => 'max:128', 'shop_brief' => 'max:255');
             //进行验证
             $validator = Validator::make($data, $rules);
             if ($validator->fails()) {
                 return Redirect::back()->withInput()->withErrors($validator);
             }
             $shopIconName = Input::get('shop_icon_name');
             $shopType = Input::get('shop_type');
             $shopPhone = Input::get('shop_phone');
             $shopProvinceID = Input::get('shop_province');
             $shopCityID = Input::get('shop_city');
             $shopDistrictID = Input::get('shop_district');
             $shopRegionID = Input::get('shop_district');
             $shopAddr = Input::get('shop_addr');
             $shopLng = Input::get('shop_longitude');
             $shopLat = Input::get('shop_latitude');
             $shopKeywords = Input::get('shop_keywords');
             $shopBrief = Input::get('shop_brief');
             $shop = Shop::where('wy_shopkeeper', $userID)->where('wy_shop_id', $shopID)->first();
             if (empty($shop)) {
                 $context = array("errorCode" => -15012, "userID" => $userID, "shopID" => $shopID);
                 Log::error(Lang::get('errormessages.-15012'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15012'));
             }
             $shop->wy_shop_icon = $shopIconName;
             $shop->wy_shop_type = $shopType;
             $shop->wy_phone = $shopPhone;
             $shop->wy_province_id = $shopProvinceID;
             $shop->wy_city_id = $shopCityID;
             $shop->wy_district_id = $shopDistrictID;
             $shop->wy_region_id = $shopRegionID;
             $shop->wy_addr = $shopAddr;
             $shop->wy_longitude = $shopLng;
             $shop->wy_latitude = $shopLat;
             $shop->wy_keywords = $shopKeywords;
             $shop->wy_brief = $shopBrief;
             $result = $shop->save();
             if ($result) {
                 $img = Img::where('wy_user_id', $userID)->where('wy_shop_id', $shop->getShopID())->first();
                 if (empty($img)) {
                     //增加图片管理表
                     $img = new Img();
                     $img->wy_user_id = $userID;
                     $img->wy_shop_id = $shop->getShopID();
                     $img->wy_img_name = $shopIconName;
                     $img->wy_img_type = IMG_TYPE_2;
                     $img->wy_create_at = Carbon::now();
                     $img->save();
                 } else {
                     $img->wy_img_name = $shopIconName;
                     $img->wy_update_at = Carbon::now();
                     $img->save();
                 }
                 return Redirect::back()->with('success', Lang::get('messages.10003'));
             } else {
                 $context = array("errorCode" => -15012, "userID" => $userID, "shopID" => $shopID, "data" => $data);
                 Log::error(Lang::get('errormessages.-15012'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15012'));
             }
             break;
         case SHOP_OPEN_RULE:
             //建立验证规则
             $rules = array('shop_delivery_time' => 'integer|digits_between:1,11|numeric|min:0', 'shop_distance' => 'digits_between:1,12|numeric|min:0');
             if ("true" != Input::get('shop_delivery_free')) {
                 $rules = array_merge($rules, array('shop_delivery_fee' => 'digits_between:1,16|numeric|min:0'));
             }
             if ("true" == Input::get('shop_has_min_amount')) {
                 $rules = array_merge($rules, array('shop_delivery_price' => 'digits_between:1,16|numeric|min:0'));
             }
             //进行验证
             $validator = Validator::make($data, $rules);
             if ($validator->fails()) {
                 return Redirect::back()->withInput()->withErrors($validator);
             }
             $shopOpenBegin = Input::get('shop_open_begin');
             $shopOpenEnd = Input::get('shop_open_end');
             $shopDeliveryBegin = Input::get('shop_delivery_begin');
             $shopDeliveryEnd = Input::get('shop_delivery_end');
             $shopDeliveryTime = Input::get('shop_delivery_time');
             $shopDistance = Input::get('shop_distance');
             $shopDistance = round($shopDistance, PRECISION_2);
             $shopDeliveryFee;
             if ("true" == Input::get('shop_delivery_free')) {
                 $shopDeliveryFee = DEFAULT_0;
             } else {
                 $shopDeliveryFee = Input::get('shop_delivery_fee');
                 $shopDeliveryFee = round($shopDeliveryFee, PRECISION_3);
             }
             $shopDeliveryPrice;
             if ("true" == Input::get('shop_has_min_amount')) {
                 $shopDeliveryPrice = Input::get('shop_delivery_price');
                 $shopDeliveryPrice = round($shopDeliveryPrice, PRECISION_3);
             } else {
                 $shopDeliveryPrice = DEFAULT_0;
             }
             $shop = Shop::where('wy_shopkeeper', $userID)->where('wy_shop_id', $shopID)->first();
             if (empty($shop)) {
                 $context = array("errorCode" => -15013, "userID" => $userID, "shopID" => $shopID);
                 Log::error(Lang::get('errormessages.-15013'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15013'));
             }
             $shop->wy_open_begin = $shopOpenBegin;
             $shop->wy_open_end = $shopOpenEnd;
             $shop->wy_delivery_begin = $shopDeliveryBegin;
             $shop->wy_delivery_end = $shopDeliveryEnd;
             $shop->wy_send_up_time = $shopDeliveryTime;
             $shop->wy_distance = $shopDistance;
             $shop->wy_express_fee = $shopDeliveryFee;
             $shop->wy_send_up_price = $shopDeliveryPrice;
             $result = $shop->save();
             if ($result) {
                 return Redirect::back()->with('success', Lang::get('messages.10004'));
             } else {
                 $context = array("errorCode" => -15013, "userID" => $userID, "shopID" => $shopID, "data" => $data);
                 Log::error(Lang::get('errormessages.-15013'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15013'));
             }
             break;
         case SHOP_OPEN_INFO:
             $shop = Shop::where('wy_shopkeeper', $userID)->where('wy_shop_id', $shopID)->first();
             if (empty($shop)) {
                 $context = array("errorCode" => -15014, "userID" => $userID, "shopID" => $shopID);
                 Log::error(Lang::get('errormessages.-15014'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15014'));
             }
             $result = $shop->save();
             if ($result) {
                 return Redirect::back()->with('success', Lang::get('messages.10005'));
             } else {
                 $context = array("errorCode" => -15014, "userID" => $userID, "shopID" => $shopID, "data" => $data);
                 Log::error(Lang::get('errormessages.-15014'), $context);
                 return Redirect::back()->withInput()->with('error', Lang::get('errormessages.-15014'));
             }
             break;
         default:
             return Redirect::back()->with('error', Lang::get('errormessages.-10042'));
             break;
     }
 }
Exemple #4
0
 /**
  * 修改商品信息
  *
  * @return Response
  */
 public function postModify()
 {
     // return Input::all();
     $shopID = base64_decode(Input::get('shop_id'));
     $headerShop = AuthController::checkShop($shopID, true);
     //提交表单数据
     $data = Input::all();
     //建立验证规则
     $rules = array('goods_price' => 'digits_between:1,16|numeric|min:0', 'goods_stock' => 'digits_between:1,16|numeric|min:0', 'goods_brief' => 'max:255');
     //进行验证
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator);
     }
     $goodsID = base64_decode(Input::get('goods_id'));
     $goodsIconName = Input::get('goods_icon_name');
     $goodsType = Input::get('goods_type');
     $goodsPrice = Input::get('goods_price');
     $goodsPrice = round($goodsPrice, PRECISION_3);
     $goodsStock = Input::get('goods_stock');
     $goodsStock = round($goodsStock, PRECISION_3);
     $goodsBrief = Input::get('goods_brief');
     $goods = Goods::where('wy_goods_id', $goodsID)->where('wy_shop_id', $shopID)->first();
     if (empty($goods)) {
         return Redirect::back()->with('error', Lang::get('errormessages.-10049'));
     }
     $goods->wy_goods_icon = $goodsIconName;
     $goods->wy_goods_type = $goodsType;
     $goods->wy_goods_sale_price = $goodsPrice;
     $goods->wy_stock = $goodsStock;
     $goods->wy_brief = $goodsBrief;
     $result = $goods->save();
     if ($result) {
         $img = Img::where('wy_user_id', Auth::id())->where('wy_shop_id', $shopID)->where('wy_goods_id', $goods->getGoodsID())->first();
         if (empty($img)) {
             //增加图片管理表
             $img = new Img();
             $img->wy_user_id = Auth::id();
             $img->wy_shop_id = $shopID;
             $img->wy_goods_id = $goods->getGoodsID();
             $img->wy_img_name = $goodsIconName;
             $img->wy_img_type = IMG_TYPE_3;
             $img->wy_create_at = Carbon::now();
             $img->save();
         } else {
             $img->wy_img_name = $goodsIconName;
             $img->wy_update_at = Carbon::now();
             $img->save();
         }
         return Redirect::back()->with('success', Lang::get('messages.10010'));
     } else {
         $context = array("errorCode" => -15017, "userID" => Auth::id(), "shopID" => $shopID, "goodsID" => $goodsID, "data" => $data);
         Log::error(Lang::get('errormessages.-15017'), $context);
         return Redirect::back()->with('error', Lang::get('errormessages.-15017'));
     }
 }
Exemple #5
0
 $node->status = 1;
 //(1 or 0): published or not
 $node->promote = 0;
 //(1 or 0): promoted to front page
 $node->comment = 2;
 // 0 = comments disabled, 1 = read only, 2 = read/write
 $node->field_pageno['und'][0]['value'] = $PageNo;
 $node->field_pagename['und'][0]['value'] = $PageName;
 $SubTitle = str_replace(" ", "", $SubTitle);
 $node->field_subtitle['und'][0]['value'] = $SubTitle;
 $node->field_riq['und'][0]['value'] = $date;
 foreach ($ImageList->children() as $key => $image) {
     $imageUrl = $image->attributes()[0];
     $imageData = new Img();
     $imageData->setAttributes(array('url' => $imageUrl, 'article_id' => $article->id));
     $imageData->save(true);
     if (file_exists($dir . $imageUrl)) {
         $url = $dir . $imageUrl;
     } else {
         if (file_exists($dir . 'm_' . $imageUrl)) {
             $url = $dir . 'm_' . $imageUrl;
         }
     }
     Image::thumb($url, $img_file . '/s_' . $imageUrl, 137, 109);
     Image::thumb($url, $img_file . '/b_' . $imageUrl, 600, 400);
     //$htmlimg="<img  src=http://localhost/admin/assets/article_img/".$date.'/b_'.$imageUrl." style=\"width:100%\"/></a>";
     $htmlimg = "<img src=\"" . ImgRoot . $date . "/b_" . $imageUrl . " \"/>";
     ////echo $htmlimg;
     $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value'];
     //if($key==1)
     $node->field_suoluetu['und'][0]['value'] = ImgRoot . $date . '/b_' . $imageUrl;