Voucher.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 代金券控制器
  10. */
  11. class Voucher extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. }
  17. /**
  18. * @api {POST} api/Voucher/voucher_tpl_list 代金券列表
  19. * @apiVersion 1.0.0
  20. * @apiGroup Voucher
  21. *
  22. * @apiParam {String} store_id 店铺ID
  23. * @apiParam {String} gettype 代金券类型
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. * @apiSuccess {Object[]} result.voucher_list 代金券模板列表 (返回字段参考vouchertemplate)
  29. * @apiSuccess {String} result.voucher_list.vouchertemplate_enddate_text 代金券过期时间描述
  30. */
  31. public function voucher_tpl_list()
  32. {
  33. $param = array();
  34. $param['store_id'] = input('param.store_id');
  35. $param['gettype'] = input('param.gettype');
  36. $voucher_model = model('voucher');
  37. $templatestate_arr = $voucher_model->getTemplateState();
  38. $voucher_gettype_array = $voucher_model->getVoucherGettypeArray();
  39. $where = array();
  40. $where[] = array('vouchertemplate_if_private', '=', 0);
  41. $where[] = array('vouchertemplate_state', '=', $templatestate_arr['usable'][0]);
  42. $store_id = intval($param['store_id']);
  43. if ($store_id > 0) {
  44. $where[] = array('vouchertemplate_store_id', '=', $store_id);
  45. }
  46. $where[] = array('vouchertemplate_gettype', 'in', array($voucher_gettype_array['points']['sign'], $voucher_gettype_array['free']['sign']));
  47. if ($param['gettype'] && in_array($param['gettype'], array('points', 'free'))) {
  48. $where[] = array('vouchertemplate_gettype', '=', $voucher_gettype_array[$param['gettype']]['sign']);
  49. }
  50. $order = 'vouchertemplate_id asc';
  51. $voucher_list = $voucher_model->getVouchertemplateList($where, '*', 20, 0, $order);
  52. if ($voucher_list) {
  53. foreach ($voucher_list as $k => $v) {
  54. $v['vouchertemplate_limit'] = floatval($v['vouchertemplate_limit']);
  55. $v['vouchertemplate_enddate_text'] = $v['vouchertemplate_enddate'] ? @date('Y.m.d', $v['vouchertemplate_enddate']) : '';
  56. $voucher_list[$k] = $v;
  57. }
  58. }
  59. ds_json_encode(10000, '', array('voucher_list' => $voucher_list));
  60. }
  61. }