SalesroomMemberController.class.php 11 KB

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