Esempio n. 1
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;
     }
 }
Esempio n. 2
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'));
     }
 }