Pointprod.php 8.9 KB

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