作者 王晓刚
1 个管道 的构建 通过 耗费 0 秒

合并分支 'wangxiaogang' 到 'master'

我的订单与快递鸟



查看合并请求 !3
... ... @@ -236,20 +236,20 @@ $configs = [
//快递鸟参数配置
'bird'=>[
//正式
//'EBusinessID' => '1472267',//电商ID
//'AppKey' => 'cc8314fd-0381-4e37-ad17-239287f1d8d2',//AppKey
'EBusinessID' => '1472267',//电商ID
'AppKey' => 'cc8314fd-0381-4e37-ad17-239287f1d8d2',//AppKey
//测试
'EBusinessID' => 'test1472267',
'AppKey' => 'f84c7071-a6c7-48ce-8fe0-11b719d88a1d',
// 'EBusinessID' => 'test1472267',
// 'AppKey' => 'f84c7071-a6c7-48ce-8fe0-11b719d88a1d',
],
//快递鸟预约取件接口寄件人参数
'sender'=>[
'Name' => "李先生",
'Mobile' => "18888888888",
'Name' => "姚先生",
'Mobile' => "15555555555",
'ProvinceName' => "河北省",
'CityName' => "石家庄市",
'ExpAreaName' => "新华区",
'Address' => "学府路121号",
'Address' => "debug",
],
];
return array_merge($configs, $runtimeConfig,$wechatConfig);
\ No newline at end of file
... ...
... ... @@ -9,38 +9,61 @@
namespace app\portal\controller;
use app\portal\model\AddressModel;
use app\portal\model\IndentModel;
use cmf\controller\HomeBaseController;
use think\Db;
class BirdController extends HomeBaseController
{
protected $EBusinessID;
protected $AppKey;
protected $indent_id;
function _initialize() {
$bird = config('bird');
$this->EBusinessID = $bird['EBusinessID'];
$this->AppKey = $bird['AppKey'];
//电商ID
defined('EBusinessID') or define('EBusinessID', $this->EBusinessID);
//电商加密私钥,快递鸟提供,注意保管,不要泄漏
defined('AppKey') or define('AppKey', $this->AppKey);
}
/**
* 预约取件
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function createOrder($indent_id = null)
{
if(empty($indent_id)){
$this->error('缺少必要参数','','','');
return "缺少必要参数";
}
$where['id'] = ['eq',$indent_id];
$this->indent_id = $indent_id;
$where1['id'] = ['eq',$this->indent_id];
$indentModel = new IndentModel();
$indent = $indentModel->findData($where);
$indent = $indentModel->findData($where1);
if(empty($indent)){
$this->error('未查询到该订单','','','');
return '未查询到该订单';
}
if($indent['state'] != 2){
$this->error('该订单不是待发货状态','','','');
return '该订单不是待发货状态';
}
$bird = config('bird');
//电商ID
defined('EBusinessID') or define('EBusinessID', $bird['EBusinessID']);
//电商加密私钥,快递鸟提供,注意保管,不要泄漏
defined('AppKey') or define('AppKey', $bird['AppKey']);
//收货地址
$where2['id'] = ['eq',$indent['indent_address']];
$addressModel = new AddressModel();
$address = $addressModel->findData($where2);
$region = explode(' ',$address['region']);
//请求url,接口正式地址:http://api.kdniao.com/api/eorderservice 测试环境地址:http://testapi.kdniao.com:8081/api/oorderservice
defined('ReqURL') or define('ReqURL', 'http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json');
defined('ReqURL') or define('ReqURL', 'http://api.kdniao.com/api/OOrderService');
//构造在线下单提交信息
$eorder = [];
$eorder["ShipperCode"] = "SF";
$eorder["OrderCode"] = "PM2016050789471";
$eorder["OrderCode"] = $indent['order_number'];
$eorder["PayType"] = 1;
$eorder["ExpType"] = 1;
$eorder['IsNotice'] = 0;
... ... @@ -53,12 +76,12 @@ class BirdController extends HomeBaseController
// $sender["Address"] = "赛格广场5401AB";
$receiver = [];
$receiver["Name"] = "李先生";
$receiver["Mobile"] = "18888888888";
$receiver["ProvinceName"] = "李先生";
$receiver["CityName"] = "深圳市";
$receiver["ExpAreaName"] = "福田区";
$receiver["Address"] = "赛格广场5401AB";
$receiver["Name"] = $address['name'];
$receiver["Mobile"] = $address['phone'];
$receiver["ProvinceName"] = $region[0];
$receiver["CityName"] = $region[1];
$receiver["ExpAreaName"] = $region[2];
$receiver["Address"] = $address['detailed'];
$commodityOne = [];
$commodityOne["GoodsName"] = "书";
... ... @@ -77,13 +100,12 @@ class BirdController extends HomeBaseController
//解析在线下单返回结果
$result = json_decode($jsonResult, true);
if ($result["ResultCode"] == "100") {
return $result['Order']['LogisticCode'];//返回快递单号
return ['code'=>20000,'msg'=>'SUCCESS','data'=>$result['Order']['LogisticCode']];//返回快递单号
} else {
return $result['Reason'];
return ['code'=>40000,'msg'=>$result['Reason']];
}
}
/**
* Json方式 提交在线下单
* @param $requestData
... ... @@ -105,6 +127,136 @@ class BirdController extends HomeBaseController
return $result;
}
/**
* 查询订单
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getOrder($indent_id = null){
if(empty($indent_id)){
$this->error('缺少必要参数','','','');
}
$this->indent_id = $indent_id;
$where['id'] = ['eq',$this->indent_id];
$indentModel = new IndentModel();
$indent = $indentModel->findData($where);
if(empty($indent)){
$this->error('未查询到该订单','','','');
}
if($indent['state'] != 5){
$this->error('该订单不是已发货状态','','','');
}
//请求url,接口正式地址:http://api.kdniao.com/api/eorderservice 测试环境地址:http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json
defined('ReqURL') or define('ReqURL', 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx');
$jsonResult = $this->getOrderTracesByJson($indent['order_number'],$indent['logistic_code']);
$result = json_decode($jsonResult,true);
if($result['Success'] == true){
return dump($result);['code'=>20000,'msg'=>'SUCCESS','data'=>['state'=>$result['State'],'traces'=>$result['Traces']]];//订单轨迹
}else{
return ['code'=>40000,'msg'=>$result['Reason']];
}
}
/**
* Json方式 查询订单物流轨迹
*/
function getOrderTracesByJson($OrderCode,$LogisticCode){
$requestData= "{'OrderCode':$OrderCode,'ShipperCode':'SF','LogisticCode':$LogisticCode}";
$datas = array(
'EBusinessID' => EBusinessID,
'RequestType' => '1002',
'RequestData' => urlencode($requestData) ,
'DataType' => '2',
);
$datas['DataSign'] = $this->encrypt($requestData, AppKey);
$result=$this->sendPost(ReqURL, $datas);
//根据公司业务处理返回的信息......
return $result;
}
/**
* 订阅订单轨迹
* @return string|void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function takeOrder($indent_id = null){
if(empty($indent_id)){
$this->error('缺少必要参数','','','');
}
$this->indent_id = $indent_id;
$where['id'] = ['eq',$this->indent_id];
$indentModel = new IndentModel();
$indent = $indentModel->findData($where);
if(empty($indent)){
$this->error('未查询到该订单','','','');
}
if($indent['state'] != 5){
$this->error('该订单不是已发货状态','','','');
}
//收货地址
$where2['id'] = ['eq',$indent['indent_address']];
$addressModel = new AddressModel();
$address = $addressModel->findData($where2);
//请求url,接口正式地址:http://api.kdniao.com/api/eorderservice 测试环境地址:http://testapi.kdniao.com:8081/api/oorderservice
defined('ReqURL') or define('ReqURL', 'http://api.kdniao.com/api/dist');
$jsonResult = $this->orderTracesSubByJson($indent['order_number'],$indent['logistic_code'],$address);
$result = json_decode($jsonResult,true);
if(empty($result['Reason'])){
return dump($result);//订单轨迹
}else{
return $result['Reason'];
}
}
/**
* Json方式 物流信息订阅
*/
public function orderTracesSubByJson($OrderCode,$LogisticCode,$address){
$sender = config('sender');
$region = explode(' ',$address['region']);
$requestData="{'OrderCode': '$OrderCode',".
"'ShipperCode':'SF',".
"'LogisticCode':'$LogisticCode',".
"'PayType':1,".
"'ExpType':1,".
"'IsNotice':0,".
"'Sender':".
"{".
"'Company':'LV','Name':'$sender[Name]','Mobile':'$sender[Mobile]','ProvinceName':'$sender[ProvinceName]','CityName':'$sender[CityName]','ExpAreaName':'$sender[ExpAreaName]','Address':'$sender[Address]'},".
"'Receiver':".
"{".
"'Company':'GCCUI','Name':'$address[name]','Mobile':'$address[phone]','ProvinceName':'$region[0]','CityName':'$region[1]','ExpAreaName':'$region[2]','Address':'$address[detailed]'},".
"'Commodity':".
"[{".
"'GoodsName':'书'}],".
"'Remark':'小心轻放'}";
$datas = array(
'EBusinessID' => EBusinessID,
'RequestType' => '1008',
'RequestData' => urlencode($requestData) ,
'DataType' => '2',
);
$datas['DataSign'] = $this->encrypt($requestData, AppKey);
$result = $this->sendPost(ReqURL, $datas);
//根据公司业务处理返回的信息......
return $result;
}
/**
* post提交数据
... ... @@ -120,6 +272,10 @@ class BirdController extends HomeBaseController
}
$post_data = implode('&', $temps);
$url_info = parse_url($url);
if(empty($url_info['port']))
{
$url_info['port']=80;
}
$httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
$httpheader .= "Host:" . $url_info['host'] . "\r\n";
$httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/6/7
* Time: 16:48
*/
namespace app\portal\controller;
use app\portal\model\IndentModel;
use cmf\controller\HomeBaseController;
class LoadController extends HomeBaseController
{
public function index(){
$indentModel = new IndentModel();
$where['state'] = ['eq',2];
$data = $indentModel->selectData($where);
if(!empty($data)){
foreach($data as $key => $vo){
$birdController = new BirdController();
$result = $birdController->getOrder($vo['id']);
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -9,6 +9,7 @@
namespace app\portal\controller;
use app\portal\model\AddressModel;
use app\portal\model\IndentGoodsModel;
use app\portal\model\IndentModel;
use cmf\controller\WeChatBaseController;
... ... @@ -52,13 +53,16 @@ class OrderController extends WeChatBaseController
$where1['uid'] = ['eq',$user_id];
$where1['id'] = ['eq',$id];
$indentModel = new IndentModel();
$data = $indentModel->findData($where1);
$data = $indentModel->findData($where1)->toArray();
if(empty($data)){
$this->error('未查询到该订单','','','');
}
$where2['indent_id'] = ['eq',$data['id']];
$indentGoodsModel = new IndentGoodsModel();
$indentGoods = $indentGoodsModel->selectData($where2);
$addressModle = new AddressModel();
$address = $addressModle->findData(['id'=>$data['indent_address']])->toArray();
$data['address'] = $address;
$data['indent_goods'] = $indentGoods;
$this->assign('data',$data);
return $this->fetch();
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/6/7
* Time: 11:48
*/
namespace app\portal\model;
use think\Model;
class AddressModel extends Model
{
/**
* 获取单条数据
* @param $where
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -32,7 +32,7 @@
<!-- 全部 -->
<div class="myorder_con1" style="display: block">
<foreach name="data" item="vo">
<a href="">
<a href="{:url('order/get_one',array('id'=>$vo['id']))}">
<div class="myorder_information">
<!-- 订单 -->
<div class="myorder_the">
... ... @@ -85,9 +85,9 @@
<div class="myorder_bottom2_1">取消订单</div>
<div class="myorder_bottom2_2">去支付</div>
<elseif condition="$vo.state eq 2"/>
<a href="w_Ypayment.html">
<div class="myorder_bottom2_2">查看订单</div>
</a>
<!--<a href="w_Ypayment.html">-->
<!--<div class="myorder_bottom2_2">查看订单</div>-->
<!--</a>-->
<elseif condition="$vo.state eq 5"/>
<a href="w_logistics.html">
<div class="myorder_bottom2_2">查看物流</div>
... ... @@ -105,7 +105,7 @@
<div class="myorder_con1">
<foreach name="data" item="vo">
<if condition="$vo.state eq 4">
<a href="">
<a href="{:url('order/get_one',array('id'=>$vo['id']))}">
<div class="myorder_information">
<!-- 订单 -->
<div class="myorder_the">
... ... @@ -158,9 +158,9 @@
<div class="myorder_bottom2_1">取消订单</div>
<div class="myorder_bottom2_2">去支付</div>
<elseif condition="$vo.state eq 2"/>
<a href="w_Ypayment.html">
<div class="myorder_bottom2_2">查看订单</div>
</a>
<!--<a href="w_Ypayment.html">-->
<!--<div class="myorder_bottom2_2">查看订单</div>-->
<!--</a>-->
<elseif condition="$vo.state eq 5"/>
<a href="w_logistics.html">
<div class="myorder_bottom2_2">查看物流</div>
... ... @@ -179,7 +179,7 @@
<div class="myorder_con1">
<foreach name="data" item="vo">
<if condition="$vo.state eq 2">
<a href="">
<a href="{:url('order/get_one',array('id'=>$vo['id']))}">
<div class="myorder_information">
<!-- 订单 -->
<div class="myorder_the">
... ... @@ -232,9 +232,9 @@
<div class="myorder_bottom2_1">取消订单</div>
<div class="myorder_bottom2_2">去支付</div>
<elseif condition="$vo.state eq 2"/>
<a href="w_Ypayment.html">
<div class="myorder_bottom2_2">查看订单</div>
</a>
<!--<a href="w_Ypayment.html">-->
<!--<div class="myorder_bottom2_2">查看订单</div>-->
<!--</a>-->
<elseif condition="$vo.state eq 5"/>
<a href="w_logistics.html">
<div class="myorder_bottom2_2">查看物流</div>
... ... @@ -253,7 +253,7 @@
<div class="myorder_con1">
<foreach name="data" item="vo">
<if condition="$vo.state eq 5">
<a href="">
<a href="{:url('order/get_one',array('id'=>$vo['id']))}">
<div class="myorder_information">
<!-- 订单 -->
<div class="myorder_the">
... ... @@ -306,9 +306,9 @@
<div class="myorder_bottom2_1">取消订单</div>
<div class="myorder_bottom2_2">去支付</div>
<elseif condition="$vo.state eq 2"/>
<a href="w_Ypayment.html">
<div class="myorder_bottom2_2">查看订单</div>
</a>
<!--<a href="w_Ypayment.html">-->
<!--<div class="myorder_bottom2_2">查看订单</div>-->
<!--</a>-->
<elseif condition="$vo.state eq 5"/>
<a href="w_logistics.html">
<div class="myorder_bottom2_2">查看物流</div>
... ... @@ -327,7 +327,7 @@
<div class="myorder_con1">
<foreach name="data" item="vo">
<if condition="$vo.state eq 3">
<a href="">
<a href="{:url('order/get_one',array('id'=>$vo['id']))}">
<div class="myorder_information">
<!-- 订单 -->
<div class="myorder_the">
... ... @@ -380,9 +380,9 @@
<div class="myorder_bottom2_1">取消订单</div>
<div class="myorder_bottom2_2">去支付</div>
<elseif condition="$vo.state eq 2"/>
<a href="w_Ypayment.html">
<div class="myorder_bottom2_2">查看订单</div>
</a>
<!--<a href="w_Ypayment.html">-->
<!--<div class="myorder_bottom2_2">查看订单</div>-->
<!--</a>-->
<elseif condition="$vo.state eq 5"/>
<a href="w_logistics.html">
<div class="myorder_bottom2_2">查看物流</div>
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>学考无忧</title>
<link rel="stylesheet" href="__TMPL__/public/assets/css/reset.css" />
<link rel="stylesheet" href="__TMPL__/public/assets/css/base.css" />
<style>
.pay_banner {
width: 100%;
height: 1.3rem;
background-size: cover;
background-image: url("__TMPL__/public/assets/images/55.png");
}
.order_address {
padding: 0.28rem 0 0.42rem;
box-sizing: border-box;
background-repeat: no-repeat;
background-image: url("__TMPL__/public/assets/images/32.png");
background-position: bottom;
background-size: 100% 0.06rem;
}
</style>
</head>
<body>
<div class="Dpayment">
<!-- 顶部 -->
<div class="order_top">
<img src="__TMPL__/public/assets/images/left.png" alt="" />
<p>我的订单</p>
</div>
<!-- 顶部banner -->
<div class="pay_banner">
<div class="pay_bannerLeft">
<div class="pay_bannerImg">
<img src="__TMPL__/public/assets/images/53.png" alt="" />
</div>
<p>
<if condition="$data.state eq 4">
待付款
<elseif condition="$data.state eq 2"/>
待发货
<elseif condition="$data.state eq 5"/>
已发货
<elseif condition="$data.state eq 3"/>
已完成
</if>
</p>
</div>
</div>
<!-- 地址 -->
<div class="order_address">
<!-- 有地址 -->
<a href="">
<div class="order_addressYes">
<div class="or_addressYesImg1">
<img src="__TMPL__/public/assets/images/38.png" alt="" />
</div>
<div class="or_addressYesTxt1">
<div class="or_addressYesTxt2">
<div class="or_addressName">{$data.address.name}</div>
<p class="or_addressPhone">{$data.phone}</p>
</div>
<p class="or_address_detailed">
{$data.address.region}{$data.address.detailed}
</p>
</div>
<div class="or_addressYesImg2">
<img src="__TMPL__/public/assets/images/29.png" alt="" />
</div>
</div>
</a>
</div>
<!-- 订单信息 -->
<div class="order_news">
<h1 class="order_newsTit">订单信息</h1>
<ul class="order_newsUl">
<foreach name="$data.indent_goods" item="i_g">
<li>
<div class="order_newsImg">
<img src="{:cmf_get_image_url($i_g['thumbnail'])}" alt="" />
</div>
<div class="order_newsCon">
<div class="order_newsTxt1 txt-cut">
{$i_g.book_name}
</div>
<div class="order_newsTxt2">×<span>{$i_g.number}</span></div>
<div class="order_newsTxt3">
<p class="de_topTxt1_1"><span>{$i_g.price}</span></p>
<p class="de_topTxt1_2"><span>{$i_g.pricing}</span></p>
</div>
</div>
</li>
<php>$sum[] = $i_g['price']*$i_g['number'];</php>
</foreach>
</ul>
</div>
<!-- 支付方式/配送方式 -->
<div class="order_Etc">
<div class="order_Etc1 ypayTxt">
<p>订单编号:</p>
<p>{$data.order_number}</p>
</div>
<div class="order_Etc1 ypayTxt">
<p>下单时间:</p>
<p>{:date('Y-m-d H:i:s',$data.create_time)}</p>
</div>
<div class="order_Etc1 ypayTxt">
<p>配送方式:</p>
<if condition="$data.is_courier eq 0">
<p>统一配送(0元)</p>
<elseif condition="$data.id_courier eq 1"/>
<p>快递({$data.money-array_sum($sum)}元)</p>
</if>
</div>
</div>
<!-- 实付金额: -->
<div class="ypay_price">
<p class="ypay_price1">实付金额:</p>
<p class="de_topTxt1_1"><span>{$data.money}</span></p>
</div>
<!-- 底部 -->
<div class="pay_bottom">
<div class="pay_bottom2">
<a href="w_logistics.html">
<div class="pay_bottom2_1">物流信息</div>
</a>
<div class="pay_bottom2_2">售后咨询</div>
</div>
</div>
</div>
<script src="__TMPL__/public/assets/js/base.js"></script>
</body>
</html>
\ No newline at end of file
... ...