SalesroomController.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author zcy 2020-09-18
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class SalesroomController 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. $this->state = I('request.state','');
  22. $condition = "";
  23. if (!empty($keyword)) {
  24. $condition .= " and (room_address like '%".$keyword."%' or room_name like '%".$keyword."%' or mobile like '%".$keyword."%') ";
  25. }
  26. if(!empty($this->state)){
  27. if($this->state == 2){
  28. $condition .= " and state= 0 ";
  29. }else{
  30. $condition .= " and state= ".$this->state;
  31. }
  32. }
  33. $supply_id = 0;
  34. if (defined('ROLE') && ROLE == 'agenter' )
  35. {
  36. $supper_info = get_agent_logininfo();
  37. $supply_id = $supper_info['id'];
  38. $condition .= " and supply_id= ".$supply_id;
  39. }
  40. $list = M()->query('SELECT * FROM '. C('DB_PREFIX'). "lionfish_comshop_salesroom WHERE 1=1 "
  41. . $condition . ' order by displayorder desc, id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  42. foreach ($list as $k=>$v) {
  43. if(empty($v['supply_id'])){
  44. $list[$k]['supply_name'] = "平台";
  45. }else{
  46. $supply_info = M('lionfish_comshop_supply')->where( array('id' => $v['supply_id']) )->field('shopname')->find();
  47. $list[$k]['supply_name'] = $supply_info['shopname'];
  48. }
  49. $list[$k]['member_count'] = M('lionfish_comshop_salesroom_relative_member')->where( array('salesroom_id' => $v['id']) )->count();
  50. $list[$k]['disable_time'] = date('Y-m-d H:i:s',$v['disable_time']);
  51. }
  52. $total = M('lionfish_comshop_salesroom')->where("1=1 ".$condition)->count();
  53. $pager = pagination2($total, $pindex, $psize);
  54. $this->list = $list;
  55. $this->pager = $pager;
  56. $this->display();
  57. }
  58. /**
  59. * 编辑添加
  60. */
  61. public function add()
  62. {
  63. $id = I('request.id');
  64. if (!empty($id)) {
  65. $item = M('lionfish_comshop_salesroom')->where( array('id' => $id) )->find();
  66. if(!empty($item['supply_id'])){
  67. $item['supply_info'] = M('lionfish_comshop_supply')->where( array('id' => $item['supply_id']) )->find();
  68. }
  69. $this->id = $id;
  70. $this->item = $item;
  71. }
  72. $supply_id = 0;
  73. if (defined('ROLE') && ROLE == 'agenter' )
  74. {
  75. $supper_info = get_agent_logininfo();
  76. $supply_id = $supper_info['id'];
  77. }
  78. $this->supply_id = $supply_id;
  79. if (IS_POST) {
  80. $data = I('request.data');
  81. if($supply_id > 0){
  82. $data['supply_id'] = $supply_id;
  83. }
  84. D('Seller/Salesroom')->update($data);
  85. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  86. }
  87. $this->display('Salesroom/add');
  88. }
  89. /**
  90. * 改变状态
  91. */
  92. public function change()
  93. {
  94. $id = I('request.id');
  95. //ids
  96. if (empty($id)) {
  97. $ids = I('request.ids');
  98. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  99. }
  100. if (empty($id)) {
  101. show_json(0, array('message' => '参数错误'));
  102. }
  103. $type = I('request.type');
  104. $value = I('request.value');
  105. if (!(in_array($type, array('state')))) {
  106. show_json(0, array('message' => '参数错误'));
  107. }
  108. $items = M('lionfish_comshop_salesroom')->where( array('id' => array('in', $id) ) )->select();
  109. foreach ($items as $item) {
  110. if($value == 0){
  111. M('lionfish_comshop_salesroom')->where( array('id' => $item['id']) )->save( array($type => $value,'disable_time'=>time()) );
  112. D('Seller/Salesroom')->update_hxgoods($item['id']);
  113. }else{
  114. M('lionfish_comshop_salesroom')->where( array('id' => $item['id']) )->save( array($type => $value) );
  115. }
  116. }
  117. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  118. }
  119. /**
  120. * 删除
  121. */
  122. public function delete()
  123. {
  124. $id = I('request.id');
  125. if (empty($id)) {
  126. $ids = I('request.ids');
  127. $id = (is_array($ids) ? implode(',', $ids) : 0);
  128. }
  129. $items = M('lionfish_comshop_salesroom')->field('id,room_name')->where( array('id' => array('in', $id) ) )->select();
  130. if (empty($item)) {
  131. $item = array();
  132. }
  133. foreach ($items as $item) {
  134. M('lionfish_comshop_salesroom')->where( array('id' => $item['id']) )->delete();
  135. D('Seller/Salesroom')->update_hxgoods($item['id']);
  136. }
  137. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  138. }
  139. public function query(){
  140. $_GPC = I('request.');
  141. $kwd = I('request.keyword','');
  142. $condition = ' 1 ';
  143. if (!empty($kwd)) {
  144. $condition .= ' AND ( `room_name` LIKE '.'"%' . $kwd . '%"'.' or `mobile` LIKE '.'"%' . $kwd . '%"'.' or `room_address` LIKE '.'"%' . $kwd . '%"'.' )';
  145. }
  146. $supply_id = I('request.supply_id', 0);
  147. if (defined('ROLE') && ROLE == 'agenter' )
  148. {
  149. $supper_info = get_agent_logininfo();
  150. $supply_id = $supper_info['id'];
  151. $condition.= ' AND supply_id='.$supply_id;
  152. }else{
  153. if(empty($supply_id)){
  154. $supply_id = 0;
  155. }
  156. $condition.= ' AND supply_id='.$supply_id;
  157. }
  158. $condition.=' AND state=1 ';
  159. $ds = M('lionfish_comshop_salesroom')->where( $condition )->field('id,room_name,room_logo,supply_id,room_address,mobile')->select();
  160. $s_html = "";
  161. foreach ($ds as &$value) {
  162. if(empty($value['supply_id'])){
  163. $value['supply_name'] = "平台";
  164. }else{
  165. $supply_info = M('lionfish_comshop_supply')->where( array('id' => $value['supply_id']) )->field('shopname')->find();
  166. $value['supply_name'] = $supply_info['shopname'];
  167. }
  168. $value['room_name'] = htmlspecialchars($value['room_name'], ENT_QUOTES);
  169. $value['room_logo'] = tomedia($value['room_logo']);
  170. $s_html .= "<tr><td><img src='".$value['room_logo']."' style='width:30px;height:30px;padding1px;border:1px solid #ccc' />&nbsp;&nbsp;{$value[room_name]}</td>";
  171. $s_html .= "<td>{$value['room_address']}</td>";
  172. $s_html .= "<td>{$value['supply_name']}</td>";
  173. $s_html .= "<td>{$value['mobile']}</td>";
  174. if( isset($_GPC['template']) && $_GPC['template'] == 'mult'){
  175. $s_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_mult_link" data-json=\''.json_encode($value).'\'>选择</a></td></tr>';
  176. }else if( isset($_GPC['template']) && $_GPC['template'] == 'mult_goods'){
  177. $s_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_mult_goods_link" data-json=\''.json_encode($value).'\'>选择</a></td></tr>';
  178. }else{
  179. $s_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_dan_link" data-json=\''.json_encode($value).'\'>选择</a></td></tr>';
  180. }
  181. }
  182. unset($value);
  183. if( isset($_GPC['is_ajax']) && $_GPC['is_ajax'] == 1)
  184. {
  185. echo json_encode( array('code' =>0, 'html' => $s_html) );
  186. die();
  187. }
  188. $url = 'salesroom/query';
  189. $this->url = $url;
  190. $this->ds = $ds;
  191. $this->gpc = $_GPC;
  192. $this->kwd = $kwd;
  193. $this->supply_id = $supply_id;
  194. $this->display();
  195. }
  196. }
  197. ?>