Pointmallvoucher.php 3.7 KB

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