RecipeController.class.php 17 KB

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