public function wxpay_app() { $period_id = Input::get('period_id'); $period = Period::find($period_id); // 判断时间段有效性 if (!isset($period)) { return Response::json(array('error_code' => 2, 'message' => '无该时间段,请重新选择')); } if ($period->current >= $period->total) { return Response::json(array('error_code' => 3, 'message' => '已满人,请重新选择')); } $schedule = $period->schedule; $doctor = $schedule->doctor; $user_id = Session::get('user.id'); // 选择指定挂号账户 if (Input::has('account_id')) { $account_id = Input::get('account_id'); $account = RegisterAccount::find($account_id); if (!isset($account)) { return Response::json(array('error_code' => 4, 'message' => '不存在该挂号账户')); } if ($account->user_id != $user_id) { return Response::json(array('error_code' => 5, 'message' => '无效账户')); } } else { $account = RegisterAccount::where('user_id', $user_id)->first(); if (!isset($account)) { return Response::json(array('error_code' => 6, 'message' => '请先申请挂号账户')); } $account_id = $account->id; } $user_id = Session::get('user.id'); $attach = array('period_id' => (int) Input::get('period_id'), 'account_id' => $account_id); try { $period = Period::find(Input::get('period_id')); $schedule = $period->schedule; $doctor = $schedule->doctor; $order = $this->create_order($user_id, 'APP', json_encode($attach), (int) ($doctor->register_fee * 100)); $para = array('appid' => $order['appid'], 'partnerid' => WxPayConfig::MCHID, 'prepayid' => $order['prepay_id'], 'package' => 'Sign=WXPay', 'noncestr' => WxPayApi::getNonceStr(), 'timestamp' => time()); $wxpay_result = new WxPayResults(); $wxpay_result->FromArray($para); $wxpay_result->SetSign(); $package = $wxpay_result->GetValues(); } catch (Exception $e) { return Response::json(array('error_code' => 1, 'message' => $e->getMessage())); } return Response::json(array('error_code' => 0, 'package' => $package)); }
public function add_record() { $period_id = Input::get('period_id'); $period = Period::find($period_id); if (!isset($period)) { return Response::json(array('error_code' => 2, 'message' => '无该时间段,请重新选择')); } if ($period->current >= $period->total) { return Response::json(array('error_code' => 3, 'message' => '已满人,请重新选择')); } $schedule = $period->schedule; $doctor = $schedule->doctor; $user_id = Session::get('user.id'); if (Input::has('account_id')) { $account_id = Input::get('account_id'); $account = RegisterAccount::find($account_id); if (!isset($account)) { return Response::json(array('error_code' => 4, 'message' => '不存在该挂号账户')); } if ($account->user_id != $user_id) { return Response::json(array('error_code' => 5, 'message' => '无效账户')); } } else { $account = RegisterAccount::where('user_id', $user_id)->first(); if (!isset($account)) { return Response::json(array('error_code' => 6, 'message' => '请先申请挂号账户')); } $account_id = $account->id; } try { DB::beginTransaction(); RegisterRecord::create(array('status' => 0, 'fee' => $doctor->register_fee, 'period_id' => $period->id, 'doctor_id' => $doctor->id, 'account_id' => $account_id, 'user_id' => $user_id)); $period->current += 1; $period->save(); $message = new Message(); $message->from_uid = $user_id; $message->to_uid = $doctor->user->id; $message->content = $account->user->real_name . '挂号'; $message->timestamp = time(); $message->status = 3; $message->save(); DB::commit(); } catch (Exception $e) { DB::rollback(); return Response::json(array('error_code' => 1, 'message' => '添加失败')); } return Response::json(array('error_code' => 0, 'message' => '添加成功')); }
public function delete_account() { if (Input::has('account_id')) { $account = RegisterAccount::find(Input::get('account_id')); if (!isset($account)) { return Response::json(array('error_code' => 2, 'message' => '不存在该账户')); } if ($account->user_id != Session::get('user.id')) { return Response::json(array('error_code' => 3, 'message' => '无效账户')); } } else { $account = RegisterAccount::where('user_id', Session::get('user.id'))->first(); if (!isset($account)) { return Response::json(array('error_code' => 4, 'message' => '无挂号账户')); } } if (!$account->delete()) { return Response::json(array('error_code' => 1, 'message' => '删除失败')); } return Response::json(array('error_code' => 0, 'message' => '删除成功')); }
public function user_center() { $register_account = RegisterAccount::where('user_id', Session::get('user.id'))->first(); return View::make('user.center', array('account' => $register_account)); }