添加后台代理代码
This commit is contained in:
205
codes/agent/game/api/source/apis/order.php
Normal file
205
codes/agent/game/api/source/apis/order.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With");
|
||||
header("Access-Control-Allow-Credentials: true");
|
||||
header("Content-Type: text/html; charset=utf-8");
|
||||
|
||||
/**
|
||||
* 登录相关接口
|
||||
*/
|
||||
use phprs\util\Verify;
|
||||
use phprs\util\exceptions\Forbidden;
|
||||
use phprs\util\Logger;
|
||||
use phprs\util\exceptions\NotFound;
|
||||
use phprs\ezsql\Sql;
|
||||
use phprs\util\exceptions\BadRequest;
|
||||
|
||||
require_once 'apiBase.php';
|
||||
/**
|
||||
*
|
||||
* 订单管理
|
||||
* @path("/order")
|
||||
*/
|
||||
class Order extends apiBase{
|
||||
/**
|
||||
* 购买订单生成(错误代码:12701-12750)
|
||||
* @route({"POST","/add"})
|
||||
* @param({"appid","$._POST.appid"}) 所属公众号
|
||||
* @param({"devkey","$._POST.devkey"}) 外部应用ID
|
||||
* @param({"sid","$._POST.sid"}) 临时会员ID
|
||||
* @param({"scode","$._POST.scode"}) 客户端票据
|
||||
* @param({"goodsprice","$._POST.goodsprice"}) 商品费用
|
||||
* @param({"dispatchprice","$._POST.dispatchprice"}) 运费
|
||||
* @param({"title","$._POST.title"}) 支付主题
|
||||
* @param({"sendtype","$._POST.sendtype"}) 1为快递,2为自提
|
||||
* @param({"address","$._POST.address"}) 收货地址
|
||||
* @param({"goodstype","$._POST.goodstype"}) 商品类型(1:实体商品,2:虚拟商品)
|
||||
* @param({"remark","$._POST.remark"}) 订单留言
|
||||
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
||||
*/
|
||||
public function orderAdd($appid='', $devkey='',$sid='',$scode='',$goodsprice='',$dispatchprice='',$title='',$sendtype='',$address='{=NULL=}',$goodstype='',$remark='') {
|
||||
// 验证公共参数是否合法
|
||||
parent::init($appid,$devkey,$sid,$scode);
|
||||
$verify_result = parent::verify();
|
||||
|
||||
if( !is_error_api($verify_result) ){
|
||||
$result = array();
|
||||
|
||||
if ( !is_numeric($goodsprice) ) {
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12701;
|
||||
$result["msg"] = "请正确传入goodsprice";
|
||||
return $result;
|
||||
}
|
||||
if ( !is_numeric($dispatchprice) ) {
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12702;
|
||||
$result["msg"] = "请正确传入dispatchprice";
|
||||
return $result;
|
||||
}
|
||||
if(empty($title)){
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12703;
|
||||
$result["msg"] = "请传入title";
|
||||
return $result;
|
||||
}
|
||||
if( !is_numeric($sendtype) ){
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12704;
|
||||
$result["msg"] = "请正确传入sendtype";
|
||||
return $result;
|
||||
}
|
||||
if(intval($goodstype)==1 && intval($sendtype)==1){
|
||||
if ( $address=='{=NULL=}' ){
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12705;
|
||||
$result["msg"] = "请传入收货地址";
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
if( !is_numeric($goodstype) ){
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12706;
|
||||
$result["msg"] = "请正确传入goodstype";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 生成随机订单编号 begin
|
||||
$ordersn = date('ymd') . random(10, 1);//订单编号
|
||||
while(true){
|
||||
$order_list = Sql::select('syweb_order.*')
|
||||
->from('syweb_order')
|
||||
->where('syweb_order.ordersn=?', $ordersn)
|
||||
->get($this->db ,null);
|
||||
if (!empty($order_list) && count($order_list)>0) {
|
||||
$ordersn = date('ymd') . random(10, 1);//订单编号
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 生成随机订单编号 begin
|
||||
|
||||
if( $this->userInfo["auth_type"]==0 ){
|
||||
$openId = $this->userInfo["openid"]; // 微信用户的openId
|
||||
$data = array(
|
||||
'app_id' => $this->appInfo["id"],// 所属应用
|
||||
'business_id' => $this->businessInfo["id"],// 所属商家
|
||||
'from_user' => $openId,// 购买用户
|
||||
'ordersn' => $ordersn,//订单编号
|
||||
'title' => $title,//订单标题
|
||||
'price' => $goodsprice + $dispatchprice,//总价
|
||||
'status' => 0,//订单状态
|
||||
'sendtype' => intval($sendtype),// 1为快递,2为自提
|
||||
'paytype' => '0',
|
||||
'goodstype' => intval($goodstype),// 商品类型(1:实体商品,2:虚拟商品)
|
||||
'remark' => $remark,//留言
|
||||
'address' => $address,// 收货地址
|
||||
'goodsprice' => $goodsprice,//商品价格
|
||||
'dispatchprice' => $dispatchprice,//运费
|
||||
'paydetail' => '',
|
||||
'createtime' => TIMESTAMP//订单创建时间
|
||||
);
|
||||
|
||||
$pdo = $this->db;
|
||||
$pdo->beginTransaction();
|
||||
$orderid = Sql::insertInto('syweb_order')->values($data)->exec($pdo)->lastInsertId();
|
||||
$pdo->commit();
|
||||
|
||||
if (!empty($orderid)) {
|
||||
$result["error"] = "0";
|
||||
$result["order"] = $data;
|
||||
return $result;
|
||||
}else{
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12707; // 订单生成失败
|
||||
$result["msg"] = "订单生成失败";
|
||||
return $result;
|
||||
}
|
||||
}else{
|
||||
// QQ登录状态
|
||||
}
|
||||
}else{
|
||||
return $verify_result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单ID查询订单详情(错误代码:12751-12800)
|
||||
* @route({"POST","/"})
|
||||
* @param({"appid","$._POST.appid"}) 所属公众号
|
||||
* @param({"devkey","$._POST.devkey"}) 外部应用ID
|
||||
* @param({"sid","$._POST.sid"}) 临时会员ID
|
||||
* @param({"scode","$._POST.scode"}) 客户端票据
|
||||
* @param({"orderSN","$._POST.orderSN"}) 订单编号
|
||||
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
||||
*/
|
||||
public function getOrder($appid='',$devkey='',$sid='',$scode='',$orderSN='') {
|
||||
// 验证公共参数是否合法
|
||||
parent::init($appid,$devkey,$sid,$scode);
|
||||
$verify_result = parent::verify();
|
||||
|
||||
if( !is_error_api($verify_result) ){
|
||||
$result = array();
|
||||
|
||||
if ( empty($orderSN) ) {
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12751;
|
||||
$result["msg"] = "请传入orderSN";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if( $this->userInfo["auth_type"]==0 ){
|
||||
$openId =$this->userInfo["openid"]; // 微信用户的openId
|
||||
$orderInfo = Sql::select('syweb_order.*')
|
||||
->from('syweb_order')
|
||||
->where('syweb_order.app_id=? and syweb_order.business_id=? and syweb_order.ordersn=?', $this->appInfo['id'],$this->businessInfo['id'],$orderSN)
|
||||
->get($this->db ,null);
|
||||
|
||||
if (!empty($orderInfo)) {
|
||||
$result["error"] = "0";
|
||||
$result["order"] = $orderInfo;
|
||||
return $result;
|
||||
}else{
|
||||
$result["error"] = "1";
|
||||
$result["error_code"] = 12752;
|
||||
$result["msg"] = "订单不存在或已经被删除。";
|
||||
return $result;
|
||||
}
|
||||
}else{
|
||||
// QQ登录状态
|
||||
}
|
||||
}else{
|
||||
return $verify_result;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inject("ioc_factory") */
|
||||
private $factory;
|
||||
/**
|
||||
* @property({"default":"@db"})
|
||||
* @var PDO
|
||||
*/
|
||||
public $db;
|
||||
// 此处删除了代码
|
||||
}
|
||||
Reference in New Issue
Block a user