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);
 }
Example #2
0
 public static function addLog($command, $message)
 {
     $log = new LogCronjob();
     $log->created_at = Tools::getNow();
     $log->command = $command;
     $log->message = $message;
     $log->save();
 }
 public function addProduct()
 {
     $this->baseValidate();
     $now = Tools::getNow();
     $this->created_at = $now;
     $this->p_status = 1;
     return $this->save();
 }
Example #4
0
 public static function checkBlacklist($u_id)
 {
     $now = Tools::getNow();
     $blacklist = AuctionBlacklist::where('u_id', '=', $u_id)->where('start_at', '<', $now)->where('end_at', '>', $now)->first();
     if (empty($blacklist)) {
         return true;
     } else {
         return false;
     }
 }
 public function listAuctions()
 {
     $per_page = Input::get('per_page', 30);
     try {
         $now = Tools::getNow();
         $list = Auction::with('eventItem')->join('event_items', function ($q) {
             $q->on('event_items.e_id', '=', 'auctions.e_id');
         })->where('event_items.e_end_at', '<', $now)->orderBy('event_items.e_end_at', 'DESC')->paginate($per_page);
         $data = [];
         foreach ($list as $key => $auction) {
             $data[] = $auction->showDetail();
         }
         $re = Tools::reTrue('获取往届竞拍成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取往届竞拍失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function import()
 {
     $this->baseValidate();
     $chk = UserImportWechat::where('u_ext_id', '=', $this->u_ext_id)->first();
     $u_id = 0;
     if (empty($chk)) {
         $re = $this->register($this->u_ext_id, $this->u_ext_token, $this->u_nickname, $this->u_head_img, $this->u_gender);
         $this->u_id = $re['u_id'];
         $this->created_at = Tools::getNow();
         $this->save();
         $u_id = $re['u_id'];
     } else {
         $u_id = $chk->u_id;
     }
     $re = $this->login($u_id);
     $re['import_type'] = 'wechat';
     return $re;
 }
Example #7
0
 public function register($ext_id, $ext_token = '', $nickname = '', $head_img = '', $gender = 3)
 {
     $user = new User();
     $user->u_nickname = $nickname;
     $user->u_name = $nickname;
     $user->u_sex = $gender;
     $user->u_birthday = Tools::getNow('Y-m-d');
     $user->u_token = $user->getUniqueToken();
     $user->u_invite_code = $user->getInviteCode();
     $user->created_at = Tools::getNow();
     $user->updated_at = Tools::getNow();
     $user->u_type = 1;
     $user->u_status = 1;
     $user->save();
     if (!$nickname) {
         $user->u_nickname = $this->u_id;
         $user->u_name = $this - u_id;
         $user->save();
     }
     $data = ['u_id' => $user->u_id, 'ext_id' => $ext_id, 'ext_token' => $ext_token];
     return $data;
 }
 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 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 listSellCrowdFunding()
 {
     $per_page = Input::get('per_page', 30);
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $filter_option = Input::get('filter_option', 0);
     try {
         $now = Tools::getNow();
         $user = User::chkUserByToken($token, $u_id);
         $query = CrowdFunding::with(['city', 'school', 'user', 'product', 'eventItem', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }])->join('event_items', function ($q) {
             $q->on('event_items.e_id', '=', 'crowd_fundings.e_id');
         })->where('crowd_fundings.u_id', '=', $u_id);
         switch ($filter_option) {
             case 1:
                 $query = $query->where('crowd_fundings.c_status', '=', 1);
                 break;
             case 2:
                 $query = $query->where('crowd_fundings.c_status', '=', 2);
                 break;
             case 3:
                 $query = $query->where('event_items.e_start_at', '>', $now);
                 break;
             case 4:
                 $query = $query->where('crowd_fundings.c_status', '=', 4);
                 break;
             case 5:
                 $query = $query->where('crowd_fundings.c_status', '=', 5);
                 break;
             case 6:
                 $query = $query->where('crowd_fundings.c_status', '=', 3);
                 break;
             default:
                 break;
         }
         $list = $query->orderBy('crowd_fundings.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);
 }
Example #11
0
 public function addLog()
 {
     $this->baseValidate();
     $this->created_at = Tools::getNow();
     return $this->save();
 }
 public function addLog()
 {
     $now = Tools::getNow();
     $this->created_at = $now;
     return $this->save();
 }
 public function flea()
 {
     $city = Input::get('city', 0);
     $province = Input::get('province', 0);
     $school = Input::get('school', 0);
     $key = Input::get('key', '');
     $range = Input::get('range', 0);
     $u_id = Input::get('u_id');
     $is_follow = Input::get('is_follow', 0);
     $cate = Input::get('cate', 0);
     $filter_option = Input::get('filter_option', 0);
     // 1-within 1 day, 2-within 3 days, 3-within 7 days
     $perPage = Input::get('per_page', 30);
     $page = Input::get('page', 1);
     try {
         if (!$school) {
             $range = 2;
         }
         if (!$u_id) {
             throw new Exception("请传入有效的用户id", 2001);
         }
         $user = User::find($u_id);
         $user->load('school');
         $query = Product::with(['user', 'booth' => function ($q) {
             $q->with(['school']);
         }, 'quantity', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }]);
         $query = $query->select('products.*')->where('products.p_status', '=', 1)->where('products.p_type', '=', 2);
         $query = $query->leftJoin('booths', function ($q) {
             $q->on('booths.b_id', '=', 'products.b_id');
         });
         if ($is_follow) {
             $query = $query->rightJoin('booth_follows', function ($q) use($u_id) {
                 $q->on('booths.b_id', '=', 'booth_follows.b_id')->where('booth_follows.u_id', '=', $u_id);
             });
             $school = 0;
             $city = 0;
             $range = 1;
         }
         if ($school && $range == 3) {
             $query = $query->where('booths.s_id', '=', $school);
         }
         if ($city && $province && $range == 2) {
             $query = $query->where('booths.c_id', '=', $city)->where('booths.pv_id', '=', $province);
         }
         if ($cate) {
             $query = $query->where('products.p_cate', '=', $cate);
         }
         if ($key) {
             $query = $query->where(function ($q) use($key) {
                 $q->where('booths.b_product_source', 'LIKE', '%' . $key . '%')->orWhere('booths.b_product_category', 'LIKE', '%' . $key . '%')->orWhere('booths.b_desc', 'LIKE', '%' . $key . '%')->orWhere('booths.b_title', 'LIKE', '%' . $key . '%')->orWhere('products.p_title', 'LIKE', '%' . $key . '%')->orWhere('products.p_desc', 'LIKE', '%' . $key . '%');
             });
         }
         if ($filter_option) {
             if ($filter_option == 1) {
                 $days = 1;
             } elseif ($filter_option == 2) {
                 $days = 3;
             } else {
                 $days = 7;
             }
             $now = Tools::getNow(false);
             $now->modify('-' . $days . ' days');
             $date = $now->format('Y-m-d H:i:s');
             $query = $query->where('products.active_at', '>', $date);
         }
         $list = $query->orderBy('products.created_at', 'DESC')->paginate($perPage);
         $data = [];
         $start = 0;
         $end = 0;
         foreach ($list as $k => $product) {
             $tmp = $product->showInList();
             if ($k == 0) {
                 $start = $end = $tmp['created_at_timestamps'];
             } else {
                 $start = min($start, $tmp['created_at_timestamps']);
                 $end = max($end, $tmp['created_at_timestamps']);
             }
             if (empty($tmp['booth']['school'])) {
                 $tmp['school'] = [];
             } else {
                 $tmp['school'] = $tmp['booth']['school'];
             }
             if (empty($tmp['booth']['city'])) {
                 $tmp['city'] = [];
             } else {
                 $tmp['city'] = $tmp['booth']['city'];
             }
             unset($tmp['booth']);
             if (count($product->praises) > 0) {
                 $tmp['is_praised'] = 1;
             } else {
                 $tmp['is_praised'] = 0;
             }
             $tmp['item_type'] = 1;
             $data[] = $tmp;
         }
         if (!$key) {
             $start = $start > 0 ? date('Y-m-d H:i:s', $start) : null;
             $end = $end > 0 && $page != 1 ? date('Y-m-d H:i:s', $end) : null;
             if ($page == 1 && $list->getTotal() < $per_page) {
                 $start = null;
             }
             $ad = Advertisement::fetchAd(3, $start, $end, $school, $city, $province, $range);
             if ($ad && $data) {
                 $data = Advertisement::mergeArray($data, $ad);
             } elseif ($ad && !$data && $page < 2) {
                 $data = $ad;
             }
         }
         $re = Tools::reTrue('获取跳蚤市场商品成功', $data, $list);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取跳蚤市场商品失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Example #14
0
 public static function fetchAd($position, $start_at, $end_at, $s_id = 0, $c_id = 0, $p_id = 0, $range = 1)
 {
     $query = Advertisement::select('advertisements.*')->with(['eventItem'])->where('advertisements.ad_status', '>', 0)->join('event_positions', function ($q) use($position) {
         $q->on('event_positions.e_id', '=', 'advertisements.e_id')->where('event_positions.position', '=', $position);
     })->join('event_ranges', function ($q) {
         $q->on('event_ranges.e_id', '=', 'advertisements.e_id');
     });
     if ($range == 1) {
         $query = $query->where('event_ranges.s_id', '=', 0)->where('event_ranges.c_id', '=', 0)->where('event_ranges.p_id', '=', 0);
     }
     if ($range == 2) {
         $query = $query->where(function ($q) use($c_id, $p_id) {
             $q->where(function ($qq) use($c_id, $p_id) {
                 $qq->where('event_ranges.c_id', '=', $c_id)->where('event_ranges.p_id', '=', $p_id);
             })->orWhere(function ($qq) {
                 $qq->where('event_ranges.s_id', '=', 0)->where('event_ranges.c_id', '=', 0)->where('event_ranges.p_id', '=', 0);
             });
         });
     }
     if ($range == 3) {
         $query = $query->where(function ($q) use($s_id) {
             $q->where(function ($qq) use($s_id) {
                 $qq->where('event_ranges.s_id', '=', $s_id);
             })->orWhere(function ($qq) {
                 $qq->where('event_ranges.s_id', '=', 0)->where('event_ranges.c_id', '=', 0)->where('event_ranges.p_id', '=', 0);
             });
         });
     }
     $query = $query->join('event_items', function ($q) {
         $q->on('event_items.e_id', '=', 'advertisements.e_id');
     });
     if ($start_at) {
         $query = $query->where('advertisements.created_at', '>', $start_at);
     }
     if ($end_at) {
         $query = $query->where('advertisements.created_at', '<', $end_at);
     }
     $now = Tools::getNow();
     $query = $query->where('event_items.e_start_at', '<', $now)->where('event_items.e_end_at', '>', $now);
     $query->orderBy('advertisements.created_at', 'DESC');
     $ads = $query->get();
     if (count($ads) > 0) {
         $data = [];
         foreach ($ads as $key => $ad) {
             $tmp = $ad->showInList();
             $tmp['item_type'] = 2;
             $data[] = $tmp;
         }
     } else {
         $data = null;
     }
     return $data;
 }
Example #15
0
 public function addCrowdFunding()
 {
     $this->baseValidate();
     $now = Tools::getNow();
     $this->created_at = $now;
     return $this->save();
 }
Example #16
0
 public function addOrganiztion()
 {
     $this->created_at = Tools::getNow();
     $this->o_status = 1;
     $this->save();
 }
Example #17
0
 public function addClub()
 {
     $this->created_at = Tools::getNow();
     $this->c_status = 1;
     $this->save();
 }
 public function postFunding()
 {
     $u_id = Tools::getOfficialUserId();
     $b_id = Tools::getOfficialBoothId();
     $title = Input::get('title', '');
     $amount = Input::get('amount', 0);
     $time = Input::get('time', 0);
     $yield_time = Input::get('yield_time', 0);
     $shipping = Input::get('shipping', 0);
     $shipping_fee = Input::get('shipping_fee', 0);
     $brief = Input::get('brief', '');
     $yield_desc = Input::get('yield_desc', '');
     $content = Input::get('content', '');
     $open_file = Input::get('open_file', 0);
     $active_at = Input::get('active_at');
     $local_only = Input::get('local_only', 0);
     $range = Input::get('range', 1);
     $cities = Input::get('cities', 0);
     $schools = Input::get('schools', 0);
     if (empty($active_at)) {
         $active_at = Tools::getNow();
     }
     $mobile = Input::get('mobile', '');
     $price = Input::get('price', 0);
     $quantity = Input::get('quantity', 0);
     $is_limit = Input::get('is_limit', 0);
     $img_token = Input::get('img_token', '');
     $content = urldecode($content);
     DB::beginTransaction();
     try {
         $user = User::find($u_id);
         $user->load('profileBase', 'school');
         $booth = Booth::find($b_id);
         // add event
         $event = new EventItem();
         $event->e_title = $title;
         $event->e_brief = $brief;
         $event->e_range = $range;
         $event->e_start_at = $active_at;
         $date_obj = new DateTime($active_at);
         $date_obj->modify('+' . $time . ' days');
         $event->e_end_at = $date_obj->format('Y-m-d H:i:s');
         $event->addEvent();
         $e_id = $event->e_id;
         // add funding
         $crowd_funding = new CrowdFunding();
         $crowd_funding->u_id = $u_id;
         $crowd_funding->b_id = $booth->b_id;
         $crowd_funding->c_yield_desc = $yield_desc;
         $crowd_funding->c_content = $content;
         $crowd_funding->c_yield_time = $yield_time;
         $crowd_funding->u_mobile = $mobile;
         $crowd_funding->c_time = $time;
         $crowd_funding->c_shipping = $shipping;
         $crowd_funding->c_shipping_fee = $shipping_fee;
         $crowd_funding->c_target_amount = $amount;
         $crowd_funding->c_amount = 0.0;
         $crowd_funding->c_local_only = $local_only;
         $crowd_funding->c_praise_count = 0;
         $crowd_funding->c_remark = '';
         $crowd_funding->c_open_file = $open_file;
         $crowd_funding->c_status = 4;
         $crowd_funding->c_cate = 8;
         $crowd_funding->e_id = $e_id;
         $crowd_funding->addCrowdFunding();
         if ($img_token) {
             $imgObj = new Img('crowd_funding', $img_token);
             $crowd_funding->c_imgs = $imgObj->getSavedImg($crowd_funding->cf_id);
             $crowd_funding->save();
             $imgObj = new Img('event', $img_token);
             $event->cover_img = $imgObj->getSavedImg($event->e_id);
             $event->save();
         }
         // add funding product
         $funding_product = new CrowdFundingProduct();
         $funding_product->cf_id = $crowd_funding->cf_id;
         $funding_product->u_id = $u_id;
         $funding_product->b_id = $booth->b_id;
         $funding_product->p_title = $title;
         $funding_product->p_desc = '';
         $funding_product->p_price = $price;
         $funding_product->p_target_quantity = $quantity;
         $funding_product->p_sort = 0;
         if ($is_limit) {
             $funding_product->p_max_quantity = $quantity;
         } else {
             $funding_product->p_max_quantity = 0;
         }
         $funding_product->addProduct();
         if ($range == 1) {
             $event_range = new EventRange(['c_id' => 0, 'p_id' => 0, 's_id' => 0]);
             $event->ranges()->save($event_range);
         }
         if ($cities && $range == 2) {
             $city_sets = explode(',', $cities);
             foreach ($city_sets as $key => $set) {
                 $array = explode('|', $set);
                 $event_range = new EventRange(['c_id' => $array[0], 'p_id' => $array[1]]);
                 if ($key) {
                     $new_event = $crowd_funding->cloneCrowdFunding();
                 } else {
                     $new_event = $event;
                 }
                 $new_event->ranges()->save($event_range);
             }
         }
         if ($schools && $range == 3) {
             $schools = explode(',', $schools);
             foreach ($schools as $key => $school) {
                 $event_range = new EventRange(['s_id' => $school]);
                 if ($key) {
                     $new_event = $crowd_funding->cloneCrowdFunding();
                 } else {
                     $new_event = $event;
                 }
                 $new_event->ranges()->save($event_range);
             }
         }
         $re = Tools::reTrue('添加众筹成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '添加众筹失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
 public function postOrder($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', '');
     $shipping_name = Input::get('shipping_name', '');
     $shipping_phone = Input::get('shipping_phone', '');
     $shipping_address = Input::get('shipping_address', '');
     $comment = Input::get('comment', '');
     DB::beginTransaction();
     try {
         $user = User::chkUserByToken($token, $u_id);
         $now = Tools::getNow();
         $auction = Auction::find($id);
         if (empty($auction) || $auction->a_status != 2) {
             throw new Exception("请求的竞拍不存在", 2001);
         }
         $auction->load(['eventItem']);
         $bid = AuctionBid::find($auction->a_win_id);
         if (empty($bid) || $bid->is_pay) {
             throw new Exception("出价信息有误", 2001);
         }
         $limit = new DateTime($auction->eventItem->e_end_at);
         $limit->modify('+3 days');
         $now = Tools::getNow(false);
         if ($limit < $now) {
             $blacklist = new AuctionBlacklist();
             $blacklist->u_id = $u_id;
             $blacklist->a_id = $auction->a_id;
             $blacklist->start_at = $now;
             $now->modify('+7 days');
             $blacklist->end_at = $now->format('Y-m-d H:i:s');
             $blacklist->remark = '超时未购买';
             $blacklist->save();
             $auction->a_status = 4;
             $auction->save();
             throw new Exception("竞拍已超时, 无法购买", 2);
             //when exception code is 2, commit anyway after catch
         }
         // add cart
         $cart = new Cart();
         $cart->p_id = $auction->a_id;
         $cart->p_name = $auction->eventItem->e_title;
         $cart->u_id = $u_id;
         $cart->b_id = Tools::getMakerBooth();
         $cart->created_at = Tools::getNow();
         $cart->c_quantity = 1;
         $cart->c_price = $auction->a_win_price;
         $cart->c_amount = $auction->a_win_price;
         $cart->c_discount = 100;
         $cart->c_price_origin = $auction->a_cost;
         $cart->c_amount_origin = $auction->a_cost;
         $cart->c_status = 2;
         $cart->c_type = 4;
         $re = $cart->save();
         if (!$re) {
             throw new Exception("提交库存失败", 7006);
         }
         $shipping_name = $shipping_name ? $shipping_name : $user->u_name;
         $shipping_phone = $shipping_phone ? $shipping_phone : $user->u_mobile;
         // 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 = 0.0;
         $order->o_shipping_name = $shipping_name;
         $order->o_shipping_phone = $shipping_phone;
         $order->o_shipping_address = $shipping_address;
         $order->o_delivery_time = Tools::getNow();
         $order->o_shipping = 1;
         $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 => [$cart->c_id]]);
         $data = ['order_no' => $order_group_no];
         $re = Tools::reTrue('提交订单成功', $data);
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '提交订单失败:' . $e->getMessage());
         if ($e->getCode() == 2) {
             DB::commit();
         } else {
             DB::rollback();
         }
     }
     return Response::json($re);
 }
Example #20
0
 public function addNot()
 {
     $this->n_status = 1;
     $this->created_at = Tools::getNow();
     return $this->save();
 }
 public function putFlea($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $mobile = Input::get('mobile', '');
     $prodName = Input::get('prod_name', '');
     $prodDesc = Input::get('content', '');
     $prodBrief = Input::get('prod_brief', '');
     $price = Input::get('price', '');
     $publish = Input::get('publish', 1);
     $product_cate = Input::get('cate', 7);
     $active_at = Input::get('active_at');
     $open_file = Input::get('open_file', 0);
     if (empty($active_at)) {
         $active_at = Tools::getNow();
     }
     $img_token = Input::get('img_token', '');
     $prodDesc = urldecode($prodDesc);
     $modified_img = Input::get('modified_img', '');
     $modified_img_index = Input::get('modified_img_index', '');
     if ($modified_img) {
         $modified_img = explode(',', $modified_img);
     }
     try {
         $user = User::chkUserByToken($token, $u_id);
         $product = Product::find($id);
         if (empty($product) || $product->u_id != $u_id) {
             throw new Exception("没有找到请求的产品", 1);
         }
         $product->p_title = $prodName;
         $product->p_desc = $prodDesc;
         $product->sort = 1;
         $product->p_cate = $product_cate;
         $product->p_brief = $prodBrief;
         $product->p_status = $publish == 1 ? 1 : 2;
         $product->p_price_origin = $price;
         $product->p_price = $price;
         $product->active_at = $active_at;
         $product->p_mobile = $mobile;
         $product->open_file = $open_file;
         $old_imgs = Img::toArray($product->p_imgs);
         if (empty($old_imgs['cover_img'])) {
             $cover_img = '';
         } else {
             $cover_img = $old_imgs['cover_img'];
             unset($old_imgs['cover_img']);
         }
         if (is_numeric($modified_img_index)) {
             $imgObj = new Img('product', $img_token);
             $new_paths = [];
             if (!empty($modified_img)) {
                 foreach ($modified_img as $old_path) {
                     $new_path = $imgObj->reindexImg($id, $modified_img_index, $old_path);
                     $new_paths[] = $new_path;
                     $modified_img_index++;
                 }
                 foreach ($old_imgs as $obj) {
                     if (!in_array($obj, $new_paths)) {
                         $imgObj->remove($id, $obj);
                     }
                 }
                 $new_paths = Img::attachHost($new_paths);
                 $product->p_imgs = implode(',', $new_paths);
             }
         }
         if ($cover_img) {
             if ($product->p_imgs) {
                 $product->p_imgs .= ',' . $cover_img;
             } else {
                 $product->p_imgs = $cover_img;
             }
         }
         if ($img_token) {
             $imgObj = new Img('product', $img_token);
             $imgs = $imgObj->getSavedImg($id, $product->p_imgs, true);
             if (!empty($modified_img)) {
                 foreach ($modified_img as $del) {
                     if (array_key_exists($del, $imgs)) {
                         unset($imgs[$del]);
                     }
                 }
             }
             $product->p_imgs = implode(',', $imgs);
         }
         $product->save();
         $re = Tools::reTrue('更新产品成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '更新产品失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Example #22
0
 public function addEvent()
 {
     $this->created_at = Tools::getNow();
     $this->e_status = 1;
     return $this->save();
 }
Example #23
0
 public function fakeUser()
 {
     $this->u_school_id = rand(1, 2569);
     $this->u_password = 111111;
     $this->u_token = $this->getUniqueToken();
     $this->u_password = Hash::make($this->u_password);
     $this->u_status = 1;
     $this->u_change = 1;
     $this->u_type = 1;
     $this->u_sex = 3;
     $this->u_birthday = Tools::getNow('Y-m-d');
     $this->save();
     $this->u_invite_code = $this->getInviteCode();
     $this->save();
 }
Example #24
0
 public static function cronYouCheater()
 {
     $date = Tools::getNow(false);
     $now = $date->format('Y-m-d H:i:s');
     $date->modify('-2 days');
     $end = $date->format('Y-m-dH:i:s');
     $auction = Auction::join('event_items', function ($q) {
         $q->on('event_items.e_id', '=', 'auctions.e_id');
     })->where('event_items.e_end_at', '<', $end)->where(function ($q) {
         $q->where('auctions.a_status', '=', 2)->orWhere('auctions.a_status', '=', 1);
     })->first();
     if (empty($auction)) {
         throw new Exception("没有需要处理的竞拍", 2000);
     }
     if ($auction->a_status == 2 && $auction->a_win_id) {
         $win = AuctionBid::find($auction->a_win_id);
         if (!empty($win)) {
             $date->modify('+10 days');
             $end = $date->format('Y-m-d H:i:s');
             $blacklist = new AuctionBlacklist();
             $blacklist->u_id = $win->u_id;
             $blacklist->a_id = $auction->a_id;
             $blacklist->start_at = $now;
             $blacklist->end_at = $end;
             $blacklist->remart = '超时未购买';
             $blacklist->save();
         }
     }
     $auction->a_status = 4;
     $auction->save();
     return true;
 }