/**
  * 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();
     }
 }
 /**
  * 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();
     }
 }
Example #3
0
 public function checkoutCrowdFunding()
 {
     if ($this->c_type != 2) {
         return true;
     }
     // push msg to seller
     $booth = Booth::find($this->b_id);
     $product = CrowdFundingProduct::find($this->p_id);
     $product->confirmProduct($this->c_quantity);
     $funding = CrowdFunding::find($product->cf_id);
     $funding->c_amount += $this->c_amount;
     $funding->save();
     $msg = new MessageDispatcher($booth->u_id);
     $msg->fireCateToUser('您的众筹' . $funding->c_title . '已有人认购', 1, $funding->cf_id);
     return true;
 }
 public function fakeCrowdFundingPurches($id)
 {
     set_time_limit(0);
     $this->login();
     $bottom = Input::get('bottom', '');
     $top = Input::get('top', '');
     $p_id = Input::get('p_id', '');
     try {
         if (!$p_id || !$top || !$bottom) {
             throw new Exception("需要关键数据", 1);
         }
         $funding = CrowdFunding::find($id);
         $funding->load(['eventItem']);
         $product = CrowdFundingProduct::find($p_id);
         $quantity = 1;
         $users = User::where('u_mobile', '>=', $bottom)->where('u_mobile', '<=', $top)->get();
         foreach ($users as $key => $user) {
             $u_id = $user->u_id;
             // sku need to be calulated before cart generated
             $product->loadProduct($quantity);
             // add cart
             $cart = new Cart();
             $cart->p_id = $p_id;
             $cart->p_name = $product->p_title;
             $cart->u_id = $u_id;
             $cart->b_id = $product->b_id;
             $cart->created_at = Tools::getNow();
             $cart->c_quantity = $quantity;
             $cart->c_price = $product->p_price;
             $cart->c_amount = $product->p_price * $quantity;
             $cart->c_discount = 100;
             $cart->c_price_origin = $product->p_price;
             $cart->c_amount_origin = $product->p_price * $quantity;
             $cart->c_status = 2;
             $cart->c_type = 2;
             $re = $cart->save();
             if (!$re) {
                 throw new Exception("提交库存失败", 7006);
             }
             $shipping_address = 'Fake Purches';
             $shipping_name = $user->u_name;
             $shipping_phone = $user->u_mobile;
             $date_obj = new DateTime($funding->eventItem->e_start_at);
             $delivery_time_obj = $date_obj->modify('+' . ($funding->c_time + $funding->c_yield_time) . 'days');
             // add order
             $order_group_no = Order::generateOrderGroupNo($u_id);
             $rnd_str = rand(10, 99);
             $order_no = $order_group_no . $cart->b_id . $rnd_str;
             $order = new Order();
             $order->u_id = $u_id;
             $order->b_id = $cart->b_id;
             $order->o_amount_origin = $cart->c_amount_origin;
             $order->o_amount = $cart->c_amount;
             $order->o_shipping_fee = $funding->c_shipping_fee;
             $order->o_shipping_name = $shipping_name;
             $order->o_shipping_phone = $shipping_phone;
             $order->o_shipping_address = $shipping_address;
             $order->o_delivery_time = $delivery_time_obj->format('Y-m-d H:i:s');
             $order->o_shipping = $funding->c_shipping;
             $order->o_comment = 'Fake Order';
             $order->o_number = $order_no;
             $order->o_group_number = $order_group_no;
             $o_id = $order->addOrder();
             Cart::bindOrder([$order->o_id => [$cart->c_id]]);
             $cart->checkout();
             $order->o_status = 2;
             $order->o_shipping_status = 10;
             $order->paied_at = Tools::getNow();
             $order->save();
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     echo "done";
 }
Example #5
0
 public function listFavoriteCrowd()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id');
     $per_page = Input::get('per_page', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $list = CrowdFunding::select('crowd_fundings.*', 'favorites.created_at')->with(['user', 'city', 'school', 'eventItem', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }])->join('favoriables', function ($q) {
             $q->on('crowd_fundings.cf_id', '=', 'favoriables.favoriable_id')->where('favoriables.favoriable_type', '=', 'CrowdFunding');
         })->join('favorites', function ($q) {
             $q->on('favorites.id', '=', 'favoriables.favorite_id')->where('favorites.u_id', '=', $this->u_id);
         })->orderBy('favorites.created_at', 'DESC')->paginate($per_page);
         $data = [];
         foreach ($list as $key => $funding) {
             $tmp = $funding->showInList();
             $tmp['is_praised'] = 0;
             if (count($funding->praises) > 0) {
                 $tmp['is_praised'] = 1;
             }
             $data[] = $tmp;
         }
         $re = Tools::reTrue('获取用户列表成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取用户列表失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function listParticipates($id)
 {
     $per_page = Input::get('per_page');
     try {
         $funding = CrowdFunding::find($id);
         if (empty($funding) || $funding->c_status < 3) {
             throw new Exception("没有找到请求的众筹信息", 1);
         }
         $participates = $funding->getParticipates($per_page);
         $data = [];
         foreach ($participates as $key => $user) {
             $tmp = $user->showInList();
             $tmp['o_id'] = $user->o_id;
             $tmp['shipping_address'] = $user->o_shipping_address;
             $tmp['comment'] = $user->o_comment;
             $tmp['shipping_phone'] = $user->o_shipping_phone;
             $tmp['quantity'] = $user->c_quantity;
             $data[] = $tmp;
         }
         $re = Tools::reTrue('获取参与用户成功', $data, $participates);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取参与用户失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Example #7
0
 public function cloneCrowdFunding()
 {
     $this->load(['eventItem', 'product']);
     $event = new EventItem();
     $event->o_id = $this->eventItem->o_id;
     $event->e_title = $this->eventItem->e_title;
     $event->cover_img = $this->eventItem->cover_img;
     $event->e_brief = $this->eventItem->e_brief;
     $event->url = $this->eventItem->url;
     $event->e_range = $this->eventItem->e_range;
     $event->e_start_at = $this->eventItem->e_start_at;
     $event->e_end_at = $this->eventItem->e_end_at;
     $event->created_at = $this->eventItem->created_at;
     $event->e_status = $this->eventItem->e_status;
     $event->save();
     $funding = new CrowdFunding();
     $funding->u_id = $this->u_id;
     $funding->b_id = $this->b_id;
     $funding->c_status = $this->c_status;
     $funding->c_yield_desc = $this->c_yield_desc;
     $funding->c_content = $this->c_content;
     $funding->c_imgs = $this->c_imgs;
     $funding->c_yield_time = $this->c_yield_time;
     $funding->c_time = $this->c_time;
     $funding->c_shipping = $this->c_shipping;
     $funding->c_shipping_fee = $this->c_shipping_fee;
     $funding->c_target_amount = $this->c_target_amount;
     $funding->c_cate = $this->c_cate;
     $funding->created_at = $this->created_at;
     $funding->c_open_file = $this->c_open_file;
     $funding->c_praise_count = $this->c_praise_count;
     $funding->c_remark = $this->c_remark;
     $funding->c_amount = $this->c_amount;
     $funding->u_mobile = $this->u_mobile;
     $funding->c_local_only = $this->c_local_only;
     $funding->e_id = $event->e_id;
     $funding->save();
     $product = new CrowdFundingProduct();
     $product->cf_id = $funding->cf_id;
     $product->u_id = $this->product->u_id;
     $product->b_id = $this->product->b_id;
     $product->p_imgs = $this->product->p_imgs;
     $product->p_title = $this->product->p_title;
     $product->p_desc = $this->product->p_desc;
     $product->p_price = $this->product->p_price;
     $product->p_status = $this->product->p_status;
     $product->p_max_quantity = $this->product->p_max_quantity;
     $product->p_target_quantity = $this->product->p_target_quantity;
     $product->p_sort = $this->product->p_sort;
     $product->created_at = $this->product->created_at;
     $product->p_sold_quantity = $this->product->p_sold_quantity;
     $product->p_cart_quantity = $this->product->p_cart_quantity;
     $product->save();
     return $event;
 }
 public function delFunding($id)
 {
     $u_id = Tools::getOfficialUserId();
     DB::beginTransaction();
     try {
         $user = User::find($u_id);
         $crowd_funding = CrowdFunding::find($id);
         $crowd_funding->delCrowdFunding();
         $re = Tools::reTrue('删除众筹成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '删除众筹失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }