Activity.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 Activity extends BaseMall
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/activity.lang.php');
  18. }
  19. /*
  20. * 显示所有活动列表
  21. */
  22. function index()
  23. {
  24. $condition = array();
  25. $activity_model = model('activity');
  26. $condition[] = array('activity_type', '=', 1);
  27. $condition[] = array('activity_startdate', '<=', TIMESTAMP);
  28. $condition[] = array('activity_enddate', '>=', TIMESTAMP);
  29. $condition[] = array('activity_state', '=', 1);
  30. $activity_list = $activity_model->getActivityList($condition, 10);
  31. View::assign('activity_list', $activity_list);
  32. View::assign('show_page', $activity_model->page_info->render());
  33. View::assign('html_title', config('ds_config.site_name') . ' - ' . lang('activity_list'));
  34. return View::fetch($this->template_dir . 'activity_index');
  35. }
  36. /**
  37. * 单个活动信息页
  38. */
  39. public function detail()
  40. {
  41. //得到导航ID
  42. $nav_id = intval(input('param.nav_id'));
  43. View::assign('index_sign', $nav_id);
  44. //查询活动信息
  45. $activity_id = intval(input('param.activity_id'));
  46. if ($activity_id <= 0) {
  47. $this->error(lang('param_error')); //'缺少参数:活动编号'
  48. }
  49. $activity = model('activity')->getOneActivityById($activity_id);
  50. if (empty($activity) || $activity['activity_type'] != '1' || $activity['activity_state'] != 1 || $activity['activity_startdate'] > TIMESTAMP || $activity['activity_enddate'] < TIMESTAMP) {
  51. $this->error(lang('activity_index_activity_not_exists')); //'指定活动并不存在'
  52. }
  53. View::assign('activity', $activity);
  54. $editable_page_model = model('editable_page');
  55. $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_path' => 'activity/detail', 'editable_page_client' => 'pc', 'editable_page_item_id' => $activity_id));
  56. if ($editable_page_info) {
  57. $editable_page_info['editable_page_theme_config'] = json_decode($editable_page_info['editable_page_theme_config'], true);
  58. View::assign('editable_page', $editable_page_info);
  59. $editable_page_config_model = model('editable_page_config');
  60. $editable_page_config_list = $editable_page_config_model->getEditablePageConfigList(array(array('editable_page_id', '=', $editable_page_info['editable_page_id'])));
  61. $config_list = array();
  62. foreach ($editable_page_config_list as $key => $val) {
  63. $config_info = json_decode($val['editable_page_config_content'], true);
  64. $model_id = $val['editable_page_model_id'];
  65. $var_html = array();
  66. if (!empty($config_info)) {
  67. require_once PLUGINS_PATH . '/editable_page_model/' . $model_id . '/config.php';
  68. $model_name = 'Model' . $model_id;
  69. $model = new $model_name();
  70. $res = $model->filterData($config_info);
  71. if ($res['code']) {
  72. $res = $model->formatData(json_encode($res['data']));
  73. if ($res['code']) {
  74. $var_html['config_info'] = $res['data'];
  75. }
  76. }
  77. }
  78. $html = View::fetch('../../../plugins/editable_page_model/' . $model_id . '/index', $var_html);
  79. $config_list[] = array(
  80. 'val' => $val,
  81. 'html' => $html,
  82. );
  83. }
  84. View::assign('config_list', $config_list);
  85. View::assign('editable_page', $editable_page_info);
  86. } else {
  87. //查询活动内容信息
  88. $condition = array();
  89. $condition[] = array('activitydetail.activity_id', '=', $activity_id);
  90. $condition[] = array('activitydetail.activitydetail_state', '=', '1');
  91. $activitydetail_model = model('activitydetail');
  92. $activitydetail_list = $activitydetail_model->getGoodsJoinList($condition, 100, 'activitydetail_sort asc', 'goods.goods_commonid');
  93. View::assign('show_page', $activitydetail_model->page_info->render());
  94. View::assign('activitydetail_list', $activitydetail_list);
  95. }
  96. View::assign('html_title', config('ds_config.site_name') . ' - ' . $activity['activity_title']);
  97. return View::fetch($this->template_dir . 'activity_show');
  98. }
  99. }