Marketmanage.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 营销活动控制器
  10. */
  11. class Marketmanage extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/marketmanage.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Marketmanage/get_info 营销活动详情
  20. * @apiVersion 1.0.0
  21. * @apiGroup Marketmanage
  22. *
  23. * @apiParam {Int} marketmanage_id 活动ID
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. */
  29. public function get_info()
  30. {
  31. $marketmanage_id = intval(input('param.marketmanage_id'));
  32. if ($marketmanage_id < 0) {
  33. ds_json_encode(10001, lang('param_error'));
  34. }
  35. $marketmanage_model = model('marketmanage');
  36. $condition = array();
  37. $condition[] = array('marketmanage_id', '=', $marketmanage_id);
  38. $marketmanage = $marketmanage_model->getOneMarketmanage($condition);
  39. if (!$marketmanage) {
  40. ds_json_encode(10001, lang('market_activity_not_exist'));
  41. }
  42. if ($marketmanage['marketmanage_begintime'] > TIMESTAMP) {
  43. ds_json_encode(10001, lang('market_activity_not_begin'));
  44. }
  45. if ($marketmanage['marketmanage_endtime'] < TIMESTAMP) {
  46. ds_json_encode(10001, lang('market_activity_not_end'));
  47. }
  48. $marketmanage['marketmanage_begintime_text'] = date('Y.m.d', $marketmanage['marketmanage_begintime']);
  49. $marketmanage['marketmanage_endtime_text'] = date('Y.m.d', $marketmanage['marketmanage_endtime']);
  50. //获取奖项设置
  51. $marketmanageaward_list = $marketmanage_model->getMarketmanageAwardList(array(array('marketmanage_id', '=', $marketmanage_id), array('marketmanageaward_count', '>', 0)));
  52. if (!$marketmanageaward_list) {
  53. ds_json_encode(10001, lang('market_award_set_error'));
  54. }
  55. foreach ($marketmanageaward_list as $k => $v) {
  56. switch ($v['marketmanageaward_type']) {
  57. case 1:
  58. $marketmanageaward_list[$k]['marketmanageaward_text'] = $v['marketmanageaward_point'] . lang('ds_point');
  59. break;
  60. case 2:
  61. $bonus_model = model('bonus');
  62. $condition = array();
  63. $condition[] = array('bonus_id', '=', $v['bonus_id']);
  64. $bonus = $bonus_model->getOneBonus($condition); //获取当前红包的领取金额
  65. if (!$bonus) {
  66. ds_json_encode(10001, lang('bonus_set_error'));
  67. }
  68. if ($bonus['bonus_type'] != 3) {
  69. ds_json_encode(10001, lang('bonus_set_error'));
  70. }
  71. if ($bonus['bonus_pricetype']) {
  72. $marketmanageaward_list[$k]['marketmanageaward_text'] = floatval($bonus['bonus_fixedprice']) . lang('bonus_fixedprice_notice');
  73. } else {
  74. $marketmanageaward_list[$k]['marketmanageaward_text'] = floatval($bonus['bonus_randomprice_start']) . '~' . floatval($bonus['bonus_randomprice_end']) . lang('bonus_randomprice_notice');
  75. }
  76. break;
  77. case 3:
  78. $voucher_model = model('voucher');
  79. //验证是否可以兑换代金券
  80. $where = array();
  81. $where[] = array('vouchertemplate_id', '=', $v['vouchertemplate_id']);
  82. $where[] = array('vouchertemplate_state', '=', 1);
  83. $where[] = array('vouchertemplate_enddate', '>', TIMESTAMP);
  84. $template_info = $voucher_model->getVouchertemplateInfo($where);
  85. if (empty($template_info)) {
  86. ds_json_encode(10001, lang('vouchertemplate_set_error'));
  87. }
  88. $marketmanageaward_list[$k]['marketmanageaward_text'] = $template_info['vouchertemplate_price'] . lang('vouchertemplate_notice');
  89. break;
  90. default:
  91. ds_json_encode(10001, lang('bargain_not_exist'));
  92. }
  93. }
  94. $can_draw = true;
  95. $message = '';
  96. $count_left = 0;
  97. $memeber_id = $this->getMemberIdIfExists();
  98. if ($marketmanage['marketmanage_jointype'] != 2 && $memeber_id) { //有参与次数限制
  99. //判断当前用户是否参与过
  100. $condition = array();
  101. $condition[] = array('marketmanage_id', '=', $marketmanage_id);
  102. $condition[] = array('member_id', '=', $memeber_id);
  103. $marketmanage_joincount = $marketmanage['marketmanage_joincount'];
  104. switch ($marketmanage['marketmanage_jointype']) {
  105. case 0:
  106. break;
  107. case 1:
  108. $condition[] = array('marketmanagelog_time', 'between', array(strtotime(date('Y-m-d 0:0:0')), TIMESTAMP));
  109. break;
  110. default:
  111. ds_json_encode(10001, lang('marketmanage_jointype_set_error'));
  112. }
  113. $marketmanagelog = $marketmanage_model->getMarketmanageLogList($condition);
  114. if (count($marketmanagelog) >= $marketmanage_joincount) {
  115. $can_draw = false;
  116. $message = sprintf(lang('marketmanage_joincount_error'), count($marketmanagelog));
  117. } else {
  118. $count_left = $marketmanage_joincount - count($marketmanagelog);
  119. }
  120. }
  121. $result = array('marketmanage_info' => $marketmanage, 'marketmanageaward_list' => $marketmanageaward_list, 'can_draw' => $can_draw, 'count_left' => $count_left);
  122. ds_json_encode(10000, $message, $result);
  123. }
  124. /**
  125. * @api {POST} api/Marketmanage/get_list 营销活动列表
  126. * @apiVersion 1.0.0
  127. * @apiGroup Marketmanage
  128. *
  129. * @apiSuccess {String} code 返回码,10000为成功
  130. * @apiSuccess {String} message 返回消息
  131. * @apiSuccess {Object} result 返回数据
  132. */
  133. public function get_list()
  134. {
  135. $marketmanage_model = model('marketmanage');
  136. $type = intval(input('param.type'));
  137. if (!empty($type)) {
  138. $condition[] = array('marketmanage_type', '=', $type);
  139. }
  140. //获取活动列表
  141. $condition[] = array('marketmanage_endtime', '>', TIMESTAMP);
  142. $marketmanage_list = $marketmanage_model->getMarketmanageList($condition, 10);
  143. foreach ($marketmanage_list as $k => $v) {
  144. switch ($v['marketmanage_type']) {
  145. case 1:
  146. $marketmanage_list[$k]['marketmanage_type'] = lang('market_1');
  147. break;
  148. case 2:
  149. $marketmanage_list[$k]['marketmanage_type'] = lang('market_2');
  150. break;
  151. case 3:
  152. $marketmanage_list[$k]['marketmanage_type'] = lang('market_3');
  153. break;
  154. case 4:
  155. $marketmanage_list[$k]['marketmanage_type'] = lang('market_4');
  156. break;
  157. default:
  158. }
  159. $marketmanage_list[$k]['marketmanage_begintime'] = date("Y-m-d H:i:s", $marketmanage_list[$k]['marketmanage_begintime']);
  160. $marketmanage_list[$k]['marketmanage_endtime'] = date("Y-m-d H:i:s", $marketmanage_list[$k]['marketmanage_endtime']);
  161. }
  162. $result = array_merge(array('marketmanage_list' => $marketmanage_list), mobile_page($marketmanage_model->page_info));
  163. ds_json_encode(10000, '', $result);
  164. }
  165. }