315 lines
11 KiB
PHP
315 lines
11 KiB
PHP
<?php
|
||
|
||
namespace addon\ali1688\model;
|
||
class Choice extends CloudApi
|
||
{
|
||
|
||
|
||
/***
|
||
* 添加产品关注
|
||
* @param $productId
|
||
* @return bool
|
||
* @throws \Exception
|
||
*/
|
||
public function followGoods($productId)
|
||
{
|
||
// 获取基本参数
|
||
$result = $this->requestApi('com.alibaba.product/alibaba.product.follow', ['productId' => $productId]);
|
||
$result = json_decode($result, true);
|
||
if ($result['code'] == 0) {
|
||
return true;
|
||
} else {
|
||
return $result;
|
||
}
|
||
}
|
||
|
||
/***
|
||
* 解除关注
|
||
* @param $productId
|
||
* @return mixed|true
|
||
* @throws \Exception
|
||
*/
|
||
public function unfollowGoods($productId)
|
||
{
|
||
// 获取基本参数
|
||
$result = $this->requestApi('com.alibaba.product/alibaba.product.unfollow.crossborder', ['productId' => $productId]);
|
||
$result = json_decode($result, true);
|
||
if ($result['code'] == 0) {
|
||
return true;
|
||
} else {
|
||
return $result;
|
||
}
|
||
}
|
||
|
||
|
||
//关键字搜索商品列表
|
||
public function productlist($data)
|
||
{
|
||
$api = 'com.alibaba.fenxiao/jxhy.product.getPageList';
|
||
if(isset($data['filters'])&&$data['filters']){
|
||
$data['filters'] = json_encode(array_values($data['filters']),true);
|
||
}else{
|
||
$data['filters'] = json_encode(['isOnePsaleFreePost']);
|
||
}
|
||
$result = json_decode($this->requestApi($api, $data), true);
|
||
if (isset($result['result']['success']) && isset($result['result']['result'])) {
|
||
$results = $result['result']['result'];
|
||
$itemId = array_column($results, 'itemId');
|
||
$info = model('supply_goods_warehousing')->getColumn([['open_offer_id', 'in', $itemId], ['site_id', '=', $this->site_id]], 'open_offer_id', 'open_offer_id');
|
||
foreach ($results as &$item) {
|
||
if (isset($info[$item['itemId']])) {
|
||
$item['is_warehousing'] = 1;
|
||
} else {
|
||
$item['is_warehousing'] = 0;
|
||
}
|
||
}
|
||
$result['result']['result'] = $results;
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
// public function productlist($data)
|
||
// {
|
||
//
|
||
// $data = $this->handleSearchData($data);
|
||
// $api = 'com.alibaba.fenxiao/alibaba.pifatuan.product.list';
|
||
// $result = json_decode($this->requestApi($api, $data), true);
|
||
// if (isset($result['result']['success']) && isset($result['result']['result'])) {
|
||
// $results = $result['result']['result']['resultList'];
|
||
// $pageInfo = ['currentPage' => $result['result']['result']['pageIndex'],
|
||
// 'pageSize' => $result['result']['result']['sizePerPage'],
|
||
// 'totalRecords' => $result['result']['result']['totalRecords'],
|
||
// ];
|
||
// $itemId = array_column($results, 'itemId');
|
||
// $info = model('supply_goods_warehousing')->getColumn([['open_offer_id', 'in', $itemId], ['site_id', '=', $this->site_id]], 'open_offer_id', 'open_offer_id');
|
||
// foreach ($results as &$item) {
|
||
// if (isset($info[$item['itemId']])) {
|
||
// $item['is_warehousing'] = 1;
|
||
// } else {
|
||
// $item['is_warehousing'] = 0;
|
||
// }
|
||
// }
|
||
// $result['result']['result'] = $results;
|
||
// $result['result']['pageInfo'] = $pageInfo;
|
||
// }
|
||
// return $result;
|
||
// }
|
||
|
||
//获取商品详情
|
||
public function productInfoGet($itemIds)
|
||
{
|
||
$this->gatewayHost = 'https://gw.open.1688.com/openapi/param2/2/';
|
||
$api = 'com.alibaba.fenxiao/alibaba.pifatuan.product.detail.list';
|
||
if (is_array($itemIds)) {
|
||
return json_decode($this->requestApi($api, ['offerIds' => json_encode($itemIds)]), true);
|
||
}else{
|
||
return json_decode($this->requestApi($api, ['offerIds' => json_encode([$itemIds])]), true);
|
||
}
|
||
}
|
||
//获取物流模板详情
|
||
//模板ID,(是否查询子模板,是否查询子模板费率)默认不查子模板
|
||
public function productFreightTemplate($templateId,$querySubTemplate = true,$queryRate = true){
|
||
|
||
$api = 'com.alibaba.logistics/alibaba.logistics.myFreightTemplate.list.get';
|
||
$arr = [
|
||
'templateId' => $templateId,
|
||
'querySubTemplate' => $querySubTemplate,
|
||
'queryRate' => $queryRate
|
||
];
|
||
|
||
return json_decode($this->requestApi($api, $arr), true);
|
||
}
|
||
|
||
|
||
|
||
//添加分销店铺(买家)
|
||
public function buyerOutshopAdd()
|
||
{
|
||
$api = 'com.alibaba.fenxiao/alibaba.fenxiao.buyer.outshop.add';
|
||
return json_decode($this->requestApi($api, ['outShopCode' => $this->site_id, 'channel' => 'other']), true);
|
||
}
|
||
|
||
//添加分销商品关系(买家)
|
||
public function buyerOutproductRelationAdd()
|
||
{
|
||
$api = 'com.alibaba.fenxiao/alibaba.fenxiao.buyer.outproduct.relation.add';
|
||
$data = [
|
||
'channel' => 'other',
|
||
'outShopCode' => $this->site_id,
|
||
'outItemCode' => '6',
|
||
'openOfferId' => 'BgnuDNkhiXPv88gpE3sfbA==',
|
||
];
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
|
||
//根据地址解析地区码
|
||
public function addressCodeParse($address)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.addresscode.parse';
|
||
|
||
return json_decode($this->requestApi($api, ['addressInfo' => $address]), true)['result'];
|
||
}
|
||
|
||
//查询是否开通免密支付
|
||
public function payProtocolPay()
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.pay.protocolPay.isopen';
|
||
|
||
return json_decode($this->requestApi($api), true);
|
||
}
|
||
|
||
//查询订单可以支持的支付渠道
|
||
public function payWayQuery($orderId)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.payWay.query';
|
||
|
||
return json_decode($this->requestApi($api, ['orderId' => $orderId]), true);
|
||
}
|
||
|
||
//发起免密支付
|
||
public function protocolPayPreparePay($orderId)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.pay.protocolPay.preparePay';
|
||
|
||
return json_decode($this->requestApi($api, ['tradeWithholdPreparePayParam' => ['orderId' => $orderId]]), true);
|
||
}
|
||
|
||
//获取交易订单的物流信息
|
||
public function getLogisticsInfos($orderId)
|
||
{
|
||
$api = 'com.alibaba.logistics/alibaba.trade.getLogisticsInfos.buyerView';
|
||
|
||
return json_decode($this->requestApi($api, ['orderId' => $orderId]), true);
|
||
}
|
||
|
||
//获取交易订单的物流跟踪信息
|
||
public function getLogisticsTraceInfo($orderId)
|
||
{
|
||
$api = 'com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView';
|
||
|
||
return json_decode($this->requestApi($api, ['orderId' => $orderId, 'webSite' => '1688']), true);
|
||
}
|
||
|
||
//查询退款退货原因(用于创建退款退货)
|
||
public function getRefundReasonList($data)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.getRefundReasonList';
|
||
|
||
$array = [
|
||
'orderId' => $data['orderId'],
|
||
'orderEntryIds' => $data['orderEntryIds'],
|
||
'goodsStatus' => $data['goodsStatus'],
|
||
];
|
||
|
||
return json_decode($this->requestApi($api, $array), true);
|
||
}
|
||
|
||
//创建退款退货申请
|
||
public function createRefund($data)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.createRefund';
|
||
|
||
$array = [
|
||
'orderId' => $data['orderId'],
|
||
'orderEntryIds' => $data['orderEntryIds'],
|
||
'disputeRequest' => $data['disputeRequest'],
|
||
'applyPayment' => $data['applyPayment'],
|
||
'applyCarriage' => $data['applyCarriage'],
|
||
'applyReasonId' => $data['applyReasonId'],
|
||
'description' => $data['description'],
|
||
'goodsStatus' => $data['goodsStatus'],
|
||
];
|
||
|
||
return json_decode($this->requestApi($api, $array), true);
|
||
}
|
||
|
||
//上传退款退货凭证
|
||
public function uploadRefundVoucher($imageData)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.uploadRefundVoucher';
|
||
|
||
return json_decode($this->requestApi($api, ['imageData' => $imageData]), true);
|
||
}
|
||
|
||
//查询退款单列表(买家视角)
|
||
public function queryOrderRefundList($data)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.refund.buyer.queryOrderRefundList';
|
||
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//查询退款单详情-根据订单ID(买家视角)
|
||
public function OpQueryBatchRefundByOrderIdAndStatus($data)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.refund.OpQueryBatchRefundByOrderIdAndStatus';
|
||
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//查询退款单详情-根据退款单ID(买家视角)
|
||
public function OpQueryOrderRefund($data)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.refund.OpQueryOrderRefund';
|
||
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//退款单操作记录列表(买家视角)
|
||
public function OpQueryOrderRefundOperationList($data)
|
||
{
|
||
$api = 'com.alibaba.trade/alibaba.trade.refund.OpQueryOrderRefundOperationList';
|
||
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//买家提交退款货信息
|
||
public function refundReturnGoods($data)
|
||
{
|
||
$api = 'com.alibaba.trade:alibaba.trade.refund.returnGoods';
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//订购的订单列表
|
||
public function pieceorderGet($data)
|
||
{
|
||
$api = 'cn.alibaba.open/alibaba.app.pieceorder.get';
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//app 在服务市场被订购的订单列表
|
||
public function orderGet($data)
|
||
{
|
||
$api = 'cn.alibaba.open/app.order.get';
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
|
||
//获取某个应用最近一个月的到期订单信息
|
||
public function expireGet($data)
|
||
{
|
||
$api = 'cn.alibaba.open:app.expire.get';
|
||
return json_decode($this->requestApi($api, $data), true);
|
||
}
|
||
//处理数据
|
||
protected function handleSearchData(&$data){
|
||
if(!isset($data['categoryId']) && $data['keywords'] == ''){
|
||
$data['keywords'] = '零食';
|
||
}else if(isset($data['categoryId']) && $data['categoryId'] == '' && $data['keywords'] == ''){
|
||
$data['keywords'] = '零食';
|
||
}
|
||
//默认一键包邮
|
||
if(!isset($data['filterFreePostage'])){
|
||
$data['filterFreePostage'] = true;
|
||
}
|
||
//是否包邮,是否一键代发,是否七天无理由退款,是否48小时发货
|
||
$arr = ['filterFreePostage','filterYjdf','filter7dNoReasonReturn','filter48hShip'];
|
||
foreach($data as $key => $val){
|
||
if(in_array($key,$arr)){
|
||
$data[$key] = $data[$key] > 0 ? true : false;
|
||
}
|
||
}
|
||
return $data;
|
||
}
|
||
}
|