public function buy($type = 'online')
 {
     // 验证是否签约
     $user = get_user() or $this->error('请先登录!', '/login');
     $contract = M('loan_user_contract')->find($user['uid']);
     if (!$contract || $contract['status'] == 2) {
         $this->error('您还未签约或签约不通过', '/user/contract');
         return;
     }
     if (IS_POST) {
         $user = get_user() or $this->error('请先登录!');
         $userModel = new \Common\Model\UserModel();
         $userModel->verifyCode(I('mobile'), I('verify_code')) or $this->error($userModel->getError());
         $money = I('money', 0, 'floatval');
         $first_money = I('first_money', 0, 'floatval');
         $month = I('month', 0, 'intval');
         $other = $type == 'online' ? ['url' => I('url')] : ['seller_name' => I('seller_name'), 'seller_telephone' => I('seller_telephone')];
         $orderModel = D('Loan/order');
         $order_id = $orderModel->addOther($user['uid'], $type, I('title'), $money, $first_money, $month, I('remark'), $other);
         $order_id or $this->error($orderModel->getError());
         if (IS_AJAX) {
             $this->ajaxReturn(array('status' => 1, 'order_id' => $order_id));
         } else {
             $this->assign('order_id', $order_id);
             $this->success('下单成功,请等待工作人员审核。', '/user/order', 3);
         }
         return;
     }
 }
 public function fix_user_reg()
 {
     $model = new \Common\Model\UserModel();
     $users = M()->query("select uid,created from zj_user where created BETWEEN UNIX_TIMESTAMP('2015-04-01') and UNIX_TIMESTAMP('2015-04-02') and last_login_ip=0");
     foreach ($users as $user) {
         $time = '2015-03-' . rand(10, 31) . ' ' . rand(10, 23) . ':' . rand(10, 59) . ':' . rand(10, 59);
         $model->where('uid=' . $user['uid'])->setField('created', strtotime($time));
         $model->updateStat($user['uid']);
     }
     M('user_reg')->where(['reg_year' => '2015', 'reg_month' => 3])->delete();
     M('user_reg')->where(['reg_year' => '2015', 'reg_month' => 4, 'reg_day' => 1])->delete();
     die('done');
 }
 protected function _checkOtherLogin($uid)
 {
     // 判断是否已经有新的登录设备
     $token_name = C('COOKIE_TOKEN');
     $token = cookie($token_name) ?: cookie('token');
     // 获取当前token的id
     $model = M('user_login');
     $login_id = $model->where(['uid' => $uid, 'app' => 'zjsj', 'token' => $token, 'token_status' => 1])->getField('id');
     if ($login_id && $model->where(['app' => 'zjsj', 'uid' => $uid, 'token_status' => 1, 'id' => ['gt', $login_id]])->count()) {
         $userModel = new \Common\Model\UserModel();
         $userModel->logout();
         ajax_error('此账号已在其它地方登录,系统自动退出!');
     }
 }
 public function login()
 {
     if (isset($_POST['dosubmit'])) {
         $username = I('post.username');
         $password = I('post.password');
         $identifying = I('post.identifying');
         if (empty($username)) {
             $this->error("请输入用户名");
         }
         if (empty($password)) {
             $this->error("请输入密码");
         }
         /*if(empty($identifying))$this->error("请输入验证码");
           if(!check_verify($identifying)){
               $this->error("亲,验证码输错了哦");exit(); 
           }*/
         $userModel = new \Common\Model\UserModel();
         if (is_null($data = $userModel->checkUser($username))) {
             $this->error("用户名或者密码错误");
             exit;
         }
         $password = md5($password);
         if ($password == $data['pwd']) {
             //登陆成功
             session("home_userid", $data['id']);
             cookie('userid', $data['id'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('nickname', $data['nickname'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('CommunityName', $CommunityName, array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('username', $data['username'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('score', $data['score'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             $this->success("登陆成功", "/Home/Index/index");
         } else {
             $this->error("用户名或者密码错误!");
             exit;
         }
     } else {
         $this->display();
     }
 }
 /**
  * @title 重置密码(用于找回密码时)
  *
  * @param int $mobile 手机号
  * @param string $verifyCode 验证码
  * @param string $password 新密码
  * @method post
  */
 public function forgetPassword()
 {
     $mobile = I('post.mobile');
     $password = I('post.password');
     $userModel = new \Common\Model\UserModel();
     $verifyCode = I('post.verifyCode') or ajax_error('请输入手机验证码!');
     $userModel->verifyCode($mobile, $verifyCode) or ajax_error($userModel->getError());
     $this->_updatePassword($mobile, $password);
 }
 public function verify_old_mobile()
 {
     session('verify_old', false);
     $userModel = new \Common\Model\UserModel();
     if ($userModel->verifyCode($this->user['mobile'], I('post.verify_old')) === true) {
         session('verify_old', true);
         $this->ajaxReturn(array('ok' => 1));
     } else {
         $this->ajaxReturn(array('ok' => 0, 'message' => $userModel->getError()));
     }
 }
 public function order()
 {
     if (I('post.month', 0, 'intval') > 0) {
         $userModel = new \Common\Model\UserModel();
         $userModel->verifyCode(I('post.mobile'), I('post.verify_code')) or $this->error($userModel->getError());
     }
     $goods = $this->_goods();
     $this->assign('goods', $goods);
     $first_money = I('first_money', 0, 'floatval');
     $month = I('month', 0, 'intval');
     $quantity = I('quantity', 1, 'intval');
     $remark = I('remark');
     $payee_account_type = I('payee_account_type', 0, 'intval');
     $payee_account = I('account');
     $orderModel = new \Loan\Model\OrderModel();
     $order_id = $orderModel->addGoods($this->_user['uid'], $goods['id'], $quantity, $first_money, $month, $goods['property_remark'], $remark, $payee_account_type, $payee_account);
     $order_id or $this->error($orderModel->getError());
     if (IS_AJAX) {
         $this->ajaxReturn(array('status' => 1, 'order_id' => $order_id));
     } else {
         if ($month) {
             $this->assign('order_id', $order_id);
             $this->success('下单成功,请等待工作人员审核。', '/user/order', 3);
         } else {
             $this->redirect('/pay/alipay/' . $order_id);
         }
     }
 }
 public function changeMobile()
 {
     $uid = I('uid', 0, 'intval');
     $user = M('user')->find($uid) or $this->error('找不到此用户信息!');
     if (IS_POST) {
         $model = new \Common\Model\UserModel();
         $model->changeMobile($user['mobile'], I('mobile'), 3) or $this->error($model->getError());
         $this->success('手机号已成功更换为:' . I('mobile'));
         exit;
     }
     $this->assign('info', $user);
     $this->meta_title = '更换手机号';
     $this->display();
 }
 /**
  * @title 设置交易密码
  *
  * @param string $password 新密码
  * @param string $verifyCode 手机验证码
  *       
  * @method GET
  */
 public function setTradePassword()
 {
     $password = I('post.password') or ajax_error('请输入交易密码!');
     $verifyCode = I('post.verifyCode') or ajax_error('请输入手机验证码!');
     // 验证手机号
     $userModel = new \Common\Model\UserModel();
     $userModel->verifyCode($this->_user['mobile'], $verifyCode) or ajax_error($userModel->getError());
     $user = $userModel->field('salt')->where(['uid' => $this->_user['uid']])->find() or ajax_error('ACCOUNT_NOT_FOUND', '此账号不存在!');
     // 更新密码
     M('snack_building_master')->where(['uid' => $this->_user['uid']])->setField('trade_password', $userModel->password($password, $user['salt']));
     ajax_success();
 }
 public function login()
 {
     if (isset($_POST['dosubmit'])) {
         $account = I('post.account');
         $password = I('post.password');
         $identifying = I('post.identifying');
         if (empty($account)) {
             $this->error("请输入用户名");
         }
         if (empty($password)) {
             $this->error("请输入密码");
         }
         if (empty($identifying)) {
             $this->error("请输入验证码");
         }
         if (!check_verify($identifying)) {
             $this->error("亲,验证码输错了哦");
             exit;
         }
         $user = new \Common\Model\UserModel();
         $data = $user->where(array("account" => $account))->find();
         if (is_null($data) || empty($data)) {
             $this->error("用户名或者密码错误");
             exit;
         }
         //判断是否是站长
         /*if ($data['mn']!=1) {//是否是小区(对应user表中的ccode字段)站长  0否  1是
              $this->error("您不是小区站长");exit();
           }*/
         $password = md5($password);
         if ($data['mn'] != 1) {
             $this->error("您不是小区站长");
             exit;
         }
         if ($password == $data['pwd']) {
             session("home_userid", $data['id']);
             cookie('userid', $data['id'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             $ccode = $data['ccode'];
             //小区代码
             $CommunityModel = new \Common\Model\CommunityModel();
             $CommunityName = $CommunityModel->getNameByCcode($ccode);
             cookie('nickname', $data['nickname'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('CommunityName', $CommunityName, array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('account', $data['account'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             cookie('score', $data['score'], array('expire' => 86400 * 30, 'prefix' => 'home_'));
             //查询用户的当前佣金
             $curcash = M('agent')->where(array('uid' => $data['id']))->getField('curcash');
             if (empty($curcash) || is_null($curcash)) {
                 $curcash = 0;
             }
             cookie('curcash', $curcash, array('expire' => 86400 * 30, 'prefix' => 'home_'));
             //登陆成功
             //查询用户的邀请码
             $UsericodeModel = new \Common\Model\UsericodeModel();
             $UserCode = $UsericodeModel->getCode($data['id']);
             cookie('UserCode', $UserCode, array('expire' => 86400 * 30, 'prefix' => 'home_'));
             $this->success("登陆成功", "/Home/Index/index");
         } else {
             $this->error("用户名或者密码错误");
             exit;
         }
     } else {
         $this->display();
     }
 }
 /**
  * 设置用户的交易密码(若没有用户记录,则会自动初始化)
  *
  * @param int $uid 用户编号
  * @param string $password 交易密码
  *       
  * @return boolean
  */
 public function checkPassword($uid, $password)
 {
     $userModel = new \Common\Model\UserModel();
     $user = $userModel->field('salt')->find($uid);
     if (!$user) {
         return $this->_error('此用户不存在!');
     }
     $password_encode = $userModel->password($password, $user['salt']);
     return $this->where(['uid' => $uid])->getField('password') == $password_encode;
 }
 public function verify()
 {
     if (I('post.month', 0, 'intval') > 0) {
         $userModel = new \Common\Model\UserModel();
         $verify_code = I('post.verify_code') or $this->error('请输入手机验证码');
         $userModel->verifyCode(I('post.mobile'), $verify_code) or $this->error($userModel->getError());
     }
 }
 public function check_success($id)
 {
     $company = $this->find($id);
     if (!$company) {
         $this->error = '此商铺信息不存在!';
         return false;
     }
     if ($company['status'] == 1) {
         $this->error = '禁止操作:此商铺信息已审核通过,请刷新后重试';
         return false;
     }
     // 判断信息是否完善
     if (!$company['name']) {
         $this->error = '请先输入商铺名!';
         return false;
     }
     // 需更新的数据
     $data = ['status' => 1];
     // 关联账号
     if ($company['uid'] == 0) {
         // 未关联,则读取手机号
         $mobile = $company['telephone'];
         if (!preg_match('/^1\\d{10}$/', $mobile)) {
             $this->error = '自动关联商家账号时,无法读取正确的手机号!';
             return false;
         }
         $uname = $realname = trim($company['contact']);
         if (!$uname) {
             $this->error = '自动关联商家账号时,无法读取商家用户名!';
             return false;
         }
         $uid = M('user')->where(['mobile' => $mobile])->getField('uid');
         if (!$uid) {
             // 自动创建用户
             $userModel = new \Common\Model\UserModel();
             $uid = $userModel->addUser($mobile, $uname, $realname, uniqid());
             if (!$uname) {
                 $this->error = $userModel->getError();
                 return false;
             }
         }
         $data['uid'] = $uid;
     }
     $this->where(['id' => $id])->save($data);
     return true;
 }