Pointprod.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Pointprod extends BasePointShop {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/pointprod.lang.php');
  20. //判断系统是否开启积分兑换功能
  21. if (config('ds_config.pointprod_isuse') != 1) {
  22. $this->error(lang('pointprod_unavailable'), (string)url('Index/index'));
  23. }
  24. View::assign('index_sign', 'pointshop');
  25. }
  26. public function index() {
  27. $this->plist();
  28. }
  29. /**
  30. * 积分商品列表
  31. */
  32. public function plist() {
  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');exit;
  122. }
  123. /**
  124. * 积分礼品详细
  125. */
  126. public function pinfo() {
  127. $pid = intval(input('id'));
  128. if (!$pid) {
  129. $this->error(lang('pointprod_parameter_error'), (string)url('Pointshop/index'));
  130. }
  131. $pointprod_model = model('pointprod');
  132. //查询兑换礼品详细
  133. $prodinfo = $pointprod_model->getOnlinePointProdInfo(array(array('pgoods_id' ,'=', $pid)));
  134. if (empty($prodinfo)) {
  135. $this->error(lang('pointprod_record_error'), (string)url('Pointprod/plist'));
  136. }
  137. View::assign('prodinfo', $prodinfo);
  138. //更新礼品浏览次数
  139. $tm_tm_visite_pgoods = cookie('tm_visite_pgoods');
  140. $tm_tm_visite_pgoods = $tm_tm_visite_pgoods ? explode(',', $tm_tm_visite_pgoods) : array();
  141. if (!in_array($pid, $tm_tm_visite_pgoods)) {//如果已经浏览过该商品则不重复累计浏览次数
  142. $result = $pointprod_model->editPointProdViewnum($pid);
  143. if ($result['state'] == true) {//累加成功则cookie中增加该商品ID
  144. $tm_tm_visite_pgoods[] = $pid;
  145. cookie('tm_visite_pgoods', implode(',', $tm_tm_visite_pgoods));
  146. }
  147. }
  148. //查询兑换信息
  149. $pointorder_model = model('pointorder');
  150. $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
  151. $where = array();
  152. $where[]=array('point_orderstate','<>', $pointorderstate_arr['canceled'][0]);
  153. $where[]=array('pointog_goodsid','=',$pid);
  154. $orderprod_list = $pointorder_model->getPointorderAndGoodsList($where, '*', 'pointsordergoods.pointog_recid desc');
  155. if ($orderprod_list) {
  156. $buyerid_arr = array();
  157. foreach ($orderprod_list as $k => $v) {
  158. $buyerid_arr[] = $v['point_buyerid'];
  159. }
  160. $memberlist_tmp = model('member')->getMemberList(array(array('member_id','in', $buyerid_arr)), 'member_id,member_avatar');
  161. $memberlist = array();
  162. if ($memberlist_tmp) {
  163. foreach ($memberlist_tmp as $v) {
  164. $memberlist[$v['member_id']] = $v;
  165. }
  166. }
  167. foreach ($orderprod_list as $k => $v) {
  168. $v['member_avatar'] = get_member_avatar_for_id($v['point_buyerid']);
  169. $orderprod_list[$k] = $v;
  170. }
  171. }
  172. View::assign('orderprod_list', $orderprod_list);
  173. //热门积分兑换商品
  174. $recommend_pointsprod = $pointprod_model->getRecommendPointProd(5);
  175. View::assign('recommend_pointsprod', $recommend_pointsprod);
  176. $seo_param = array();
  177. $seo_param['name'] = $prodinfo['pgoods_name'];
  178. $seo_param['key'] = $prodinfo['pgoods_keywords'];
  179. $seo_param['description'] = $prodinfo['pgoods_description'];
  180. $this->_assign_seo(model('seo')->type('point_content')->param($seo_param)->show());
  181. //分类导航
  182. $nav_link = array(
  183. 0 => array('title' => lang('homepage'), 'link' => HOME_SITE_URL),
  184. 1 => array('title' => lang('integral_center'), 'link' => (string)url('Pointshop/index')),
  185. 2 => array('title' => lang('gift_redemption_details'))
  186. );
  187. View::assign('nav_link_list', $nav_link);
  188. return View::fetch($this->template_dir . 'pointprod_info');
  189. }
  190. }