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 postUserFromWechat()
 {
     $mobile = Input::get('mobile');
     $pass = Input::get('pass');
     $school_id = Input::get('school');
     $vCode = Input::get('vcode');
     DB::beginTransaction();
     try {
         $user = new User();
         $user->u_school_id = $school_id;
         $user->u_mobile = $mobile;
         $user->u_password = $pass;
         // verify vcode via phone
         $phone = new Phone($mobile);
         $phone->authVCode($vCode);
         $data = $user->register();
         // add user wallet
         $wallet = new UsersWalletBalances();
         $wallet->u_id = $user->u_id;
         $wallet->w_balance = 0.0;
         $wallet->w_freez = 0.0;
         $wallet->save();
         $re = ['data' => $data, 'result' => 2000, 'info' => '注册成功'];
         DB::commit();
     } catch (Exception $e) {
         $re = ['data' => [], 'info' => $e->getMessage(), 'result' => 2001];
         DB::rollback();
     }
     return Response::json($re);
 }
Beispiel #3
0
 public function postWalletDraw()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $amount = Input::get('amount');
     $payment = Input::get('payment', '');
     $account = Input::get('account', '');
     $b_id = Input::get('b_id', 0);
     $holder = Input::get('holder', '');
     DB::beginTransaction();
     try {
         if ($payment == 1 && (!$b_id || !$holder)) {
             throw new Exception("提现到银行卡需要填写持卡人姓名并选择银行", 9008);
         }
         $user = User::chkUserByToken($token, $u_id);
         $draw = new UsersDraw();
         $draw->u_id = $u_id;
         $draw->d_payment = $payment;
         $draw->d_account = $account;
         $draw->d_amount = $amount;
         $draw->b_id = $b_id;
         $draw->b_holder_name = $holder;
         $d_id = $draw->addDraw();
         $wallet = UsersWalletBalances::find($u_id);
         $wallet->freez($amount);
         $data['id'] = $d_id;
         $re = Tools::reTrue('提现申请成功', $data);
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '提现申请失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
 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);
 }
Beispiel #5
0
 public function confirm()
 {
     $this->getSummary();
     foreach ($this->_bills as $key => $bill) {
         $booth = Booth::find($key);
         $wallet = UsersWalletBalances::find($booth->u_id);
         if ($booth->b_with_fund) {
             $fund = Fund::where('b_id', '=', $key)->where('t_is_close', '=', 0)->first();
             if (empty($fund)) {
                 $wallet->putIn($bill['total']['paied']);
             }
         } else {
             $wallet->putIn($bill['total']['paied']);
         }
     }
     $this->o_shipping_status = 10;
     return $this->save();
 }