Marketmanage.php 8.2 KB

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