SolitaireController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class SolitaireController extends CommonController{
  16. public function index()
  17. {
  18. $_GPC = I('request.');
  19. $pindex = max(1, intval($_GPC['page']));
  20. $psize = 20;
  21. if (!empty($_GPC['keyword'])) {
  22. $_GPC['keyword'] = trim($_GPC['keyword']);
  23. $condition .= ' and solitaire_name like "%'.$_GPC['keyword'].'%"';
  24. }
  25. $now_time = time();
  26. if( isset($_GPC['type']) && $_GPC['type'] > 0 )
  27. {
  28. switch( $_GPC['type'] )
  29. {
  30. case 1:
  31. //进行中 lionfish_comshop_solitaire state appstate begin_time end_time
  32. $condition .= " and state =1 and appstate=1 and begin_time <= {$now_time} and end_time > {$now_time} ";
  33. break;
  34. case 2:
  35. //未开始
  36. $condition .= " and state =1 and appstate=1 and begin_time > {$now_time} ";
  37. break;
  38. case 3:
  39. //已结束
  40. $condition .= " and state =1 and appstate=1 and end_time < {$now_time} ";
  41. break;
  42. case 4:
  43. //未审核
  44. $condition .= " and appstate=0 ";
  45. break;
  46. case 5:
  47. //已拒绝
  48. $condition .= " and appstate=2 ";
  49. break;
  50. }
  51. }
  52. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_solitaire
  53. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize );
  54. //id,接龙名称, 社区接龙团长,参与接龙人数,浏览人数,接龙时间,接龙状态。
  55. foreach( $list as $key => $val )
  56. {
  57. //head_id
  58. $head_info = M('lionfish_community_head')->field('community_name,head_name')->where( array('id' => $val['head_id'] ) )->find();
  59. $val['head_info'] = $head_info;
  60. $order_count = M('lionfish_comshop_solitaire_order')->where( array('soli_id' => $val['id'] ) )->count();
  61. $val['order_count'] = $order_count;
  62. $invite_count = M('lionfish_comshop_solitaire_invite')->where( array('soli_id' => $val['id'] ) )->count();
  63. $val['invite_count'] = $invite_count;
  64. $goods_count = M('lionfish_comshop_solitaire_goods')->where( array('soli_id' => $val['id'] ) )->count();
  65. $val['goods_count'] = $goods_count;
  66. $list[$key] = $val;
  67. }
  68. $total = M('lionfish_comshop_solitaire')->where( '1 '.$condition )->count();
  69. $pager = pagination2($total, $pindex, $psize);
  70. $this->list = $list;
  71. $this->pager = $pager;
  72. $this->_GPC = $_GPC;
  73. //全部接龙
  74. $all_count = M('lionfish_comshop_solitaire')->count();
  75. if( empty($all_count) )
  76. {
  77. $all_count = 0;
  78. }
  79. $this->all_count = $all_count;
  80. //进行中的
  81. $count_status_1 = M('lionfish_comshop_solitaire')->where( "appstate=1 and state=1 and begin_time <={$now_time} and end_time >{$now_time} " )->count();
  82. if( empty($count_status_1) )
  83. {
  84. $count_status_1 = 0;
  85. }
  86. $this->count_status_1 = $count_status_1;
  87. //未开始({$count_status_2}
  88. $count_status_2 = M('lionfish_comshop_solitaire')->where( "appstate=1 and state=1 and begin_time >{$now_time} " )->count();
  89. if( empty($count_status_2) )
  90. {
  91. $count_status_2 = 0;
  92. }
  93. $this->count_status_2 = $count_status_2;
  94. //已结束({$count_status_3})
  95. $count_status_3 = M('lionfish_comshop_solitaire')->where("appstate=1 and state=1 and end_time <={$now_time} ")->count();
  96. if( empty($count_status_3) )
  97. {
  98. $count_status_3 = 0;
  99. }
  100. $this->count_status_3 = $count_status_3;
  101. //未审核({$count_status_4}
  102. $count_status_4 = M('lionfish_comshop_solitaire')->where("appstate=0")->count();
  103. if( empty($count_status_4) )
  104. {
  105. $count_status_4 = 0;
  106. }
  107. $this->count_status_4 = $count_status_4;
  108. //已拒绝({$count_status_5}
  109. $count_status_5 = M('lionfish_comshop_solitaire')->where("appstate=2")->count();
  110. if( empty($count_status_5) )
  111. {
  112. $count_status_5 = 0;
  113. }
  114. $this->count_status_5 = $count_status_5;
  115. $this->display();
  116. }
  117. //
  118. /**
  119. * 删除群接龙
  120. */
  121. public function delete()
  122. {
  123. $_GPC = I('request.');
  124. $id = intval($_GPC['id']);
  125. if (empty($id)) {
  126. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  127. }
  128. $items = M('lionfish_comshop_solitaire')->field('id')->where('id in( ' . $id . ' )')->select();
  129. if (empty($item)) {
  130. $item = array();
  131. }
  132. foreach ($items as $item) {
  133. M('lionfish_comshop_solitaire')->where( array('id' => $item['id']) )->delete();
  134. }
  135. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  136. }
  137. public function detail()
  138. {
  139. $_GPC = I('request.');
  140. //id=11
  141. $id = $_GPC['id'];
  142. $solitaire_info = M('lionfish_comshop_solitaire')->where( array('id' => $id ) )->find();
  143. $now_time = time();
  144. $state_str = "";
  145. if( $solitaire_info['appstate'] == 0 )
  146. {
  147. $state_str = '待审核';
  148. }else if( $solitaire_info['appstate'] == 2 )
  149. {
  150. $state_str = '已拒绝';
  151. } else if( $solitaire_info['appstate'] == 1 )
  152. {
  153. //
  154. if( $solitaire_info['state'] == 1 )
  155. {
  156. if( $solitaire_info['begin_time'] > $now_time )
  157. {
  158. $state_str = '未开始';
  159. }else if( $solitaire_info['begin_time'] <= $now_time && $solitaire_info['end_time'] > $now_time )
  160. {
  161. $state_str = '进行中';
  162. }else if( $solitaire_info['end_time'] < $now_time ){
  163. $state_str = '已结束';
  164. }
  165. }else if( $solitaire_info['state'] == 0 )
  166. {
  167. $state_str = '已禁用';
  168. }
  169. }
  170. $this->solitaire_info = $solitaire_info;
  171. $this->state_str = $state_str;
  172. $this->id = $id;
  173. $this->_GPC = $_GPC;
  174. $head_info = M('lionfish_community_head')->where( array('id' => $solitaire_info['head_id'] ) )->find();
  175. $this->head_info = $head_info;
  176. $soli_goods = M('lionfish_comshop_solitaire_goods')->field('goods_id')->where( array('soli_id' => $id ) )->select();
  177. $goods_arr = array();
  178. $goods_ids = array();
  179. if( !empty($soli_goods) )
  180. {
  181. foreach($soli_goods as $val)
  182. {
  183. $goods_ids[] = $val['goods_id'];
  184. }
  185. $goods_ids_str = implode(',', $goods_ids);
  186. $sql = "select g.id,g.goodsname,g.codes,g.price,productprice,total from ".C('DB_PREFIX')."lionfish_comshop_goods as g , ".C('DB_PREFIX')."lionfish_comshop_good_common as gc
  187. where g.id=gc.goods_id and g.id in ({$goods_ids_str}) ";
  188. $goods_arr = M()->query($sql);
  189. foreach( $goods_arr as $k => $v )
  190. {
  191. $image_s = D('Home/Pingoods')->get_goods_images($v['id']);
  192. $v['image'] = $image_s['image'];
  193. $goods_arr[$k] = $v;
  194. }
  195. //goods_images $image = load_model_class('pingoods')->get_goods_images($goods_id);
  196. }
  197. // lionfish_comshop_solitaire_order
  198. //团长昵称
  199. $this->goods_arr = $goods_arr;
  200. $order_count = M('lionfish_comshop_solitaire_order')->where( array('soli_id' => $id ) )->count();
  201. $this->order_count = $order_count;
  202. //soli_id order_id
  203. $order_sql = "select o.* from ".C('DB_PREFIX')."lionfish_comshop_order as o, ".C('DB_PREFIX')."lionfish_comshop_solitaire_order as so
  204. where o.order_id = so.order_id and so.soli_id ={$id} order by o.order_id asc ";
  205. $order_list = M()->query($order_sql);
  206. foreach( $order_list as $key => $val )
  207. {
  208. $order_goods = M('lionfish_comshop_order_goods')->field('quantity')->where( array('order_id' => $val['order_id'] ) )->select();
  209. $val['order_goods'] = $order_goods;
  210. /****/
  211. $buy_quantity = 0;
  212. $buy_quantity = M('lionfish_comshop_order_goods')->where( array('order_id' => $val['order_id'] ) )->sum('quantity');
  213. $mb_info = M('lionfish_comshop_member')->field('username,avatar')->where( array('member_id' => $val['member_id'] ) )->find();
  214. $val['mb_info'] = $mb_info;
  215. $val['buy_quantity'] = $buy_quantity;
  216. $order_list[$key] = $val;
  217. }
  218. $this->order_list = $order_list;
  219. // lionfish_comshop_order_status
  220. $order_status_all = M('lionfish_comshop_order_status')->select();
  221. $order_status_arr = array();
  222. foreach( $order_status_all as $val )
  223. {
  224. $order_status_arr[$val['order_status_id']] = $val['name'];
  225. }
  226. $this->order_status_arr = $order_status_arr;
  227. $this->display();
  228. }
  229. public function add()
  230. {
  231. $_GPC = I('request.');
  232. $id = intval($_GPC['id']);
  233. $is_mult = 1;
  234. if (!empty($id)) {
  235. $item = M('lionfish_comshop_solitaire')->where( array('id' => $id ) )->find();
  236. $limit_goods = array();
  237. $item['piclist'] = array();
  238. $piclist = array();
  239. $images_list = unserialize($item['images_list']);
  240. if( !empty($images_list) )
  241. {
  242. foreach( $images_list as $key => $val )
  243. {
  244. $med_image = tomedia( $val );
  245. $piclist[] = array('image' => $med_image, 'thumb' => $med_image ); //$val['image'];
  246. }
  247. $item['piclist'] = $piclist;
  248. }
  249. $item['content'] = htmlspecialchars_decode( $item['content'] );
  250. $headinfo = M('lionfish_community_head')->where( array('id' => $item['head_id'] ) )->find();
  251. $this->headinfo = $headinfo;
  252. $limit_goods = array();
  253. //ims_ soli_id goods_id
  254. $sql = "select g.id as gid, g.goodsname from ".C('DB_PREFIX')."lionfish_comshop_solitaire_goods as gs left join ".C('DB_PREFIX')."lionfish_comshop_goods as g on gs.goods_id = g.id where gs.soli_id={$id}";
  255. $goods_list = M()->query($sql);
  256. $limit_goods = array();
  257. if( !empty($goods_list) )
  258. {
  259. foreach( $goods_list as $key => $val )
  260. {
  261. $thumb = D('Home/Pingoods')->get_goods_images($val['gid']);
  262. if( empty($thumb['thumb']) )
  263. {
  264. $val['image'] = tomedia($thumb['image']);
  265. }else{
  266. $val['image'] = $thumb['thumb'];
  267. }
  268. $goods_list[$key] = $val;
  269. }
  270. $limit_goods = $goods_list;
  271. }
  272. $this->limit_goods = $limit_goods;
  273. //ims_lionfish_comshop_goods_images
  274. $is_mult = 0;
  275. }else{
  276. $item = array();
  277. $item['begin_time'] = time();
  278. $item['end_time'] = $item['begin_time'] + 86400 *2;
  279. }
  280. $this->is_mult = $is_mult;
  281. $this->item = $item;
  282. if (IS_POST) {
  283. $data = $_GPC['data'];
  284. $goods_list = $_GPC['goods_list'];
  285. $images_list = $_GPC['images_list'];
  286. $head_dan_id = $_GPC['head_dan_id'];
  287. $time = $_GPC['time'];//start end
  288. if( empty($head_dan_id) )
  289. {
  290. show_json(0, array('message' => '请选择团长') );
  291. }
  292. if( empty($goods_list) )
  293. {
  294. show_json(0, array('message' => '请选择商品') );
  295. }
  296. //bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp
  297. $img = array('.bmp','.png','.tif','.gif','.pcx','.tga','.exif','.fpx','.svg','.psd','.cdr','.pcd','.dxf','.ufo','.eps','.ai','.raw','.WMF','.webp');
  298. $count = 0;
  299. foreach($img as $var){
  300. $content_img = strstr($data['content'], $var);
  301. if($content_img){
  302. $count++ ;
  303. }
  304. }
  305. if( !empty($count) )
  306. {
  307. show_json(0, '图片类型必须为JPG格式');
  308. die();
  309. }
  310. $need_data = array();
  311. $need_data['data'] = $data;
  312. $need_data['goods_list'] = $goods_list;
  313. $need_data['images_list'] = $images_list;
  314. $need_data['head_dan_id'] = $head_dan_id;
  315. $need_data['head_id_list'] = $_GPC['head_id'];
  316. $need_data['time'] = $time;
  317. // print_r($goods_list);die;
  318. D('Seller/Solitaire')->updatedo($need_data);
  319. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  320. }
  321. // die;
  322. $this->display();
  323. }
  324. public function changestate()
  325. {
  326. $_GPC = I('request.');
  327. $value = $_GPC['value'];
  328. $id = $_GPC['id'];
  329. M('lionfish_comshop_solitaire')->where( array('id' => $id ) )->save( array('state' => $value ) );
  330. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  331. }
  332. public function change()
  333. {
  334. $_GPC = I('request.');
  335. $value = $_GPC['value'];
  336. $id = $_GPC['id'];
  337. M('lionfish_comshop_solitaire')->where( array('id' => $id ) )->save( array('appstate' => $value ) );
  338. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  339. }
  340. public function config()
  341. {
  342. $_GPC = I('request.');
  343. if ( IS_POST ) {
  344. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  345. $data['solitaire_target'] = isset($data['solitaire_target']) ? $data['solitaire_target'] : 0;
  346. D('Seller/Config')->update($data);
  347. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  348. }
  349. $data = D('Seller/Config')->get_all_config();
  350. $this->data = $data;
  351. $this->display();
  352. }
  353. }
  354. ?>