Pointmallvoucher.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 控制器
  10. */
  11. class Pointmallvoucher extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/voucher.lang.php');
  17. //判断系统是否开启积分兑换功能
  18. if (config('ds_config.points_isuse') != 1 || config('ds_config.pointprod_isuse') != 1) {
  19. ds_json_encode(10001, lang('pointshop_unavailable'));
  20. }
  21. if (config('ds_config.voucher_allow') != 1) {
  22. ds_json_encode(10001, lang('voucher_pointunavailable'));
  23. }
  24. }
  25. public function index()
  26. {
  27. $this->pointmallvoucher();
  28. }
  29. /**
  30. * 平台代金券列表
  31. */
  32. public function pointmallvoucher()
  33. {
  34. $mallvouchertemplate_model = model('mallvouchertemplate');
  35. $where = array();
  36. $where[] = array('mallvouchertemplate_startdate', '<', TIMESTAMP);
  37. $where[] = array('mallvouchertemplate_enddate', '>', TIMESTAMP);
  38. $gc_id = intval(input('gc_id'));
  39. if ($gc_id > 0) {
  40. $gc_idarr = array();
  41. $goodsclasslist = model('goodsclass')->getChildClass($gc_id);
  42. foreach ($goodsclasslist as $k => $v) {
  43. $gc_idarr[] = $v['gc_id'];
  44. }
  45. $gccondition = implode(',', $gc_idarr);
  46. $where[] = array('mallvouchertemplate_gcid', 'in', $gccondition);
  47. }
  48. $orderby = 'mallvouchertemplate_id desc';
  49. $mallvoucherlist = $mallvouchertemplate_model->getMallvouchertemplateList($where, 10, $orderby);
  50. $page_count = $mallvouchertemplate_model->page_info;
  51. //查询平台分类
  52. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  53. $result = array_merge(array('mallvoucherlist' => $mallvoucherlist, 'gc_list' => $gc_list), mobile_page($page_count));
  54. ds_json_encode(10000, '', $result);
  55. }
  56. /**
  57. * 兑换代金券保存信息
  58. *
  59. */
  60. public function mallvoucherexchange_save()
  61. {
  62. $member_id = $this->getMemberIdIfExists();
  63. $condition = array();
  64. $condition[] = array('member_id', '=', $member_id);
  65. $member_name = model('member')->getMemberInfo($condition, 'member_name');
  66. if (!$member_id) {
  67. ds_json_encode(10001, lang('param_error'));
  68. }
  69. $vid = intval(input('post.vid'));
  70. if ($vid <= 0) {
  71. ds_json_encode(10001, lang('param_error'));
  72. }
  73. $mallvouchertemplate_model = model('mallvouchertemplate');
  74. //验证是否可以兑换代金券
  75. $data = $mallvouchertemplate_model->getCanChangeTemplateInfo($vid, $member_id);
  76. if ($data['state'] == false) {
  77. ds_json_encode(10001, $data['msg']);
  78. }
  79. //添加代金券信息
  80. $data = $mallvouchertemplate_model->exchangeMallvoucher($data['info'], $member_id, $member_name['member_name']);
  81. if ($data['state'] == true) {
  82. ds_json_encode(10000, $data['msg']);
  83. } else {
  84. ds_json_encode(10001, $data['msg']);
  85. }
  86. }
  87. }