Activity.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * 控制器
  6. */
  7. class Activity extends MobileMall {
  8. public function initialize() {
  9. parent::initialize();
  10. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/activity.lang.php');
  11. }
  12. /*
  13. * 显示所有活动列表
  14. */
  15. function index()
  16. {
  17. $condition = array();
  18. $activity_model = model('activity');
  19. $activitydetail_model = model('activitydetail');
  20. $condition[]=array('activity_type','=',1);
  21. $condition[]=array('activity_startdate','<=',TIMESTAMP);
  22. $condition[]=array('activity_enddate','>=',TIMESTAMP);
  23. $condition[]=array('activity_state','=',1);
  24. $activity_list = $activity_model->getActivityList($condition, 10);
  25. foreach($activity_list as $key => $val){
  26. $activity_list[$key]['activity_banner_mobile_url']=ds_get_pic(ATTACH_ACTIVITY,$val['activity_banner_mobile']);
  27. $condition=array();
  28. $condition[]=array('activity_id','=',$val['activity_id']);
  29. $condition[]=array('activitydetail_state','=',1);
  30. $goods_list=$activitydetail_model->getGoodsJoinList($condition,3,'activitydetail_sort asc');
  31. foreach($goods_list as $k => $v){
  32. $goods_list[$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $v['store_id']);
  33. }
  34. $activity_list[$key]['goods_list']=$goods_list;
  35. }
  36. $result = array_merge(array('activity_list' => $activity_list), mobile_page(is_object($activity_model->page_info) ? $activity_model->page_info : ''));
  37. ds_json_encode(10000, '', $result);
  38. }
  39. /**
  40. * 单个活动信息页
  41. */
  42. public function detail() {
  43. //查询活动信息
  44. $activity_id = intval(input('param.activity_id'));
  45. if ($activity_id <= 0) {
  46. ds_json_encode(10001,lang('param_error')); //'缺少参数:活动编号'
  47. }
  48. $cache_key='api-activity-'.$activity_id;
  49. $result = rcache($cache_key);
  50. if (empty($result)) {
  51. $activity = model('activity')->getOneActivityById($activity_id);
  52. $result=array('activity'=>$activity);
  53. wcache($cache_key, $result);
  54. }
  55. $activity=$result['activity'];
  56. if (empty($activity) || $activity['activity_type'] != '1' || $activity['activity_state'] != 1 || $activity['activity_startdate'] > TIMESTAMP || $activity['activity_enddate'] < TIMESTAMP) {
  57. ds_json_encode(10001,lang('activity_index_activity_not_exists')); //'指定活动并不存在'
  58. }
  59. $activity['activity_banner_mobile_url']=ds_get_pic(ATTACH_ACTIVITY,$activity['activity_banner_mobile']);
  60. $activitydetail_model=model('activitydetail');
  61. //查询活动内容信息
  62. $condition = array();
  63. $condition[] = array('activitydetail.activity_id','=',$activity_id);
  64. $condition[] = array('activitydetail.activitydetail_state','=','1');
  65. $activitydetail_list = $activitydetail_model->getGoodsJoinList($condition,$this->pagesize,'activitydetail_sort asc','goods.goods_commonid');
  66. foreach($activitydetail_list as $key => $val){
  67. $activitydetail_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
  68. }
  69. $result = array_merge(array('activity'=>$activity,'activitydetail_list'=>$activitydetail_list), mobile_page(is_object($activitydetail_model->page_info) ? $activitydetail_model->page_info : ''));
  70. ds_json_encode(10000, '', $result);
  71. }
  72. }
  73. ?>