SalesroomController.class.php 8.0 KB

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