feat: init project codebase
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
require "vendor/zto/zopsdk-php/ZopClient.php";
|
||||
require "vendor/zto/zopsdk-php/ZopProperties.php";
|
||||
require "vendor/zto/zopsdk-php/ZopRequest.php";
|
||||
|
||||
use zop\ZopClient;
|
||||
use zop\ZopRequest;
|
||||
use zop\ZopProperties;
|
||||
|
||||
/**
|
||||
* User_model class.
|
||||
*
|
||||
* @extends CI_Model
|
||||
*/
|
||||
class Zto_model extends MY_Model {
|
||||
|
||||
public function request($path='', $data=[])
|
||||
{
|
||||
$conf = $this->config->item('zto');
|
||||
// ZopProperties类的构造方法接收两个参数,分别是companyid和key,都需要注册中通开放平台后到个人中心查看
|
||||
$properties = new ZopProperties($conf['id'], $conf['key']);
|
||||
$client = new ZopClient($properties);
|
||||
$request = new ZopRequest();
|
||||
$request->setUrl($conf['host'].$path);
|
||||
//$request->setData(json_encode($data));
|
||||
$request->addParam('orderGroup',$data);
|
||||
//$request->addParam('orderGroup','{"partnerCode":"130520142013234","type":1,"tradeId":"2701843","mailNo":"1000000000016","sender":{"id":"130520142010","name":"李琳","company":"新南电子商务有限公司","mobile":"13912345678","phone":"021-87654321","prov":"上海市","city":"上海市","county":"青浦区","address":"华新镇华志路123号","zipcode":"610012"},"receiver":{"id":"130520142097","name":"杨逸嘉","company":"逸嘉实业有限公司","mobile":"13687654321","phone":"010-22226789","prov":"四川省","city":"成都市","county":"武侯区","address":"育德路497号","zipcode":"610012"},"items":[{"id":"1234567","name":"迷你风扇","category":"电子产品","material":"金属","size":"12,11,23","weight":"1","unitprice":"79","quantity":"1","remark":"黑色大号"},{"name":"USB3.0集线器","quantity":"1","remark":""}],"starttime":"2013-05-20 12:00:00","endtime":"2013-05-20 15:00:00","weight":753,"size":"12,23,11","quantity":2,"price":12650,"freight":1000,"premium":50,"packCharges":100,"otherCharges":0,"orderSum":0,"collectMoneytype":"CNY","collectSum":1200,"remark":"请勿摔货"}');
|
||||
|
||||
$ret = $client->execute($request);
|
||||
return json_decode($ret,true);
|
||||
}
|
||||
|
||||
//总对总订单,无用
|
||||
public function plateOrder($sample=[],$address=[])
|
||||
{
|
||||
$data = [
|
||||
"systemParameter"=> [
|
||||
"serviceCode"=> "StoreDeliverGoods"
|
||||
],
|
||||
"orderInfo"=> [
|
||||
"bagSize"=> "20,10,30",
|
||||
"partnerCode"=> "3608036589234",
|
||||
"companyCode"=> "GP1551922487",
|
||||
"customerId"=> "zto001",
|
||||
"hallCode"=> "S2044",
|
||||
"billCode"=> null,
|
||||
"pickUpCode"=> null,
|
||||
"startTime"=> null,
|
||||
"endTime"=> null,
|
||||
"siteCode"=> "",
|
||||
"weight"=> 1.23,
|
||||
"freight"=> 0,
|
||||
"orderSum"=> 230.12,
|
||||
"otherCharges"=> 0,
|
||||
"packCharges"=> 0,
|
||||
"premium"=> 0,
|
||||
"price"=> 0,
|
||||
"quantity"=> "1",
|
||||
"returnAddress"=> "江苏省苏州市姑苏区绿地大道320号金茂大厦负一楼203仓库",
|
||||
"remark"=> "",
|
||||
"receiver"=> [
|
||||
"address"=> "外街道00号",
|
||||
"city"=> "苏州市",
|
||||
"company"=> "中通快递",
|
||||
"county"=> "朝阳区",
|
||||
"id"=> "",
|
||||
"mobile"=> "13262709999",
|
||||
"name"=> "黄某",
|
||||
"phone"=> "",
|
||||
"prov"=> "江苏省",
|
||||
"zipCode"=> ""
|
||||
],
|
||||
"sender"=> [
|
||||
"address"=> "华志路1685号",
|
||||
"city"=> "蚌埠市",
|
||||
"company"=> "中通快递股份有限公司",
|
||||
"county"=> "怀远县",
|
||||
"id"=> "15097756",
|
||||
"mobile"=> "15216800000",
|
||||
"name"=> "测试",
|
||||
"phone"=> "",
|
||||
"prov"=> "安徽省",
|
||||
"zipCode"=> ""
|
||||
]
|
||||
]
|
||||
];
|
||||
$ret = $this->request('plateOrder',$data);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
//散客预约订单
|
||||
public function OpenOrderCreate($sample=[],$address=[])
|
||||
{
|
||||
$data = [
|
||||
'orderGroup'=>[
|
||||
"partnerCode"=> $sample['device_id'],//合作商订单号,为调用方生成,可以传订单号、主键、UUID等
|
||||
"type"=> 2,//订单类型 1 普通订单(线上),2线下联系订单 默认1
|
||||
"tradeId"=> $sample['device_id'],//交易号,由合作商平台产生。
|
||||
"mailNo"=> "",//运单号(有则提供,线下联系订单必须提供)
|
||||
"sender"=> [
|
||||
"id"=> $address['tel'],
|
||||
"name"=> $address['name'],
|
||||
"company"=> "",
|
||||
"mobile"=> $address['tel'],
|
||||
"phone"=> "",
|
||||
"prov"=> $address['province'],
|
||||
"city"=> $address['city'],
|
||||
"county"=> $address['district'],
|
||||
"address"=> $address['address'],
|
||||
"zipcode"=> ""
|
||||
],
|
||||
"receiver"=> [
|
||||
"id"=> "",
|
||||
"name"=> "杨逸嘉",
|
||||
"company"=> "逸嘉实业有限公司",
|
||||
"mobile"=> "13687654321",
|
||||
"phone"=> "010-22226789",
|
||||
"prov"=> "四川省",
|
||||
"city"=> "成都市",
|
||||
"county"=> "武侯区",
|
||||
"address"=> "育德路497号",
|
||||
"zipcode"=> "610012"
|
||||
],
|
||||
"items"=> [
|
||||
[
|
||||
"id"=> "1234567",
|
||||
"name"=> "唾液样本",
|
||||
"category"=> "电子产品",
|
||||
"material"=> "金属",
|
||||
"size"=> "12,11,23",
|
||||
"weight"=> "1",
|
||||
"unitprice"=> "79",
|
||||
"quantity"=> "1",
|
||||
"remark"=> "黑色大号"
|
||||
]
|
||||
],
|
||||
"starttime"=> "2013-05-20 12=>00=>00",
|
||||
"endtime"=> "2013-05-20 15=>00=>00",
|
||||
"weight"=> 100,
|
||||
"size"=> "12,23,11",
|
||||
"quantity"=> 1,
|
||||
"price"=> 50,
|
||||
"freight"=> 1000,
|
||||
"premium"=> 50,
|
||||
"packCharges"=> 100,
|
||||
"otherCharges"=> 0,
|
||||
"orderSum"=> 0,
|
||||
"collectMoneytype"=> "CNY",
|
||||
"collectSum"=> 1200,
|
||||
"remark"=> ""
|
||||
]
|
||||
];
|
||||
$ret = $this->request('OpenOrderCreate',$data);
|
||||
/*
|
||||
* Array
|
||||
(
|
||||
[message] => 服务暂不可用
|
||||
[result] =>
|
||||
[status] =>
|
||||
[statusCode] => S203
|
||||
)
|
||||
*/
|
||||
if($ret['status']){
|
||||
//存订单
|
||||
$order = $ret['result'];
|
||||
$row = [
|
||||
/*
|
||||
'partner_code'=>$order['partnerCode'],//合作商订单号
|
||||
'bill_code'=>$order['billCode'],// 运单号
|
||||
'up_data'=>$order['upData'],// 状态:0-新增 1-更新
|
||||
'mark'=>$order['mark'],// 三段码| 大头笔
|
||||
'site_name'=>$order['siteName'],// 集包地
|
||||
'site_code'=>$order['siteCode'],// 签约网点
|
||||
*/
|
||||
'order_code'=>$order['orderCode'],// 中通订单号
|
||||
];
|
||||
//订阅快递信息
|
||||
$this->add($row);
|
||||
return [true,''];
|
||||
}
|
||||
log_message('error', $ret['message']);
|
||||
return [false,$ret['message']];
|
||||
}
|
||||
|
||||
|
||||
//散客预约订单,测试
|
||||
public function test()
|
||||
{
|
||||
$data = [
|
||||
//'orderGroup'=>[
|
||||
"partnerCode"=> 'test20200210',//合作商订单号,为调用方生成,可以传订单号、主键、UUID等
|
||||
"type"=> 1,//订单类型 1 普通订单(线上),2线下联系订单 默认1
|
||||
"tradeId"=> 'test20200210',//交易号,由合作商平台产生。
|
||||
//"mailNo"=> "",//运单号(有则提供,线下联系订单必须提供)
|
||||
"sender"=> [
|
||||
"id"=> '1',
|
||||
"name"=> '罗线上',
|
||||
"company"=> "",
|
||||
"mobile"=> '15815725225',
|
||||
"phone"=> "",
|
||||
"prov"=> '广东省',
|
||||
"city"=> '深圳市',
|
||||
"county"=> '宝安区',
|
||||
"address"=> '创业立交附近新湖路一号',
|
||||
"zipcode"=> ""
|
||||
],
|
||||
"receiver"=> [
|
||||
//"id"=> "",
|
||||
"name"=> "杨逸嘉",
|
||||
"company"=> "中兴通讯有限公司",
|
||||
"mobile"=> "13687654321",
|
||||
"phone"=> "010-22226789",
|
||||
"prov"=> "四川省",
|
||||
"city"=> "成都市",
|
||||
"county"=> "武侯区",
|
||||
"address"=> "育德路497号",
|
||||
"zipcode"=> "610012"
|
||||
],
|
||||
"items"=> [
|
||||
[
|
||||
"id"=> "1234567",
|
||||
"name"=> "唾液样本",
|
||||
"category"=> "电子产品",
|
||||
"material"=> "金属",
|
||||
"size"=> "12,11,23",
|
||||
"weight"=> "1",
|
||||
"unitprice"=> "79",
|
||||
"quantity"=> "1",
|
||||
"remark"=> "黑色大号"
|
||||
]
|
||||
],
|
||||
"starttime"=> "2020-02-20 12:00:00",
|
||||
"endtime"=> "2020-02-30 15:00:00",
|
||||
"weight"=> 100,
|
||||
"size"=> "12,23,11",
|
||||
"quantity"=> 1,
|
||||
"price"=> 50,
|
||||
"freight"=> 1000,
|
||||
"premium"=> 50,
|
||||
"packCharges"=> 100,
|
||||
"otherCharges"=> 0,
|
||||
"orderSum"=> 0,
|
||||
"collectMoneytype"=> "CNY",
|
||||
"collectSum"=> 1200,
|
||||
"remark"=> ""
|
||||
//]
|
||||
];
|
||||
|
||||
$data = [
|
||||
"partnerCode"=> 'test20200210',//合作商订单号,为调用方生成,可以传订单号、主键、UUID等
|
||||
"sender"=> [
|
||||
"id"=> '1',
|
||||
"name"=> '罗线上',
|
||||
"mobile"=> '15815725225',
|
||||
"prov"=> '广东省',
|
||||
"city"=> '深圳市',
|
||||
"county"=> '宝安区',
|
||||
"address"=> '创业立交附近新湖路一号',
|
||||
],
|
||||
"receiver"=> [
|
||||
"name"=> "杨逸嘉",
|
||||
"mobile"=> "13687654321",
|
||||
"prov"=> "四川省",
|
||||
"city"=> "成都市",
|
||||
"county"=> "武侯区",
|
||||
"address"=> "育德路497号",
|
||||
]
|
||||
];
|
||||
$ret = $this->request('OpenOrderCreate',$data);
|
||||
print_r($ret);die;
|
||||
}
|
||||
|
||||
public function subscribeData($sample='',$address='')
|
||||
{
|
||||
}
|
||||
|
||||
//获取快件轨迹信息
|
||||
public function traceInterfaceNewTraces($order_id)
|
||||
{
|
||||
$conf = $this->config->item('zto');
|
||||
$data = [
|
||||
"company_id"=> $conf['id'],
|
||||
"msg_type"=> 'NEW_TRACES',
|
||||
"data"=> json_encode([$order_id]),
|
||||
];
|
||||
return $this->request('traceInterfaceNewTraces',$data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user