Pointprod.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Pointprod extends BasePointShop
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/pointprod.lang.php');
  18. //判断系统是否开启积分兑换功能
  19. if (config('ds_config.pointprod_isuse') != 1) {
  20. $this->error(lang('pointprod_unavailable'), (string)url('Index/index'));
  21. }
  22. View::assign('index_sign', 'pointshop');
  23. }
  24. public function index()
  25. {
  26. $this->plist();
  27. }
  28. /**
  29. * 积分商品列表
  30. */
  31. public function plist()
  32. {
  33. //查询会员及其附属信息
  34. $result = parent::pointshopMInfo(true);
  35. $member_info = $result['member_info'];
  36. unset($result);
  37. $pointprod_model = model('pointprod');
  38. //展示状态
  39. $pgoodsshowstate_arr = $pointprod_model->getPgoodsShowState();
  40. //开启状态
  41. $pgoodsopenstate_arr = $pointprod_model->getPgoodsOpenState();
  42. $member_model = model('member');
  43. //查询会员等级
  44. $membergrade_arr = $member_model->getMemberGradeArr();
  45. View::assign('membergrade_arr', $membergrade_arr);
  46. //查询兑换商品列表
  47. $where = array();
  48. $where[] = array('pgoods_show', '=', $pgoodsshowstate_arr['show'][0]);
  49. $where[] = array('pgoods_state', '=', $pgoodsopenstate_arr['open'][0]);
  50. //会员级别
  51. $level_filter = array();
  52. if (input('level')) {
  53. $level_filter[] = array('search', '=', intval(input('level')));
  54. }
  55. if (intval(input('isable')) == 1) {
  56. $level_filter[] = array('isable', '=', intval($member_info['level']));
  57. }
  58. if (count($level_filter) > 0) {
  59. if (isset($level_filter['search']) && isset($level_filter['isable'])) {
  60. $where[] = array('pgoods_limitmgrade', '=', $level_filter['search']);
  61. $where[] = array('pgoods_limitmgrade', '<=', $level_filter['isable']);
  62. } elseif (isset($level_filter['search'])) {
  63. $where[] = array('pgoods_limitmgrade', '=', $level_filter['search']);
  64. } elseif (isset($level_filter['isable'])) {
  65. $where[] = array('pgoods_limitmgrade', '<=', $level_filter['isable']);
  66. }
  67. }
  68. //查询仅我能兑换和所需积分
  69. $points_filter = array();
  70. if (intval(input('isable')) == 1) {
  71. $points_filter['isable'] = $member_info['member_points'];
  72. }
  73. if (intval(input('points_min')) > 0) {
  74. $points_filter['min'] = intval(input('points_min'));
  75. }
  76. if (intval(input('points_max')) > 0) {
  77. $points_filter['max'] = intval(input('points_max'));
  78. }
  79. if (count($points_filter) > 0) {
  80. asort($points_filter);
  81. if (count($points_filter) > 1) {
  82. $points_filter = array_values($points_filter);
  83. $where[] = array('pgoods_points', 'between', array($points_filter[0], $points_filter[1]));
  84. } else {
  85. if (isset($points_filter['min'])) {
  86. $where[] = array('pgoods_points', '>=', $points_filter['min']);
  87. } elseif (isset($points_filter['max'])) {
  88. $where[] = array('pgoods_points', '<=', $points_filter['max']);
  89. } elseif (isset($points_filter['isable'])) {
  90. $where[] = array('pgoods_points', '<=', $points_filter['isable']);
  91. }
  92. }
  93. }
  94. //排序
  95. $orderby = '';
  96. switch (input('orderby')) {
  97. case 'stimedesc':
  98. $orderby = 'pgoods_starttime desc,';
  99. break;
  100. case 'stimeasc':
  101. $orderby = 'pgoods_starttime asc,';
  102. break;
  103. case 'pointsdesc':
  104. $orderby = 'pgoods_points desc,';
  105. break;
  106. case 'pointsasc':
  107. $orderby = 'pgoods_points asc,';
  108. break;
  109. }
  110. $orderby .= 'pgoods_sort asc,pgoods_id desc';
  111. $pointprod_list = $pointprod_model->getPointProdList($where, '*', $orderby, '', 20);
  112. View::assign('pointprod_list', $pointprod_list);
  113. View::assign('show_page', $pointprod_model->page_info->render());
  114. //分类导航
  115. $nav_link = array(
  116. 0 => array('title' => lang('homepage'), 'link' => HOME_SITE_URL),
  117. 1 => array('title' => lang('integral_center'), 'link' => (string)url('Pointshop/index')),
  118. 2 => array('title' => lang('gift_redemption_list'))
  119. );
  120. View::assign('nav_link_list', $nav_link);
  121. echo View::fetch($this->template_dir . 'pointprod_list');
  122. exit;
  123. }
  124. /**
  125. * 积分礼品详细
  126. */
  127. public function pinfo()
  128. {
  129. $pid = intval(input('id'));
  130. if (!$pid) {
  131. $this->error(lang('pointprod_parameter_error'), (string)url('Pointshop/index'));
  132. }
  133. $pointprod_model = model('pointprod');
  134. //查询兑换礼品详细
  135. $prodinfo = $pointprod_model->getOnlinePointProdInfo(array(array('pgoods_id', '=', $pid)));
  136. if (empty($prodinfo)) {
  137. $this->error(lang('pointprod_record_error'), (string)url('Pointprod/plist'));
  138. }
  139. View::assign('prodinfo', $prodinfo);
  140. //更新礼品浏览次数
  141. $tm_tm_visite_pgoods = cookie('tm_visite_pgoods');
  142. $tm_tm_visite_pgoods = $tm_tm_visite_pgoods ? explode(',', $tm_tm_visite_pgoods) : array();
  143. if (!in_array($pid, $tm_tm_visite_pgoods)) { //如果已经浏览过该商品则不重复累计浏览次数
  144. $result = $pointprod_model->editPointProdViewnum($pid);
  145. if ($result['state'] == true) { //累加成功则cookie中增加该商品ID
  146. $tm_tm_visite_pgoods[] = $pid;
  147. cookie('tm_visite_pgoods', implode(',', $tm_tm_visite_pgoods));
  148. }
  149. }
  150. //查询兑换信息
  151. $pointorder_model = model('pointorder');
  152. $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
  153. $where = array();
  154. $where[] = array('point_orderstate', '<>', $pointorderstate_arr['canceled'][0]);
  155. $where[] = array('pointog_goodsid', '=', $pid);
  156. $orderprod_list = $pointorder_model->getPointorderAndGoodsList($where, '*', 'pointsordergoods.pointog_recid desc');
  157. if ($orderprod_list) {
  158. $buyerid_arr = array();
  159. foreach ($orderprod_list as $k => $v) {
  160. $buyerid_arr[] = $v['point_buyerid'];
  161. }
  162. $memberlist_tmp = model('member')->getMemberList(array(array('member_id', 'in', $buyerid_arr)), 'member_id,member_avatar');
  163. $memberlist = array();
  164. if ($memberlist_tmp) {
  165. foreach ($memberlist_tmp as $v) {
  166. $memberlist[$v['member_id']] = $v;
  167. }
  168. }
  169. foreach ($orderprod_list as $k => $v) {
  170. $v['member_avatar'] = get_member_avatar_for_id($v['point_buyerid']);
  171. $orderprod_list[$k] = $v;
  172. }
  173. }
  174. View::assign('orderprod_list', $orderprod_list);
  175. //热门积分兑换商品
  176. $recommend_pointsprod = $pointprod_model->getRecommendPointProd(5);
  177. View::assign('recommend_pointsprod', $recommend_pointsprod);
  178. $seo_param = array();
  179. $seo_param['name'] = $prodinfo['pgoods_name'];
  180. $seo_param['key'] = $prodinfo['pgoods_keywords'];
  181. $seo_param['description'] = $prodinfo['pgoods_description'];
  182. $this->_assign_seo(model('seo')->type('point_content')->param($seo_param)->show());
  183. //分类导航
  184. $nav_link = array(
  185. 0 => array('title' => lang('homepage'), 'link' => HOME_SITE_URL),
  186. 1 => array('title' => lang('integral_center'), 'link' => (string)url('Pointshop/index')),
  187. 2 => array('title' => lang('gift_redemption_details'))
  188. );
  189. View::assign('nav_link_list', $nav_link);
  190. return View::fetch($this->template_dir . 'pointprod_info');
  191. }
  192. }