| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/3/25 21:38
- */
- namespace common\components\dada;
- use common\components\dada\api\cityCodeApi;
- use common\components\dada\api\orderApi;
- use common\components\dada\api\reasonsApi;
- use common\components\dada\config\config;
- use common\components\dada\protocol\requestClient;
- use common\components\util;
- use Yii;
- //达达快递
- class dada
- {
- //cityCode
- public static function getCityCode($sourceId)
- {
- $config = self::getConfig($sourceId);
- $api = new cityCodeApi('');
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- //
- /*
- [{
- "reason": "没有配送员接单",
- "id": 1
- }, {
- "reason": "配送员没来取货",
- "id": 2
- }, {
- "reason": "配送员态度太差",
- "id": 3
- }, {
- "reason": "顾客取消订单",
- "id": 4
- }, {
- "reason": "订单填写错误",
- "id": 5
- }, {
- "reason": "配送员让我取消此单",
- "id": 34
- }, {
- "reason": "配送员不愿上门取货",
- "id": 35
- }, {
- "reason": "我不需要配送了",
- "id": 36
- }, {
- "reason": "配送员以各种理由表示无法完成订单",
- "id": 37
- }, {
- "reason": "其他",
- "id": 10000
- }]
- */
- public static function getCancelReason($sourceId)
- {
- $config = self::getConfig($sourceId);
- $api = new reasonsApi('');
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- //新增订单
- /*
- *
- shop_no String 是 门店编号,门店创建后可在门店列表和单页查看
- origin_id String 是 第三方订单ID
- city_code String 是 订单所在城市的code(查看各城市对应的code值)
- cargo_price Double 是 订单金额(单位:元)
- is_prepay Integer 是 是否需要垫付 1:是 0:否 (垫付订单金额,非运费)
- receiver_name String 是 收货人姓名
- receiver_address String 是 收货人地址
- receiver_lat Double 是 收货人地址纬度(高德坐标系,若是其他地图经纬度需要转化成高德地图经纬度,高德地图坐标拾取器)
- receiver_lng Double 是 收货人地址经度(高德坐标系,若是其他地图经纬度需要转化成高德地图经纬度,高德地图坐标拾取器)
- callback String 是 回调URL(查看回调说明)
- cargo_weight Double 是 订单重量(单位:Kg)
- receiver_phone String 否 收货人手机号(手机号和座机号必填一项)
- receiver_tel String 否 收货人座机号(手机号和座机号必填一项)
- tips Double 否 小费(单位:元,精确小数点后一位)
- info String 否 订单备注
- cargo_type Integer 否 订单商品类型:食品小吃-1,饮料-2,鲜花-3,文印票务-8,便利店-9,水果生鲜-13,同城电商-19, 医药-20,蛋糕-21,酒品-24,小商品市场-25,服装-26,汽修零配-27,数码-28,小龙虾-29,火锅-51,其他-5
- cargo_num Integer 否 订单商品数量
- invoice_title String 否 发票抬头
- origin_mark String 否 订单来源标示(只支持字母,最大长度为10)
- origin_mark_no String 否 订单来源编号,最大长度为30,该字段可以显示在骑士APP订单详情页面,示例:origin_mark_no:"#京东到家#1"达达骑士APP看到的是:#京东到家#1
- is_use_insurance Integer 否是否使用保价费(0:不使用保价,1:使用保价; 同时,请确保填写了订单金额(cargo_price))商品保价费(当商品出现损坏,可获取一定金额的赔付)保费=配送物品实际价值*费率(5‰),配送物品价值及最高赔付不超过10000元, 最高保费为50元(物品价格最小单位为100元,不足100元部分按100元认定,保价费向上取整数, 如:物品声明价值为201元,保价费为300元*5‰=1.5元,取整数为2元。)若您选择不保价,若物品出现丢失或损毁,最高可获得平台30元优惠券。 (优惠券直接存入用户账户中)。
- is_finish_code_needed Integer 否 收货码(0:不需要;1:需要。收货码的作用是:骑手必须输入收货码才能完成订单妥投)
- delay_publish_time Integer 否 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约,可以支持未来3天内的订单发预约单。)
- is_direct_delivery Integer 否 是否选择直拿直送(0:不需要;1:需要。选择直拿直送后,同一时间骑士只能配送此订单至完成,同时,也会相应的增加配送费用)
- product_list Object 否 订单商品明细
- pick_up_pos String 否 货架信息,该字段可在骑士APP订单备注中展示
- product_list:参数
- sku_name String 是 商品名称,限制长度128
- src_product_no String 是 商品编码,限制长度64
- count Double 是 商品数量,精确到小数点后两位
- unit String 否 商品单位,默认:件
- */
- /*
- {
- "status": "success",
- "result": {
- "distance": 53459.98,
- "fee": 51.0
- "deliverFee": 51.0
- },
- "code": 0,
- "msg": "成功"
- }
- */
- public static function addOrder($sourceId, $params)
- {
- $config = self::getConfig($sourceId);
- $api = new orderApi();
- //body内容
- $api->addOrder($params);
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- //运费查询(参数跟新增订单一致)
- public static function queryDeliverFee($sourceId, $params)
- {
- $config = self::getConfig($sourceId);
- $api = new orderApi();
- $api->queryDeliverFee($params);
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- //订单重发(参数跟新增订单一致)
- public static function reAddOrder($sourceId, $params)
- {
- $config = self::getConfig($sourceId);
- $api = new orderApi();
- $api->reAddOrder($params);
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- //订单取消 (可以用自定义的理由)
- /*
- order_id String 是 第三方订单编号
- cancel_reason_id Integer 是 取消原因ID(取消原因列表)
- cancel_reason String 否 取消原因(当取消原因ID为其他时,此字段必填)
- */
- public static function formalCancel($sourceId, $orderSn, $reasonId, $reason = '')
- {
- $config = self::getConfig($sourceId);
- $api = new orderApi();
- $params = [
- 'order_id' => $orderSn,
- 'cancel_reason_id' => $reasonId,
- ];
- if ($reasonId == 10000) {
- $params['cancel_reason'] = $reason;
- }
- $api->formalCancel($params);
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- //订单状态查询
- public static function statusQuery($sourceId, $orderSn)
- {
- $config = self::getConfig($sourceId);
- $api = new orderApi();
- $params = [
- 'order_id' => $orderSn,
- ];
- $api->queryOrderStatus($params);
- $client = new requestClient($config, $api);
- $resp = $client->makeRequest();
- return self::handleResp($resp);
- }
- public static function getConfig($sourceId)
- {
- if (empty($sourceId)) {
- util::fail("请先开通达达配送");
- }
- $config = new config();
- //$online = Yii::$app->params['dadaOnline'];
- $appKey = Yii::$app->params['dadaAppKey'];
- $appSecret = Yii::$app->params['dadaAppSecret'];
- if (getenv('YII_ENV', 'local') == 'production') {
- $config->setSourceId($sourceId);
- $config->setHost('https://newopen.imdada.cn');
- } else {
- //测试 :商户id: 73753 门店id: 11047059
- $config->setSourceId(73753);
- $config->setHost("http://newopen.qa.imdada.cn");
- }
- $config->setAppKey($appKey);
- $config->setAppSecret($appSecret);
- return $config;
- }
- public static function handleResp($resp)
- {
- if ($resp->getStatus() != 'success') {
- util::fail($resp->getMsg());
- }
- return $resp->getResult();
- }
- }
|