Skip to content

Commit

Permalink
集成当面付,修复若干bug
Browse files Browse the repository at this point in the history
  • Loading branch information
assimon committed Apr 18, 2018
1 parent b081927 commit d3841d7
Show file tree
Hide file tree
Showing 38 changed files with 1,985 additions and 275 deletions.
2 changes: 1 addition & 1 deletion app/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static function db(){
static function systemInfo()
{
return [
'version' => 'v1.1.bate',
'version' => 'v1.2.bate',
];
}

Expand Down
132 changes: 132 additions & 0 deletions app/controller/PayBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
namespace YS\app\controller;


use YS\app\libs\Controller;

class PayBase extends Controller
{
public $order;
public $acp;

/**检查订单并返回订单信息
* @param $id
* @return bool|mixed
*/
public function checkOrder($id,$ismsg = 1)
{
$this->order = $this->model()->select()->from('orders')->where(array('fields' => 'orderid=?', 'values' => array($id)))->fetchRow();
if((!$this->order || $this->order['status'] > 0) && $ismsg == 1)exit('订单不存在或已支付!');
return $this->order;
}

/**获取支付参数
* @param $code
* @return bool|mixed
*/
public function checkAcp($code)
{
$this->acp = $this->model()->select()->from('acp')->where(array('fields' => 'code=?', 'values' => array($code)))->fetchRow();
if(!$this->acp || $this->acp['userid']== "" || $this->acp['userkey']== "")exit('平台未配置支付参数,请联系管理员');
return $this->acp;
}


public function updateOrder($orderid,$type,$paysid)
{
//查询订单是否已更改
$order = $this->model()->select()->from('orders')->where(array('fields' => 'orderid=? ', 'values' => array($orderid)))->fetchRow();
if($order['status'] > 0) return true;
$data['status'] = 1;
$data['payid'] = $paysid;
$data['paytype'] = $type;
/**
* 自动发卡 获取卡密到订单信息 然后去掉库存 改变卡密状态
*/
if($order['otype'] == 0){
$kami = $this->model()->select()->from('kami')->limit($order['onum'])->where(array('fields' => ' `gid` = '.$order['gid'].' AND `is_ste` = 0', 'values' => ''))->fetchAll();
$info = '';
$ids = '';
if(!$kami){
$data['status'] = 5;
}else{
$data['status'] = 3;
foreach ($kami as $v){
$ids.= $v['id'].',';
$info .= '卡号: '.$v['kano'];
if($v['kapwd']){
$info.=' ---- 卡密: '.$v['kapwd']."<br/>";
}else{
$info.=' ---- 卡密: 无需卡密!<br/>';
}
}
$data['info'] = $info;
//设置卡密过期
$config = $this->setConfig;
//拼接sql
$sql = "UPDATE ".$config::db()['prefix']."kami SET `is_ste` = 1 WHERE `id` IN (".trim($ids,',').")";
$res = $this->model()->query($sql);
//减去库存
$goods = $this->model()->select()->from('goods')->where(array('fields' => 'id=?', 'values' => array($order['gid'])))->fetchRow();
$gdata['kuc'] = $goods['kuc']-$order['onum'];
$this->model()->from('goods')->updateSet($gdata)->where(array('fields' => 'id = ?', 'values' => array($goods['id'])))->update();

}
}
$status = $this->model()->from('orders')->updateSet($data)->where(array('fields' => 'orderid = ?', 'values' => array($orderid)))->update();
if($status)
{
if($this->config['email_state'] == 1){
$this->sendEmail($order['account'],$order,$data['info']);
}
return true;
}else{
return false;
}

}


/**邮件发送
* @param $email
* @param $order
*/
private function sendEmail($email,$order,$info = '')
{
//自动发卡通知
if($order['otype'] == 0){
$mailtpl = $this->model()->select()->from('mailtpl')->where(array('fields' => 'is_state=? and cname=?', 'values' => array(0, '卡密发送')))->fetchRow();
$mdata = [
'sitename' => $this->config['sitename'],
'gname' => $order['oname'],
'orid' => $order['orderid'],
'ornum' => $order['onum'],
'cmoney' => $order['cmoney'],
'ctime' => date('Y-m-d H:i',$order['ctime']),
'orderinfo' => $info,
'url' => $this->config['siteurl']
];
$newData = $this->res->replaceMailTpl($mailtpl, $mdata);
$subject = array('title' => $newData['title'], 'email' => $email, 'content' => $newData['content']);
$this->res->sendMail($subject, $this->config);
}else{
$mailtpl = $this->model()->select()->from('mailtpl')->where(array('fields' => 'is_state=? and cname=?', 'values' => array(0, '管理员通知')))->fetchRow();
$mdata = [
'sitename' => $this->config['sitename'],
'gname' => $order['oname'],
'orid' => $order['orderid'],
'ornum' => $order['onum'],
'cmoney' => $order['cmoney'],
'ctime' => date('Y-m-d H:i',$order['ctime']),
'url' => $this->config['siteurl']
];
$newData = $this->res->replaceMailTpl($mailtpl, $mdata);
$subject = array('title' => $newData['title'], 'email' => $this->config['email'], 'content' => $newData['content']);
$this->res->sendMail($subject, $this->config);
}


}


}
11 changes: 10 additions & 1 deletion app/controller/chaka.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class chaka extends Controller
{
public function index()
{
$this->put('chaka.php');
$oid = $this->req->get('oid');
$order = $this->model()->select()->from('orders')->where(array('fields' => 'orderid=?', 'values' => array($oid)))->fetchRow();

$this->put('chaka.php',$order);
}

/**
Expand Down Expand Up @@ -75,11 +78,17 @@ class=\"am-btn am-btn-default \"><span class=\"am-icon-eye\"></span>订单详情

}

/**
* 订单详情
*/
public function orderInfo()
{

$id = $this->req->post('id') ? $this->req->post('id') : 0;
$data = $this->model()->select()->from('orders')->where(array('fields' => 'orderid=?', 'values' => array($id)))->fetchRow();
if (!$data) resMsg(0, null, '订单不存在');
resMsg(1, $data, 'ok');


}
}
38 changes: 30 additions & 8 deletions app/controller/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,36 @@ public function postOrder()
<div class=\"am-alert am-alert-success\"><strong>订单保存成功,请点击以下方式在线付款:</strong></div>
</div>
<div class=\"am-form-group\">
<div class=\"am-u-sm-12 am-u-sm-push-2\">
<a target='_blank' href=\"/pay/index?id=".$orderid."&type=alipay&paycode=blpay\" class=\"am-btn am-btn-warning am-round am-icon-credit-card-alt\">支付宝</a>
<a target='_blank' href=\"/pay/index?id=".$orderid."&type=wxpay&paycode=blpay\" class=\"am-btn am-btn-success am-round am-icon-wechat\">微信</a>
<a target='_blank' href=\"/pay/index?id=".$orderid."&type=qqpay&paycode=blpay\" class=\"am-btn am-btn-default am-round am-icon-qq\">QQ钱包</a>
<a target='_blank' href=\"/pay/index?id=".$orderid."&type=tenpay&paycode=blpay\" class=\"am-btn am-btn-primary am-round am-icon-credit-card\">财付通</a>
</div>
</div>
";
<div class=\"am-u-sm-12 am-u-sm-push-2\">";
/**
* 支付方式选择
*/
$payset = $this->model()->select()->from('acp')->where(array('fields' => ' is_ste > 0', 'values' => array()))->fetchAll();

if($payset){
foreach ($payset as $v){
switch ($v['code']){
case 'blpay':
$html.= " <a target='_blank' href=\"/pay/index?id=".$orderid."&type=alipay&paycode=".$v['code']."\" class=\"am-btn am-btn-warning am-round am-icon-credit-card-alt\">BL支付宝</a>
<a href=\"/pay/index?id=".$orderid."&type=wxpay&paycode=".$v['code']."\" class=\"am-btn am-btn-success am-round am-icon-wechat\">BL微信</a>
<a href=\"/pay/index?id=".$orderid."&type=qqpay&paycode=".$v['code']."\" class=\"am-btn am-btn-default am-round am-icon-qq\">BLQQ钱包</a>
<a href=\"/pay/index?id=".$orderid."&type=tenpay&paycode=".$v['code']."\" class=\"am-btn am-btn-primary am-round am-icon-credit-card\">BL财付通</a>";
break;
case 'zfbf2f':
$html.= "<a href=\"/pay/index?id=".$orderid."&type=alipay&paycode=".$v['code']."\" class=\"am-btn am-btn-warning am-round am-icon-credit-card-alt\">支付宝当面付</a>";
break;
case 'paysapi':
$html.= "<a href=\"/pay/index?id=".$orderid."&type=1&paycode=".$v['code']."\" class=\"am-btn am-btn-warning am-round am-icon-credit-card-alt\">支付宝扫码</a>
<a target='_blank' href=\"/pay/index?id=".$orderid."&type=2&paycode=".$v['code']."\" class=\"am-btn am-btn-success am-round am-icon-wechat\">微信扫码</a>";
break;
}
}
}
$html.= "</div>
</div>";



resMsg(1,$html,'下单成,请支付!');

}
Expand Down
Loading

0 comments on commit d3841d7

Please sign in to comment.