Pointmallvoucher.php 3.9 KB

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