123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace Home\Controller;
- use Think\Model;
- use Overtrue\Pinyin\Pinyin;
- /**
- * DuduApi
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-01T21:51:08+0800
- */
- class DuduApiController extends CommonController {
- /**
- * [_initialize 前置操作-继承公共前置方法]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-03T12:39:08+0800
- */
- public function _initialize() {
- // 调用父类前置方法
- parent::_initialize();
- }
- public function addUser() {
- $uid = I('uid');//iptv业务编号
- $where['uid'] = $uid;
- $user = M('iptv_users')->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');
- }
-
- }
|