Esempio n. 1
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";
 }
 public function delCrowdFunding($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     DB::beginTransaction();
     try {
         $user = User::chkUserByToken($token, $u_id);
         $crowd_funding = CrowdFunding::find($id);
         if (empty($crowd_funding) || $crowd_funding->u_id != $u_id) {
             throw new Exception("无法获取到请求的众筹", 2001);
         }
         $crowd_funding->delCrowdFunding();
         $re = Tools::reTrue('删除众筹成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '删除众筹失败:' . $e->getMessage());
         DB::rollback();
     }
     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);
 }
 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);
 }