文件
mashangyoujiu/Application/Sellapi/Controller/GetVipInfoController.class.php

112 行
4.8 KiB
PHP
可执行文件

<?php
namespace Sellapi\Controller;
use Think\Controller;
//[1.4.88]
/**
* Class GetVipInfoController
* @package Sellapi\Controller 收银机结算页面获取会员信息
*/
class GetVipInfoController extends Controller
{
//+=======================================================================
//- 2018-09-03 微信会员卡绑定实体会员卡
//+=======================================================================
public function bindCard()
{
if ($_POST) {
$vipid = I("post.id");//会员id
$guideid = I("post.guideid");//会员id
$cardNum = I("post.cardnum");//会员卡号 PS:默认手机号,
$cardKey = I("post.card_key");//实体会员卡EXTRA_ID,用来给现有会员绑定实体卡
// $primaryid = I("post.primaryid");//会员卡主店id
$merchantid = I("post.merchantid");//商户id
if ($vipid == '' || $cardKey == '' || $merchantid == '' || $guideid == '') {
$res['status'] = 0;
$res['msg'] = '参数错误,请重新登陆';
} else {
//需要先检查实体会员EXTRA_ID是否已被使用
$find = M("retail_vip")->where(array('card_key' => $cardKey))->find();
if (!empty($find)) {
$res['status'] = 0;
$res['msg'] = '抱歉,该会员卡已被绑定,无法再次绑定';
} else {
//还需要检查会员是否已绑定实体卡
$map['id'] = $vipid;
//$map['mobile_phone'] = $cardNum;
$map['merchantid'] = $merchantid;
$vip = M("retail_vip")->where($map)->find();
if (empty($vip)) {
$res['status'] = 0;
$res['msg'] = '未查询到会员信息';
} else {
if (!empty($vip['card_key'])) {
$res['status'] = 0;
$res['msg'] = '抱歉,该用户已绑定实体卡';
} else {
//绑定实体卡
$data['guideid'] = $guideid;
$data['card_key'] = $cardKey;
$bind = M("retail_vip")->where($map)->save($data);
if ($bind) {
$res['status'] = 1;
$res['msg'] = '绑定成功';
} else {
$res['status'] = 0;
$res['msg'] = '绑定失败';
}
}
}
}
}
$this->ajaxReturn($res);
}
}
//+=======================================================================
//- 2018-09-05 解绑会员卡
//+=======================================================================
public function untieCard()
{
if ($_POST) {
$uid = I("post.id");//用户id
$merchantid = I("post.merchantid");//商户id
$pwd = I("post.pwd");//会员卡支付密码
if ($uid == '' || $merchantid == '' || $pwd == '') {
$res['status'] = 0;
$res['msg'] = '参数错误,请重新登录';
} else {
//先查看会员是否绑定会员卡
$find = M("retail_vip")->where(array('id' => $uid, 'merchantid' => $merchantid))->find();
if ($find['card_key'] == '0') {
$res['status'] = 0;
$res['msg'] = '该会员暂未绑定实体会员卡';
} else {
//解绑操作需验证用户支付密码
$CryptrModel = new \Addons\Api\Crypto ();//加解密
$orignPwd = $CryptrModel->encrypt($pwd, date('YmdHis', $find['addtime']));
if ($orignPwd != $find['password']) {
$res['status'] = 0;
$res['msg'] = '密码有误,请重新输入';
} else {
//进行解绑操作 card_key字段为字符串0
$data['card_key'] = '0';
$untie = M("retail_vip")->where(array('id' => $uid, 'merchantid' => $merchantid))->save($data);
if ($untie) {
$res['status'] = 1;
$res['msg'] = '解绑成功';
} else {
$res['status'] = 0;
$res['msg'] = '解绑失败';
}
}
}
}
}
$this->ajaxReturn($res);
}
}