270 行
11 KiB
PHP
可执行文件
270 行
11 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
//[1.4.13]
|
||
class VipCardController extends BaseController
|
||
{
|
||
|
||
public function index()
|
||
{
|
||
//获取用户信息
|
||
$userinfo = session("ls_userinfo");
|
||
$info = M('wx_membercard')->where(array('merchantid' => $userinfo['merchantid']))->find();
|
||
if ($info) {
|
||
$info['time'] = date('Y-m-d H:i:s', $info['time']);//时间戳处理
|
||
$this->assign('info', $info);
|
||
}
|
||
$arr = array(
|
||
'addMemberCardShow' => '/index.php/Retail/VipCard/addMemberCardShow',
|
||
'deleteCard' => '/index.php/Retail/VipCard/deleteCard',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
//创建会员卡
|
||
public function addMemberCard()
|
||
{
|
||
if (IS_POST) {
|
||
$user = session("ls_userinfo");//获取用户信息
|
||
$find_storeid = M('wx_membercard')->where(array('merchantid' => $user['merchantid']))->find();
|
||
if ($find_storeid) { //判断该商户是否已创建会员卡
|
||
$re['status'] = 0;
|
||
$re['msg'] = "已存在会员卡,请勿重复创建";
|
||
} else {
|
||
//接受数据
|
||
$post = I('post.');
|
||
if ($_FILES['logo_url']['error'] != 0 && !$post['logo_url_id']) {
|
||
$re['status'] = 0;
|
||
$re['msg'] = "请上传LOGO";
|
||
$this->ajaxReturn($re);
|
||
}
|
||
$title = 'http';
|
||
if ($_SERVER['HTTPS'] == 'on') {
|
||
$title .= 's';
|
||
}
|
||
$title = $title . '://' . $_SERVER['HTTP_HOST'];
|
||
if ($_FILES['logo_url']['error'] == 0) {
|
||
$item = array(
|
||
'add_time' => time(),
|
||
'from_type_id' => 21,
|
||
'localUrl' => 'Merchant/VipCard',
|
||
'user_type' => 3,
|
||
'merchant_id' => $user['id']
|
||
);
|
||
$uploads = uploadFiles($item);
|
||
/*if ($_FILES['logo_bg_url']['error'] == 0) {
|
||
if (!empty($uploads['logo_bg_url']['savePath'])) {
|
||
$post['logo_bg_url_id'] = $uploads['logo_bg_url']['id'];
|
||
if ($uploads['logo_bg_url']['storage_type'] == 1) {
|
||
$post['logo_bg_url'] = $title . $uploads['logo_bg_url']['savePath'];
|
||
} else {
|
||
$post['logo_bg_url'] = $uploads['logo_bg_url']['savePath'];
|
||
}
|
||
} else {
|
||
$re['status'] = 0;
|
||
$re['msg'] = "背景图片上传失败";
|
||
$this->ajaxReturn($re);
|
||
}
|
||
}*/
|
||
if ($_FILES['logo_url']['error'] == 0) {
|
||
if (!empty($uploads['logo_url']['savePath'])) {
|
||
$post['logo_url_id'] = $uploads['logo_url']['id'];
|
||
if ($uploads['logo_url']['storage_type'] == 1) {
|
||
$post['logo_url'] = $title . $uploads['logo_url']['savePath'];
|
||
} else {
|
||
$post['logo_url'] = $uploads['logo_url']['savePath'];
|
||
}
|
||
} else {
|
||
$re['status'] = 0;
|
||
$re['msg'] = "LOGO上传失败";
|
||
$this->ajaxReturn($re);
|
||
}
|
||
}
|
||
} else {
|
||
/* if (!empty($post['logo_bg_url_id'])) {
|
||
$img = D('ImageGallery')->getOneField(array('id' => $post['logo_bg_url_id']),'path');
|
||
if($img){
|
||
$post['logo_bg_url'] = $img;
|
||
}
|
||
}*/
|
||
if (!empty($post['logo_url_id'])) {
|
||
$img = D('ImageGallery')->getOneField(array('id' => $post['logo_url_id']),'path');
|
||
if($img){
|
||
$post['logo_url'] = $img;
|
||
}
|
||
}
|
||
}
|
||
$post['merchantid'] = $user['merchantid'];//商户id
|
||
$post['time'] = time();//创建时间
|
||
//将服务转成字符串
|
||
if (!empty($post['business_service'])) {
|
||
$post['business_service'] = implode(',', $post['business_service']);
|
||
}
|
||
//分享
|
||
if (!isset($post['can_share'])) {
|
||
$post['can_share'] = 1;
|
||
}
|
||
$wx_card = A('WxMembercard')->activationceshi($post);
|
||
if ($wx_card['errcode'] == 0) {
|
||
$re['status'] = 1;
|
||
$re['msg'] = "发布成功";
|
||
$re['data'] = $wx_card;
|
||
} else {
|
||
$errcode = $wx_card['errcode'];
|
||
switch ($errcode) {
|
||
case "48001":
|
||
$errtext = "公众号未开通权限。";
|
||
break;
|
||
}
|
||
$errtext .= "错误提示:" . $wx_card['errmsg'];
|
||
$re['status'] = 2;//0已存在1可以创建2创建失败
|
||
$re['msg'] = $errtext;
|
||
}
|
||
|
||
}
|
||
$this->ajaxReturn($re);
|
||
}
|
||
}
|
||
|
||
//修改页
|
||
public function addMemberCardShow()
|
||
{
|
||
|
||
$type = I('get.id');
|
||
if ($type) {
|
||
$info = M('wx_membercard')->where(array('id' => $type))->find();
|
||
if ($info) {
|
||
$info['time'] = date('Y-m-d H:i:s', $info['time']);
|
||
$server = explode(',', $info['business_service']);
|
||
$this->assign('info', $info);
|
||
$this->assign('server', $server);
|
||
}
|
||
}
|
||
$this->display();
|
||
}
|
||
|
||
//新增
|
||
public function create()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
//修改会员卡
|
||
public function modifyCard()
|
||
{
|
||
$post = I('post.');
|
||
$user = session('ls_userinfo');
|
||
if (!empty($user)) {
|
||
$old = M('wx_membercard')->where(array('merchantid' => $user['id']))->find();
|
||
$title = 'http';
|
||
if ($_SERVER['HTTPS'] == 'on') {
|
||
$title .= 's';
|
||
}
|
||
$title = $title . '://' . $_SERVER['HTTP_HOST'];
|
||
if ($_FILES['logo_url']['error'] == 0) {
|
||
$item = array(
|
||
'add_time' => time(),
|
||
'from_type_id' => 21,
|
||
'localUrl' => 'Merchant/VipCard',
|
||
'user_type' => 3,
|
||
'merchant_id' => $user['id']
|
||
);
|
||
$uploads = uploadFiles($item);
|
||
/*if ($_FILES['logo_bg_url']['error'] == 0) {
|
||
if (!empty($uploads['logo_bg_url']['savePath'])) {
|
||
$post['logo_bg_url_id'] = $uploads['logo_bg_url']['id'];
|
||
if ($uploads['logo_bg_url']['storage_type'] == 1) {
|
||
$post['logo_bg_url'] = $title . $uploads['logo_bg_url']['savePath'];
|
||
} else {
|
||
$post['logo_bg_url'] = $uploads['logo_bg_url']['savePath'];
|
||
}
|
||
} else {
|
||
$re['status'] = 0;
|
||
$re['mesg'] = "背景图片上传失败";
|
||
$this->ajaxReturn($re);
|
||
}
|
||
}*/
|
||
if ($_FILES['logo_url']['error'] == 0) {
|
||
if (!empty($uploads['logo_url']['savePath'])) {
|
||
$post['logo_url_id'] = $uploads['logo_url']['id'];
|
||
if ($uploads['logo_url']['storage_type'] == 1) {
|
||
$post['logo_url'] = $title . $uploads['logo_url']['savePath'];
|
||
} else {
|
||
$post['logo_url'] = $uploads['logo_url']['savePath'];
|
||
}
|
||
} else {
|
||
$re['status'] = 0;
|
||
$re['mesg'] = "LOGO上传失败";
|
||
$this->ajaxReturn($re);
|
||
}
|
||
}
|
||
} else {
|
||
/*if (!empty($post['logo_bg_url_id'])) {
|
||
$img = D('ImageGallery')->getFind(array('id' => $post['logo_bg_url_id']));
|
||
if($img['storage_type']==1){
|
||
$post['logo_bg_url'] = $title.$img['path'];
|
||
}else{
|
||
$post['logo_bg_url'] = $img['path'];
|
||
}
|
||
} else if (!empty($old)) {
|
||
$post['logo_bg_url'] = $old['logo_bg_url'] ? $old['logo_bg_url'] : false;
|
||
}*/
|
||
if (!empty($post['logo_url_id'])) {
|
||
$img = D('ImageGallery')->getFind(array('id' => $post['logo_url_id']));
|
||
if($img['storage_type']==1){
|
||
$post['logo_url'] = $title.$img['path'];
|
||
}else{
|
||
$post['logo_url'] = $img['path'];
|
||
}
|
||
} else if (!empty($old)) {
|
||
$post['logo_url'] = $old['logo_url'] ? $old['logo_url'] : false;
|
||
}
|
||
}
|
||
$success = A('WxMembercard')->modify($post);
|
||
if ($success) {
|
||
$re['status'] = 1;
|
||
$re['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 {
|
||
$re['status'] = 0;
|
||
$re['msg'] = "保存失败";
|
||
}
|
||
} else {
|
||
$re['status'] = 0;
|
||
$re['msg'] = "登录超时";
|
||
}
|
||
$this->ajaxReturn($re);
|
||
}
|
||
|
||
//删除会员卡
|
||
public function deleteCard()
|
||
{
|
||
$id = I('post.id');
|
||
if ($id) {
|
||
$delete = M('wx_membercard')->where(array('id' => $id))->delete();
|
||
if ($delete) {
|
||
$re['status'] = 1;//0删除失败1删除成功
|
||
$re['mesg'] = "删除成功,为了不影响商户更换公众号无法删除,请到公众号后台删除官方会员卡";
|
||
//操作日志记录
|
||
$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 {
|
||
$re['status'] = 0;//0删除失败1删除成功
|
||
$re['mesg'] = "删除失败";
|
||
}
|
||
$this->ajaxReturn($re);
|
||
}
|
||
}
|
||
} |