SigninrewardController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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 SigninrewardController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function get_signinreward_baseinfo()
  21. {
  22. $_GPC = I('request.');
  23. $token = $_GPC['token'];
  24. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  25. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  26. {
  27. echo json_encode( array('code' => 1) );
  28. die();
  29. }
  30. $member_id = $weprogram_token['member_id'];
  31. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  32. //以下是数据
  33. $isopen_signinreward = D('Home/Front')->get_config_by_name('isopen_signinreward');
  34. $isopen_signinreward = empty($isopen_signinreward) ? 0 : $isopen_signinreward;
  35. $signinreward_day1_score = D('Home/Front')->get_config_by_name('signinreward_day1_score');
  36. $signinreward_day1_score = empty($signinreward_day1_score) ? 0 : $signinreward_day1_score;
  37. $signinreward_day2_score = D('Home/Front')->get_config_by_name('signinreward_day2_score');
  38. $signinreward_day2_score = empty($signinreward_day2_score) ? 0 : $signinreward_day2_score;
  39. $signinreward_day3_score = D('Home/Front')->get_config_by_name('signinreward_day3_score');
  40. $signinreward_day3_score = empty($signinreward_day3_score) ? 0 : $signinreward_day3_score;
  41. $signinreward_day4_score = D('Home/Front')->get_config_by_name('signinreward_day4_score');
  42. $signinreward_day4_score = empty($signinreward_day4_score) ? 0 : $signinreward_day4_score;
  43. $signinreward_day5_score = D('Home/Front')->get_config_by_name('signinreward_day5_score');
  44. $signinreward_day5_score = empty($signinreward_day5_score) ? 0 : $signinreward_day5_score;
  45. $signinreward_day6_score = D('Home/Front')->get_config_by_name('signinreward_day6_score');
  46. $signinreward_day6_score = empty($signinreward_day6_score) ? 0 : $signinreward_day6_score;
  47. $signinreward_day7_score = D('Home/Front')->get_config_by_name('signinreward_day7_score');
  48. $signinreward_day7_score = empty($signinreward_day7_score) ? 0 : $signinreward_day7_score;
  49. $modify_signinreward_logo = D('Home/Front')->get_config_by_name('modify_signinreward_logo');
  50. if( !empty($modify_signinreward_logo) )
  51. {
  52. $modify_signinreward_logo = tomedia($modify_signinreward_logo);
  53. }
  54. $signinreward_share_title = D('Home/Front')->get_config_by_name('signinreward_share_title');
  55. $signinreward_share_title = empty($signinreward_share_title) ? '': $signinreward_share_title;
  56. $signinreward_share_image = D('Home/Front')->get_config_by_name('signinreward_share_image');
  57. if( !empty($signinreward_share_image) )
  58. {
  59. $signinreward_share_image = tomedia($signinreward_share_image);
  60. }
  61. $signinreward_pagenotice = D('Home/Front')->get_config_by_name('signinreward_pagenotice');
  62. $signinreward_pagenotice = empty($signinreward_pagenotice) ? '': htmlspecialchars_decode($signinreward_pagenotice);
  63. $result = array();
  64. $result['isopen_signinreward'] = $isopen_signinreward;
  65. $result['signinreward_day1_score'] = $signinreward_day1_score;
  66. $result['signinreward_day2_score'] = $signinreward_day2_score;
  67. $result['signinreward_day3_score'] = $signinreward_day3_score;
  68. $result['signinreward_day4_score'] = $signinreward_day4_score;
  69. $result['signinreward_day5_score'] = $signinreward_day5_score;
  70. $result['signinreward_day6_score'] = $signinreward_day6_score;
  71. $result['signinreward_day7_score'] = $signinreward_day7_score;
  72. $result['modify_signinreward_logo'] = $modify_signinreward_logo;
  73. $result['signinreward_share_title'] = $signinreward_share_title;
  74. $result['signinreward_share_image'] = $signinreward_share_image;
  75. $result['signinreward_pagenotice'] = $signinreward_pagenotice;
  76. //会员积分
  77. $score = $member_info['score'];
  78. //今日是否签到了。昨天是否连续签到。
  79. $today_signintime = strtotime( date('Y-m-d'). ' 00:00:00' );
  80. $today_signin_info = M('lionfish_comshop_signinreward_record')->where( array('member_id' =>$member_id , 'signin_time' => $today_signintime ) )->find();
  81. $today_is_signin = 0;//今日是否签到过
  82. $has_continuity_day = 0;//已经连续签到几天
  83. $show_day_arr = array();
  84. if( !empty($today_signin_info) )
  85. {
  86. $today_is_signin = 1;
  87. if( $today_signin_info['continuity_day'] > 0 )
  88. {
  89. $continuity_day = $today_signin_info['continuity_day'];
  90. $has_continuity_day = $continuity_day;
  91. for($i =1; $i <=$continuity_day;$i++ )
  92. {
  93. $tmp = array();
  94. $datetime = $today_signintime - ($continuity_day - $i) * 86400;
  95. $tmp['is_signin'] = 1;
  96. $tmp['is_today'] = $datetime == $today_signintime ? 1 : 0;
  97. $tmp['date'] = date('m月d日', $datetime);
  98. $show_day_arr[] = $tmp;
  99. }
  100. $del_day = 7 - $continuity_day;
  101. if( $del_day > 0 )
  102. {
  103. for($i =1; $i <=$del_day;$i++ )
  104. {
  105. $tmp = array();
  106. $datetime = $today_signintime + ($i) * 86400;
  107. $tmp['is_signin'] = 0;
  108. $tmp['is_today'] = 0;
  109. $tmp['date'] = date('m月d日', $datetime);
  110. $show_day_arr[] = $tmp;
  111. }
  112. }
  113. }
  114. }else{
  115. //今日未签到
  116. $yes_signintime = strtotime( date('Y-m-d'). ' 00:00:00' ) - 86400;
  117. $yes_signin_info = M('lionfish_comshop_signinreward_record')->where( array('member_id' =>$member_id , 'signin_time' => $yes_signintime ) )->find();
  118. if( !empty($yes_signin_info) )
  119. {
  120. //昨日有签到
  121. $continuity_day = $yes_signin_info['continuity_day'];
  122. $has_continuity_day = $continuity_day;
  123. for($i =1; $i <=$continuity_day;$i++ )
  124. {
  125. $tmp = array();
  126. $datetime = $yes_signintime - ($continuity_day - $i) * 86400;
  127. $tmp['is_signin'] = 1;
  128. $tmp['is_today'] = 0;
  129. $tmp['date'] = date('m月d日', $datetime);
  130. $show_day_arr[] = $tmp;
  131. }
  132. $del_day = 7 - $continuity_day;
  133. if( $del_day > 0 )
  134. {
  135. for($i =1; $i <=$del_day;$i++ )
  136. {
  137. $tmp = array();
  138. $datetime = $yes_signintime + ($i) * 86400;
  139. $tmp['is_signin'] = 0;
  140. $tmp['is_today'] = $datetime == $today_signintime ? 1 : 0;
  141. $tmp['date'] = date('m月d日', $datetime);
  142. $show_day_arr[] = $tmp;
  143. }
  144. }
  145. }else{
  146. //昨日未签到
  147. $has_continuity_day = 0;
  148. for($i =1; $i <=7;$i++ )
  149. {
  150. $tmp = array();
  151. $datetime = $yes_signintime + ($i) * 86400;
  152. $tmp['is_signin'] = 0;
  153. $tmp['is_today'] = $datetime == $today_signintime ? 1 : 0;
  154. $tmp['date'] = date('m月d日', $datetime);
  155. $show_day_arr[] = $tmp;
  156. }
  157. }
  158. }
  159. $result['score'] = $score;
  160. $result['today_is_signin'] = $today_is_signin;
  161. $result['has_continuity_day'] = $has_continuity_day;
  162. $result['show_day_arr'] = $show_day_arr;
  163. echo json_encode( array('code' => 0, 'data' => $result) );
  164. die();
  165. }
  166. public function sub_signin()
  167. {
  168. $gpc = I('request.');
  169. $token = $gpc['token'];
  170. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  171. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  172. {
  173. echo json_encode( array('code' => 1) );
  174. die();
  175. }
  176. $member_id = $weprogram_token['member_id'];
  177. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  178. $isopen_signinreward = D('Home/Front')->get_config_by_name('isopen_signinreward');
  179. $isopen_signinreward = empty($isopen_signinreward) ? 0 : $isopen_signinreward;
  180. if( $isopen_signinreward != 1 )
  181. {
  182. echo json_encode( array('code' => 1,'msg' => '签到奖励功能未开启') );
  183. die();
  184. }
  185. $signinreward_day1_score = D('Home/Front')->get_config_by_name('signinreward_day1_score');
  186. $signinreward_day1_score = empty($signinreward_day1_score) ? 0 : $signinreward_day1_score;
  187. $signinreward_day2_score = D('Home/Front')->get_config_by_name('signinreward_day2_score');
  188. $signinreward_day2_score = empty($signinreward_day2_score) ? 0 : $signinreward_day2_score;
  189. $signinreward_day3_score = D('Home/Front')->get_config_by_name('signinreward_day3_score');
  190. $signinreward_day3_score = empty($signinreward_day3_score) ? 0 : $signinreward_day3_score;
  191. $signinreward_day4_score = D('Home/Front')->get_config_by_name('signinreward_day4_score');
  192. $signinreward_day4_score = empty($signinreward_day4_score) ? 0 : $signinreward_day4_score;
  193. $signinreward_day5_score = D('Home/Front')->get_config_by_name('signinreward_day5_score');
  194. $signinreward_day5_score = empty($signinreward_day5_score) ? 0 : $signinreward_day5_score;
  195. $signinreward_day6_score = D('Home/Front')->get_config_by_name('signinreward_day6_score');
  196. $signinreward_day6_score = empty($signinreward_day6_score) ? 0 : $signinreward_day6_score;
  197. $signinreward_day7_score = D('Home/Front')->get_config_by_name('signinreward_day7_score');
  198. $signinreward_day7_score = empty($signinreward_day7_score) ? 0 : $signinreward_day7_score;
  199. $result = array();
  200. $result['signinreward_day1_score'] = $signinreward_day1_score;
  201. $result['signinreward_day2_score'] = $signinreward_day2_score;
  202. $result['signinreward_day3_score'] = $signinreward_day3_score;
  203. $result['signinreward_day4_score'] = $signinreward_day4_score;
  204. $result['signinreward_day5_score'] = $signinreward_day5_score;
  205. $result['signinreward_day6_score'] = $signinreward_day6_score;
  206. $result['signinreward_day7_score'] = $signinreward_day7_score;
  207. $today_signintime = strtotime( date('Y-m-d'). ' 00:00:00' );
  208. $today_signin_info = M('lionfish_comshop_signinreward_record')->where( array('member_id' =>$member_id, 'signin_time' => $today_signintime ) )->find();
  209. if( !empty($today_signin_info) )
  210. {
  211. echo json_encode( array('code' => 1,'msg' => '今天已经签到过了') );
  212. die();
  213. }else{
  214. //查询昨天是否已经签到了
  215. $yes_signintime = strtotime( date('Y-m-d'). ' 00:00:00' ) - 86400;
  216. $yes_signin_info = M('lionfish_comshop_signinreward_record')->where( array('member_id' =>$member_id, 'signin_time' => $yes_signintime ) )->find();
  217. $has_qian = 1;
  218. if( !empty($yes_signin_info) )
  219. {
  220. $has_qian = $yes_signin_info['continuity_day'] +1;
  221. $has_qian = $has_qian > 7 ? 7 : $has_qian;
  222. }
  223. $get_score = $result["signinreward_day{$has_qian}_score"];
  224. $ins_data = array();
  225. $ins_data['member_id'] = $member_id;
  226. $ins_data['continuity_day'] = $has_qian;
  227. $ins_data['reward_socre'] = $get_score;
  228. $ins_data['signin_time'] = $today_signintime;
  229. $ins_data['addtime'] = time();
  230. M('lionfish_comshop_signinreward_record')->add($ins_data);
  231. D('Admin/Member')->sendMemberPointChange($member_id,$get_score, 0 , '连续签到'.$has_qian.'天赠送'.$get_score.'积分','signin_send');
  232. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  233. $score = $member_info['score'];
  234. echo json_encode( array('code' =>0, 'score' => $score, 'continuity_day' => $has_qian,'reward_socre' => $get_score ) );
  235. die();
  236. }
  237. }
  238. public function load_sign_goodslist()
  239. {
  240. $_GPC = I('request.');
  241. $pageNum = isset($_GPC['pageNum']) ? $_GPC['pageNum'] : 1;
  242. $is_random = 0;
  243. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  244. $cate_info = '';
  245. $gid = 0;
  246. $offset = ($pageNum - 1) * $per_page;
  247. $limit = "{$offset},{$per_page}";
  248. $token = $_GPC['token'];
  249. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  250. $is_member_level_buy = 0;
  251. $is_vip_card_member = 0;
  252. $is_open_vipcard_buy = 0;
  253. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  254. {
  255. // echo json_encode( array('code' => 2) );
  256. // die();
  257. }else{
  258. $member_id = $weprogram_token['member_id'];
  259. }
  260. //整点秒杀begin
  261. $is_seckill = 0;
  262. $seckill_time = 0;
  263. //整点秒杀end
  264. $now_time = time();
  265. $where = " g.grounding =1 and g.is_seckill =0 and g.type ='integral' ";
  266. $goods_ids_nohead_arr = M('lionfish_comshop_goods')->field('id')->where( array('type' => 'integral' ) )->select();
  267. $ids_arr = array();
  268. if( !empty($goods_ids_nohead_arr) )
  269. {
  270. foreach($goods_ids_nohead_arr as $val){
  271. $ids_arr[] = $val['id'];
  272. }
  273. }
  274. $ids_str = implode(',',$ids_arr);
  275. if( !empty($ids_str) )
  276. {
  277. $where .= " and g.id in ({$ids_str})";
  278. } else{
  279. $where .= " and 0 ";
  280. }
  281. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  282. $where .= " and gc.is_new_buy=0 and gc.is_spike_buy = 0 ";
  283. $community_goods = D('Home/Pingoods')->get_new_community_index_goods('','','g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video ', $where,$offset,$per_page);
  284. if( !empty($community_goods) )
  285. {
  286. $full_money = 0;
  287. $full_reducemoney = 0;
  288. $is_open_vipcard_buy = 0;
  289. $is_open_vipcard_buy = 0;
  290. $is_open_fullreduction = 0;
  291. $cart= D('Home/Car');
  292. $list = array();
  293. $copy_text_arr = array();
  294. foreach($community_goods as $val)
  295. {
  296. $tmp_data = array();
  297. $tmp_data['actId'] = $val['id'];
  298. $tmp_data['spuName'] = $val['goodsname'];
  299. $tmp_data['spuCanBuyNum'] = $val['total'];
  300. $tmp_data['spuDescribe'] = $val['subtitle'];
  301. $tmp_data['end_time'] = $val['end_time'];
  302. $tmp_data['is_take_vipcard'] = $val['is_take_vipcard'];
  303. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  304. $productprice = $val['productprice'];
  305. $tmp_data['marketPrice'] = explode('.', $productprice);
  306. if( !empty($val['big_img']) )
  307. {
  308. $tmp_data['bigImg'] = tomedia($val['big_img']);
  309. }
  310. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  311. if( !empty($good_image) )
  312. {
  313. $tmp_data['skuImage'] = tomedia($good_image['image']);
  314. }
  315. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  316. $price_arr['price'] = round($price_arr['price'],0);
  317. $price_arr['card_price'] = round($price_arr['card_price'],0);
  318. $price_arr['levelprice'] = round($price_arr['levelprice'],0);
  319. $price = $price_arr['price'];
  320. if( $pageNum == 1 )
  321. {
  322. $copy_text_arr[] = array('goods_name' => $val['goodsname'], 'price' => $price);
  323. }
  324. $tmp_data['actPrice'] = explode(' ', $price);
  325. $tmp_data['card_price'] = $price_arr['card_price'];
  326. $tmp_data['levelprice'] = $price_arr['levelprice']; // 会员等级价格
  327. $tmp_data['is_mb_level_buy'] = $price_arr['is_mb_level_buy']; //是否 会员等级 可享受
  328. //card_price
  329. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  330. if( !empty($tmp_data['skuList']) )
  331. {
  332. $tmp_data['car_count'] = 0;
  333. }else{
  334. $car_count = $cart->get_wecart_goods($val['id'],"",$head_id ,$token);
  335. if( empty($car_count) )
  336. {
  337. $tmp_data['car_count'] = 0;
  338. }else{
  339. $tmp_data['car_count'] = $car_count;
  340. }
  341. }
  342. if($is_open_fullreduction == 0)
  343. {
  344. $tmp_data['is_take_fullreduction'] = 0;
  345. }else if($is_open_fullreduction == 1){
  346. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  347. }
  348. // 商品角标
  349. $label_id = unserialize($val['labelname']);
  350. if($label_id){
  351. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  352. if($label_info){
  353. if($label_info['type'] == 1){
  354. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  355. } else {
  356. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  357. }
  358. }
  359. $tmp_data['label_info'] = $label_info;
  360. }
  361. $tmp_data['is_video'] = empty($val['video']) ? false : true;
  362. $list[] = $tmp_data;
  363. }
  364. $is_show_list_timer = D('Home/Front')->get_config_by_name('is_show_list_timer');
  365. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  366. echo json_encode(array('code' => 0,'now_time' => time(), 'list' => $list ,'is_vip_card_member' => $is_vip_card_member,'is_member_level_buy' => $is_member_level_buy ,'copy_text_arr' => $copy_text_arr, 'cur_time' => time() ,'full_reducemoney' => $full_reducemoney,'full_money' => $full_money,'is_open_vipcard_buy' => $is_open_vipcard_buy,'is_open_fullreduction' => $is_open_fullreduction,'is_show_list_timer'=>$is_show_list_timer, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar ));
  367. die();
  368. }else{
  369. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  370. echo json_encode( array('code' => 1, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar) );
  371. die();
  372. }
  373. }
  374. }