Compare commits
2 Commits
b3f52b21d1
...
26898a42a0
| Author | SHA1 | Date | |
|---|---|---|---|
| 26898a42a0 | |||
| 251692d012 |
@ -345,6 +345,52 @@ class Index
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//获取待支付订单列表
|
||||
public function getPendingOrders()
|
||||
{
|
||||
$key = Db::name("setting")->where("vkey", "key")->find();
|
||||
$key = $key ? $key['vvalue'] : "";
|
||||
$t = input("t");
|
||||
$sign = input("sign");
|
||||
$type = input("type");
|
||||
|
||||
if (!$t || !$sign) {
|
||||
return json($this->getReturn(-1, "请传入时间戳和签名"));
|
||||
}
|
||||
|
||||
$_sign = md5($t . $key);
|
||||
if ($_sign != $sign) {
|
||||
return json($this->getReturn(-1, "签名校验不通过"));
|
||||
}
|
||||
|
||||
$query = Db::name("pay_order")
|
||||
->where("state", 0)
|
||||
->order("create_date desc")
|
||||
->limit(50);
|
||||
|
||||
if ($type !== null && $type !== '') {
|
||||
$query->where("type", intval($type));
|
||||
}
|
||||
|
||||
$rows = $query->select();
|
||||
$data = array();
|
||||
foreach ($rows as $row) {
|
||||
$data[] = array(
|
||||
"payId" => $row['pay_id'],
|
||||
"orderId" => $row['order_id'],
|
||||
"param" => $row['param'],
|
||||
"payType" => intval($row['type']),
|
||||
"price" => floatval($row['price']),
|
||||
"reallyPrice" => floatval($row['really_price']),
|
||||
"state" => intval($row['state']),
|
||||
"timeOut" => intval((Db::name("setting")->where("vkey", "close")->find())['vvalue']),
|
||||
"date" => intval($row['create_date'])
|
||||
);
|
||||
}
|
||||
|
||||
return json($this->getReturn(1, "成功", $data));
|
||||
}
|
||||
//关闭订单
|
||||
public function closeOrder(){
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
@ -519,6 +565,59 @@ class Index
|
||||
|
||||
}
|
||||
|
||||
//App按订单推送付款数据接口
|
||||
public function appPushOrder(){
|
||||
$this->closeEndOrder();
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
$orderId = input("orderId");
|
||||
$tradeNo = input("tradeNo");
|
||||
$t = input("t");
|
||||
|
||||
if (!$orderId || !$t) {
|
||||
return json($this->getReturn(-1, "参数不完整"));
|
||||
}
|
||||
|
||||
$_sign = $orderId.$tradeNo.$t.$key;
|
||||
if (md5($_sign)!=input("sign")){
|
||||
return json($this->getReturn(-1, "签名校验不通过"));
|
||||
}
|
||||
|
||||
Db::name("setting")
|
||||
->where("vkey","lastpay")
|
||||
->update(array(
|
||||
"vvalue"=>time()
|
||||
));
|
||||
|
||||
$res = Db::name("pay_order")->where("order_id",$orderId)->find();
|
||||
if (!$res){
|
||||
return json($this->getReturn(-1, "云端订单编号不存在"));
|
||||
}
|
||||
|
||||
if ($res['state']==1){
|
||||
return json($this->getReturn(1, "订单已完成"));
|
||||
}
|
||||
|
||||
if ($res['state']!=0){
|
||||
return json($this->getReturn(-1, "订单状态不允许推送"));
|
||||
}
|
||||
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$res['order_id'])
|
||||
->delete();
|
||||
|
||||
Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>1,"pay_date"=>time(),"close_date"=>time()));
|
||||
|
||||
$notifyResult = $this->notifyOrder($res);
|
||||
if ($notifyResult === "success"){
|
||||
return json($this->getReturn(1, "成功"));
|
||||
}else{
|
||||
Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>2));
|
||||
return json($this->getReturn(-1,"异步通知失败",$notifyResult));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//关闭过期订单接口(请用定时器至少1分钟调用一次)
|
||||
public function closeEndOrder(){
|
||||
@ -605,4 +704,25 @@ class Index
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function notifyOrder($res)
|
||||
{
|
||||
$url = $res['notify_url'];
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
|
||||
$p = "payId=".$res['pay_id']."¶m=".$res['param']."&type=".$res['type']."&price=".$res['price']."&reallyPrice=".$res['really_price'];
|
||||
|
||||
$sign = $res['pay_id'].$res['param'].$res['type'].$res['price'].$res['really_price'].$key;
|
||||
$p = $p . "&sign=".md5($sign);
|
||||
|
||||
if (strpos($url,"?")===false){
|
||||
$url = $url."?".$p;
|
||||
}else{
|
||||
$url = $url."&".$p;
|
||||
}
|
||||
|
||||
return $this->getCurl($url);
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,10 +21,12 @@ Route::any('createOrder','index/index/createOrder');
|
||||
|
||||
Route::any('getOrder','index/index/getOrder');
|
||||
Route::any('checkOrder','index/index/checkOrder');
|
||||
Route::any('getPendingOrders','index/index/getPendingOrders');
|
||||
Route::any('getState','index/index/getState');
|
||||
|
||||
Route::any('appHeart','index/index/appHeart');
|
||||
Route::any('appPush','index/index/appPush');
|
||||
Route::any('appPushOrder','index/index/appPushOrder');
|
||||
|
||||
|
||||
Route::any('closeEndOrder','index/index/closeEndOrder');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user