Activity.php 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Activity extends MobileMall {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/activity.lang.php');
  20. }
  21. /*
  22. * 显示所有活动列表
  23. */
  24. function index()
  25. {
  26. $condition = array();
  27. $activity_model = model('activity');
  28. $activitydetail_model = model('activitydetail');
  29. $condition[]=array('activity_type','=',1);
  30. $condition[]=array('activity_startdate','<=',TIMESTAMP);
  31. $condition[]=array('activity_enddate','>=',TIMESTAMP);
  32. $condition[]=array('activity_state','=',1);
  33. $activity_list = $activity_model->getActivityList($condition, 10);
  34. foreach($activity_list as $key => $val){
  35. $activity_list[$key]['activity_banner_mobile_url']=ds_get_pic(ATTACH_ACTIVITY,$val['activity_banner_mobile']);
  36. $condition=array();
  37. $condition[]=array('activity_id','=',$val['activity_id']);
  38. $condition[]=array('activitydetail_state','=',1);
  39. $goods_list=$activitydetail_model->getGoodsJoinList($condition,3,'activitydetail_sort asc');
  40. foreach($goods_list as $k => $v){
  41. $goods_list[$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $v['store_id']);
  42. }
  43. $activity_list[$key]['goods_list']=$goods_list;
  44. }
  45. $result = array_merge(array('activity_list' => $activity_list), mobile_page(is_object($activity_model->page_info) ? $activity_model->page_info : ''));
  46. ds_json_encode(10000, '', $result);
  47. }
  48. /**
  49. * 单个活动信息页
  50. */
  51. public function detail() {
  52. //查询活动信息
  53. $activity_id = intval(input('param.activity_id'));
  54. if ($activity_id <= 0) {
  55. ds_json_encode(10001,lang('param_error')); //'缺少参数:活动编号'
  56. }
  57. $cache_key='api-activity-'.$activity_id;
  58. $result = rcache($cache_key);
  59. if (empty($result)) {
  60. $activity = model('activity')->getOneActivityById($activity_id);
  61. $result=array('activity'=>$activity);
  62. wcache($cache_key, $result);
  63. }
  64. $activity=$result['activity'];
  65. if (empty($activity) || $activity['activity_type'] != '1' || $activity['activity_state'] != 1 || $activity['activity_startdate'] > TIMESTAMP || $activity['activity_enddate'] < TIMESTAMP) {
  66. ds_json_encode(10001,lang('activity_index_activity_not_exists')); //'指定活动并不存在'
  67. }
  68. $activity['activity_banner_mobile_url']=ds_get_pic(ATTACH_ACTIVITY,$activity['activity_banner_mobile']);
  69. $activitydetail_model=model('activitydetail');
  70. //查询活动内容信息
  71. $condition = array();
  72. $condition[] = array('activitydetail.activity_id','=',$activity_id);
  73. $condition[] = array('activitydetail.activitydetail_state','=','1');
  74. $activitydetail_list = $activitydetail_model->getGoodsJoinList($condition,$this->pagesize,'activitydetail_sort asc','goods.goods_commonid');
  75. foreach($activitydetail_list as $key => $val){
  76. $activitydetail_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
  77. }
  78. $result = array_merge(array('activity'=>$activity,'activitydetail_list'=>$activitydetail_list), mobile_page(is_object($activitydetail_model->page_info) ? $activitydetail_model->page_info : ''));
  79. ds_json_encode(10000, '', $result);
  80. }
  81. }
  82. ?>