RecipeController.class.php 12 KB

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