文件
mashangyoujiu/Application/Retail/Controller/VipconfigController.class.php

514 行
20 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Common\Model\RetailMerchantConfigModel;
use Common\Model\RetailVipConfigModel;
use Think\Controller;
use Think\Page;
//[1.9.12]
class VipconfigController extends BaseController
{
public function index()
{
$merchant_id = session('merchant_userinfo')['id'];
$info = M('vip_config')->where(array('merchantid' => $merchant_id))->find();
$info['vip_detail'] = htmlspecialchars_decode($info['vip_detail']);
$info['plus_flower_type'] = $info['plus_flower_type'] ? $info['plus_flower_type'] : 1;
$info['plus_recharge_type'] = $info['plus_recharge_type'] ? $info['plus_recharge_type'] : 1;
$info['percent'] = $info['percent'] ? round($info['percent']) :'';
$info['recharge_integral'] = $info['recharge_integral'] ? intval($info['recharge_integral']) :'';
$this->assign('vipset', $info);
$MerchantConfig = D('MerchantConfig')->getFind(array('merchant_id' => $merchant_id));
if (!$MerchantConfig) {
$MerchantConfig['other_pay'] = 1;
$MerchantConfig['pay_to_vip_state'] = '0';
}
$MerchantConfig['integral_arrive_cash_rate'] = $MerchantConfig['integral_arrive_cash_rate'] * 100;
$this->assign('MerchantConfig', $MerchantConfig);
$arr = array(
'vipconfigset' => '/index.php/Retail/Vipconfig/vipconfigset',
'plus_vipconfigset' => '/index.php/Retail/Vipconfig/plus_vipconfigset',
'saveIntegralSet' => '/index.php/Retail/BaseSet/saveIntegralSet',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function vipconfigset()
{
if (IS_POST) {
$userinfo = session("ls_userinfo");
$merchantid = $userinfo['merchantid'];
//会员积分验证
$signin_give = I('post.signin_give');
$infoscore = I('post.infoscore');
$preg_match = "/^[0-9]*$/";
if($signin_give !== '' && !preg_match($preg_match,$signin_give)){
$res['status'] = 0;
$res['msg'] = '请输入正确的赠送积分';
$this->ajaxReturn($res);
}
if($infoscore !== '' && !preg_match($preg_match,$infoscore)){
$res['status'] = 0;
$res['msg'] = '请输入正确的赠送积分';
$this->ajaxReturn($res);
}
$info = M('vip_config')->where(array('merchantid' => $merchantid))->find();
$data = array(
'signin_give' => I('post.signin_give') ? I('post.signin_give') : 0,
'infoscore' => I('post.infoscore') ? I('post.infoscore') : 0,
'vip_detail' => I('post.vip_detail') ? I('post.vip_detail') : '',
'percent_state' => I('post.percent_state'),
'vip_pay_integral_state' => I('post.vip_pay_integral_state'),
'recharge_state' => I('post.recharge_state'),
'goods_integral_state' => I('post.goods_integral_state') ? I('post.goods_integral_state') : 2,
);
if ($data['percent_state'] == 1) {
//开启消费得积分
$data['flower_price'] = I('post.flower_price'); //消费金额
$data['percent'] = I('post.percent') ? I('post.percent') : 0.00;
}
if ($data['recharge_state'] == 1) {
//开启充值获得积分
$data['recharge_price'] = I('post.recharge_price'); //充值金额
$data['recharge_integral'] = I('post.recharge_integral') ? I('post.recharge_integral') : 0.00;
}
if ($info) {
$ret = M('vip_config')->where(array('id' => $info['id']))->save($data);
} else {
$data['merchantid'] = $merchantid;
$data['addtime'] = time();
$ret = M('vip_config')->add($data);
}
if ($ret !== false) {
$rt['status'] = 1;
$rt['msg'] = '设置成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '常规会员积分设置修改';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$rt['status'] = 0;
$rt['msg'] = '设置失败';
}
$this->ajaxReturn($rt);
}
}
//plus会员提交
public function plus_vipconfigset()
{
$merchant_id = session("merchant_userinfo")['id'];
$data = I('post.');
$vip_config_model = new RetailVipConfigModel();
$verify_data = $vip_config_model->verify_param($data); //参数验证
if ($verify_data['status'] == 0) {
$this->ajaxReturn($verify_data);
}
$config_info = $vip_config_model->getFind(array('merchantid' => $merchant_id));
if ($config_info) {
$data['id'] = $config_info['id'];
} else {
$data['merchantid'] = $merchant_id;
}
$res = $vip_config_model->addPlusData($data);
if ($res['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = 'Plus会员积分设置修改';//操作行为描述
action_log($source, $type, $request_data, $desc);
}
$this->ajaxReturn($res);
}
//积分抵现
public function saveIntegralSet()
{
$data = I("post.");
$mer_config = new RetailMerchantConfigModel();
$verify_data = $mer_config->verify_data($data);
if($verify_data['status'] == 0){
$this->ajaxReturn($verify_data);
}
$data['merchant_id'] = session('merchant_userinfo')['id'];
$res = $mer_config->market_add($data);
if ($res['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '编辑积分抵现设置';//操作行为描述
action_log($source, $type, $request_data, $desc);
}
$this->ajaxReturn($res);
}
public function upload()
{
$upload = new \Think\Upload (); // 实例化上传类
$upload->maxSize = 1048576 / 1; // 设置附件上传大小1M/1
$upload->exts = array(
'jpg',
'png',
'jpeg',
); // 设置附件上传类型
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
$upload->savePath = '/Vip/'; // 设置附件上传(子)目录
$upload->saveName = array(
'uniqid',
''
);
// 上传文件
$info = $upload->upload();
$path['path'] = '/' . 'Uploads' . $info['file']['savepath'] . $info['file']['savename'];
$this->ajaxReturn($path);
}
/**
* 会员注册福利
*/
public function welfare()
{
$this->display();
}
// 屏蔽库存不足的优惠券
public function getCanUseMCoupon()
{
$userinfo = session("ls_userinfo");
$merchantid = $userinfo['merchantid'];
$type = I('get.type');
$time = time();
$w['type'] = 1;
$w['status'] = 1;
$w['coupon_num'] = array('gt', 0);
$w['_string'] = "(coupontype = 1 AND endtime > {$time}) OR (coupontype = 2) OR (coupontype = 3)";
$Ad['merchantid'] = $merchantid;
$Ad['type'] = 1;
$map = $Ad;
$map['status'] = array('in', '1,2');
$map['mcouponid'] = array('EXP', 'IS NOT NULL');
$ids = M('retail_vip_register_welfare')->where($map)->getField('mcouponid', true);
$ids = $ids ? $ids : array(0);
$w['id'] = array('not in', $ids);
$w['coupon_num'] = array('GT', 0);
$page = I('get.page');
$limit = I('get.limit');
$w['merchantid'] = $merchantid;
$count = M('retail_mcoupon')->where($w)->count();
$list = M('retail_mcoupon')->where($w)
->page($page, $limit)
->order('addtime desc')
->select();
// 查询出所有可用门店
$storelist = M('retail_store')
->where(array('merchantid' => $merchantid, 'store_status' => 0, 'state' => 0))
->field('id,storetag')
->select();
$gradeall = M('retail_vip_integral')
->where(array('merchantid' => $merchantid))
->field('id,cardname')
->select();
foreach ($list as $k => &$v) {
$v['type'] = 2;
$v['typename'] = '进行中';
$v['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
if ($v['coupontype'] == 1) {
$v['usetime'] = date('Y-m-d H:i:s', $v['starttime']) . '到' . date('Y-m-d H:i:s', $v['endtime']);
if ($v['starttime'] > $time) {
$v['type'] = 1; // 未开始
$v['typename'] = '未开始';
}
if ($v['endtime'] < $time || $v['coupon_num'] <= 0) {
$v['type'] = 3; // 已结束
$v['typename'] = '已结束';
}
} else if ($v['coupontype'] == 2) {
$v['usetime'] = "会员领取当日起" . $v['daynum'] . '天内有效';
if ($v['coupon_num'] > 0) {
$v['type'] = 2;
$v['typename'] = '进行中';
} else {
$v['type'] = 3;
$v['typename'] = '已结束';
}
} else if ($v['coupontype'] == 3) {
$v['usetime'] = "会员领取次日日起" . $v['daynum'] . '天内有效';
if ($v['coupon_num'] > 0) {
$v['type'] = 2;
$v['typename'] = '进行中';
} else {
$v['type'] = 3;
$v['typename'] = '已结束';
}
} else {
$v['usetime'] = "错误的优惠券,建议删除";
$v['type'] = 3;
$v['typename'] = '已结束';
}
if ($v['status'] == 2) {
$v['type'] = 3;
$v['typename'] = '已结束';
}
// 可用门店
if ($v['storeids'] == 0) {
$v['storelist'] = array(array('id' => 0, 'storetag' => '所有门店'));
} else {
$v['storelist'] = array();
$v['storeids'] = trim($v['storeids'], ',');
$storeids = explode(',', $v['storeids']);
foreach ($storelist as $key => $val) {
if (in_array($val['id'], $storeids)) {
$v['storelist'][] = $val;
}
}
$v['data'] = $storeids;
}
// 可用会员等级
if ($v['coupon_gradeid'] == 0) {
$v['gradelist'] = array(array('id' => 0, 'cardname' => '所有会员'));
} else {
$v['gradelist'] = array();
$v['coupon_gradeid'] = trim($v['coupon_gradeid'], ',');
$gradeids = explode(',', $v['coupon_gradeid']);
foreach ($gradeall as $key => $val) {
if (in_array($val['id'], $gradeids)) {
$v['gradelist'][] = $val;
}
}
}
}
$rt['code'] = 0;
$rt['msg'] = '';
$rt['count'] = (int)$count;
$rt['data'] = $list;
$this->ajaxReturn($rt);
}
// 保存设置
public function setWelfare()
{
if (IS_POST) {
$post = I('post.');
$counponid = $post['id'];
$userinfo = session("ls_userinfo");
$merchantid = $userinfo['merchantid'];
$Ad['merchantid'] = $merchantid;
$Ad['type'] = 1;
$Ad['mcouponid'] = $counponid;
$map = $Ad;
$map['status'] = array('in', '1,2');
$one = M('retail_vip_register_welfare')->where($map)->getField('id');
if ($one) {
$rt['status'] = 0;
$rt['msg'] = "该优惠券已加入注册福利";
} else {
$add = M('retail_vip_register_welfare')->add($Ad);
if ($add) {
$rt['status'] = 1;
$rt['msg'] = "成功";
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '添加优惠券为新会员福利';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$rt['status'] = 0;
$rt['msg'] = "失败";
}
}
$this->ajaxReturn($rt);
}
}
public function getWelfare()
{
$userinfo = session("ls_userinfo");
$merchantid = $userinfo['merchantid'];
$page = I('post.page');
$limit = I('post.limit');
$w['merchantid'] = $merchantid;
$w['status'] = array('in', '1,2');
$count = M('retail_vip_register_welfare')->where($w)->count();
$list = M('retail_vip_register_welfare')->where($w)
->page($page, $limit)
->order('id desc')
->select();
// 查询出所有可用门店
$storelist = M('retail_store')
->where(array('merchantid' => $merchantid, 'store_status' => 0, 'state' => 0))
->field('id,storetag')
->select();
$gradeall = M('retail_vip_integral')
->where(array('merchantid' => $merchantid))
->field('id,cardname')
->select();
$time = time();
foreach ($list as $k => &$v) {
$v['w_status'] = $v['status'];
$v['index'] = $k + 1 + $limit * ($page - 1);
$info = M('retail_mcoupon')->where(array('id' => $v['mcouponid']))->find();
foreach ($info as $kk => $vv) {
if (!$v[$kk]) {
$v[$kk] = $vv;
}
}
$v['type'] = 2;
$v['typename'] = '进行中';
$v['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
if ($v['coupontype'] == 1) {
$v['usetime'] = date('Y-m-d H:i:s', $v['starttime']) . '到' . date('Y-m-d H:i:s', $v['endtime']);
if ($v['starttime'] > $time) {
$v['type'] = 1; // 未开始
$v['typename'] = '未开始';
}
if ($v['endtime'] < $time || $v['coupon_num'] <= 0) {
$v['type'] = 3; // 已结束
$v['typename'] = '已结束';
}
} else if ($v['coupontype'] == 2) {
$v['usetime'] = "会员领取当日起" . $v['daynum'] . '天内有效';
if ($v['coupon_num'] > 0) {
$v['type'] = 2;
$v['typename'] = '进行中';
} else {
$v['type'] = 3;
$v['typename'] = '已结束';
}
} else if ($v['coupontype'] == 3) {
$v['usetime'] = "会员领取次日日起" . $v['daynum'] . '天内有效';
if ($v['coupon_num'] > 0) {
$v['type'] = 2;
$v['typename'] = '进行中';
} else {
$v['type'] = 3;
$v['typename'] = '已结束';
}
} else {
$v['usetime'] = "错误的优惠券,建议删除";
$v['type'] = 3;
$v['typename'] = '已结束';
}
if ($v['status'] == 2) {
$v['type'] = 3;
$v['typename'] = '已结束';
}
// 可用门店
if ($v['storeids'] == 0) {
$v['storelist'] = array(array('id' => 0, 'storetag' => '所有门店'));
} else {
$v['storelist'] = array();
$v['storeids'] = trim($v['storeids'], ',');
$storeids = explode(',', $v['storeids']);
foreach ($storelist as $key => $val) {
if (in_array($val['id'], $storeids)) {
$v['storelist'][] = $val;
}
}
$v['data'] = $storeids;
}
// 可用会员等级
if ($v['coupon_gradeid'] == 0) {
$v['gradelist'] = array(array('id' => 0, 'cardname' => '所有会员'));
} else {
$v['gradelist'] = array();
$v['coupon_gradeid'] = trim($v['coupon_gradeid'], ',');
$gradeids = explode(',', $v['coupon_gradeid']);
foreach ($gradeall as $key => $val) {
if (in_array($val['id'], $gradeids)) {
$v['gradelist'][] = $val;
}
}
}
}
$rt['code'] = 0;
$rt['msg'] = '';
$rt['count'] = (int)$count;
$rt['data'] = $list;
$this->ajaxReturn($rt);
}
public function changestatus()
{
if (IS_POST) {
$id = I('post.id');
$status = I('post.status');
$field = I('post.field');
if ($status == 3 && $field != 'status') {
$rt['status'] = 0;
$rt['msg'] = '设置失败,请检查';
$this->ajaxReturn($rt);
}
$res = M('retail_vip_register_welfare')->where(array('id' => $id))->save(array($field => $status));
if ($res) {
$rt['status'] = 1;
$rt['msg'] = '设置成功';
//操作日志记录
if ($field == 'wx_register') {
$msg = '修改公众号注册状态';
} elseif ($field == 'cashier_register') {
$msg = '修改店内注册状态';
} else {
$msg = '修改状态';
}
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '新会员注册福利优惠券:' . $msg;//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$rt['status'] = 0;
$rt['msg'] = '设置失败,请检查';
}
$this->ajaxReturn($rt);
}
}
/**
* 删除测试会员
*/
public function delTemporaryVip()
{
if (IS_POST) {
$userinfo = session("ls_userinfo");
$merchantid = $userinfo['merchantid'];
$phone = I('post.phone');
$vip = M('retail_vip')
->where(array('mobile_phone' => $phone, 'merchantid' => $merchantid, 'status' => 1))
->find();
if ($vip) {
$res = M('retail_vip')
->where(array('id' => $vip['id']))
->setField('status', 2);
} else {
$res = false;
}
if ($res) {
$rt['status'] = 1;
$rt['msg'] = '删除成功';
} else {
$rt['status'] = 0;
$rt['msg'] = '删除失败';
}
$this->ajaxReturn($rt);
}
}
}