You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
296 lines
16 KiB
296 lines
16 KiB
<?php
|
|
/**
|
|
* 支付模型层
|
|
* @package model
|
|
*/
|
|
include_once(SERVER_ROOT."/model/mBase.php");
|
|
|
|
// 拼多多
|
|
include_once (SERVER_ROOT."/library/pinduoduo/pdd_api.php");
|
|
|
|
|
|
class mPdd extends mBase {
|
|
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
public function getPddAuthUrl() {
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET);
|
|
return $obj->getWebAuthUrl(PDD_REDIRECT_URI, PDD_AUTH_STATE);
|
|
}
|
|
|
|
public function getPddAccessToken($code) {
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET);
|
|
$res = $obj->getAccessToken($code);
|
|
$res = json_decode($res, true);
|
|
|
|
return $res['pop_auth_token_create_response'];
|
|
}
|
|
|
|
private function getPddToken($name='', $shop_id=0) {
|
|
if (empty($name) && empty($shop_id)) {
|
|
$this->setError('店铺id或店铺名称不能为空');
|
|
return false;
|
|
}
|
|
|
|
$obj = new mShop();
|
|
if ($name) {
|
|
$shopinfo = $obj->getShopByName($name);
|
|
} elseif ($shop_id) {
|
|
$shopinfo = $obj->getShopById($shop_id);
|
|
}
|
|
|
|
if (!$shopinfo) {
|
|
$this->setError('店铺信息不存在');
|
|
return false;
|
|
}
|
|
|
|
if (strtotime($shopinfo['expire_time']) < time()) {
|
|
$this->setError(false, '授权已过期');
|
|
return false;
|
|
}
|
|
|
|
return $shopinfo['access_token'];
|
|
}
|
|
|
|
/**
|
|
* 获取拼多多订单信息
|
|
* @param unknown $tid
|
|
* @param unknown $pay_id
|
|
*/
|
|
public function getPddOrderInfo($tid, $name) {
|
|
$access_token = $this->getPddToken($name);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
|
|
$res = $obj->getOrderInformation($tid);
|
|
// {"order_info_get_response":{"request_id":"16547568855546893","order_info":{"support_nationwide_warranty":0,"country":"中国","group_status":1,"free_sf":0,"discount_amount":0.0,"platform_discount":0.0,"return_freight_payer":0,"order_status":1,"id_card_num":"","risk_control_status":0,"province":"","town_id":0,"item_list":[{"goods_name":"checkpass论文查重无限次数低价免注册查重","outer_goods_id":"","goods_price":1.0,"goods_id":329073007863,"sku_id":1115504481445,"goods_count":1,"goods_spec":"千字符","outer_id":"","goods_img":"https://img.pddpic.com/mms-material-img/2022-03-28/0c075d33-b036-46f7-a0bf-d40774f68190.png.a.jpeg"}],"pay_no":"","last_ship_time":"2022-06-11 14:37:23","delivery_one_day":0,"created_time":"2022-06-09 14:37:14","card_info_list":[],"refund_status":1,"town":"","is_stock_out":0,"receiver_address_mask":"","receive_time":"","pay_time":"2022-06-09 14:37:23","gift_list":[],"capital_free_discount":0.0,"receiver_phone_mask":"13*******67","country_id":0,"city_id":0,"invoice_status":0,"service_fee_detail":[],"city":"","order_tag_list":[{"name":"delivery_one_day","value":0},{"name":"no_trace_delivery","value":0},{"name":"self_contained","value":0},{"name":"return_freight_payer","value":0},{"name":"free_sf","value":0},{"name":"duoduo_wholesale","value":0},{"name":"support_nationwide_warranty","value":0},{"name":"only_support_replace","value":0},{"name":"oversea_tracing","value":0},{"name":"distributional_sale","value":0},{"name":"open_in_festival","value":0},{"name":"same_city_distribution","value":0},{"name":"region_black_delay_shipping","value":0},{"name":"has_subsidy_postage","value":0},{"name":"has_sf_express_service","value":0},{"name":"community_group","value":0},{"name":"has_ship_additional","value":0},{"name":"ship_additional_order","value":0}],"is_lucky_flag":1,"yyps_time":"","mkt_biz_type":0,"shipping_type":0,"remark":"","pre_sale_time":"","inner_transaction_id":"","order_change_amount":0.0,"only_support_replace":0,"logistics_id":0,"updated_at":"2022-06-09 14:37:33","street":"","receiver_name_mask":"","receiver_name":"","tracking_number":"","pay_type":"","duoduo_wholesale":0,"buyer_memo":"","is_pre_sale":0,"shipping_time":"","home_delivery_type":0,"after_sales_status":0,"address":"","id_card_name":"","self_contained":0,"goods_amount":1.0,"pay_amount":1.0,"seller_discount":0.0,"address_mask":"","yyps_date":"","confirm_status":1,"confirm_time":"2022-06-09 14:37:23","stock_out_handle_status":-1,"postage":0.0,"province_id":0,"cat_id_3":9056,"cat_id_4":0,"cat_id_1":8726,"receiver_address":"","cat_id_2":8786,"trade_type":0,"urge_shipping_time":"","receiver_phone":"$3MpaxbKBnse9$AgAAAAF2+qYGan7+ggANYOk6e6B2tcD3m4NUAgu6bY4=$0$$","order_sn":"220609-635730697112661"}}}
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
$order_info = $res['order_info_get_response']['order_info'];
|
|
|
|
// 成交状态:0:未成交、1:已成交、2:已取消
|
|
if ($order_info['confirm_status'] != 1) {
|
|
$confirm_status_desc = '';
|
|
if ($order_info['order_status'] == 0) $confirm_status_desc = '未成交';
|
|
if ($order_info['order_status'] == 2) $confirm_status_desc = '已取消';
|
|
|
|
$this->setError('当前订单 '.$tid.' 成交状态为'.$confirm_status_desc.',无法使用');
|
|
return false;
|
|
}
|
|
|
|
// 退款状态,枚举值:1:无售后或售后关闭,2:售后处理中,3:退款中,4: 退款成功
|
|
if ($order_info['refund_status'] != 1) {
|
|
$order_refund_status_desc = '';
|
|
if ($order_info['refund_status'] == 2) $order_refund_status_desc = '售后处理中';
|
|
if ($order_info['refund_status'] == 3) $order_refund_status_desc = '退款中';
|
|
if ($order_info['refund_status'] == 4) $order_refund_status_desc = '退款成功';
|
|
|
|
$this->setError('当前订单 '.$tid.' 售后('.$order_refund_status_desc.')状态,无法使用');
|
|
return false;
|
|
}
|
|
|
|
// 发货状态,枚举值:1:待发货,2:已发货待签收,3:已签收
|
|
if ($order_info['order_status'] != 1) {
|
|
$order_status_desc = '';
|
|
if ($order_info['order_status'] == 2) $order_status_desc = '已发货待签收';
|
|
if ($order_info['order_status'] == 3) $order_status_desc = '已签收';
|
|
|
|
$this->setError('当前订单 '.$tid.' 非待发货('.$order_status_desc.')状态,无法使用');
|
|
return false;
|
|
}
|
|
|
|
// 成团状态:0:拼团中、1:已成团、2:团失败
|
|
if ($order_info['group_status'] != 1) {
|
|
$group_status_desc = '';
|
|
if ($order_info['group_status'] == 0) $group_status_desc = '拼团中';
|
|
if ($order_info['group_status'] == 2) $group_status_desc = '团失败';
|
|
$this->setError('当前订单 '.$tid.' 成团状态为'.$group_status_desc.',无法使用');
|
|
return false;
|
|
}
|
|
|
|
// 售后状态 0:无售后 2:买家申请退款,待商家处理 3:退货退款,待商家处理 4:商家同意退款,退款中 5:平台同意退款,退款中 6:驳回退款,待买家处理 7:已同意退货退款,待用户发货 8:平台处理中 9:平台拒绝退款,退款关闭 10:退款成功 11:买家撤销 12:买家逾期未处理,退款失败 13:买家逾期,超过有效期 14:换货补寄待商家处理 15:换货补寄待用户处理 16:换货补寄成功 17:换货补寄失败 18:换货补寄待用户确认完成 21:待商家同意维修 22:待用户确认发货 24:维修关闭 25:维修成功 27:待用户确认收货 31:已同意拒收退款,待用户拒收 32:补寄待商家发货
|
|
if ($order_info['after_sales_status'] != 0) {
|
|
$this->setError('当前订单 '.$tid.' 售后中,无法使用');
|
|
return false;
|
|
}
|
|
|
|
// 是否为预售商品 1表示是 0表示否
|
|
if ($order_info['is_pre_sale'] == 1) {
|
|
$this->setError('当前订单 '.$tid.' 为预售商品,无法使用');
|
|
return false;
|
|
}
|
|
|
|
// goods_amount 商品金额(元)商品金额=商品销售价格*商品数量-订单改价折扣金额
|
|
// seller_discount 店铺优惠金额
|
|
// discount_amount 折扣金额(元)折扣金额=平台优惠+商家优惠+团长免单优惠金额
|
|
// pay_amount 支付金额(元)支付金额=商品金额-折扣金额+邮费+服务费
|
|
|
|
$payment = 0;
|
|
foreach($order_info['item_list'] as $item){
|
|
if($item['goods_price']+0 == 0) continue;
|
|
if($item['goods_count']+0 == 0) continue;
|
|
|
|
$payment = $item['goods_price'] * $item['goods_count'];
|
|
|
|
$order_info['numiid2num'][$item['goods_id']] = $item['goods_count'];
|
|
$order_info['numiid2skuid'][$item['goods_id']] = $item['sku_id'];
|
|
}
|
|
$order_info['payment'] = $order_info['goods_amount'];
|
|
$order_info['total_payment'] = $payment;
|
|
$order_info['num'] = $order_info['item_list'][0]['goods_count'];
|
|
|
|
return $order_info;
|
|
}
|
|
|
|
public function getPddGoodsList($goods_name, $name) {
|
|
$access_token = $this->getPddToken($name);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
|
|
$res = $obj->getGoodsList($goods_name);
|
|
|
|
// {"goods_list_get_response":{"goods_list":[{"is_more_sku":1,"goods_name":"checkpass论文查重无限次数低价免注册查重","thumb_url":"https://img.pddpic.com/gaudit-image/2022-03-28/edac0af376a509b227714488bd5dfa37.jpeg","goods_reserve_quantity":0,"image_url":"","sku_list":[{"outer_goods_id":"","is_sku_onsale":1,"reserve_quantity":0,"sku_id":1115504481445,"outer_id":"","spec":"千字符","sku_quantity":1277},{"outer_goods_id":"","is_sku_onsale":1,"reserve_quantity":0,"sku_id":1115476736663,"outer_id":"","spec":"无限次数","sku_quantity":1495}],"goods_quantity":2772,"goods_id":329073007863,"is_onsale":1}],"total_count":1,"request_id":"16551061312578732"}}
|
|
$res = json_decode($res, true);
|
|
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['goods_list_get_response']['goods_list'];
|
|
}
|
|
|
|
|
|
public function getPddGoodsInformation($goods_id, $name) {
|
|
$access_token = $this->getPddToken($name);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
|
|
$res = $obj->getGoodsInformation($goods_id);
|
|
|
|
// {"goods_info_get_response":{"goods_info":{"goods_name":"checkpass论文查重无限次数低价免注册查重","last_category":"论文检测与查询","image_url":"","shipment_limit_second":"172800","goods_quantity":2772,"goods_id":"329073007863","goods_sn":"329073007863","goods_category":"教育培训","is_onsale":"1","is_refundable":"0","second_hand":0,"sku_list":[{"single_price":"12.00","sku_img":"https://img.pddpic.com/mms-material-img/2022-03-28/3cd06438-b959-42ac-936a-93c273367355.png.a.jpeg","outer_goods_id":"","is_sku_onsale":"1","sku_id":"1115476736663","group_price":"10.00","outer_id":"","spec":"无限次数","sku_quantity":"1495"},{"single_price":"2.00","sku_img":"https://img.pddpic.com/mms-material-img/2022-03-28/0c075d33-b036-46f7-a0bf-d40774f68190.png.a.jpeg","outer_goods_id":"","is_sku_onsale":"1","sku_id":"1115504481445","group_price":"1.00","outer_id":"","spec":"千字符","sku_quantity":"1277"}],"goods_type":"1","group_required_customer_num":"2"},"request_id":"16551080285427607"}}
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['goods_info_get_response']['goods_info'];
|
|
}
|
|
|
|
public function getPddOrderStatus($tids, $name='', $shopid=0) {
|
|
$access_token = $this->getPddToken($name, $shopid);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
|
|
$res = $obj->getOrderStatus(implode(',', $tids));
|
|
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['order_status_get_response']['order_status_list'];
|
|
}
|
|
|
|
public function getPddOrderList($name, $start_date, $end_date, $order_status, $refund_status, $page=1, $page_size=100) {
|
|
$access_token = $this->getPddToken($name);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
|
|
$start_confirm_at = strtotime($start_date);
|
|
$end_confirm_at = strtotime($end_date);
|
|
|
|
$res = $obj->getOrderList($start_confirm_at, $end_confirm_at, $order_status, $refund_status, $page, $page_size);
|
|
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['order_list_get_response'];
|
|
}
|
|
|
|
public function getPddIncrOrderList($name, $start_date, $end_date, $order_status, $refund_status, $page=1, $page_size=100) {
|
|
$access_token = $this->getPddToken($name);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
|
|
$start_updated_at = strtotime($start_date);
|
|
$end_updated_at = strtotime($end_date);
|
|
|
|
$res = $obj->getIncrementOrderNumberList($start_updated_at, $end_updated_at, $order_status, $refund_status, $page, $page_size);
|
|
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['order_sn_increment_get_response'];
|
|
}
|
|
|
|
public function getPddDdyPdpUsers($owner_id='', $start_modified='', $end_modified='', $page_no=1, $page_size=200) {
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET);
|
|
$res = $obj->getDdyPdpUsers($owner_id, $start_modified, $end_modified, $page_no, $page_size);
|
|
|
|
$this->writeLog('pdd', 'getPddDdyPdpUsers.log', $res);
|
|
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['ddy_pdp_users_get_response'];
|
|
|
|
}
|
|
|
|
public function addPddDdyPdpUser($name) {
|
|
$access_token = $this->getPddToken($name);
|
|
if (!$access_token) {
|
|
$this->setError($this->getError());
|
|
return false;
|
|
}
|
|
$obj = new PDD(PDD_CLIENT_ID, PDD_CLIENT_SECRET, $access_token);
|
|
$res = $obj->addDdyPdpUser(RDS_ID);
|
|
|
|
$this->writeLog('pdd', 'addPddDdyPdpUser.log', $res);
|
|
|
|
$res = json_decode($res, true);
|
|
if (isset($res['error_response'])) {
|
|
$this->setError($res['error_response']['error_msg'].' '.$res['error_response']['sub_msg']);
|
|
return false;
|
|
}
|
|
|
|
return $res['ddy_pdp_user_add_response'];
|
|
}
|
|
|
|
}
|