/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('booths', function ($table) {
         $table->integer('pv_id');
         // 省id
     });
     Schema::table('crowd_fundings', function ($table) {
         $table->integer('pv_id');
         // 省id
     });
     Schema::table('promotion_infos', function ($table) {
         $table->integer('pv_id');
     });
     $list = Booth::with(['school'])->get();
     foreach ($list as $key => $booth) {
         $pv_id = $booth->school->t_province;
         $booth->pv_id = $pv_id;
         $booth->save();
     }
     $list = CrowdFunding::with(['school'])->get();
     foreach ($list as $key => $funding) {
         $pv_id = $funding->school->t_province;
         $funding->pv_id = $pv_id;
         $funding->save();
     }
     $list = PromotionInfo::with(['school'])->get();
     foreach ($list as $key => $promo) {
         $pv_id = $promo->school->t_province;
         $promo->pv_id = $pv_id;
         $promo->save();
     }
 }
 public function pushPromo($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $promo = PromotionInfo::find($id);
         $now_obj = new DateTime();
         $last_update_obj = new DateTime($promo->updated_at);
         $diff = $now_obj->diff($last_update_obj);
         if ($diff->days == 0 && $promo->p_push_count < 3) {
             $promo->p_push_count++;
             $promo->updated_at = $now_obj->format('Y-m-d H:i:s');
         } else {
             throw new Exception("每天只能推送3次", 7001);
         }
         $re = Tools::reTrue('商品置顶成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '商品置顶失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Beispiel #3
0
 public function putProduct($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $prodName = Input::get('prod_name', '');
     $prodBrief = Input::get('prod_brief', '');
     $prodDesc = Input::get('prod_desc', '');
     $prodCost = Input::get('prod_cost', 0);
     $prodPriceOri = Input::get('prod_price', 0);
     $prodDiscount = Input::get('prod_discount', 0);
     $prodStock = Input::get('prod_stock', 0);
     $publish = Input::get('publish', 1);
     $promoDesc = Input::get('promo', '');
     $promoRange = Input::get('promo_range', 0);
     $product_cate = Input::get('cate', 7);
     $imgToken = Input::get('img_token', '');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $product = Product::find($id);
         if (!isset($product->p_id) || $product->u_id != $u_id) {
             throw new Exception("没有找到请求的产品", 1);
         }
         if ($prodDiscount > 0) {
             $prodPrice = $prodPriceOri * $prodDiscount / 100;
         } else {
             $prodPrice = $prodPriceOri;
         }
         $product->p_title = $prodName;
         $product->p_cost = $prodCost;
         $product->p_price_origin = $prodPriceOri;
         $product->p_price = $prodPrice;
         $product->p_discount = $prodDiscount;
         $product->p_desc = $prodDesc;
         $product->sort = 1;
         $product->p_cate = $product_cate;
         $product->p_brief = $prodBrief;
         $product->p_status = $publish == 1 ? 1 : 2;
         $product->saveProduct($prodStock);
         if ($promoDesc) {
             $user->load('school');
             $promo = PromotionInfo::find($id);
             if (!isset($promo->p_id)) {
                 $promo = new PromotionInfo();
                 $promo->p_id = $id;
                 $promo->p_content = $promoDesc;
                 $promo->c_id = $user->school->t_city;
                 $promo->s_id = $user->school->t_id;
                 $promo->pv_id = $user->school->t_province;
                 $promo->b_id = $product->b_id;
                 $promo->p_range = $promoRange;
                 $promo->addPromo();
             }
             $promo->p_status = 1;
             $promo->save();
         }
         if ($imgToken) {
             $imgObj = new Img('product', $imgToken);
             $imgs = $imgObj->getSavedImg($id, $product->p_imgs, true);
             $product->p_imgs = implode(',', $imgs);
             $product->save();
         }
         $re = Tools::reTrue('更新产品成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '更新产品失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function postPromoPraise($id)
 {
     $token = Input::get('token');
     $u_id = Input::get('u_id');
     $type = Input::get('type');
     $promo = PromotionInfo::find($id);
     try {
         if (empty($promo)) {
             throw new Exception("请求的促销信息不存在", 7001);
         }
         $user = User::chkUserByToken($token, $u_id);
         $result = 2000;
         if ($type == 1) {
             $promo->p_praise_count += 1;
             $praise = new PromotionPraise();
             $praise->prom_id = $id;
             $praise->u_id = $user->u_id;
             $praise->u_name = $user->u_nickname;
             $praise->addPraise();
             $info = '点赞成功';
         } elseif ($type == 2) {
             if ($promo->p_praise_count > 0) {
                 $promo->p_praise_count -= 1;
             }
             $praise = PromotionPraise::where('prom_id', '=', $id)->where('u_id', '=', $user->u_id)->first();
             if (!empty($praise->t_id)) {
                 $praise->delete();
             }
             $info = '取消赞成功';
         } else {
             throw new Exception("请求的操作不存在", 7001);
         }
         $promo->save();
         $re = Tools::reTrue($info);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '点赞失败:' . $e->getMessage());
     }
     return Response::json($re);
 }