/** * 兑换 * */ function exchange() { $json['status'] = 0; $tid = $_REQUEST['tid']; $openid = $_REQUEST['openid']; $gc = M('jiyuedu_order'); $huiyuan = check_vip($openid); $score = getCredits($huiyuan['card_no']); if (1 == $tid && $score < 100) { $json['status'] = 0; $json['info'] = "积分不足"; echo json_encode($json); exit; } $arr = array('tid' => $tid, 'tel' => $huiyuan['huiyuan_tel'], 'name' => $huiyuan['huiyuan_name'], 'openid' => $openid, 'ctime' => getSysTime()); $state = $gc->add($arr); if ($state) { if ($tid == 1) { deductCredits($huiyuan['card_no'], 100); //扣除积分 $scorearr = array('qid' => '00001', 'orderid' => $state, 'score' => 100, 'huiyuanopenid' => $openid, 'huiyuantel' => $huiyuan['huiyuan_tel'], 'ctime' => getSysTime()); M('score_scorelog')->add($scorearr); //记录扣除积分日志 } $person_m = M('jiyuedu_person'); if ($tid == 2) { $person_m->where(array('openid' => $openid))->save(array('num' => 0)); //清空阅读数 //TODO } $json['status'] = 1; $json['key'] = $state; $json['info'] = "兑换成功"; } else { $json['info'] = "兑换失败"; } echo json_encode($json); }
function updateScoreById($id) { $mod = M('Score_order'); $info = $mod->where('id=' . $id)->find(); deductCredits($info['card_no'], $info['score']); }
function doAdd() { $data['status'] = 0; header("Content-type: text/html; charset=utf-8"); $mod = M('Exchange_order'); $gc = M('Exchange_qrcode'); //$huiyuaninfo = check_vip(wx_openid()); // $url = 'http://a.forcent.cn/ldh/store.php/Member/requestQrcode/' . $_REQUEST['url']; $qid = $_REQUEST['qid']; //二维码ID $data['info'] = $_REQUEST['qid']; //$where['uid'] = $_REQUEST['uid']; $orderinfo = $this->getOrderInfo(array('qid' => $qid, 'status' => 1)); $qrinfo = $gc->where('id=' . $qid)->find(); //查询二维码信息 $card_no = $orderinfo['card_no']; //会员卡号 $huiyuan_score = getCredits($card_no); //会员积分 //判断是否需要支付金额 if (!$orderinfo) { $data['info'] = '订单已失效'; $this->ajaxReturn($data); } $productInfo = M('Exchange_product')->where('id=' . $orderinfo['pid'])->find(); if ($productInfo['num'] >= $productInfo['total']) { $data['info'] = '库存不足'; $this->ajaxReturn($data); } else { if ($huiyuan_score >= $qrinfo['score']) { $state = $mod->where('id=' . $orderinfo['id'])->save(array('status' => 2, 'paytime' => $this->crtTime())); //更新订单状态 if ($state) { //减积分操作 $qty = deductCredits($card_no, $orderinfo['score']); if ($qty) { $scorelog['qid'] = $orderinfo['qid']; $scorelog['orderid'] = $orderinfo['id']; $scorelog['score'] = $orderinfo['score']; $scorelog['huiyuantel'] = $orderinfo['huiyuantel']; $scorelog['huiyuanopenid'] = $orderinfo['openid']; $scorelog['ctime'] = $this->crtTime(); M('Score_scorelog')->add($scorelog); //$sql = M('Exchange_qrcode')->getLastSql(); // file_put_contents("./ljhasdkjahsdkjasd.txt", var_export($sql, true)); } //更新二维码状态 $udata['status'] = 2; $udata['utime'] = $this->crtTime(); M('Exchange_qrcode')->where('id=' . $_REQUEST['qid'])->save($udata); //更新库存 $parr['num'] = $productInfo['num'] + 1; M('Exchange_product')->where('id=' . $orderinfo['pid'])->save($parr); $data['status'] = 1; $this->ajaxReturn($data); } else { $data['info'] = '付款失败'; $this->ajaxReturn($data); } } else { $data['info'] = '积分不足'; $this->ajaxReturn($data); } } }
function doAdd1() { $data['status'] = 0; header("Content-type: text/html; charset=utf-8"); $mod = M('Score_order'); $gc = M('Score_qrcode'); $huiyuaninfo = check_vip(wx_openid()); $qrdata = $gc->where('id=' . $_REQUEST['qid'])->find(); //二维码状态 if (2 == $qrdata['status']) { if ($huiyuaninfo['open_id'] == $qrdata['openid']) { $data['info'] = '已支付'; $this->ajaxReturn($data); } else { $data['info'] = '订单已失效'; $this->ajaxReturn($data); } } else { $where['qid'] = $_REQUEST['qid']; $where['uid'] = $_REQUEST['uid']; $where['status'] = 1; $card_no = $huiyuaninfo['card_no']; //会员卡号 $huiyuan_score = getCredits($card_no); //$data['info'] = $_REQUEST['score']; // $this->ajaxReturn($data);exit; if ($huiyuan_score >= $_REQUEST['score']) { $state = $mod->where($where)->save(array('status' => 2, 'paytime' => $this->crtTime())); //更新订单状态 if ($state) { //减积分操作 $qty = deductCredits($card_no, $_REQUEST['score']); if ($qty) { $scorelog['huiyuanid'] = $huiyuaninfo['huiyuan_id']; $scorelog['score'] = $_REQUEST['score']; $scorelog['huiyuantel'] = $huiyuaninfo['huiyuan_tel']; $scorelog['huiyuanopenid'] = $huiyuaninfo['open_id']; $scorelog['ctime'] = $this->crtTime(); M('Score_scorelog')->add($scorelog); //$sql = M('Score_qrcode')->getLastSql(); // file_put_contents("./ljhasdkjahsdkjasd.txt", var_export($sql, true)); } //更新二维码状态 $udata['status'] = 2; $udata['utime'] = $this->crtTime(); M('Score_qrcode')->where('id=' . $_REQUEST['qid'])->save($udata); $data['status'] = 1; $this->ajaxReturn($data); } else { $data['info'] = '付款失败'; $this->ajaxReturn($data); } } else { $data['info'] = '积分不足'; $this->ajaxReturn($data); } } }