public function postFavorite($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $type = Input::get('type', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $booth = Booth::find($id);
         if (empty($booth)) {
             throw new Exception("请求的店铺不存在", 2001);
         }
         $chk = $booth->favorites()->where('favorites.u_id', '=', $u_id)->first();
         if ($type == 1) {
             if (empty($chk)) {
                 $data = ['u_id' => $u_id, 'created_at' => Tools::getNow(), 'u_name' => $user->u_nickname];
                 $favorite = new Favorite($data);
                 $booth->favorites()->save($favorite);
             }
         } else {
             if (!empty($chk)) {
                 $booth->favorites()->detach($chk->id);
                 $chk->delete();
             }
         }
         $re = Tools::reTrue('操作成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '操作失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function getBooth($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $booth = Booth::find($id);
         if (empty($booth) || $booth->u_id != $u_id) {
             throw new Exception("无法获取请求的店铺", 7001);
         }
         $data = $booth->showDetail();
         $re = Tools::reTrue('获取店铺信息成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取店铺信息失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Beispiel #3
0
 public function listUser()
 {
     $token = Input::get('token', '');
     $ids = Input::get('ids', '');
     $ids = explode(',', $ids);
     try {
         $user = User::chkUserByToken($token);
         $friends = User::whereIn('u_id', $ids)->get();
         // return all users without any restriction case IM will use all users
         $data = [];
         foreach ($friends as $key => $friend) {
             $data[] = $friend->showInImList();
         }
         $re = Tools::reTrue('获取信息成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取信息失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function countNots()
 {
     $u_id = Input::get('u_id', 0);
     $token = Input::get('token', '');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $list = Notification::join('notification_receivers', function ($q) {
             $q->on('notifications.n_id', '=', 'notification_receivers.n_id');
         })->leftJoin('notification_reads', function ($q) {
             $q->on('notification_reads.n_id', '=', 'notifications.n_id');
         })->where('notification_reads.u_id', '=', $u_id)->where('notifications.n_status', '=', 1)->where('notification_receivers.to_type', '=', '2')->where('notification_receivers.to_id', '=', 0)->orWhere('notification_receivers.to_id', '=', $u_id)->havingRaw('(`t_notification_reads`.`is_read` <> 1 AND `t_notification_reads`.`is_del` <> 1) OR (`t_notification_reads`.`is_read` IS NULL AND `t_notification_reads`.`is_del` IS NULL )')->get();
         $count = count($list);
         $data = ['count' => $count];
         $re = Tools::reTrue('获取消息成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取消息失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function updateBooth($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $lat = Input::get('lat', 0);
     $lng = Input::get('lng', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $booth = Booth::find($id);
         if ($booth->u_id != $user->u_id) {
             throw new Exception("您无法操作该店铺", 7001);
         }
         $booth->latitude = $lat;
         $booth->longitude = $lng;
         $booth->save();
         $re = Tools::reTrue('更新店铺地址成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '更新店铺地址:' . $e->getMessage());
     }
 }
 public function bid($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $price = Input::get('price', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         if (!$price) {
             throw new Exception("请输入价格", 2001);
         }
         $auction = Auction::find($id);
         $auction->load(['eventItem']);
         $now = Tools::getNow();
         if ($auction->eventItem->e_start_at > $now) {
             throw new Exception("还没开始", 2001);
         }
         if ($auction->eventItem->e_end_at < $now) {
             throw new Exception("已经结束", 2001);
         }
         if ($auction->a_cost < $price) {
             throw new Exception("竞拍价格不能超过市场价", 2001);
         }
         if (!AuctionBid::checkBlacklist($u_id)) {
             throw new Exception("现在还无法出价", 2001);
         }
         $bid = new AuctionBid();
         $bid->a_id = $id;
         $bid->u_id = $u_id;
         $bid->b_price = $price;
         $bid->addBid();
         $re = Tools::reTrue('出价成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '出价失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Beispiel #7
0
 public function putHeadImg()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $img_token = Input::get('img_token');
     try {
         $user = User::chkUserByToken($token, $u_id);
         if ($img_token) {
             $imgObj = new Img('user', $img_token);
             $imgs = $imgObj->getSavedImg($u_id, implode(',', [$user->u_head_img]), true);
             $head_img = Img::filterKey('head_img', $imgs);
             $user->u_head_img = implode(',', $head_img);
             $user->save();
         } else {
             throw new Exception("请上传头像", 2001);
         }
         $data['head_img'] = $head_img;
         $re = Tools::reTrue('修改头像成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '修改头像失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function postReply($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $content = Input::get('content', '');
     $to_u_id = Input::get('to', 0);
     $to = Input::get('parent', 0);
     try {
         $product = Product::find($id);
         $product->p_reply_count += 1;
         $user = User::chkUserByToken($token, $u_id);
         $to_user = User::find($to_u_id);
         if (empty($to_user)) {
             $to_u_id = 0;
             $to_u_name = '';
         } else {
             $to_u_name = $to_user->u_nickname;
             if ($product->p_type == 2) {
                 $cate = Notification::$CATE_FLEA;
             } else {
                 $cate = Notification::$CATE_PRODUCT_PROMO;
             }
             $msg = new MessageDispatcher();
             $msg->fireCateToUser('您有新的用户回复', $cate, $id);
         }
         $data = ['to_id' => $to, 'created_at' => Tools::getNow(), 'content' => $content, 'u_id' => $u_id, 'u_name' => $user->u_nickname, 'status' => 1, 'to_u_id' => $to_u_id, 'to_u_name' => $to_u_name];
         $reply = new Reply($data);
         $product->replies()->save($reply);
         $product->save();
         $re = Tools::reTrue('回复成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '回复失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function listBuyCrowdFunding()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $per_page = Input::get('per_page', 30);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $query = CrowdFunding::select('crowd_fundings.*')->with(['city', 'school', 'user', 'product', 'eventItem', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }])->join('crowd_funding_products', function ($q) {
             $q->on('crowd_fundings.cf_id', '=', 'crowd_funding_products.cf_id');
         })->join('carts', function ($q) {
             $q->on('carts.p_id', '=', 'crowd_funding_products.p_id')->where('carts.c_type', '=', 2)->where('carts.u_id', '=', $this->u_id)->where('carts.c_status', '=', 3);
         });
         $list = $query->orderBy('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 postOrder()
 {
     $now = new DateTime();
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $amount_origin = Input::get('amount_origin', 0);
     $amount = Input::get('amount', 0);
     $shipping_fee = Input::get('shipping_fee', 0);
     $shipping_name = Input::get('shipping_name', '');
     $shipping_phone = Input::get('shipping_phone', '');
     $shipping_address = Input::get('shipping_address', '');
     $shipping = Input::get('shipping', 1);
     $delivery_time = Input::get('delivery_time', $now->format('Y-m-d H:i:s'));
     $comment = Input::get('comment', '');
     $carts = Input::get('carts', null);
     DB::beginTransaction();
     try {
         if (empty($carts)) {
             throw new Exception("请传入有效的购物车", 1);
         }
         $carts = explode(',', $carts);
         $user = User::chkUserByToken($token, $u_id);
         $list = Cart::whereIn('c_id', $carts)->get();
         $total_amount = 0;
         $total_amount_origin = 0;
         $b_ids = [];
         $amount_origin_sum = 0;
         $amount_sum = 0;
         $groups = [];
         foreach ($list as $key => $cart) {
             if ($cart->u_id != $u_id) {
                 throw new Exception("没有权限操作该购物车", 7001);
             }
             if ($cart->c_status > 1) {
                 throw new Exception("购物车无效", 7005);
             }
             $cart->updateCart($cart->c_quantity);
             if (empty($groups[$cart->b_id]['amount_origin'])) {
                 $groups[$cart->b_id]['amount_origin'] = 0;
                 $groups[$cart->b_id]['amount'] = 0;
                 $groups[$cart->b_id]['carts_ids'] = [];
             }
             $groups[$cart->b_id]['amount_origin'] += $cart->c_amount_origin;
             $groups[$cart->b_id]['amount'] += $cart->c_amount;
             $groups[$cart->b_id]['carts_ids'][] = $cart->c_id;
             $b_ids[] = $cart->b_id;
             $amount_sum += $groups[$cart->b_id]['amount'];
             $amount_origin_sum += $groups[$cart->b_id]['amount_origin'];
         }
         if ($amount_origin_sum != $amount_origin || $amount_sum != $amount) {
             throw new Exception("支付金额已刷新, 请重新提交订单", 9003);
         }
         $order_group_no = Order::generateOrderGroupNo($u_id);
         foreach ($groups as $b_id => $group) {
             $rnd_str = rand(10, 99);
             $order_no = $order_group_no . $b_id . $rnd_str;
             $order = new Order();
             $order->u_id = $u_id;
             $order->b_id = $b_id;
             $order->o_amount_origin = $group['amount_origin'];
             $order->o_amount = $group['amount'];
             $order->o_shipping_fee = $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;
             $order->o_shipping = $shipping;
             $order->o_comment = $comment;
             $order->o_number = $order_no;
             $order->o_group_number = $order_group_no;
             $o_id = $order->addOrder();
             Cart::bindOrder([$order->o_id => $group['carts_ids']]);
         }
         // push msg to seller
         $list = Booth::whereIn('b_id', $b_ids)->get();
         foreach ($list as $key => $booth) {
             $obj = new MessageDispatcher($booth->u_id);
             $obj->fireTextToUser('您有新的订单, 请及时发货');
         }
         $re = Tools::reTrue('提交订单成功', ['order_no' => $order_group_no]);
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Beispiel #11
0
 public function wechatPayPreOrder()
 {
     $order_no = Input::get('order_no', '');
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $order = Order::getOrderByNo($order_no);
         $product_names = Cart::where('o_id', '=', $order->o_id)->lists('p_name');
         $wechat = new WechatPay();
         $body = $product_names[0] . '等商品';
         $params = ['out_trade_no' => $order_no, 'total_fee' => $order->o_amount, 'body' => $body, 'detail' => implode(',', $product_names)];
         $re = $wechat->preOrder($params);
         $re = Tools::reTrue('微信预支付成功', $re);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '微信预支付失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function postBank()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', '');
     // id bank
     $bankId = Input::get('bank', 0);
     // bank card number
     $cardNum = Input::get('card_num', '');
     // card holder name
     $cardHolderName = Input::get('holder_name', '');
     // card holder phone
     $cardHolderPhone = Input::get('holder_phone', '');
     // card holder identy
     $cardHolderID = Input::get('holder_id', '');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $card = TmpUserProfileBankcard::find($u_id);
         if (!isset($card->u_id)) {
             $card = new TmpUserProfileBankcard();
         }
         if ($card->u_status == 1) {
             throw new Exception("您的审核已经通过", 3002);
         }
         $card->u_id = $u_id;
         $card->b_id = $bankId;
         $card->b_card_number = $cardNum;
         $card->b_holder_name = $cardHolderName;
         $card->b_holder_phone = $cardHolderPhone;
         $card->b_holder_id_number = $cardHolderID;
         $card->register();
         $re = Tools::reTrue('提交银行卡信息成功');
     } catch (Exception $e) {
         // TmpUserProfileBankcard::clearByUser($u_id);
         $re = Tools::reFalse($e->getCode(), '提交银行卡信息失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 /**
  * disable reply
  * @author Kydz 2015-06-17
  * @param  int $id reply id
  * @return respose
  */
 public function disableReply($id)
 {
     $token = Input::get('token');
     $u_id = Input::get('u_id');
     $reply = PostsReply::find($id);
     try {
         User::chkUserByToken($token, $u_id);
         $reply->disable();
         $re = ['result' => 2000, 'data' => [], 'info' => ['评论删除成功']];
     } catch (Exception $e) {
         $re = ['result' => 2001, 'data' => [], 'info' => $e->getMessage()];
     }
     return Response::json($re);
 }
 public function listAuctions()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', '');
     $won = Input::get('won');
     $per_page = Input::get('per_page', 30);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $query = Auction::with('eventItem')->join('event_items', function ($q) {
             $q->on('event_items.e_id', '=', 'auctions.e_id');
         })->join('auction_bids', function ($q) {
             $q->on('auction_bids.a_id', '=', 'auctions.a_id');
         })->where('auction_bids.u_id', '=', $u_id);
         if ($won) {
             $query = $query->where('auction_bids.is_win', '=', 1);
         }
         $query = $query->groupBy('auctions.a_id')->orderBy('auctions.created_at', 'DESC');
         $list = $query->paginate($per_page);
         $data = [];
         foreach ($list as $key => $auction) {
             $data[] = $auction->showDetail();
         }
         $re = Tools::reTrue('获取竞拍成功', $data, $list);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取竞拍失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 /**
  * remove friend
  *
  * @param  int  $id
  * @return Response
  */
 public function remove()
 {
     $u_id = Input::get('u_id', 0);
     $token = Input::get('token', '');
     $friend = Input::get('friend', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $userFriend = UsersFriend::findLinkById($u_id, $friend);
         if ($userFriend === UsersFriend::$RELATION_NONE) {
         } else {
             $userFriend->remove();
         }
         $re = Tools::reTrue('删除好友成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '删除好友失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function listFlea()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $per_page = Input::get('per_page', 30);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $query = Product::with(['booth' => function ($q) {
             $q->with(['user', 'school']);
         }, 'quantity', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }])->where('u_id', '=', $u_id)->where('p_type', '=', 2);
         $list = $query->orderBy('created_at', 'DESC')->paginate($per_page);
         $data = [];
         foreach ($list as $key => $product) {
             $tmp = $product->showInList();
             if (count($product->praises) > 0) {
                 $tmp['is_praised'] = 1;
             } else {
                 $tmp['is_praised'] = 0;
             }
             $data[] = $tmp;
         }
         $re = Tools::reTrue('获取我发布的产品成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取我发布的产品失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Beispiel #17
0
 /**
  * update user info
  * @author Kydz 2015-06-14
  * @return bool
  */
 public function updateUser($imgToken = '')
 {
     $validator = Validator::make(['nickname' => $this->u_nickname, 'school_id' => $this->u_school_id, 'pass' => $this->u_password], ['nickname' => 'sometimes|max:32', 'school_id' => 'sometimes', 'pass' => 'sometimes']);
     if ($validator->fails()) {
         $msg = $validator->messages();
         throw new Exception($msg->first(), 1);
     }
     $user = User::chkUserByToken($this->u_token, $this->u_id);
     isset($this->u_nickname) ? $user->u_nickname = $this->u_nickname : '';
     isset($this->u_age) ? $user->u_age = $this->u_age : '';
     isset($this->u_name) ? $user->u_name = $this->u_name : '';
     isset($this->u_sex) ? $user->u_sex = $this->u_sex : '';
     isset($this->u_school_id) ? $user->u_school_id = $this->u_school_id : '';
     isset($this->u_password) ? $user->u_password = Hash::make($this->u_password) : '';
     if ($imgToken) {
         $img = new Img('user', $imgToken);
         $user->u_head_img = $img->getSavedImg($user->u_id, $user->u_head_img);
         $user->u_head_img = implode(',', $user->u_head_img);
     }
     $user->updated_at = date('Y-m-d H:i:s');
     if (!$user->save()) {
         throw new Exception("更新用户信息失败", 1);
     } else {
         return true;
     }
 }