BmPromoterTwoAction.class.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 BmPromoterTwoAction extends CommonAction
  10. {
  11. public function index()
  12. {
  13. //更新推广商子集个数
  14. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/NewModel.class.php');
  15. fanwe_require(APP_ROOT_PATH . 'mapi/lib/models/bm_promoterModel.class.php');
  16. $bm_promoter_obj = new bm_promoterModel();
  17. $bm_promoter_obj->update_promoter_two_child(0,600,'admin');
  18. $map['pid']=array('gt',0);
  19. $map['status']=array('eq',1);
  20. if (trim($_REQUEST['name']) != '') {
  21. $map['name'] = array('like', '%' . trim($_REQUEST['name']) . '%');
  22. }
  23. $mobile = strim($_REQUEST['mobile']);
  24. if ($mobile != '') {
  25. $map['mobile'] = array('eq', $mobile);
  26. }
  27. $id = intval($_REQUEST['id']);
  28. if ($id) {
  29. $map['id'] = array('eq', $id);
  30. }
  31. $create_time_2=empty($_REQUEST['create_time_2'])?to_date(get_gmtime(),'Y-m-d'):strim($_REQUEST['create_time_2']);
  32. $create_time_2=to_timespan($create_time_2)+24*3600;
  33. if(trim($_REQUEST['create_time_1'])!='')
  34. {
  35. $map["create_time"] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  36. }
  37. $binding_user_id = intval($_REQUEST['binding_user_id']);
  38. if($binding_user_id){
  39. $map['user_id'] = array('eq', $binding_user_id);
  40. }
  41. $is_effect = intval($_REQUEST['is_effect']);
  42. if(isset($_REQUEST['is_effect']) && $is_effect >=0){
  43. $map['is_effect'] = array('eq', $is_effect);
  44. }
  45. $parent_name = strim($_REQUEST['parent_name']);
  46. if($parent_name){
  47. $parents=$GLOBALS['db']->getALL("select user_id from ".DB_PREFIX."bm_promoter where name like '%".$parent_name."%'");
  48. if($parents){
  49. $parent_ids=array_map('array_shift',$parents);
  50. $map['pid'] = array('in', $parent_ids);
  51. }else{
  52. $map['pid'] = -1;
  53. }
  54. }
  55. $p_promoter_id = intval($_REQUEST['p_promoter_id']);
  56. if($p_promoter_id >0){
  57. $p_user_id=$GLOBALS['db']->getOne("select user_id from ".DB_PREFIX."bm_promoter where id=".$p_promoter_id." ");
  58. $map['pid'] = array('eq', $p_user_id);
  59. }
  60. if (method_exists($this, '_filter')) {
  61. $this->_filter($map);
  62. }
  63. $name = 'BmPromoter';
  64. $model = M($name);
  65. if (!empty ($model)) {
  66. $this->_list($model, $map);
  67. }
  68. $this->display();
  69. }
  70. public function edit()
  71. {
  72. $id = intval($_REQUEST ['id']);
  73. $condition['id'] = $id;
  74. $vo = M("BmPromoter")->where($condition)->find();
  75. $vo['parent_name'] = M("BmPromoter")->where("user_id=".intval($vo['pid']))->getField("name");
  76. $vo['user'] = M("User")->where("id=".intval($vo['user_id'])."")->find();
  77. $this->assign('vo', $vo);
  78. $this->display();
  79. }
  80. public function update()
  81. {
  82. B('FilterString');
  83. $data = M("BmPromoter")->create();
  84. $data_info = M("BmPromoter")->where("id=" . intval($data['id']))->find();
  85. $log_info = $data_info['name'];
  86. if (!$data_info) {
  87. $this->error("请选择编辑的推广商");
  88. }
  89. if (!check_empty($data['mobile'])) {
  90. $this->error("登录手机号不能为空");
  91. }
  92. if (!check_mobile($data['mobile'])) {
  93. $this->error("请输入正确的手机号");
  94. }
  95. if(intval($GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where mobile='".$data['mobile']."' and status =1 and id <> ".intval($data_info['id'])."") )>0){
  96. $this->error("登录手机号已存在");
  97. }
  98. if (!check_empty($data['name'])) {
  99. $this->error("推广商名称不能为空");
  100. }
  101. if(intval($GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where name='".$data['name']."' and status =1 and id <> ".intval($data_info['id'])."") )>0){
  102. $this->error("推广商名称已存在");
  103. }
  104. $binding_mobile=strim($_REQUEST['binding_mobile']);
  105. if (!check_empty($binding_mobile)) {
  106. $this->error("绑定会员不能为空");
  107. }
  108. $check_user_info=$this->check_user($binding_mobile,$data_info['user_id']);
  109. $check_user=$check_user_info['user'];
  110. $check_user_id=intval($check_user['id']);
  111. if($check_user_info['status'] ==0){
  112. $this->error($check_user_info['info']);
  113. }
  114. // 更新数据
  115. if($data['pwd'] !=''){
  116. $data['pwd']=md5($data['pwd']);
  117. }else{
  118. unset($data['pwd']);
  119. }
  120. if($check_user_id>0 && $data_info['user_id'] != $check_user_id){
  121. $data['user_id']=$check_user_id;
  122. }
  123. $list = M("BmPromoter")->save($data);
  124. if (false !== $list) {
  125. if($check_user_id>0 && $data_info['user_id'] >0 && $data_info['user_id'] != $check_user_id){
  126. $GLOBALS['db']->query("update ".DB_PREFIX."user set bm_pid= ".intval($check_user_id)." where bm_pid=".intval($data_info['user_id'])."");
  127. }
  128. //成功提示
  129. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  130. $this->success(L("UPDATE_SUCCESS"));
  131. } else {
  132. //错误提示
  133. save_log($log_info . L("UPDATE_FAILED"), 0);
  134. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  135. }
  136. }
  137. public function set_effect()
  138. {
  139. $id = intval($_REQUEST['id']);
  140. $ajax = intval($_REQUEST['ajax']);
  141. $user_info = M("BmPromoter")->getById($id);
  142. $c_is_effect = M("BmPromoter")->where("id=".$id)->getField("is_effect"); //当前状态
  143. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  144. $result=M("BmPromoter")->where("id=".$id)->setField("is_effect",$n_is_effect);
  145. save_log($user_info['user_name'].l("SET_EFFECT_".$n_is_effect),1);
  146. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1);
  147. }
  148. //账户管理
  149. public function account()
  150. {
  151. require_once APP_ROOT_PATH."/admin/Lib/Action/UserCommonAction.class.php";
  152. require_once APP_ROOT_PATH."/system/libs/user.php";
  153. $common = new UserCommon();
  154. $data = $_REQUEST;
  155. $status = $common->account($data);
  156. }
  157. //账户修改
  158. public function modify_account()
  159. {
  160. require_once APP_ROOT_PATH."/admin/Lib/Action/UserCommonAction.class.php";
  161. require_once APP_ROOT_PATH."/system/libs/user.php";
  162. $common = new UserCommon();
  163. $data = $_REQUEST;
  164. $status = $common->modify_account($data);
  165. if($status){
  166. $this->success(L("UPDATE_SUCCESS"));
  167. }else{
  168. $this->error("累计充值数据有误!");
  169. }
  170. }
  171. public function delete()
  172. {
  173. }
  174. public function foreverdelete()
  175. {
  176. }
  177. //检查绑定会员
  178. public function check_user($binding_mobile,$binding_user_id_old)
  179. {
  180. $return=array("status"=>0,"info"=>"");
  181. $binding_mobile=$binding_mobile?$binding_mobile:strim($_REQUEST['binding_mobile']);
  182. $binding_user_id_old=$binding_user_id_old?$binding_user_id_old:intval($_REQUEST['binding_user_id_old']);
  183. $ajax=intval($_REQUEST['ajax']);
  184. if(!check_mobile($binding_mobile)){
  185. $return["info"]="请输入正确的会员的手机号";
  186. $this->return_info($return,$ajax);
  187. }
  188. //是否有会员
  189. $user_info=$GLOBALS['db']->getRow("select id,bm_pid,is_effect,nick_name from ".DB_PREFIX."user where mobile= ".$binding_mobile." ");
  190. if(!$user_info){
  191. $return["status"]=0;
  192. $return["info"]="会员未注册,请注册后再绑定";
  193. return $this->return_info($return,$ajax);
  194. }
  195. //编辑时,如果和原来的user_id值一样,直接返回会员信息
  196. if($binding_user_id_old == $user_info['id']){
  197. $return["status"]=1;
  198. $return["user"]=$user_info;
  199. return $this->return_info($return,$ajax);
  200. }
  201. //会员是否有效
  202. if($user_info['is_effect'] ==0){
  203. $return["status"]=0;
  204. $return["info"]="无效的会员";
  205. return $this->return_info($return,$ajax);
  206. }
  207. //是否是三级推广会员
  208. if($user_info['bm_pid'] >0){
  209. $return["status"]=0;
  210. $return["info"]="该会员已是推广会员,不能绑定";
  211. return $this->return_info($return,$ajax);
  212. }
  213. //是否已是绑定推广商
  214. $count_promoter=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where user_id=".intval($user_info['id'])."");
  215. if($count_promoter >0){
  216. $return["status"]=0;
  217. $return["info"]="该会员已绑定推广商";
  218. return $this->return_info($return,$ajax);
  219. }
  220. $return["status"]=1;
  221. $return["user"]=$user_info;
  222. return $this->return_info($return,$ajax);
  223. }
  224. public function return_info($data,$ajax)
  225. {
  226. if(intval($ajax) ==1){
  227. echo admin_ajax_return($data);
  228. exit;
  229. }else{
  230. return $data;
  231. }
  232. }
  233. }
  234. ?>