<?php
include_once 'PospalCertificate.class.php';//请求引入
include_once 'PospalApiUrlBuilder.class.php';//接口地址引入
include_once 'PospalApiClient.class.php';//请求头类引入
include_once 'CommonUtils.php';//其它
//收银订单推送
//$souyin_appid->当前门店的appid,$souyin_key->当前门店的key 。 (找客户官方要!!!,注册的后台查看不到,头疼)
$certificate = new PospalCertificate($souyin_appid, $souyin_key, new PospalApiUrlBuilder(SHOUYIN_URL));
//初始化参数
$tuisong_ = 1;//是否正常推送
$message = '';//错误提示
$sy_orderno = '';//推送成功后的收银订单
$items = array();
if ($shouyin_uid == '') {//如果推送的商品中有一个不存在唯一标识,则推送失败
$tuisong_ = 0;
$message .= '不存在商品唯一标识,' . '【商品序号:***】' . '【门店规格序号:***】;';
}
$items[0]["productUid"] = $rslist["shouyin_uid"];//商品在银豹系统中的唯一标识
$items[0]["comment"] = $rslist["jine_title"];//商品名称
$items[0]["quantity"] = $rslist["productnum"];//数量
$items[0]["manualSellPrice"] = $rslist["jiage"];//单价
$add_txt = '姓名:***' . PHP_EOL . '电话:***' . PHP_EOL . '地址:***';
$sendData = array(
"appId" => $certificate->getAppId(),
"payMethod" => 'Wxpay',//自定义支付方式payCode_102,Wxpay,表示微信支付
"orderRemark" => $rsDG["contact"] . ' 支付方式:微信小程序余额支付',//订单备注
"orderDateTime" => $rsDG["adddate"],//订单产生的时间
"contactAddress" => $add_txt,//订单产生的时间
"contactName" => $rm["name"],//姓名
"contactTel" => $rm["mobile"],//手机号
"items" => $items,//商品列表
"deliveryType" => '0',//配送类型,默认为0-外卖单。0外卖单;1店内单,自助单
"payOnLine" => "1",//是否已经完成线上付款。若线上已付款,则设置payOnLine=1 且payMethod 只能为Wxpay或Alipay 或自定义支付方式。否则,该参数不传
"orderSource" => "openApi",//为openApi时,商品单价按用户传值固定不变;为空时,按网单下单正常逻辑来计算
"daySeq" => $rsDG["quhuo_dan"],//牌号,取餐号。当orderSource=openApi时,才生效,如果不传,不会默认生成。 当orderSource!=openApi时,后台会默认生成一个
"totalAmount" => $ShopJine,//总金额,orderSource不为空时,totalAmount必填
);
if ($tuisong_) {
try {
$apiclient = new PospalApiClient();
$urlBuilder = $certificate->getPospalApiUrlBuilder();
$json = $apiclient->doRequest($urlBuilder->addOnLineOrder(), $sendData, $certificate->getAppKey());
$message = $json;
$result = jsonDecode($json);
$paymethods = $result["data"];
$sy_orderno = $paymethods["orderNo"];
} catch (Exception $e) {
$message = $e->getMessage();
// print "糟糕,运行出错,是什么问题???";
}
}
//结果存储到订单中
$dataArr_or_shouyin = array();
$dataArr_or_shouyin["yin_messages"] = $message;
$dataArr_or_shouyin["sy_orderno"] = $sy_orderno;
//修改数据
_update('shop_order', $dataArr_or_shouyin, $rsDG["id"]);
?>
评论0