RecipeController.class.php 13 KB

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