XyPromoterTwoAction.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class XyPromoterTwoAction extends CommonAction
  10. {
  11. public function index()
  12. {
  13. $map['pid']=array('gt',0);
  14. $map['status']=array('eq',1);
  15. if (trim($_REQUEST['name']) != '') {
  16. $map['name'] = array('like', '%' . trim($_REQUEST['name']) . '%');
  17. }
  18. $mobile = strim($_REQUEST['mobile']);
  19. if ($mobile != '') {
  20. $map['mobile'] = array('eq', $mobile);
  21. }
  22. $id = intval($_REQUEST['id']);
  23. if ($id) {
  24. $map['id'] = array('eq', $id);
  25. }
  26. $create_time_2=empty($_REQUEST['create_time_2'])?to_date(get_gmtime(),'Y-m-d'):strim($_REQUEST['create_time_2']);
  27. $create_time_2=to_timespan($create_time_2)+24*3600;
  28. if(trim($_REQUEST['create_time_1'])!='')
  29. {
  30. $map["create_time"] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  31. }
  32. $user_id = intval($_REQUEST['user_id']);
  33. if($user_id){
  34. $map['user_id'] = array('eq', $user_id);
  35. }
  36. $is_effect = intval($_REQUEST['is_effect']);
  37. if(isset($_REQUEST['is_effect']) && $is_effect >=0){
  38. $map['is_effect'] = array('eq', $is_effect);
  39. }
  40. $parent_name = strim($_REQUEST['parent_name']);
  41. if($parent_name){
  42. $parents=$GLOBALS['db']->getALL("select user_id from ".DB_PREFIX."bm_promoter where name like '%".$parent_name."%' and pid=0");
  43. if($parents){
  44. $parent_ids=array_map('array_shift',$parents);
  45. $map['pid'] = array('in', $parent_ids);
  46. }else{
  47. $map['pid'] = -1;
  48. }
  49. }
  50. $pid = intval($_REQUEST['pid']);
  51. if($pid){
  52. $map['pid'] = array('eq', $pid);
  53. }
  54. if (method_exists($this, '_filter')) {
  55. $this->_filter($map);
  56. }
  57. $name = 'BmPromoter';
  58. $model = M($name);
  59. if (!empty ($model)) {
  60. $this->_list($model, $map);
  61. }
  62. $this->display();
  63. }
  64. public function edit()
  65. {
  66. $id = intval($_REQUEST ['id']);
  67. $condition['id'] = $id;
  68. $vo = M("BmPromoter")->where($condition)->find();
  69. $vo['parent_name'] = M("BmPromoter")->where("user_id=".intval($vo['pid']))->getField("name");
  70. $vo['user'] = M("User")->where("id=".intval($vo['user_id'])."")->find();
  71. $this->assign('vo', $vo);
  72. $this->display();
  73. }
  74. public function update()
  75. {
  76. B('FilterString');
  77. $data = M("BmPromoter")->create();
  78. $data_info = M("BmPromoter")->where("id=" . intval($data['id']))->find();
  79. $log_info = $data_info['name'];
  80. if (!$data_info) {
  81. $this->error("请选择编辑的推广商");
  82. }
  83. if (!check_empty($data['mobile'])) {
  84. $this->error("登录手机号不能为空");
  85. }
  86. if (!check_mobile($data['mobile'])) {
  87. $this->error("请输入正确的手机号");
  88. }
  89. if (!check_empty($data['name'])) {
  90. $this->error("推广商名称不能为空");
  91. }
  92. $binding_mobile=strim($_REQUEST['binding_mobile']);
  93. if (!check_empty($binding_mobile)) {
  94. $this->error("绑定会员不能为空");
  95. }
  96. $check_user_info=$this->check_user($binding_mobile,$data_info['user_id']);
  97. $check_user=$check_user_info['user'];
  98. $check_user_id=intval($check_user['id']);
  99. if($check_user_info['status'] ==0){
  100. $this->error($check_user_info['info']);
  101. }
  102. // 更新数据
  103. if($data['pwd'] !=''){
  104. $data['pwd']=md5($data['pwd']);
  105. }else{
  106. unset($data['pwd']);
  107. }
  108. if($check_user_id>0 && $data_info['user_id'] != $check_user_id){
  109. $data['user_id']=$check_user_id;
  110. }
  111. $list = M("BmPromoter")->save($data);
  112. if (false !== $list) {
  113. if($check_user_id>0 && $data_info['user_id'] >0 && $data_info['user_id'] != $check_user_id){
  114. $GLOBALS['db']->query("update ".DB_PREFIX."user set bm_pid= ".intval($check_user_id)." where bm_pid=".intval($data_info['user_id'])."");
  115. }
  116. //成功提示
  117. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  118. $this->success(L("UPDATE_SUCCESS"));
  119. } else {
  120. //错误提示
  121. save_log($log_info . L("UPDATE_FAILED"), 0);
  122. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  123. }
  124. }
  125. public function set_effect()
  126. {
  127. $id = intval($_REQUEST['id']);
  128. $ajax = intval($_REQUEST['ajax']);
  129. $user_info = M("BmPromoter")->getById($id);
  130. $c_is_effect = M("BmPromoter")->where("id=".$id)->getField("is_effect"); //当前状态
  131. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  132. $result=M("BmPromoter")->where("id=".$id)->setField("is_effect",$n_is_effect);
  133. save_log($user_info['user_name'].l("SET_EFFECT_".$n_is_effect),1);
  134. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1);
  135. }
  136. //账户管理
  137. public function account()
  138. {
  139. require_once APP_ROOT_PATH."/admin/Lib/Action/UserCommonAction.class.php";
  140. require_once APP_ROOT_PATH."/system/libs/user.php";
  141. $common = new UserCommon();
  142. $data = $_REQUEST;
  143. $status = $common->account($data);
  144. }
  145. //账户修改
  146. public function modify_account()
  147. {
  148. require_once APP_ROOT_PATH."/admin/Lib/Action/UserCommonAction.class.php";
  149. require_once APP_ROOT_PATH."/system/libs/user.php";
  150. $common = new UserCommon();
  151. $data = $_REQUEST;
  152. $status = $common->modify_account($data);
  153. if($status){
  154. $this->success(L("UPDATE_SUCCESS"));
  155. }else{
  156. $this->error("累计充值数据有误!");
  157. }
  158. }
  159. public function delete()
  160. {
  161. }
  162. public function foreverdelete()
  163. {
  164. }
  165. //检查绑定会员
  166. public function check_user($binding_mobile,$binding_user_id_old)
  167. {
  168. $return=array("status"=>0,"info"=>"");
  169. $binding_mobile=$binding_mobile?$binding_mobile:strim($_REQUEST['binding_mobile']);
  170. $binding_user_id_old=$binding_user_id_old?$binding_user_id_old:intval($_REQUEST['binding_user_id_old']);
  171. $ajax=intval($_REQUEST['ajax']);
  172. if(!check_mobile($binding_mobile)){
  173. $return["info"]="请输入正确的会员的手机号";
  174. $this->return_info($return,$ajax);
  175. }
  176. //是否有会员
  177. $user_info=$GLOBALS['db']->getRow("select id,bm_pid,is_effect,nick_name,society_id from ".DB_PREFIX."user where mobile= ".$binding_mobile." ");
  178. if(!$user_info){
  179. $return["status"]=0;
  180. $return["info"]="会员未注册,请注册后再绑定";
  181. return $this->return_info($return,$ajax);
  182. }
  183. //编辑时,如果和原来的user_id值一样,直接返回会员信息
  184. if($binding_user_id_old == $user_info['id']){
  185. $return["status"]=1;
  186. $return["user"]=$user_info;
  187. return $this->return_info($return,$ajax);
  188. }
  189. //会员是否有效
  190. if($user_info['is_effect'] ==0){
  191. $return["status"]=0;
  192. $return["info"]="无效的会员";
  193. return $this->return_info($return,$ajax);
  194. }
  195. //是否是三级推广会员
  196. if($user_info['bm_pid'] >0){
  197. $return["status"]=0;
  198. $return["info"]="该会员已是公会,不能绑定";
  199. return $this->return_info($return,$ajax);
  200. }
  201. //是否是公会成员
  202. if($user_info['society_id'] >0){
  203. $return["status"]=0;
  204. $return["info"]="该会员已是公会成员,不能绑定";
  205. return $this->return_info($return,$ajax);
  206. }
  207. //是否已是绑定推广商
  208. $count_promoter=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where user_id=".intval($user_info['id'])."");
  209. if($count_promoter >0){
  210. $return["status"]=0;
  211. $return["info"]="该会员被绑定了";
  212. return $this->return_info($return,$ajax);
  213. }
  214. $return["status"]=1;
  215. $return["user"]=$user_info;
  216. return $this->return_info($return,$ajax);
  217. }
  218. public function return_info($data,$ajax)
  219. {
  220. if(intval($ajax) ==1){
  221. echo admin_ajax_return($data);
  222. exit;
  223. }else{
  224. return $data;
  225. }
  226. }
  227. //收礼物日志
  228. public function closed_prop(){
  229. $now=get_gmtime();
  230. $promoter_id = intval($_REQUEST['promoter_id']);
  231. $promoter_info=$GLOBALS['db']->getRow("select id,name,user_id from ".DB_PREFIX."bm_promoter where id= ".$promoter_id."");
  232. if(!$promoter_info){
  233. $this->error("请选择查看对象");
  234. }
  235. $prop_list = M("prop")->where("is_effect <>0")->findAll();
  236. //输出搜索年月
  237. $current_Year = date('Y');
  238. $current_YM = to_date(NOW_TIME,'Ym');
  239. for ($i=0; $i<5; $i++)
  240. {
  241. $years_list[$i] = $current_Year - $i;
  242. }
  243. for ($i=01; $i<13; $i++)
  244. {
  245. $month_list[$i] = str_pad(0+$i,2,0,STR_PAD_LEFT);
  246. }
  247. $user_id = intval($promoter_info['user_id']);
  248. $user_ids=$GLOBALS['db']->getALL("select id from ".DB_PREFIX."user where society_id in (select society_id from ".DB_PREFIX."user where bm_pid=".$user_id.")");
  249. if(!$user_ids){
  250. $this->assign("promoter_info",$promoter_info);
  251. $this->assign("prop",$prop_list);
  252. $this->assign("years_list",$years_list);
  253. $this->assign("month_list",$month_list);
  254. $this->assign("list", array());
  255. $this->assign("count",intval($count));
  256. $this->assign('total_ticket',intval($total_ticket));
  257. $this->display ();
  258. exit;
  259. }
  260. $user_ids=array_map('array_shift',$user_ids);
  261. $where = "l.to_user_id in(".implode(',',$user_ids).")";
  262. $model = D ("video_prop");
  263. //赠送时间
  264. $years =isset($_REQUEST['years'])?strim($_REQUEST['years']):-1;
  265. $month =isset($_REQUEST['month'])?strim($_REQUEST['month']):-1;
  266. if($years !=-1 && $years==-1){
  267. $this->error("请选择月份");
  268. }
  269. if($years==-1 && $month !=-1){
  270. $this->error("请选择年份");
  271. }
  272. if($years !=-1 && $month !=-1){
  273. $time=$years.''.$month;
  274. }else{
  275. $time=$current_YM;
  276. }
  277. //查询ID
  278. $from_user_id = intval($_REQUEST['from_user_id']);
  279. if($from_user_id>0){
  280. $parameter.= "l.from_user_id=".$from_user_id. "&";
  281. $sql_w .= "l.from_user_id=".$from_user_id." and ";
  282. }
  283. //查询昵称
  284. $nick_name = strim($_REQUEST['nick_name']);
  285. if($nick_name!='')
  286. {
  287. $parameter.= "u.nick_name like " . urlencode ( '%'.$nick_name.'%' ) . "&";
  288. $sql_w .= "u.nick_name like '%".$nick_name."%' and ";
  289. }
  290. $prop_id = intval($_REQUEST['prop_id']);
  291. if($prop_id>0) {//查询礼物
  292. $parameter .= "l.prop_id=" . intval($data['prop_id']) . "&";
  293. $sql_w .= "l.prop_id=" . intval($data['prop_id']) . " and ";
  294. }
  295. $sql_str = "SELECT l.id,l.create_ym,l.to_user_id, l.create_time,l.prop_id,l.prop_name,l.from_user_id,l.create_date,l.num,l.total_ticket,u.nick_name
  296. FROM ".DB_PREFIX."video_prop_".$time." as l
  297. LEFT JOIN ".DB_PREFIX."user AS u ON l.from_user_id = u.id" ." LEFT JOIN ".DB_PREFIX."prop AS v ON l.prop_name = v.name" ."
  298. WHERE $where "." and ".$sql_w." 1=1 ";
  299. $count_sql = "SELECT count(l.id) as tpcount
  300. FROM ".DB_PREFIX."video_prop_".$time." as l
  301. LEFT JOIN ".DB_PREFIX."user AS u ON l.from_user_id = u.id" ." LEFT JOIN ".DB_PREFIX."prop AS v ON l.prop_name = v.name" ."
  302. WHERE $where "." and ".$sql_w." 1=1 ";
  303. $total_ticket_sql = "SELECT SUM(l.total_ticket) as tpcount
  304. FROM ".DB_PREFIX."video_prop_".$time." as l
  305. LEFT JOIN ".DB_PREFIX."user AS u ON l.from_user_id = u.id" ." LEFT JOIN ".DB_PREFIX."prop AS v ON l.prop_name = v.name" ."
  306. WHERE $where "." and ".$sql_w." 1=1 ";
  307. $count = $GLOBALS['db']->getOne($count_sql);
  308. $total_ticket = $GLOBALS['db']->getOne($total_ticket_sql);
  309. $volist = $this->_Sql_list($model,$sql_str,'&'.$parameter,1,0,$count_sql);
  310. foreach($volist as $k=>$v){
  311. if($volist[$k]['prop_id']==12){
  312. $volist[$k]['total_ticket']='';
  313. }
  314. $volist[$k]['create_time']=date('Y-m-d',$volist[$k]['create_time']);
  315. }
  316. $this->assign("promoter_info",$promoter_info);
  317. $this->assign("prop",$prop_list);
  318. $this->assign("years_list",$years_list);
  319. $this->assign("month_list",$month_list);
  320. $this->assign("list", $volist);
  321. $this->assign("count",intval($count));
  322. $this->assign('total_ticket',intval($total_ticket));
  323. $this->display ();
  324. }
  325. }
  326. ?>