RecipeController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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 Home\Controller;
  15. class RecipeController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function get_index_info()
  21. {
  22. $is_open_recipe = D('Home/Front')->get_config_by_name('is_open_recipe');
  23. $modify_recipe_name = D('Home/Front')->get_config_by_name('modify_recipe_name');
  24. $modify_recipe_share_title = D('Home/Front')->get_config_by_name('modify_recipe_share_title');
  25. $modify_vipcard_share_image = D('Home/Front')->get_config_by_name('modify_vipcard_share_image');
  26. $is_open_recipe = empty($is_open_recipe) || $is_open_recipe == 0 ? 0 : 1;
  27. $modify_recipe_name = empty($modify_recipe_name) || $modify_recipe_name == '' ? '菜谱' : $modify_recipe_name;
  28. $modify_recipe_share_title = empty($modify_recipe_share_title) ? '':$modify_recipe_share_title;
  29. $modify_vipcard_share_image = empty($modify_vipcard_share_image) ? '': tomedia($modify_vipcard_share_image);
  30. $cate_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods_category
  31. WHERE is_show=1 and cate_type='recipe' and pid = 0 " . '
  32. order by sort_order desc, id desc ' );
  33. if( empty($cate_list) )
  34. {
  35. $cate_list = array();
  36. }
  37. $need_data = array();
  38. $adv_list = M()->query("select * from ".C('DB_PREFIX')."lionfish_comshop_adv where type='recipe' and enabled=1
  39. order by displayorder desc , id asc ");
  40. $adv_arr = array();
  41. foreach( $adv_list as $val )
  42. {
  43. if( !empty($val['thumb']) )
  44. {
  45. $val['thumb'] = tomedia($val['thumb']);
  46. $adv_arr[] = $val;
  47. }
  48. }
  49. $need_data['is_open_recipe'] = $is_open_recipe;
  50. $need_data['modify_recipe_name'] = $modify_recipe_name;
  51. $need_data['modify_recipe_share_title'] = $modify_recipe_share_title;
  52. $need_data['modify_vipcard_share_image'] = $modify_vipcard_share_image;
  53. $need_data['cate_list'] = $cate_list;
  54. $need_data['adv_arr'] = $adv_arr;
  55. echo json_encode( array('code' => $need_data ) );
  56. die();
  57. }
  58. public function get_recipe_list()
  59. {
  60. $_GPC = I('request.');
  61. $pageNum = isset($_GPC['pageNum']) && $_GPC['pageNum'] > 0 ? $_GPC['pageNum'] : 1 ;
  62. $gid = isset($_GPC['gid']) && $_GPC['gid'] > 0 ? $_GPC['gid'] : 0;
  63. $keyword = isset($_GPC['keyword']) && !empty($_GPC['keyword']) ? $_GPC['keyword'] : '';
  64. $is_random = 0;
  65. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  66. $cate_info = '';
  67. if($gid > 0){
  68. $sub_cate_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods_category
  69. WHERE is_show=1 and cate_type='recipe' and pid = {$gid} " . '
  70. order by sort_order desc, id desc ' );
  71. $gidArr = array();
  72. $gidArr[] = $gid;
  73. foreach ($sub_cate_list as $key => $val) {
  74. $gidArr[] = $val['id'];
  75. }
  76. $gid = implode(',', $gidArr);
  77. }
  78. $where = " ";
  79. if( !empty($keyword) )
  80. {
  81. $where .= " and recipe_name like '%{$keyword}%' ";
  82. }else if( !empty($gid) )
  83. {
  84. $where .= " and cate_id in ({$gid}) ";
  85. }
  86. $offset = ($pageNum - 1) * $per_page;
  87. $limit = "{$offset},{$per_page}";
  88. $token = $_GPC['token'];
  89. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  90. $member_id = 0;
  91. if( !empty($weprogram_token) && !empty($weprogram_token['member_id']) )
  92. {
  93. $member_id = $weprogram_token['member_id'];
  94. }
  95. $list = M()->query("select * from ".C('DB_PREFIX')."lionfish_comshop_recipe where state=1 {$where} order by id desc limit {$limit} ");
  96. if( !empty($list) )
  97. {
  98. foreach( $list as $key => $val )
  99. {
  100. if( !empty($val['video'] ))
  101. {
  102. $val['is_pic_or_video'] = 2;//视频
  103. $val['video'] = tomedia($val['video']);
  104. $val['images'] = tomedia($val['images']);
  105. }else if( !empty($val['images']) )
  106. {
  107. $val['is_pic_or_video'] = 1;//图片
  108. $val['images'] = tomedia($val['images']);
  109. $val['video'] = tomedia($val['video']);
  110. }
  111. $val['username'] = '';
  112. $val['avatar'] = '';
  113. $val['has_fav'] = 0;
  114. if( $val['member_id'] >0 )
  115. {
  116. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id'] ) )->find();
  117. $val['username'] = $mb_info['username'];
  118. $val['avatar'] = $mb_info['avatar'];
  119. }
  120. if( $member_id > 0 )
  121. {
  122. $check_fav = M('lionfish_comshop_recipe_fav')->where( array('recipe_id' => $val['id'], 'member_id' => $member_id ) )->find();
  123. if( !empty($check_fav) )
  124. {
  125. $val['has_fav'] = 1;
  126. }
  127. }
  128. unset($val['content']);
  129. unset($val['content']);
  130. unset($val['sub_name']);
  131. unset($val['cate_id']);
  132. unset($val['make_time']);
  133. unset($val['make_time']);
  134. unset($val['diff_type']);
  135. unset($val['state']);
  136. $list[$key] = $val;
  137. }
  138. echo json_encode( array('code' => 0, 'data' =>$list) );
  139. die();
  140. }else{
  141. echo json_encode( array('code' => 1) );
  142. die();
  143. }
  144. }
  145. public function fav_recipe_do()
  146. {
  147. $_GPC = I('request.');
  148. $recipe_id = $_GPC['id'];
  149. $token = $_GPC['token'];
  150. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  151. if( empty($weprogram_token) )
  152. {
  153. echo json_encode( array('code' => 1, 'msg' => '请先登录') );
  154. die();
  155. }
  156. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $weprogram_token['member_id'] ) )->find();
  157. if( empty($mb_info) )
  158. {
  159. echo json_encode( array('code' => 1, 'msg' => '请先登录') );
  160. die();
  161. }
  162. $recipe_info = M('lionfish_comshop_recipe')->where( array('id' => $recipe_id ) )->find();
  163. if( empty($recipe_info) )
  164. {
  165. echo json_encode( array('code' => 1, 'msg' => '非法菜谱id' ) );
  166. die();
  167. }
  168. $fav_info = M('lionfish_comshop_recipe_fav')->where( array('recipe_id' => $recipe_id, 'member_id' => $weprogram_token['member_id'] ) )->find();
  169. if( !empty($fav_info) )
  170. {
  171. //要取消
  172. M('lionfish_comshop_recipe_fav')->where( array('id' => $fav_info['id']) )->delete();
  173. M('lionfish_comshop_recipe')->where( array('id' => $recipe_id ) )->setInc('fav_count',-1);
  174. echo json_encode( array('code' => 2,'msg' => '取消收藏成功', 'fav_count' => ($recipe_info['fav_count'] -1)) );
  175. die();
  176. }else{
  177. //要新增
  178. $ins_data = array();
  179. $ins_data['recipe_id'] = $recipe_id;
  180. $ins_data['member_id'] = $weprogram_token['member_id'];
  181. $ins_data['addtime'] = time();
  182. M('lionfish_comshop_recipe_fav')->add( $ins_data );
  183. M('lionfish_comshop_recipe')->where( array('id' => $recipe_id ) )->setInc('fav_count',1);
  184. echo json_encode( array('code' => 0,'msg' => '收藏成功' , 'fav_count' => ($recipe_info['fav_count'] +1) ) );
  185. die();
  186. }
  187. }
  188. public function get_fav_recipelist()
  189. {
  190. $_GPC = I('request.');
  191. $pageNum = isset($_GPC['pageNum']) && $_GPC['pageNum'] > 0 ? $_GPC['pageNum'] : 1 ;
  192. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  193. $token = $_GPC['token'];
  194. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  195. if( empty($weprogram_token) )
  196. {
  197. echo json_encode( array('code' => 1, 'msg' => '请先登录') );
  198. die();
  199. }
  200. $offset = ($pageNum - 1) * $per_page;
  201. $limit = "{$offset},{$per_page}";
  202. $member_id = $weprogram_token['member_id'];
  203. $sql = "select r.* from ".C('DB_PREFIX')."lionfish_comshop_recipe_fav as rf left join ".C('DB_PREFIX')."lionfish_comshop_recipe as r on rf.recipe_id = r.id
  204. where rf.member_id = {$member_id} order by rf.id desc limit {$limit} ";
  205. $list = M()->query( $sql );
  206. if( !empty($list) )
  207. {
  208. foreach( $list as $key => $val )
  209. {
  210. if( !empty($val['video'] ))
  211. {
  212. $val['is_pic_or_video'] = 2;//视频
  213. $val['video'] = tomedia($val['video']);
  214. $val['images'] = tomedia($val['images']);
  215. }else if( !empty($val['images']) )
  216. {
  217. $val['is_pic_or_video'] = 1;//图片
  218. $val['images'] = tomedia($val['images']);
  219. }
  220. $val['username'] = '';
  221. $val['avatar'] = '';
  222. $val['has_fav'] = 0;
  223. if( $val['member_id'] >0 )
  224. {
  225. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id']) )->find();
  226. $val['username'] = $mb_info['username'];
  227. $val['avatar'] = $mb_info['avatar'];
  228. }
  229. if( $member_id > 0 )
  230. {
  231. $check_fav = M('lionfish_comshop_recipe_fav')->where( array('recipe_id' => $val['id'] , 'member_id' => $member_id ) )->find();
  232. if( !empty($check_fav) )
  233. {
  234. $val['has_fav'] = 1;
  235. }
  236. }
  237. unset($val['content']);
  238. unset($val['content']);
  239. unset($val['sub_name']);
  240. unset($val['cate_id']);
  241. unset($val['make_time']);
  242. unset($val['make_time']);
  243. unset($val['diff_type']);
  244. unset($val['state']);
  245. $list[$key] = $val;
  246. }
  247. echo json_encode( array('code' => 0, 'data' =>$list) );
  248. die();
  249. }else{
  250. echo json_encode( array('code' => 1) );
  251. die();
  252. }
  253. }
  254. public function get_recipe_categorylist()
  255. {
  256. $category_list = M('lionfish_comshop_goods_category')->where( "pid=0 and cate_type='recipe' and is_show=1" )->order('sort_order desc,id asc')->select();
  257. if( !empty($category_list) )
  258. {
  259. foreach( $category_list as $key => $val )
  260. {
  261. $sub_category_list = M('lionfish_comshop_goods_category')->where( "cate_type='recipe' and pid=".$val['id']." and is_show=1" )->order('sort_order desc,id asc')->select();
  262. if( !empty($val['logo']) )
  263. {
  264. $val['logo'] = tomedia($val['logo']);
  265. }
  266. if( empty($sub_category_list) )
  267. {
  268. $val['sub_cate'] = array();
  269. }else{
  270. foreach( $sub_category_list as $kk => $vv )
  271. {
  272. if( !empty($vv['logo']) )
  273. {
  274. $vv['logo'] = tomedia($vv['logo']);
  275. }
  276. unset($vv['uniacid']);
  277. unset($vv['pid']);
  278. unset($vv['is_hot']);
  279. unset($vv['banner']);
  280. unset($vv['sort_order']);
  281. unset($vv['is_show']);
  282. unset($vv['is_show_topic']);
  283. $sub_category_list[$kk] = $vv;
  284. }
  285. $val['sub_cate'] = $sub_category_list;
  286. }
  287. unset($val['uniacid']);
  288. unset($val['pid']);
  289. unset($val['is_hot']);
  290. unset($val['banner']);
  291. unset($val['sort_order']);
  292. unset($val['is_show']);
  293. unset($val['is_show_topic']);
  294. $category_list[$key] = $val;
  295. }
  296. echo json_encode( array('code' => 0, 'data' => $category_list ) );
  297. die();
  298. }else{
  299. echo json_encode( array('code' => 1, 'msg' => '无菜谱分类数据') );
  300. die();
  301. }
  302. }
  303. public function get_recipe_detail()
  304. {
  305. $_GPC = I('request.');
  306. $id = $_GPC['id'];
  307. $head_id = isset($_GPC['head_id']) ? $_GPC['head_id']: 0;
  308. $token = $_GPC['token'];
  309. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  310. if( empty($weprogram_token) )
  311. {
  312. $member_id = 0;
  313. }else{
  314. $member_id = $weprogram_token['member_id'];
  315. }
  316. $recipe_info = M('lionfish_comshop_recipe')->where( array('id' => $id ) )->find();
  317. if( empty($recipe_info) )
  318. {
  319. echo json_encode( array('code' =>1, 'msg' => '该菜谱已经不存在') );
  320. die();
  321. }
  322. if( !empty($recipe_info['video'] ))
  323. {
  324. $recipe_info['is_pic_or_video'] = 2;//视频
  325. $recipe_info['video'] = tomedia($recipe_info['video']);
  326. $recipe_info['images'] = tomedia($recipe_info['images']);
  327. }else if( !empty($recipe_info['images']) )
  328. {
  329. $recipe_info['is_pic_or_video'] = 1;//图片
  330. $recipe_info['images'] = tomedia($recipe_info['images']);
  331. }
  332. $recipe_info['content'] = htmlspecialchars_decode($recipe_info['content']);
  333. $recipe_info['username'] = '';
  334. $recipe_info['avatar'] = '';
  335. $recipe_info['has_fav'] = 0;
  336. if($recipe_info['diff_type'] == 1)
  337. {
  338. $recipe_info['diff_name'] = '简单';
  339. }else if($recipe_info['diff_type'] == 2)
  340. {
  341. $recipe_info['diff_name'] = '容易';
  342. }else if( $recipe_info['diff_type'] == 3 ){
  343. $recipe_info['diff_name'] = '困难';
  344. }
  345. $recipe_info['diff_type'] = 0;
  346. if( $recipe_info['member_id'] >0 )
  347. {
  348. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $recipe_info['member_id'] ) )->find();
  349. $recipe_info['username'] = $mb_info['username'];
  350. $recipe_info['avatar'] = $mb_info['avatar'];
  351. }
  352. if( $member_id > 0 )
  353. {
  354. $check_fav = M('lionfish_comshop_recipe_fav')->where( array('recipe_id' =>$recipe_info['id'], 'member_id' => $member_id ) )->find();
  355. if( !empty($check_fav) )
  356. {
  357. $recipe_info['has_fav'] = 1;
  358. }
  359. }
  360. $cart= D('Home/Car');
  361. $relative_goods = M('lionfish_comshop_recipe_ingredients')->where( array('recipe_id' => $recipe_info['id'] ) )->order('id asc')->select();
  362. if( !empty($relative_goods) )
  363. {
  364. //团长休息
  365. $community_id = $head_id;
  366. foreach($relative_goods as $key => $val)
  367. {
  368. //title
  369. //subtitle goodsname
  370. $val['ingredients_title'] = $val['title'];
  371. if( !empty($val['goods_id']) )
  372. {
  373. $gd_info_list = M()->query('select g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video from
  374. '.C('DB_PREFIX')."lionfish_comshop_goods as g ,".C('DB_PREFIX')."lionfish_comshop_good_common as gc where g.id in(".$val['goods_id'].") and g.id =gc.goods_id ");
  375. $need_data = array();
  376. foreach($gd_info_list as $gd_info )
  377. {
  378. if( isset($community_id) && $community_id > 0 )
  379. {
  380. $is_can_buy = D('Seller/Communityhead')->check_goods_can_community($gd_info['id'], $community_id);
  381. if( !$is_can_buy )
  382. {
  383. continue;
  384. }
  385. // is_all_sale
  386. }
  387. $tmp_data = array();
  388. $tmp_data['actId'] = $gd_info['id'];
  389. $tmp_data['spuName'] = $gd_info['goodsname'];
  390. $tmp_data['spuCanBuyNum'] = $gd_info['total'];
  391. $tmp_data['spuDescribe'] = $gd_info['subtitle'];
  392. $tmp_data['is_take_vipcard'] = $gd_info['is_take_vipcard'];
  393. $tmp_data['soldNum'] = $gd_info['seller_count'] + $gd_info['sales'];
  394. $productprice = $gd_info['productprice'];
  395. $tmp_data['marketPrice'] = explode('.', $productprice);
  396. if( !empty($gd_info['big_img']) )
  397. {
  398. $tmp_data['bigImg'] = tomedia($gd_info['big_img']);
  399. }
  400. $good_image = D('Home/Pingoods')->get_goods_images($gd_info['id']);
  401. if( !empty($good_image) )
  402. {
  403. $tmp_data['skuImage'] = tomedia($good_image['image']);
  404. }
  405. $price_arr = D('Home/Pingoods')->get_goods_price($gd_info['id'], $member_id);
  406. $price = $price_arr['price'];
  407. if( $pageNum == 1 )
  408. {
  409. $copy_text_arr[] = array('goods_name' => $gd_info['goodsname'], 'price' => $price);
  410. }
  411. $tmp_data['actPrice'] = explode('.', $price);
  412. $tmp_data['card_price'] = $price_arr['card_price'];
  413. //card_price
  414. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($gd_info['id'],$member_id);
  415. if( !empty($tmp_data['skuList']) )
  416. {
  417. $tmp_data['car_count'] = 0;
  418. }else{
  419. $car_count = $cart->get_wecart_goods($gd_info['id'],"",$head_id ,$token);
  420. if( empty($car_count) )
  421. {
  422. $tmp_data['car_count'] = 0;
  423. }else{
  424. $tmp_data['car_count'] = $car_count;
  425. }
  426. }
  427. if($is_open_fullreduction == 0)
  428. {
  429. $tmp_data['is_take_fullreduction'] = 0;
  430. }else if($is_open_fullreduction == 1){
  431. $tmp_data['is_take_fullreduction'] = $gd_info['is_take_fullreduction'];
  432. }
  433. // 商品角标
  434. $label_id = unserialize($gd_info['labelname']);
  435. if($label_id){
  436. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  437. if($label_info){
  438. if($label_info['type'] == 1){
  439. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  440. } else {
  441. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  442. }
  443. }
  444. $tmp_data['label_info'] = $label_info;
  445. }
  446. $tmp_data['is_video'] = false;
  447. $need_data[] = $tmp_data;
  448. }
  449. $val['goods'] = $need_data;
  450. }
  451. $relative_goods[$key] = $val;
  452. }
  453. $recipe_info['recipe_ingredients'] = $relative_goods;
  454. }else{
  455. $recipe_info['recipe_ingredients'] = array();
  456. }
  457. $is_open_recipe_full_video = D('Home/Front')->get_config_by_name('is_open_recipe_full_video');
  458. echo json_encode( array('code' => 0, 'data' => $recipe_info, 'is_open_recipe_full_video'=>$is_open_recipe_full_video) );
  459. die();
  460. }
  461. }