where($where)->find(); if (!empty($uid)&&!$user) {//第一次登录 $argv['uid'] = $uid; $argv['user_token'] = I('UserToken'); $argv['created_at'] = date('Y-m-d H:i:s'); $argv['last_login_at'] = date('Y-m-d H:i:s'); // $argv['expired_time'] = I('ExpiredTime'); if (M('iptv_users')->add($argv)) { $this->userLogin($uid);//记录登录 $this->responseSuccess('', '记录成功!'); } else { $this->responseError('', '记录失败'); } } else { $data['user_token'] = I('UserToken'); $data['last_login_at'] = date('Y-m-d H:i:s'); M('iptv_users')->where($where)->save($data); $this->userLogin($uid);//记录登录 $this->responseSuccess('', '用户存在!'); } } /** * 模拟用户登录记录登录日志 * @author brent */ private function userLogin($uid){ $where = array(); $where['uid'] = $uid; //判断该用户是否存在 $userdata = M('iptv_users')->where($where)->find(); if (!isset($userdata) || empty($userdata)) { $this->responseError('用户不存在!', -1); } $data['uid'] = $uid; $data['created_at'] = date('Y-m-d H:i:s'); $data['updated_at'] = date('Y-m-d H:i:s'); if (M('iptv_user_login_log')->add($data)) { cookie('LoginStatus',100);//设置登录cookie//防止重复登录 $this->responseSuccess('', '记录成功!'); } else { $this->responseError('记录失败', -1, $error); } } // 订购结果 public function payResult() { $uid = I('uid'); $product_id = I('product_id'); $pay_result = I('pay_result',0); $type = I('type',0); if (empty($uid)) { $this->responseError('参数错误', -1); } $where['uid'] = $uid; $where['pay_result'] = 0; $where['created_at'] = array( array("gt", date('Y-m-01')), ); $order = M('iptv_order')->where($where)->find(); // echo M()->getlastSQL();die; if(empty($order)){ $data['uid'] = $uid; $data['product_id'] = $product_id; $data['pay_result'] = $pay_result; $data['created_at'] = date('Y-m-d H:i:s'); if(M('iptv_order')->add($data)){ $this->responseSuccess([], 'success'); }else{ $this->responseSuccess([], 'failed'); } } $this->responseSuccess([], 'success'); } }