Marketmanage.php 8.4 KB

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