123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- class Pointvoucher extends MobileMall
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/voucher.lang.php');
-
- if (config('ds_config.points_isuse') != 1 || config('ds_config.pointprod_isuse') != 1) {
- ds_json_encode(10001, lang('pointshop_unavailable'));
- }
- if (config('ds_config.voucher_allow') != 1) {
- ds_json_encode(10001, lang('voucher_pointunavailable'));
- }
- }
- public function index()
- {
- $this->pointvoucher();
- }
-
- public function pointvoucher()
- {
- $voucher_model = model('voucher');
-
- $templatestate_arr = $voucher_model->getTemplateState();
-
- $member_info = model('member')->getMemberInfoByID(session('member_id'));
-
- $where = array();
- $where[] = array('vouchertemplate_if_private', '=', 0);
- $where[] = array('vouchertemplate_state', '=', $templatestate_arr['usable'][0]);
- $where[] = array('vouchertemplate_enddate', '>', TIMESTAMP);
- if (intval(input('storeclass_id')) > 0) {
- $where[] = array('vouchertemplate_sc_id', '=', intval(input('storeclass_id')));
- }
- if (intval(input('price')) > 0) {
- $where[] = array('vouchertemplate_price', '=', intval(input('price')));
- }
-
- $points_filter = array();
- if (intval(input('isable')) == 1) {
- $points_filter['isable'] = $member_info['member_points'];
- }
- if (intval(input('points_min')) > 0) {
- $points_filter['min'] = intval(input('points_min'));
- }
- if (intval(input('points_max')) > 0) {
- $points_filter['max'] = intval(input('points_max'));
- }
- if (count($points_filter) > 0) {
- asort($points_filter);
- if (count($points_filter) > 1) {
- $points_filter = array_values($points_filter);
- $where[] = array('vouchertemplate_points', 'between', array($points_filter[0], $points_filter[1]));
- } else {
- if ($points_filter['min']) {
- $where[] = array('vouchertemplate_points', '>=', $points_filter['min']);
- } elseif ($points_filter['max']) {
- $where[] = array('vouchertemplate_points', '<=', $points_filter['max']);
- } elseif ($points_filter['isable']) {
- $where[] = array('vouchertemplate_points', '<=', $points_filter['isable']);
- }
- }
- }
-
- switch (input('orderby')) {
- case 'exchangenumdesc':
- $orderby = 'vouchertemplate_giveout desc,';
- break;
- case 'exchangenumasc':
- $orderby = 'vouchertemplate_giveout asc,';
- break;
- case 'pointsdesc':
- $orderby = 'vouchertemplate_points desc,';
- break;
- case 'pointsasc':
- $orderby = 'vouchertemplate_points asc,';
- break;
- default:
- $orderby = '';
- }
- $orderby .= 'vouchertemplate_id desc';
- $voucherlist = $voucher_model->getVouchertemplateList($where, '*', 0, 18, $orderby);
- $page_count = $voucher_model->page_info;
-
- $pricelist = $voucher_model->getVoucherPriceList();
-
- $store_class = rkcache('storeclass', true);
- $result = array_merge(array('voucherlist' => $voucherlist, 'pricelist' => $pricelist, 'store_class' => $store_class), mobile_page($page_count));
- ds_json_encode(10000, '', $result);
- }
-
- public function voucherexchange_save()
- {
- $member_id = $this->getMemberIdIfExists();
- if (!$member_id) {
- ds_json_encode(10001, lang('param_error'));
- }
- $vid = intval(input('post.vid'));
- if ($vid <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $seller_model = model('seller');
- $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_id));
- $voucher_model = model('voucher');
-
- $data = $voucher_model->getCanChangeTemplateInfo($vid, intval($member_id), $seller_info['store_id']);
- if ($data['state'] == false) {
- ds_json_encode(10001, $data['msg']);
- }
-
- $data = $voucher_model->exchangeVoucher($data['info'], $member_id);
- if ($data['state'] == true) {
- ds_json_encode(10000, $data['msg']);
- } else {
- ds_json_encode(10001, $data['msg']);
- }
- }
- }
|