Activity.php 4.1 KB

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