distribution.action.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. class distributionModule extends baseModule
  3. {
  4. /**
  5. * 分销/邀请注册奖励模块
  6. */
  7. public function index()
  8. {
  9. $root = array('status' => 1,'error'=>'');
  10. if(!$GLOBALS['user_info']){
  11. $root['error'] = "用户未登陆,请先登陆." .print_r($_COOKIE,1);
  12. $root['status'] = 0;
  13. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  14. }else{
  15. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  16. $page = intval($_REQUEST['p']);//取第几页数据
  17. if($page==0){
  18. $page = 1;
  19. }
  20. $page_size=30;
  21. $limit = (($page-1)*$page_size).",".$page_size;
  22. $sql = "select dl.id,dl.diamonds as ticket,dl.diamonds,dl.from_user_id as user_id,u.head_image,u.nick_name as user_name,u.nick_name from ".DB_PREFIX."distribution_log dl left join ".DB_PREFIX."user as u on u.id = dl.from_user_id where dl.to_user_id = ".$user_id." group by dl.from_user_id order by dl.ticket desc limit ".$limit ;
  23. $list = $GLOBALS['db']->getAll($sql,true,true);
  24. foreach($list as $k=>$v){
  25. $m_config = load_auto_cache("m_config");//初始化手机端配置
  26. if($v['head_image']=='')$v['head_image'] = $m_config['app_logo'];
  27. $list[$k]['head_image'] = get_spec_image($v['head_image'],150,150);
  28. $list[$k]['nick_name'] = emoji_decode($v['nick_name']);
  29. $list[$k]['user_name'] = emoji_decode($v['user_name']);
  30. }
  31. $rs_count = count($list);
  32. if ($page == 1) {
  33. $root['page'] = array('page' => $page, 'has_next' => 0);
  34. }else {
  35. $has_next = ($rs_count > $page * $page_size) ? '1' : '0';
  36. $root['page'] = array('page' => $page, 'has_next' => $has_next);
  37. }
  38. $root['data'] = $list;
  39. }
  40. ajax_return($root);
  41. }
  42. /**
  43. * 邀请注册奖励注册——页面
  44. */
  45. public function init_register()
  46. {
  47. $root = array('status' => 0,'error'=>'');
  48. $share_id = intval($_REQUEST['user_id']);
  49. $root['url'] =SITE_DOMAIN.'/mapi/index.php?ctl=distribution&act=register&user_id='.$share_id;
  50. $root['page_title'] = '手机注册';
  51. $root['app_down_url'] = SITE_DOMAIN."/appdown.php";
  52. api_ajax_return($root);
  53. }
  54. /**
  55. * 邀请注册奖励——保存
  56. */
  57. public function register()
  58. {
  59. $root = array('status' => 1,'error'=>'');
  60. if(!$_REQUEST)
  61. {
  62. app_redirect(get_domain()."/");
  63. }
  64. $user_id = intval($_REQUEST['user_id']);
  65. $mobile = strim($_REQUEST['mobile']);
  66. if($mobile==''){
  67. $root['error'] = "手机号码不能为空!";
  68. $root['status'] = 0;
  69. api_ajax_return($root);
  70. }
  71. if(!check_mobile($mobile))
  72. {
  73. $result['info'] = '手机格式错误';
  74. $root['status'] = 0;
  75. api_ajax_return($root);
  76. }
  77. $root['url'] = SITE_DOMAIN."/appdown.php";
  78. $p_user_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user where id =" . $user_id);
  79. if(intval($p_user_id)==0){
  80. $root['error'] = "上级用户不存在!";
  81. $root['status'] = 0;
  82. api_ajax_return($root);
  83. }
  84. $mobile = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user where mobile =" . $mobile);
  85. if($mobile!=''){
  86. $root['is_url'] = 1;
  87. $root['error'] = "手机号已注册!";
  88. $root['status'] = 0;
  89. }
  90. if($root['status']!=0){
  91. fanwe_require(APP_ROOT_PATH."system/libs/user.php");
  92. $result = do_login_user($_REQUEST['mobile'],$_REQUEST['verify_coder']);
  93. }
  94. if($result['status'])
  95. {
  96. $root['user_id'] = $result['user']['id'];
  97. $root['status'] = 1;
  98. if($result['user']['head_image']==''||$result['user_info']['head_image']==''){
  99. //头像
  100. $m_config = load_auto_cache("m_config");//初始化手机端配置
  101. $system_head_image = $m_config['app_logo'];
  102. if($system_head_image==''){
  103. $system_head_image = './public/attachment/test/noavatar_10.JPG';
  104. syn_to_remote_image_server($system_head_image,false);
  105. }
  106. $data = array(
  107. 'head_image' => $system_head_image,
  108. 'thumb_head_image' => get_spec_image($system_head_image,40,40),
  109. 'p_user_id' =>$p_user_id,
  110. );
  111. $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data,"UPDATE", "id=".$result['user']['id']);
  112. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  113. $user_redis = new UserRedisService();
  114. $user_redis->update_db($result['user']['id'],$data);
  115. //更新session
  116. $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id =" . $result['user']['id']);
  117. es_session::set("user_info", $user_info);
  118. }
  119. $result['user_info']['head_image'] = $system_head_image;
  120. $root['is_url'] = 1;
  121. $root['is_lack'] = $result['is_lack'];//是否缺少用户信息
  122. $root['is_agree'] = intval($result['user']['is_agree']);//是否同意直播协议 0 表示不同意 1表示同意
  123. $root['user_id'] = intval($result['user']['id']);
  124. $root['nick_name'] = $result['user']['nick_name'];
  125. $root['family_id']=intval($result['user']['family_id']);
  126. $root['family_chieftain']=intval($result['user']['family_chieftain']);
  127. $root['error'] = "注册成功";
  128. $root['user_info'] = $result['user_info'];
  129. if(intval(OPEN_REWARD_POINT)==1){
  130. $this->do_reward_point($root['user_id']);
  131. }
  132. }
  133. else
  134. {
  135. $root['status'] = 0;
  136. if($root['error']=='')$root['error'] = $result['info'];
  137. }
  138. api_ajax_return($root);
  139. }
  140. /**
  141. * 邀请奖励处理
  142. * @param $user_id
  143. * @return array
  144. */
  145. private function do_reward_point($user_id)
  146. {
  147. $root = array();
  148. $m_config = load_auto_cache("m_config");//初始化手机端配置
  149. $total_diamonds = intval($m_config['reward_point_diamonds']);
  150. $table = DB_PREFIX . 'distribution_log';
  151. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  152. $user_redis = new UserRedisService();
  153. $to_user_id = $user_redis->getOne_db($user_id, 'p_user_id');//用户总的:印票数
  154. $result = 0;
  155. if (intval($to_user_id) > 0 && $user_id > 0 && $total_diamonds > 0) {
  156. $sql = "select id from " . $table . " where type = 1 and to_user_id = " . $to_user_id . " and from_user_id = " . $user_id;
  157. $distribution_id = $GLOBALS['db']->getOne($sql);
  158. if (intval($distribution_id) > 0) {
  159. $sql = "update " . $table . " set diamonds = diamonds + " . $total_diamonds . " where id = " . $distribution_id;
  160. $GLOBALS['db']->query($sql);
  161. $result = 1;
  162. } else {
  163. //插入:邀请奖励日志
  164. $video_prop = array();
  165. $video_prop['from_user_id'] = $user_id;
  166. $video_prop['to_user_id'] = $to_user_id;
  167. $video_prop['create_date'] = "'" . to_date(NOW_TIME, 'Y-m-d') . "'";
  168. $video_prop['diamonds'] = $total_diamonds;
  169. $video_prop['create_time'] = NOW_TIME;
  170. $video_prop['create_ym'] = to_date($video_prop['create_time'], 'Ym');
  171. $video_prop['create_d'] = to_date($video_prop['create_time'], 'd');
  172. $video_prop['create_w'] = to_date($video_prop['create_time'], 'W');
  173. $video_prop['type'] = 1;
  174. //将日志写入mysql表中
  175. $field_arr = array(
  176. 'from_user_id',
  177. 'to_user_id',
  178. 'create_date',
  179. 'diamonds',
  180. 'create_time',
  181. 'create_ym',
  182. 'create_d',
  183. 'create_w',
  184. 'type'
  185. );
  186. $fields = implode(",", $field_arr);
  187. $valus = implode(",", $video_prop);
  188. $sql = "insert into " . $table . "(" . $fields . ") VALUES (" . $valus . ")";
  189. $GLOBALS['db']->query($sql);
  190. $result = $GLOBALS['db']->insert_id();
  191. }
  192. if (intval($result) > 0) {
  193. $sql = "update " . DB_PREFIX . "user set diamonds = diamonds + " . $total_diamonds . " where id = " . $to_user_id;
  194. $GLOBALS['db']->query($sql);
  195. }
  196. }
  197. return $root;
  198. }
  199. }
  200. ?>