BmPromoterTwoSubmitAction.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 BmPromoterTwoSubmitAction extends CommonAction
  10. {
  11. public function index()
  12. {
  13. $map['pid']=array('gt',0);
  14. $map['status']=array('in','0,2');
  15. if (trim($_REQUEST['name']) != '') {
  16. $map['name'] = array('like', '%' . trim($_REQUEST['name']) . '%');
  17. }
  18. $create_time_2=empty($_REQUEST['create_time_2'])?to_date(get_gmtime(),'Y-m-d'):strim($_REQUEST['create_time_2']);
  19. $create_time_2=to_timespan($create_time_2)+24*3600;
  20. if(trim($_REQUEST['create_time_1'])!='')
  21. {
  22. $map["create_time"] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  23. }
  24. $user_id = intval($_REQUEST['user_id']);
  25. if($user_id){
  26. $map['user_id'] = array('eq', $user_id);
  27. }
  28. $status = intval($_REQUEST['status']);
  29. if(isset($_REQUEST['status']) && $status >=0){
  30. $map['status'] = array('eq', $status);
  31. }
  32. $parent_name = strim($_REQUEST['parent_name']);
  33. if($parent_name){
  34. $parents=$GLOBALS['db']->getALL("select user_id from ".DB_PREFIX."bm_promoter where name like '%".$parent_name."%' and pid=0");
  35. if($parents){
  36. $parent_ids=array_map('array_shift',$parents);
  37. $map['pid'] = array('in', $parent_ids);
  38. }else{
  39. $map['pid'] = -1;
  40. }
  41. }
  42. if (method_exists($this, '_filter')) {
  43. $this->_filter($map);
  44. }
  45. $name = 'BmPromoter';
  46. $model = M($name);
  47. if (!empty ($model)) {
  48. $this->_list($model, $map);
  49. }
  50. $this->display();
  51. }
  52. public function edit()
  53. {
  54. $id = intval($_REQUEST ['id']);
  55. $condition['id'] = $id;
  56. $vo = M("BmPromoter")->where($condition)->find();
  57. $vo['parent_name'] = M("BmPromoter")->where("user_id=".intval($vo['pid'])."")->getField("name");
  58. $vo['user'] = M("User")->where("id=".intval($vo['user_id'])."")->find();
  59. $this->assign('vo', $vo);
  60. $this->display();
  61. }
  62. public function update()
  63. {
  64. B('FilterString');
  65. $data = M("BmPromoter")->create();
  66. $data_info = M("BmPromoter")->where("id=" . intval($data['id']))->find();
  67. $log_info = $data_info['name'];
  68. if (!$data_info) {
  69. $this->error("请选择审核的推广商");
  70. }
  71. if($data['status'] ==1){
  72. if (!check_empty($data_info['mobile'])) {
  73. $this->error("登录手机号不能为空");
  74. }
  75. if (!check_mobile($data_info['mobile'])) {
  76. $this->error("登录手机号不正确");
  77. }
  78. if(intval($GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where mobile='".$data_info['mobile']."' and status =1 and id <> ".intval($data_info['id'])."") )>0){
  79. $this->error("登录手机号已存在");
  80. }
  81. if (!check_empty($data_info['name'])) {
  82. $this->error("推广商名称不能为空");
  83. }
  84. if(intval($GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where name='".$data_info['name']."' and status =1 and id <> ".intval($data_info['id'])."") )>0){
  85. $this->error("推广商名称已存在");
  86. }
  87. $check_user_info=$this->check_user($data_info['user_id']);
  88. if($check_user_info['status'] ==0){
  89. $this->error($check_user_info['info']);
  90. }
  91. $data['is_effect']=1;
  92. }else{
  93. $data['is_effect']=0;
  94. }
  95. if($data['status'] ==2 && $data['memo']==''){
  96. $this->error("请输入备注");
  97. }
  98. // 更新数据
  99. $list = M("BmPromoter")->save($data);
  100. if (false != $list) {
  101. if($data['status'] ==1){
  102. $GLOBALS['db']->query("update ".DB_PREFIX."bm_promoter set child_count=(SELECT temp.id from (SELECT COUNT(id) as id from ".DB_PREFIX."bm_promoter where pid=".intval($data_info['pid'])." and is_effect=1 and status=1)temp ) where user_id= ".intval($data_info['pid'])."");
  103. }
  104. $this->assign("jumpUrl", u(MODULE_NAME . "/index", array("id" => $data['id'])));
  105. //成功提示
  106. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  107. $this->success(L("UPDATE_SUCCESS"));
  108. } else {
  109. //错误提示
  110. save_log($log_info . L("UPDATE_FAILED"), 0);
  111. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  112. }
  113. }
  114. public function foreverdelete() {
  115. //彻底删除指定记录
  116. $ajax = intval($_REQUEST['ajax']);
  117. $id = $_REQUEST ['id'];
  118. if (isset ( $id )) {
  119. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  120. $rel_data = M("BmPromoter")->where($condition)->findAll();
  121. foreach($rel_data as $data)
  122. {
  123. $info[] = $data['adm_name'];
  124. if($data["status"]==1 || $data["pid"]==0)
  125. {
  126. $this->error($data['name']."(ID:".$data["id"].")不能删除",$ajax);
  127. }
  128. }
  129. if($info) $info = implode(",",$info);
  130. $list = M("BmPromoter")->where ( $condition )->delete();
  131. if ($list!==false) {
  132. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  133. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  134. } else {
  135. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  136. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  137. }
  138. } else {
  139. $this->error (l("INVALID_OPERATION"),$ajax);
  140. }
  141. }
  142. //检查绑定会员
  143. public function check_user($user_id)
  144. {
  145. $return=array("status"=>0,"info"=>"");
  146. $user_id=intval($user_id);
  147. //是否有会员
  148. $user_info=$GLOBALS['db']->getRow("select id,bm_pid,is_effect,nick_name from ".DB_PREFIX."user where id= ".$user_id." ");
  149. if(!$user_info){
  150. $return["status"]=0;
  151. $return["info"]="绑定会员未注册,请注册后再绑定";
  152. return $return;
  153. }
  154. //会员是否有效
  155. if($user_info['is_effect'] ==0){
  156. $return["status"]=0;
  157. $return["info"]="无效的会员";
  158. return $return;
  159. }
  160. //是否是三级推广会员
  161. /*if($user_info['bm_pid'] >0){
  162. $return["status"]=0;
  163. $return["info"]="该会员已是推广会员,不能绑定";
  164. return $return;
  165. }*/
  166. //是否已是绑定推广商
  167. $count_promoter=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."bm_promoter where user_id=".intval($user_info['id'])." and status=1");
  168. if($count_promoter >0){
  169. $return["status"]=0;
  170. $return["info"]="该会员已绑定推广商";
  171. return $return;
  172. }
  173. $return["status"]=1;
  174. return $return;
  175. }
  176. }
  177. ?>