DuduApiController.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Model;
  4. use Overtrue\Pinyin\Pinyin;
  5. /**
  6. * DuduApi
  7. * @author Devil
  8. * @blog http://gong.gg/
  9. * @version 0.0.1
  10. * @datetime 2016-12-01T21:51:08+0800
  11. */
  12. class DuduApiController extends CommonController {
  13. /**
  14. * [_initialize 前置操作-继承公共前置方法]
  15. * @author Devil
  16. * @blog http://gong.gg/
  17. * @version 0.0.1
  18. * @datetime 2016-12-03T12:39:08+0800
  19. */
  20. public function _initialize() {
  21. // 调用父类前置方法
  22. parent::_initialize();
  23. }
  24. public function addUser() {
  25. $uid = I('uid');//iptv业务编号
  26. $where['uid'] = $uid;
  27. $user = M('iptv_users')->where($where)->find();
  28. if (!empty($uid)&&!$user) {//第一次登录
  29. $argv['uid'] = $uid;
  30. $argv['user_token'] = I('UserToken');
  31. $argv['created_at'] = date('Y-m-d H:i:s');
  32. $argv['last_login_at'] = date('Y-m-d H:i:s');
  33. // $argv['expired_time'] = I('ExpiredTime');
  34. if (M('iptv_users')->add($argv)) {
  35. $this->userLogin($uid);//记录登录
  36. $this->responseSuccess('', '记录成功!');
  37. } else {
  38. $this->responseError('', '记录失败');
  39. }
  40. } else {
  41. $data['user_token'] = I('UserToken');
  42. $data['last_login_at'] = date('Y-m-d H:i:s');
  43. M('iptv_users')->where($where)->save($data);
  44. $this->userLogin($uid);//记录登录
  45. $this->responseSuccess('', '用户存在!');
  46. }
  47. }
  48. /**
  49. * 模拟用户登录记录登录日志
  50. * @author brent
  51. */
  52. private function userLogin($uid){
  53. $where = array();
  54. $where['uid'] = $uid;
  55. //判断该用户是否存在
  56. $userdata = M('iptv_users')->where($where)->find();
  57. if (!isset($userdata) || empty($userdata)) {
  58. $this->responseError('用户不存在!', -1);
  59. }
  60. $data['uid'] = $uid;
  61. $data['created_at'] = date('Y-m-d H:i:s');
  62. $data['updated_at'] = date('Y-m-d H:i:s');
  63. if (M('iptv_user_login_log')->add($data)) {
  64. cookie('LoginStatus',100);//设置登录cookie//防止重复登录
  65. $this->responseSuccess('', '记录成功!');
  66. } else {
  67. $this->responseError('记录失败', -1, $error);
  68. }
  69. }
  70. // 订购结果
  71. public function payResult()
  72. {
  73. $uid = I('uid');
  74. $product_id = I('product_id');
  75. $pay_result = I('pay_result',0);
  76. $type = I('type',0);
  77. if (empty($uid)) {
  78. $this->responseError('参数错误', -1);
  79. }
  80. $where['uid'] = $uid;
  81. $where['pay_result'] = 0;
  82. $where['created_at'] = array(
  83. array("gt", date('Y-m-01')),
  84. );
  85. $order = M('iptv_order')->where($where)->find();
  86. // echo M()->getlastSQL();die;
  87. if(empty($order)){
  88. $data['uid'] = $uid;
  89. $data['product_id'] = $product_id;
  90. $data['pay_result'] = $pay_result;
  91. $data['created_at'] = date('Y-m-d H:i:s');
  92. if(M('iptv_order')->add($data)){
  93. $this->responseSuccess([], 'success');
  94. }else{
  95. $this->responseSuccess([], 'failed');
  96. }
  97. }
  98. $this->responseSuccess([], 'success');
  99. }
  100. }