public function censor() { $old_status = '审核之前的状态为: ' . Organization::getStatus($this->getOriginal('u_status')) . ', 审核之后的状态为: ' . Organization::getStatus($this->u_status) . '.'; if ($this->u_status == 2) { $content = '组织信息审核未通过, ' . $old_status . ' 备注: ' . $this->remark; } elseif ($this->u_status == 1) { $content = '组织信息审核通过, ' . $old_status; } else { $content = '审核组织信息记录, ' . $old_status; } $msg = new MessageDispatcher($this->u_id); $msg->fireTextToUser($content); $this->addCensorLog($content); return $this->save(); }
public function censor() { $old_status = '审核之前的状态为: ' . $this->getOriginal('b_status') . ', 银行卡记录id为' . $this->t_id . ', 审核之后的状态为: ' . $this->b_status . '.'; if ($this->b_status == 2) { $content = '用户银行卡信息审核未通过, ' . $old_status . ' 备注: ' . $this->remark; } elseif ($this->b_status == 1) { $content = '用户银行卡信息审核通过, ' . $old_status; } else { $content = '审核银行卡信息记录, ' . $old_status; } $msg = new MessageDispatcher($this->u_id); $msg->fireTextToUser($content); $this->addCensorLog($content); return $this->save(); }
public function confirm($comment) { $logComment = '状态改变, 由' . $this->getOriginal('d_status') . '到' . $this->d_status . ', 备注:' . $comment; if ($this->d_status == 0) { throw new Exception("不能将记录状态确认到待处理", 9008); } elseif ($this->d_status == 1) { if ($this->getOriginal('d_status') == 1) { throw new Exception("无法重复提现", 9008); } $string = '放款成功, ' . $this->d_amount . '将会转入您的账户'; } elseif ($this->d_status == 2) { $string = '放款失败, 平台备注:' . $comment; } $msg = new MessageDispatcher($this->u_id); $msg->fireTextToUser($string); return $this->save(); }
public static function cronRunTheWheel() { $now = Tools::getNow(); $auction = Auction::join('event_items', function ($q) { $q->on('event_items.e_id', '=', 'auctions.e_id'); })->where('event_items.e_end_at', '<', $now)->where('auctions.a_status', '=', 1)->orderBy('event_items.e_start_at')->first(); if (empty($auction)) { throw new Exception("没有需要处理的竞拍", 2000); } $auction->load(['eventItem']); $list = AuctionBid::where('a_id', '=', $auction->a_id)->orderBy('b_price', 'DESC')->get(); if ($list->count() <= 0) { throw new Exception("无人出价", 2000); } $win = $list->first(); if ($win->is_win) { throw new Exception("中奖信息已处理", 2000); } $user = User::find($win->u_id); $auction->a_win_username = $user->u_nickname; $auction->a_win_id = $win->b_id; $auction->a_win_price = $win->b_price; $auction->a_status = 2; foreach ($list as $key => $bid) { if ($bid->u_id == $win->u_id) { continue; } else { $msg = new MessageDispatcher($bid->u_id); $msg->fireTextToUser('非常抱歉您参与的' . $auction->eventItem->e_title . '没有拍到'); } } $price = number_format($auction->a_win_price); $msg = new MessageDispatcher($win->u_id, 1, 1, 1); $msg->setMessage(['phone' => $user->u_mobile]); $msg->fireTextToUser('恭喜您以' . $price . '元成功拍得 ' . $auction->eventItem->e_title . ' 产品。请于48小时之内在我的竞拍里完成付款,逾期视为放弃,感谢您的参与'); $win->is_win = 1; $win->is_pay = 0; $auction->save(); $win->save(); return true; }
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 testDispatchWrongHandler() { $this->setExpectedException('Sulu\\Component\\Websocket\\Exception\\HandlerNotFoundException', 'Handler "test-2" not found'); $context = $this->prophesize('Sulu\\Component\\Websocket\\MessageDispatcher\\MessageHandlerContext'); $conn = $this->prophesize('Ratchet\\ConnectionInterface'); $message = ['test' => '1']; $handler = $this->prophesize('Sulu\\Component\\Websocket\\MessageDispatcher\\MessageHandlerInterface'); $handler->handle($conn->reveal(), $message, $context->reveal()); $dispatcher = new MessageDispatcher(); $dispatcher->add('test', $handler->reveal()); $result = $dispatcher->dispatch($conn->reveal(), 'test-2', $message, ['id' => 'test'], $context->reveal()); $this->assertEquals(null, $result); }
public function postReply($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $to = Input::get('to', 0); $to_u_id = Input::get('to_u_id', 0); $content = Input::get('content', ''); try { $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; $msg = new MessageDispatcher($to_u_id); $msg->fireCateToUser('您有新的用户回复', Notification::$CATE_CROWD_FUNDING, $id); } $cf = CrowdFunding::find($id); $reply = ['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]; $replyObj = new Reply($reply); $cf->replies()->save($replyObj); $re = Tools::reTrue('回复成功'); } 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 postCrowdFunding() { $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); $active_at = Input::get('active_at'); $local_only = Input::get('local_only', 0); $is_schedule = Input::get('is_schedule', 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', ''); $img_token_2 = Input::get('img_token_2', ''); $apartment_no = Input::get('apartment_no', ''); $content = urldecode($content); DB::beginTransaction(); try { $user = User::chkUserByToken($token, $u_id); if ($cate == 8 && $user->u_type != 2) { throw new Exception("错误的发布类型", 2001); } $base = new DateTime(); $base->modify('+90 days'); $target = new DateTime($active_at); if ($base < $target) { throw new Exception("最大预发布时间不能超过3个月", 2001); } $user->load('booth', 'profileBase', 'school'); if ($apartment_no) { $tmp_base = TmpUserProfileBase::find($user->u_id); $tmp_base->u_apartment_no = $apartment_no; $tmp_base->save(); } if (empty($user->booth)) { $booth = new Booth(); $booth->u_id = $u_id; $booth->b_type = 7; $booth->c_id = $user->school->t_city; $booth->s_id = $user->school->t_id; $booth->b_with_fund = 0; $booth->latitude = $user->latitude; $booth->longitude = $user->longitude; $booth->save(); } else { $booth = $user->booth; } // add event $event = new EventItem(); $event->e_title = $title; $event->e_range = 0; $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'); $event->addEvent(); $range = new EventRange(); $range->e_id = $event->e_id; $range->s_id = $user->school->t_id; $range->c_id = $user->school->t_city; $range->p_id = $user->school->t_province; $range->save(); // add funding $crowd_funding = new CrowdFunding(); $crowd_funding->u_id = $u_id; $crowd_funding->b_id = $booth->b_id; $crowd_funding->e_id = $event->e_id; $crowd_funding->c_is_schedule = $is_schedule; $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_cate = $cate; $crowd_funding->c_local_only = $local_only; $crowd_funding->c_open_file = $open_file; if ($amount <= 50000) { $crowd_funding->c_status = 4; } else { $crowd_funding->c_status = 1; $msg = new MessageDispatcher($u_id); $msg->fireTextToUser('你此次众筹总金额已超过50000元,我们将在24小时以内进行审核,请耐心等待。'); } // if the user is an official user, set funding type to offical if ($user->u_type == 2) { $crowd_funding->c_cate = 8; } $crowd_funding->addCrowdFunding(); if ($img_token) { $imgObj = new Img('event', $img_token); $event->cover_img = $imgObj->getSavedImg($event->e_id); $event->save(); } if ($img_token_2) { $imgObj = new Img('crowd_funding', $img_token_2); $crowd_funding->c_imgs = $imgObj->getSavedImg($crowd_funding->cf_id); $crowd_funding->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(); $re = Tools::reTrue('添加众筹成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '添加众筹失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
public function censor() { $original_statue = $this->getOriginal('u_status'); $new_status = $this->u_status; $old_status = '审核之前的状态为: ' . TmpUserProfileBase::getStatus($original_statue) . ', 审核之后的状态为: ' . TmpUserProfileBase::getStatus($new_status) . '.'; if ($this->u_status == 2) { $content = '用户信息审核未通过, ' . $old_status . ' 备注: ' . $this->remark; } elseif ($this->u_status == 1) { $content = '用户信息审核通过, ' . $old_status; } else { $content = '审核信息记录, ' . $old_status; } $msg = new MessageDispatcher($this->u_id); $msg->fireTextToUser($content); $this->addCensorLog($content); return $this->save(); }
public function retriveLoan($id) { DB::beginTransaction(); $now = new DateTime(); try { $current_loan = Repayment::find($id); if (empty($current_loan)) { throw new Exception("没有找到请求的放款", 6001); } $fund = Fund::find($current_loan->f_id); if (empty($fund)) { throw new Exception("没有找到相关的基金", 6001); } $fund->load('loans'); $current_income = $fund->getCurrentPeriodIncome(); $current_loan->f_income = $current_income; $profit = $current_income - $current_loan->f_re_money; if ($profit > 0) { $wallet = UsersWalletBalances::find($fund->u_id); if (empty($wallet)) { throw new Exception("没有获取到用户钱包", 6001); } $wallet->putIn($profit); $current_loan->f_status = 4; $current_loan->f_money = $current_loan->f_re_money; } elseif ($profit == 0) { $current_loan->f_status = 3; $current_loan->f_money = $current_loan->f_re_money; } elseif ($profit < 0) { $current_loan->f_status = 2; $current_loan->f_money = $current_loan->f_income; } $current_loan->repaied_at = $now->format('Y-m-d H:i:s'); $current_loan->save(); $fund->load('loans'); $all_repaied = true; $total_loan = 0; $total_repay = 0; foreach ($fund->loans as $key => $loan) { if ($loan->f_status < 3) { $all_repaied = false; } $total_loan += $loan->f_re_money; $total_repay += $loan->f_money; } if ($all_repaied) { $total_profit = $total_repay - $total_loan; if ($profit > 0) { $qnck_profit = $total_loan * (100 + $fund->t_profit_rate) / 500; $wallet = UsersWalletBalances::find($fund->u_id); if (empty($wallet)) { throw new Exception("没有获取到用户钱包", 6001); } $wallet->getOut($qnck_profit); } $fund->t_is_close = 1; $fund->closed_at = $now->format('Y-m-d H:i:s'); } else { $fund->t_is_close = 0; } $msg = new MessageDispatcher($fund->u_id); $msg->fireTextToUser('您基金的第' . $current_loan->f_schema . '次已结账, 金额:' . $current_income); $fund->save(); $re = Tools::reTrue('回收放款成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '回收放款失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
public function enable($id) { $status = Input::get('status', 0); $remark = Input::get('remark', ''); try { $booth = booth::find($id); if (empty($booth)) { throw new Exception("没有找到请求的店铺", 10001); } if ($status == 1) { $status = 1; $msg = '您的店铺[' . $booth->b_title . ']已被启用'; } else { $status = -1; $msg = '您的店铺[' . $booth->b_title . ']已被禁用'; } $obj = new MessageDispatcher($booth->u_id); $obj->fireTextToUser($msg); $booth->b_status = $status; $booth->remark = $remark; $booth->save(); $re = Tools::reTrue('用户状态修改成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '用户状态修改失败:' . $e->getMessage()); } return Response::json($re); }
public function censorUserProfileStudent($id) { $check = Input::get('check'); try { $tmp = TmpUserProfileBase::find($id); $base = UserProfileBase::find($id); $log = new LogUserProfileCensors(); $log->u_id = $id; $log->cate = 'base'; $log->admin_id = Tools::getAdminId(); if ($check == 1) { $tmp->u_is_student_verified = 1; if (!empty($base)) { $base->u_is_student_verified = 1; } if ($tmp->u_is_id_verified) { $user = User::find($id); $user->u_is_verified = 1; $user->save(); } $log->content = '认证用户学生证信息: 通过'; } else { $tmp->u_is_student_verified = 2; if (!empty($base)) { $base->u_is_student_verified = 2; } $log->content = '认证用户学生证信息: 不通过'; } $msg = new MessageDispatcher($id); $msg->fireTextToUser($log->content); $log->addLog(); $tmp->save(); if (!empty($base)) { $base->save(); } $re = Tools::reTrue('审核用户身份证信息成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '审核用户身份证信息失败:' . $e->getMessage()); } return Response::json($re); }
public function interview() { $old_status = '审核之前的状态为: ' . $this->getOriginal('t_status') . ', 审核之后的状态为: ' . $this->t_status . '.'; if ($this->t_status == 1) { $content = '基金审核未通过, ' . $old_status . ' 备注: ' . $this->remark; } elseif ($this->t_status == 3) { $content = '基金审核通过, ' . $old_status; } else { $content = '审核基金记录, ' . $old_status; } $msg = new MessageDispatcher($this->u_id); $msg->fireTextToUser($content); $this->addCensorLog($content); return $this->save(); }
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); }