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); } }