SolitaireController.class.php 12 KB

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