SalesroomMemberController.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author zcy 2020-09-18
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class SalesroomMemberController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function index()
  20. {
  21. $pindex = I('request.page', 1);
  22. $psize = 20;
  23. $keyword = I('get.keyword','','addslashes');
  24. $keyword2 = stripslashes($keyword);
  25. $this->keyword = $keyword2;
  26. $room_id = I('request.salesroom_id');
  27. $this->state = I('request.state','');
  28. $this->room_id = $room_id;
  29. $condition = "";
  30. if (!empty($keyword)) {
  31. $condition .= " and (username like '%".$keyword."%' or mobile like '%".$keyword."%' or member_id in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member where username like '%".$keyword."%')) ";
  32. }
  33. if(!empty($room_id)){
  34. $condition .= " and id in (select smember_id from ".C('DB_PREFIX')."lionfish_comshop_salesroom_relative_member where salesroom_id = ".$room_id.") ";
  35. }
  36. if(!empty($this->state)){
  37. if($this->state == 2){
  38. $condition .= " and state= 0 ";
  39. }else{
  40. $condition .= " and state= ".$this->state;
  41. }
  42. }
  43. if (defined('ROLE') && ROLE == 'agenter' )
  44. {
  45. $supper_info = get_agent_logininfo();
  46. $supply_id = $supper_info['id'];
  47. $condition .= " and supply_id= ".$supply_id;
  48. }
  49. $list = M()->query('SELECT * FROM '. C('DB_PREFIX'). "lionfish_comshop_salesroom_member WHERE 1=1 "
  50. . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  51. foreach ($list as $k=>$v) {
  52. if(empty($v['supply_id'])){
  53. $list[$k]['supply_name'] = "平台";
  54. }else{
  55. $supply_info = M('lionfish_comshop_supply')->where( array('id' => $v['supply_id']) )->field('shopname')->find();
  56. $list[$k]['supply_name'] = $supply_info['shopname'];
  57. }
  58. $list[$k]['disable_time'] = date('Y-m-d H:i:s',$v['disable_time']);
  59. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $v['member_id']) )->field('username')->find();
  60. $list[$k]['member_name'] = $member_info['username'];
  61. $list[$k]['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
  62. $room_ids = "";
  63. $room_id_list = M('lionfish_comshop_salesroom_relative_member')->where(array('smember_id'=>$v['id']))->field('salesroom_id')->select();
  64. foreach($room_id_list as $rk=>$rv){
  65. if(empty($room_ids)){
  66. $room_ids = $rv['salesroom_id'];
  67. }else{
  68. $room_ids = $room_ids.','.$rv['salesroom_id'];
  69. }
  70. }
  71. $list[$k]['room_list'] = M('lionfish_comshop_salesroom')->where("id in (".$room_ids.")")->field('room_name')->select();
  72. }
  73. $total = M('lionfish_comshop_salesroom_member')->where("1=1 ".$condition)->count();
  74. $pager = pagination2($total, $pindex, $psize);
  75. $this->list = $list;
  76. $this->pager = $pager;
  77. //选择门店
  78. $room_list = D('Seller/Salesroom')->querySalesRoom();
  79. $this->room_list = $room_list;
  80. $this->display('Salesroom_member/index');
  81. }
  82. /**
  83. * 编辑添加
  84. */
  85. public function add()
  86. {
  87. if (IS_POST) {
  88. $supply_id = 0;
  89. if (defined('ROLE') && ROLE == 'agenter' )
  90. {
  91. $supper_info = get_agent_logininfo();
  92. $supply_id = $supper_info['id'];
  93. }
  94. $data = I('request.data');
  95. $data['supply_id'] = $supply_id;
  96. $data['salesroom_ids'] = I('request.salesroom_ids');
  97. if(!empty($data['id'])){
  98. $member_count = M('lionfish_comshop_salesroom_member')->where( array('member_id' => $data['member_id']) )->where('id <> '.$data['id'])->count();
  99. }else{
  100. $member_count = M('lionfish_comshop_salesroom_member')->where( array('member_id' => $data['member_id']) )->count();
  101. }
  102. if($member_count > 0){
  103. show_json(0, array('message' => '会员已绑定核销人员,请更换'));
  104. }
  105. D('Seller/SalesroomMember')->update($data);
  106. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  107. }else{
  108. $id = I('request.id');
  109. if (!empty($id)) {
  110. $item = M('lionfish_comshop_salesroom_member')->where( array('id' => $id) )->find();
  111. $this->id = $id;
  112. $this->item = $item;
  113. $this->member_info = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id']) )->field('avatar,username as nickname')->find();
  114. $room_ids = "";
  115. $room_id_list = M('lionfish_comshop_salesroom_relative_member')->where(array('smember_id'=>$item['id']))->field('salesroom_id')->select();
  116. foreach($room_id_list as $k=>$v){
  117. if(empty($room_ids)){
  118. $room_ids = $v['salesroom_id'];
  119. }else{
  120. $room_ids = $room_ids.','.$v['salesroom_id'];
  121. }
  122. }
  123. $this->room_list = M('lionfish_comshop_salesroom')->where("id in (".$room_ids.")")->field('id,room_name,room_logo')->select();
  124. }
  125. $this->display('Salesroom_member/add');
  126. }
  127. }
  128. /**
  129. * 改变状态
  130. */
  131. public function change()
  132. {
  133. $id = I('request.id');
  134. //ids
  135. if (empty($id)) {
  136. $ids = I('request.ids');
  137. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  138. }
  139. if (empty($id)) {
  140. show_json(0, array('message' => '参数错误'));
  141. }
  142. $type = I('request.type');
  143. $value = I('request.value');
  144. if (!(in_array($type, array('state')))) {
  145. show_json(0, array('message' => '参数错误'));
  146. }
  147. $items = M('lionfish_comshop_salesroom_member')->where( array('id' => array('in', $id) ) )->select();
  148. foreach ($items as $item) {
  149. if($value == 0){
  150. M('lionfish_comshop_salesroom_member')->where( array('id' => $item['id']) )->save( array($type => $value,'disable_time'=>time()) );
  151. }else{
  152. M('lionfish_comshop_salesroom_member')->where( array('id' => $item['id']) )->save( array($type => $value) );
  153. }
  154. }
  155. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  156. }
  157. /**
  158. * 删除
  159. */
  160. public function delete()
  161. {
  162. $id = I('request.id');
  163. if (empty($id)) {
  164. $ids = I('request.ids');
  165. $id = (is_array($ids) ? implode(',', $ids) : 0);
  166. }
  167. $items = M('lionfish_comshop_salesroom_member')->field('id,username')->where( array('id' => array('in', $id) ) )->select();
  168. if (empty($item)) {
  169. $item = array();
  170. }
  171. foreach ($items as $item) {
  172. M('lionfish_comshop_salesroom_member')->where( array('id' => $item['id']) )->delete();
  173. M('lionfish_comshop_salesroom_relative_member')->where( array('smember_id' => $item['id']) )->delete();
  174. }
  175. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  176. }
  177. public function query(){
  178. $_GPC = I('request.');
  179. $kwd = I('request.keyword','');
  180. $is_ajax = isset($_GPC['is_ajax']) ? intval($_GPC['is_ajax']) : 0;
  181. $room_id = I('request.room_id','');
  182. $condition = ' ';
  183. if (!empty($kwd)) {
  184. $condition .= ' AND ( `username` LIKE '.'"%' . $kwd . '%"'.' or `mobile` LIKE '.'"%' . $kwd . '%"'.' )';
  185. }
  186. if(!empty($room_id)){
  187. $condition .= " and id in (select smember_id from ".C('DB_PREFIX')."lionfish_comshop_salesroom_relative_member where salesroom_id = ".$room_id.") ";
  188. }
  189. $condition .= " and state= 1";
  190. $supply_id = 0;
  191. if (defined('ROLE') && ROLE == 'agenter' )
  192. {
  193. $supper_info = get_agent_logininfo();
  194. $supply_id = $supper_info['id'];
  195. $condition.= ' AND supply_id='.$supply_id;
  196. }else{
  197. $condition.= ' AND supply_id=0';
  198. }
  199. /**分页开始**/
  200. $page = isset($_GPC['page']) ? intval($_GPC['page']) : 1;
  201. $page = max(1, $page);
  202. $page_size = 10;
  203. /**分页结束**/
  204. $sql ='SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_salesroom_member WHERE 1 ' . $condition .' order by id desc' .' limit ' . (($page - 1) * $page_size) . ',' . $page_size ;
  205. $ds = M()->query($sql);
  206. $total = M('lionfish_comshop_salesroom_member')->where( '1 ' . $condition )->count();
  207. foreach ($ds as &$value) {
  208. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $value['member_id']) )->field('username,avatar')->find();
  209. $value['member_name'] = $member_info['username'];
  210. $value['avatar'] = $member_info['avatar'];
  211. if($is_ajax == 1)
  212. {
  213. $ret_html .= '<tr>';
  214. $ret_html .= ' <td><img src="'.$value['avatar'].'" style="width:30px;height: 30px;padding:1px;border:1px solid #ccc" />'. $value['username'].'</td>';
  215. $ret_html .= ' <td>'.$value['mobile'].'</td>';
  216. $ret_html .= ' <td>'.$value['member_name'].'</td>';
  217. if( isset($_GPC['template']) && $_GPC['template'] == 'mult'){
  218. $ret_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_mult_link" data-json=\''.json_encode($value).'\'>选择</a></td></tr>';
  219. }else if( isset($_GPC['template']) && $_GPC['template'] == 'mult_goods'){
  220. $ret_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_mult_goods_smember_link" data-json=\''.json_encode($value).'\'>选择</a></td></tr>';
  221. }else{
  222. $ret_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_dan_link" data-json=\''.json_encode($value).'\'>选择</a></td></tr>';
  223. }
  224. $ret_html .= '</tr>';
  225. }
  226. }
  227. $pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
  228. if( $is_ajax == 1 )
  229. {
  230. echo json_encode( array('code' => 0, 'html' => $ret_html,'pager' => $pager) );
  231. die();
  232. }
  233. unset($value);
  234. $this->ds = $ds;
  235. $this->pager = $pager;
  236. $this->gpc = $_GPC;
  237. $this->kwd = $kwd;
  238. $this->display('Salesroom_member/query');
  239. }
  240. }
  241. ?>