BmPromoterOneAction.class.php 9.4 KB

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