RecipeController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class RecipeController 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 recipe_name like "%'.$_GPC['keyword'].'%" ';
  19. }
  20. if( isset($_GPC['state']) && $_GPC['state'] != -1 )
  21. {
  22. $condition .= ' and state = '.$_GPC['state'];
  23. }
  24. if( isset($_GPC['cate']) && $_GPC['cate'] != '' )
  25. {
  26. $condition .= ' and cate_id = '.$_GPC['cate'];
  27. }
  28. $category = D('Seller/GoodsCategory')->getFullCategory(true, true,'recipe');
  29. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX') . "lionfish_comshop_recipe
  30. WHERE 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize );
  31. foreach( $list as $key => $val )
  32. {
  33. $goods_count = M('lionfish_comshop_recipe_ingredients')->where( array('recipe_id' => $val['id'] ) )->count();
  34. $val['username'] = '';
  35. $val['cate_name'] = '';
  36. if( $val['member_id'] > 0)
  37. {
  38. $mb_info = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->find();
  39. if( !empty($mb_info) )
  40. {
  41. $val['username'] = $mb_info['username'];
  42. }
  43. }
  44. if( $val['cate_id'] > 0 )
  45. {
  46. $cate_info = M('lionfish_comshop_goods_category')->where( array('id' => $val['cate_id'] ) )->find();
  47. if( !empty($cate_info) )
  48. {
  49. $val['cate_name'] = $cate_info['name'];
  50. }
  51. }
  52. $val['goods_count'] = $goods_count;
  53. $list[$key] = $val;
  54. }
  55. $total = M('lionfish_comshop_recipe')->where("1 ".$condition)->count();
  56. $pager = pagination2($total, $pindex, $psize);
  57. $this->pager = $pager;
  58. $this->list = $list;
  59. $this->category =$category;
  60. $this->_GPC = $_GPC;
  61. $this->display();
  62. }
  63. /**
  64. * 编辑添加
  65. */
  66. public function add()
  67. {
  68. $_GPC = I('request.');
  69. $id = intval($_GPC['id']);
  70. if (!empty($id)) {
  71. $item = M('lionfish_comshop_recipe')->where( array('id' => $id ) )->find();
  72. $ing_list = M('lionfish_comshop_recipe_ingredients')->where( array('recipe_id' => $id ) )->select();
  73. $limit_goods = array();
  74. $time = time();
  75. if( !empty($ing_list) )
  76. {
  77. foreach( $ing_list as $key => $val )
  78. {
  79. $need_dd = array();
  80. if( !empty($val['goods_id']) )
  81. {
  82. // $gd_info_list = M('lionfish_comshop_goods')->field('id,goodsname,grounding,begin_time,end_time,total')->where( "id in (".$val['goods_id'].")" )->select();
  83. $sql_goods = "select g.id as gid,g.goodsname,g.subtitle,g.total,g.grounding,gc.begin_time,gc.end_time from "
  84. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc "
  85. ." where g.id in (".$val['goods_id'].") and g.id=gc.goods_id order by g.id desc ";
  86. $gd_info_list = M()->query($sql_goods);
  87. if( !empty($gd_info_list) )
  88. {
  89. foreach( $gd_info_list as $gd_info )
  90. {
  91. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $gd_info['gid'] ) )->order('id asc')->find();
  92. $thumb_img = tomedia($thumb['image']);
  93. $tmp_dd = array();
  94. $tmp_dd['gid'] = $gd_info['gid'];
  95. $tmp_dd['title'] = $val['title'];
  96. $tmp_dd['goodsname'] = $gd_info['goodsname'];
  97. $tmp_dd['image'] = tomedia( $thumb_img );
  98. $tmp_dd['grounding'] = $gd_info['grounding'];
  99. if($time >= $gd_info['begin_time'] && $time <= $gd_info['end_time']){
  100. $tmp_dd['is_finished'] = 0;
  101. }else{
  102. $tmp_dd['is_finished'] = 1;//已结束
  103. }
  104. if($gd_info['total'] <= 0){
  105. $tmp_dd['is_grab'] = 1;//已抢光
  106. }else{
  107. $tmp_dd['is_grab'] = 0;
  108. }
  109. $need_dd[] = $tmp_dd;
  110. }
  111. }
  112. }
  113. $val['limit_goods'] = $need_dd;
  114. $ing_list[$key] = $val;
  115. }
  116. }
  117. //limit_goods
  118. //saler
  119. $saler = array();
  120. if( $item['member_id'] > 0 )
  121. {
  122. $saler = $mb_info = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id'] ) )->find();
  123. }
  124. $this->saler = $saler;
  125. $this->ing_list = $ing_list;
  126. $this->item = $item;
  127. }
  128. $category = D('Seller/GoodsCategory')->getFullCategory(true, true,'recipe');
  129. $this->category = $category;
  130. if ( IS_POST ) {
  131. $need_data = array();
  132. $need_data['data'] = $_GPC['data'];
  133. $need_data['sub_name'] = $_GPC['sub_name'];
  134. $need_data['diff_type'] = $_GPC['diff_type'];
  135. $need_data['sp'] = $_GPC['sp'];
  136. $need_data['state'] = $_GPC['state'];
  137. $need_data['limit_goods_list'] = $_GPC['limit_goods_list'];
  138. D('Seller/Recipe')->update($need_data);
  139. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  140. }
  141. include $this->display();
  142. }
  143. public function change()
  144. {
  145. $_GPC = I('request.');
  146. $id = intval($_GPC['id']);
  147. //ids
  148. if (empty($id)) {
  149. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  150. }
  151. if (empty($id)) {
  152. show_json(0, array('message' => '参数错误'));
  153. }
  154. $type = trim($_GPC['type']);
  155. $value = trim($_GPC['value']);
  156. if (!(in_array($type, array('state')))) {
  157. show_json(0, array('message' => '参数错误'));
  158. }
  159. $items = M('lionfish_comshop_recipe')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  160. foreach ($items as $item ) {
  161. M('lionfish_comshop_recipe')->where( array('id' => $item['id']) )->save( array($type => $value) );
  162. }
  163. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  164. }
  165. public function delete()
  166. {
  167. $_GPC = I('request.');
  168. $id = intval($_GPC['id']);
  169. if (empty($id)) {
  170. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  171. }
  172. $items = M('lionfish_comshop_recipe')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  173. if (empty($item)) {
  174. $item = array();
  175. }
  176. foreach ($items as $item) {
  177. M('lionfish_comshop_recipe')->where( array('id' => $item['id']) )->delete();
  178. M('lionfish_comshop_recipe_ingredients')->where( array('recipe_id' => $item['id']) )->delete();
  179. M('lionfish_comshop_recipe_fav')->where( array('recipe_id' => $item['id']) )->delete();
  180. }
  181. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  182. }
  183. public function config()
  184. {
  185. $_GPC = I('request.');
  186. if ( IS_POST ) {
  187. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  188. D('Seller/Config')->update($data);
  189. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  190. }
  191. $data = D('Seller/Config')->get_all_config();
  192. $this->data = $data;
  193. include $this->display();
  194. }
  195. public function slider ()
  196. {
  197. $_GPC = I('request.');
  198. $condition = ' and type="recipe" ';
  199. $pindex = max(1, intval($_GPC['page']));
  200. $psize = 20;
  201. if (!empty($_GPC['keyword'])) {
  202. $_GPC['keyword'] = trim($_GPC['keyword']);
  203. $condition .= ' and advname like "%'.$_GPC['keyword'].'%" ';
  204. }
  205. if (isset($_GPC['enabled']) && $_GPC['enabled'] >= 0) {
  206. $_GPC['enabled'] = trim($_GPC['enabled']);
  207. $condition .= ' and enabled = ' . $_GPC['enabled'];
  208. } else {
  209. $_GPC['enabled'] = -1;
  210. }
  211. $list = M()->query('SELECT id,advname,thumb,link,type,displayorder,enabled FROM ' . C('DB_PREFIX'). "lionfish_comshop_adv
  212. WHERE 1 " . $condition . ' order by displayorder desc, id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize );
  213. $total = M('lionfish_comshop_adv')->where( '1 '.$condition )->count();
  214. $pager = pagination2($total, $pindex, $psize);
  215. $this->list = $list;
  216. $this->pager = $pager;
  217. $this->_GPC = $_GPC;
  218. $this->display();
  219. }
  220. public function category()
  221. {
  222. global $_W;
  223. global $_GPC;
  224. $children = array();
  225. $category = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_goods_category WHERE cate_type="recipe" ORDER BY pid ASC, sort_order DESC');
  226. foreach ($category as $index => $row) {
  227. if (!empty($row['pid'])) {
  228. $children[$row['pid']][] = $row;
  229. unset($category[$index]);
  230. }
  231. }
  232. $this->children = $children;
  233. $this->category = $category;
  234. $this->display();
  235. }
  236. public function addcategory()
  237. {
  238. $_GPC = I('request.');
  239. $data = array();
  240. $pid = isset($_GPC['pid']) ? $_GPC['pid']:0;
  241. $id = isset($_GPC['id']) ? $_GPC['id']:0;
  242. if ( IS_POST ) {
  243. $data = $_GPC['data'];
  244. D('Seller/GoodsCategory')->update($data,'recipe');
  245. show_json(1, array('shopUrl' => U('recipe/category')));
  246. }
  247. if($id >0 )
  248. {
  249. $data = M('lionfish_comshop_goods_category')->where( array('id' => $id ) )->find();
  250. $this->data = $data;
  251. $this->id = $id;
  252. }
  253. $this->pid = $pid;
  254. $this->display();
  255. }
  256. public function category_delete()
  257. {
  258. $_GPC = I('request.');
  259. $id = intval($_GPC['id']);
  260. $item = M('lionfish_comshop_goods_category')->field( 'id, name, pid' )->where( array('id' => $id ) )->find();
  261. if (empty($item)) {
  262. show_json(0, array('message' => '抱歉,分类不存在或是已经被删除!' ));
  263. }
  264. M('lionfish_comshop_goods_category')->where( "id={$id} or pid={$id}" )->delete();
  265. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  266. }
  267. public function category_enabled()
  268. {
  269. $_GPC = I('request.');
  270. $id = intval($_GPC['id']);
  271. if (empty($id)) {
  272. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  273. }
  274. $items = M('lionfish_comshop_goods_category')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  275. foreach ($items as $item) {
  276. M('lionfish_comshop_goods_category')->where( array('id' => $item['id']) )->save( array('is_show' => intval($_GPC['enabled'])) );
  277. }
  278. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  279. }
  280. public function addslider()
  281. {
  282. $_GPC = I('request.');
  283. $id = intval($_GPC['id']);
  284. if (!empty($id)) {
  285. $item = M('lionfish_comshop_adv')->where( array('id' => $id) )->find();
  286. $this->item = $item;
  287. }
  288. if ( IS_POST ) {
  289. $data = $_GPC['data'];
  290. D('Seller/Adv')->update($data,'recipe');
  291. show_json(1, array('url' => U('recipe/slider') ) );
  292. }
  293. include $this->display();
  294. }
  295. public function changeslider()
  296. {
  297. $_GPC = I('request.');
  298. $id = intval($_GPC['id']);
  299. //ids
  300. if (empty($id)) {
  301. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  302. }
  303. if (empty($id)) {
  304. show_json(0, array('message' => '参数错误'));
  305. }
  306. $type = trim($_GPC['type']);
  307. $value = trim($_GPC['value']);
  308. if (!(in_array($type, array('enabled', 'displayorder')))) {
  309. show_json(0, array('message' => '参数错误'));
  310. }
  311. $items = M('lionfish_comshop_adv')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  312. //id/15 value: 1
  313. foreach ($items as $item) {
  314. M('lionfish_comshop_adv')->where( array('id' => $item['id']) )->save( array($type => $value) );
  315. }
  316. show_json(1);
  317. }
  318. public function deleteslider()
  319. {
  320. $_GPC = I('request.');
  321. $id = intval($_GPC['id']);
  322. //ids
  323. if (empty($id)) {
  324. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  325. }
  326. if (empty($id)) {
  327. show_json(0, array('message' => '参数错误'));
  328. }
  329. $items = M('lionfish_comshop_adv')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  330. foreach ($items as $item) {
  331. M('lionfish_comshop_adv')->where( array( 'id' => $item['id'] ) )->delete();
  332. }
  333. show_json(1);
  334. }
  335. public function order()
  336. {
  337. $_GPC = I('request.');
  338. $pindex = max(1, intval($_GPC['page']));
  339. $psize = 20;
  340. if (!empty($_GPC['keyword'])) {
  341. $_GPC['keyword'] = trim($_GPC['keyword']);
  342. $condition .= ' and order_sn like "%'.$_GPC['keyword'].'%" ';
  343. }
  344. $list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_member_card_order
  345. WHERE state= 1 " . $condition . ' order by id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize, $params);
  346. if( !empty($list) )
  347. {
  348. foreach( $list as $key => $val )
  349. {
  350. $mb_info = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->find();
  351. $val['username'] = $mb_info['username'];
  352. $list[$key] = $val;
  353. }
  354. }
  355. $total = M('lionfish_comshop_member_card_order')->where( 'state= 1 '. $condition )->count();
  356. $pager = pagination2($total, $pindex, $psize);
  357. $this->_GPC = $_GPC;
  358. $this->list = $list;
  359. $this->pager = $pager;
  360. $this->display();
  361. }
  362. }
  363. ?>