Пример #1
0
 public function putBoothDesc($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $desc = Input::get('desc', '');
     $title = Input::get('title', '');
     $img_token = Input::get('img_token', '');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $booth = Booth::find($id);
         if (empty($booth->b_id) || $booth->u_id != $u_id) {
             throw new Exception("无法获取到请求的店铺", 7001);
         }
         $booth->b_desc = $desc;
         $booth->b_title = $title;
         if ($img_token) {
             $imgObj = new Img('booth', $img_token);
             $booth->b_imgs = $imgObj->getSavedImg($booth->b_id, $booth->b_imgs);
         }
         $booth->save();
         $re = ['result' => 2000, 'data' => [], 'info' => '更新店铺成功'];
     } catch (Exception $e) {
         $code = 7001;
         if ($e->getCode() > 2000) {
             $code = $e->getCode();
         }
         $re = ['result' => $code, 'data' => [], 'info' => '更新店铺失败:' . $e->getMessage()];
     }
     return Response::json($re);
 }
Пример #2
0
 /**
  * add new post
  * @author Kydz 2015-06-17
  */
 public function addPost($imgToken)
 {
     $this->created_at = date('Y-m-d H:i:s');
     $this->p_status = 1;
     $this->baseValidate();
     if (!$this->save()) {
         throw new Exception("添加帖子失败", 1);
     }
     if ($imgToken) {
         $img = new Img('post', $imgToken);
         $this->p_content = $img->getSavedImg($this->p_id, $this->p_content);
         $this->save();
     }
     return true;
 }
Пример #3
0
 public function confirmDraw($id)
 {
     $confirm = Input::get('confirm', 0);
     $comment = Input::get('comment', '');
     $img_token = Input::get('img_token', '');
     DB::beginTransaction();
     try {
         $draw = UsersDraw::find($id);
         if (empty($draw)) {
             throw new Exception("请求的数据不存在", 10001);
         }
         $balance = UsersWalletBalances::find($draw->u_id);
         if (empty($balance)) {
             $balance = new UsersWalletBalances();
             $balance->u_id = $draw->u_id;
         }
         if ($confirm == 1) {
             $balance->deFreez($draw->d_amount);
             $draw->d_status = 1;
             $balance->getOut($draw->d_amount);
         } elseif ($confirm == 0) {
             $draw->d_status = 2;
         } else {
             throw new Exception("只有确认提现/不确认提现", 10001);
         }
         $draw->confirm($comment);
         if ($img_token) {
             $imgObj = new Img('draw', $img_token);
             $imgs = $imgObj->getSavedImg($draw->d_id);
             $draw->imgs = $imgs;
             $draw->save();
         }
         $re = Tools::reTrue('确认提现成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '确认提现失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
 public function allocateRepayment($id)
 {
     $comment = Input::get('comment', '');
     $img_token = Input::get('img_token', '');
     DB::beginTransaction();
     try {
         $repay = Repayment::find($id);
         if (empty($repay)) {
             throw new Exception("没有找到放款明细", 10001);
         }
         $repay->allocate($comment);
         if ($img_token) {
             $imgObj = new Img('loan', $img_token);
             $imgs = $imgObj->getSavedImg($repay->t_id);
             $repay->imgs = $imgs;
             $repay->save();
         }
         $fund = Fund::find($repay->f_id);
         if (empty($fund)) {
             throw new Exception("没有找到相关的基金", 1);
         }
         $fund->load('loans');
         if ($fund->chkLoansAlloc()) {
             $fund->t_status = 5;
         }
         $fund->t_status = 4;
         $fund->save();
         $msg = new MessageDispatcher($fund->u_id);
         $msg->fireTextToUser('您申请的基金第' . $repay->f_schema . '次已放款, 金额:' . $repay->f_re_money);
         $re = Tools::reTrue('放款成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '放款失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Пример #5
0
 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);
 }
Пример #6
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 putCrowdFunding($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $title = Input::get('title', '');
     $cate = Input::get('cate', 1);
     $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);
     $local_only = Input::get('local_only', 0);
     $is_schedule = Input::get('is_schedule', 0);
     $active_at = Input::get('active_at');
     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', '');
     $img_token_2 = Input::get('img_token_2', '');
     $apartment_no = Input::get('apartment_no', '');
     $content = urldecode($content);
     $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);
         if ($cate == 8 && $user->u_type != 2) {
             throw new Exception("错误的发布类型", 2001);
         }
         $crowd_funding = CrowdFunding::find($id);
         if (empty($crowd_funding) || $crowd_funding->u_id != $u_id) {
             throw new Exception("无法获取到请求的众筹", 2001);
         }
         $funding_product = CrowdFundingProduct::where('cf_id', '=', $crowd_funding->cf_id)->first();
         if (empty($funding_product)) {
             throw new Exception("库存信息丢失", 2001);
         }
         if (Cart::getCartTypeCount(Cart::$TYPE_CROWD_FUNDING, $funding_product->p_id)) {
             throw new Exception("已有人购买", 2001);
         }
         if ($apartment_no) {
             $tmp_base = TmpUserProfileBase::find($user->u_id);
             $tmp_base->u_apartment_no = $apartment_no;
             $tmp_base->save();
         }
         $event = EventItem::find($crowd_funding->e_id);
         // put funding
         $event->e_title = $title;
         $event->e_brief = $brief;
         $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');
         $crowd_funding->c_local_only = $local_only;
         $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_is_schedule = $is_schedule;
         $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_cate = $cate;
         $crowd_funding->c_open_file = $open_file;
         if ($amount <= 2000) {
             $crowd_funding->c_status = 4;
         } else {
             $crowd_funding->c_status = 1;
         }
         // if the user is an official user, set funding type to offical
         if ($user->u_type == 2) {
             $crowd_funding->c_cate = 8;
         }
         if (is_numeric($modified_img_index)) {
             $imgObj = new Img('crowd_funding', $img_token_2);
             $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++;
                 }
                 $new_paths = Img::attachHost($new_paths);
                 $crowd_funding->c_imgs = implode(',', $new_paths);
             }
         }
         if ($img_token_2) {
             $imgObj = new Img('crowd_funding', $img_token_2);
             $imgs = $imgObj->getSavedImg($crowd_funding->cf_id, $crowd_funding->c_imgs, true);
             if (!empty($modified_img)) {
                 foreach ($modified_img as $del) {
                     if (array_key_exists($del, $imgs)) {
                         unset($imgs[$del]);
                     }
                 }
             }
             $crowd_funding->c_imgs = implode(',', $imgs);
         }
         if ($img_token) {
             $img_obj = new Img('event', $img_token);
             $cover_img = $img_obj->replace($event->e_id, 'cover_img');
             $event->cover_img = $cover_img;
         }
         $crowd_funding->save();
         $event->save();
         // put funding product
         $funding_product = CrowdFundingProduct::where('cf_id', '=', $crowd_funding->cf_id)->first();
         if (empty($funding_product)) {
             throw new Exception("库存信息丢失", 2001);
         }
         $funding_product->p_price = $price;
         $funding_product->p_target_quantity = $quantity;
         if ($is_limit) {
             $funding_product->p_max_quantity = $quantity;
         } else {
             $funding_product->p_max_quantity = 0;
         }
         $funding_product->save();
         $re = Tools::reTrue('编辑众筹成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '编辑众筹失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Пример #8
0
 public function postAd()
 {
     $title = Input::get('title', '');
     $url = Input::get('url', '');
     $brief = Input::get('brief', '');
     $range = Input::get('range', '');
     $cities = Input::get('cities', '');
     $schools = Input::get('schools', '');
     $positions = Input::get('positions', '');
     $start_at = Input::get('start_at', '');
     $end_at = Input::get('end_at', '');
     $img_token = Input::get('img_token', '');
     try {
         $ad_event = new EventItem();
         $ad_event->e_title = $title;
         $ad_event->e_brief = $brief;
         $ad_event->url = $url;
         $ad_event->e_range = $range;
         $ad_event->e_start_at = $start_at;
         $ad_event->e_end_at = $end_at;
         $ad_event->addEvent();
         $e_id = $ad_event->e_id;
         if ($range == 1) {
             $event_range = new EventRange(['c_id' => 0, 'p_id' => 0, 's_id' => 0]);
             $ad_event->ranges()->save($event_range);
         }
         if ($cities && $range == 2) {
             $city_sets = explode(',', $cities);
             foreach ($city_sets as $set) {
                 $array = explode('|', $set);
                 $event_range = new EventRange(['c_id' => $array[0], 'p_id' => $array[1]]);
                 $ad_event->ranges()->save($event_range);
             }
         }
         if ($schools && $range == 3) {
             $schools = explode(',', $schools);
             foreach ($schools as $school) {
                 $event_range = new EventRange(['s_id' => $school]);
                 $ad_event->ranges()->save($event_range);
             }
         }
         if ($positions) {
             $positions = explode(',', $positions);
             foreach ($positions as $key => $position) {
                 $event_position = new EventPosition(['position' => $position]);
                 $ad_event->positions()->save($event_position);
             }
         }
         if ($img_token) {
             $imgObj = new Img('event', $img_token);
             $ad_event->cover_img = $imgObj->getSavedImg($e_id);
             $ad_event->save();
         }
         $ad = new Advertisement();
         $ad->e_id = $e_id;
         $ad->o_id = Tools::getOfficialOrgnizationId();
         $ad->addAd();
         $re = Tools::reTrue('添加广告成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '添加广告失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Пример #9
0
 private function saveClubInfo($user)
 {
     $title = Input::get('club_title', '');
     $brief = Input::get('club_brief', '');
     $img_token = Input::get('img_token_2', '');
     if ($title) {
         $club = Club::where('u_id', '=', $user->u_id)->first();
         if (empty($club)) {
             $club = new Club();
             $club->u_id = $user->u_id;
             $club->s_id = $user->u_school_id;
             $club->c_title = $title;
             $club->addClub();
         }
         $club->c_title = $title;
         $club->c_brief = $brief;
         $c_id = $club->c_id;
         $imgObj = new Img('club', $img_token);
         $club->c_imgs = $imgObj->getSavedImg($c_id, $club->c_imgs);
         $club->save();
     }
     return true;
 }
 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);
 }
Пример #11
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;
     }
 }