/**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @api {post} /yzh/account/flush 彻底删除该商户下所有用户
  * @apiName PostToolFlush
  * @apiGroup Tool
  *
  * @apiParam {String} partner 商户编号
  *
  * @apiSuccessExample Success-Response:
  * HTTP/1.1 200 OK
  * {
  *   "ok": true
  * }
  *
  */
 public function flush(Request $request)
 {
     $input = $request->all();
     Logger::sysInfo('@YzhController flush, begin, clear', $input);
     $validator = Validator::make($input, ['partner' => 'required']);
     if ($validator->fails()) {
         $errors = $validator->errors()->toArray();
         return Response::error(FaultCode::PARAMS_ERROR, $errors);
     }
     if (!in_array($input['partner'], config('Flush'))) {
         return Response::error(FaultCode::ACCESS_DENIED);
     }
     $results = DB::connection('trial')->select('select I_USER_ID from dealer_user_relation where CH_DEALER_CODE = :code', ['code' => $input['partner']]);
     if (empty($results)) {
         return Response::result(['ok' => true]);
     }
     $log = [];
     foreach ($results as $row) {
         $id = $row->I_USER_ID;
         $log[] = DB::connection('trial')->delete('delete from users where I_USER_ID = :id', ['id' => $id]);
         $log[] = DB::connection('trial')->delete('delete from user_account where I_USER_ID = :id', ['id' => $id]);
         $log[] = DB::connection('trial')->delete('delete from user_bankcards where I_USER_ID = :id', ['id' => $id]);
         $log[] = DB::connection('trial')->delete('delete from dealer_user_relation where I_USER_ID = :id', ['id' => $id]);
     }
     Logger::sysInfo('@YzhController flush, end, log', $log);
     return Response::result(['ok' => true]);
 }
 /**
  * 登录
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @api {post} /user/login 登录
  * @apiName PostLogin
  * @apiGroup User
  *
  * @apiParam {String} mobile 手机号
  * @apiParam {String} password 登录密码
  *
  * @apiSuccessExample Success-Response:
  *     {
  *         uid: 1
  *     }
  */
 public function login(Request $request)
 {
     // input
     $input = $request->all();
     // validate
     $validator = Validator::make($input, ['mobile' => 'required|size:11', 'password' => 'required|min:6']);
     if ($validator->fails()) {
         $errors = $validator->errors()->toArray();
         return Response::error(FaultCode::PARAMS_ERROR, $errors);
     }
     // grab
     $user = User::where('mobile', $input['mobile'])->first();
     if (is_null($user)) {
         return Response::error(FaultCode::USER_NOT_EXIST);
     }
     // password
     if (!CommonHelper::comparePassword($input['password'], $user->password, $user->salt)) {
         return Response::error(FaultCode::PASSWORD_NOT_MATCH);
     }
     return Response::result(['uid' => $user->uid]);
 }