use super::post_send;
use crate::{wechat::WxApiRequestBuilder, SdkResult};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryAbnormal {
pub shopid: String,
pub shop_order_id: String,
pub shop_no: String,
pub delivery_sign: String,
pub waybill_id: String,
#[serde(default)]
pub remark: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ResultCode {
pub resultcode: i32,
pub resultmsg: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AddOrder {
#[serde(default)]
pub delivery_token: Option<String>,
pub shopid: String,
pub shop_order_id: String,
pub shop_no: String,
pub delivery_sign: String,
pub delivery_id: String,
pub openid: String,
#[serde(default)]
pub sender: Option<Address>,
pub receiver: Address,
pub cargo: Cargo,
pub order_info: AddOrderInfo,
pub shop: Shop,
#[serde(default)]
pub sub_biz_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Address {
pub name: String,
pub city: String,
pub address: String,
pub address_detail: String,
pub phone: String,
pub lng: f64,
pub lat: f64,
#[serde(default)]
pub coordinate_type: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Cargo {
pub goods_value: f32,
#[serde(default)]
pub goods_height: Option<f32>,
#[serde(default)]
pub goods_length: Option<f32>,
#[serde(default)]
pub goods_width: Option<f32>,
pub goods_weight: f32,
#[serde(default)]
pub goods_detail: Option<GoodsList>,
#[serde(default)]
pub goods_pickup_info: Option<String>,
#[serde(default)]
pub goods_delivery_info: Option<String>,
pub cargo_first_class: String,
pub cargo_second_class: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GoodsList {
pub goods: Vec<Goods>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Goods {
pub good_count: i32,
pub good_name: String,
#[serde(default)]
pub good_price: Option<f32>,
#[serde(default)]
pub good_unit: Option<String>,
}
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct AddOrderInfo {
#[serde(default)]
pub delivery_service_code: Option<String>,
#[serde(default)]
pub order_type: Option<i32>,
#[serde(default)]
pub expected_delivery_time: Option<i64>,
#[serde(default)]
pub expected_finish_time: Option<i64>,
#[serde(default)]
pub expected_pick_time: Option<i64>,
#[serde(default)]
pub poi_seq: Option<String>,
#[serde(default)]
pub note: Option<String>,
#[serde(default)]
pub order_time: Option<i64>,
#[serde(default)]
pub is_insured: Option<i32>,
#[serde(default)]
pub declared_value: Option<f32>,
#[serde(default)]
pub tips: Option<f32>,
#[serde(default)]
pub is_direct_delivery: Option<i32>,
#[serde(default)]
pub cash_on_delivery: Option<f32>,
#[serde(default)]
pub cash_on_pickup: Option<f32>,
#[serde(default)]
pub rider_pick_method: Option<i32>,
#[serde(default)]
pub is_finish_code_needed: Option<i32>,
#[serde(default)]
pub is_pickup_code_needed: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Shop {
pub wxa_path: String,
pub img_url: String,
pub goods_name: String,
pub goods_count: i32,
#[serde(default)]
pub wxa_appid: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AddOrderRes {
pub resultcode: i32,
pub resultmsg: String,
pub fee: f32,
pub deliverfee: f32,
pub couponfee: f32,
pub tips: f32,
pub insurancefee: f32,
pub distance: f32,
pub waybill_id: String,
pub order_status: i32,
pub finish_code: i32,
pub pickup_code: i32,
pub dispatch_duration: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Tip {
pub shopid: String,
pub shop_order_id: String,
pub shop_no: String,
pub delivery_sign: String,
pub waybill_id: String,
pub openid: String,
pub tips: f32,
pub remark: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CancelOrder {
pub shopid: String,
pub shop_order_id: String,
pub shop_no: String,
pub delivery_sign: String,
pub delivery_id: String,
#[serde(default)]
pub waybill_id: Option<String>,
pub cancel_reason_id: i32,
#[serde(default)]
pub cancel_reason: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CancelOrderRes {
pub resultcode: i32,
pub resultmsg: String,
pub deduct_fee: i32,
pub desc: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ImmeDeliveryList {
pub resultcode: i32,
pub resultmsg: String,
pub list: Vec<DeliveryInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DeliveryInfo {
pub delivery_id: String,
pub delivery_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BindAccountRes {
pub resultcode: i32,
pub resultmsg: String,
pub shop_list: Vec<BindShop>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BindShop {
pub delivery_id: String,
pub shopid: String,
pub audit_result: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryOrder {
pub shopid: String,
pub shop_order_id: String,
pub shop_no: String,
pub delivery_sign: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OrderInfo {
pub resultcode: i32,
pub resultmsg: String,
pub order_status: i32,
pub waybill_id: String,
pub rider_name: String,
pub rider_phone: String,
pub rider_lng: f64,
pub rider_lat: f64,
pub reach_time: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MockUpdateOrder {
pub shopid: String,
pub shop_order_id: String,
pub action_time: i64,
pub order_status: i32,
#[serde(default)]
pub action_msg: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PreAddOrder {
pub shopid: String,
pub shop_order_id: String,
pub shop_no: String,
pub delivery_sign: String,
pub delivery_id: String,
pub openid: String,
pub sender: Option<Address>,
pub receiver: Address,
pub cargo: Cargo,
pub order_info: AddOrderInfo,
pub shop: Shop,
#[serde(default)]
pub sub_biz_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PreAddOrderRes {
pub resultcode: i32,
pub resultmsg: String,
pub fee: i32,
pub deliverfee: i32,
pub couponfee: i32,
pub tips: i32,
pub insurancefee: i32,
pub distance: i32,
pub dispatch_duration: i32,
pub delivery_token: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RealMockUpdateOrder {
pub shopid: String,
pub shop_order_id: String,
pub action_time: i32,
pub order_status: i32,
#[serde(default)]
pub action_msg: Option<String>,
pub delivery_sign: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateOrder {
pub wx_token: String,
pub shopid: String,
pub shop_order_id: String,
#[serde(default)]
pub shop_no: Option<String>,
pub waybill_id: String,
pub action_time: i64,
pub order_status: i32,
#[serde(default)]
pub action_msg: Option<String>,
pub wxa_path: String,
#[serde(default)]
pub agent: Option<Agent>,
#[serde(default)]
pub expected_delivery_time: Option<i64>,
}
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Agent {
pub name: String,
pub phone: String,
#[serde(default)]
pub is_phone_encrypted: Option<i32>,
}
pub struct ImmediateDeliveryModule<'a, T: WxApiRequestBuilder>(pub(crate) &'a T);
impl<'a, T: WxApiRequestBuilder> ImmediateDeliveryModule<'a, T> {
pub async fn abnormal_confirm(&self, data: &QueryAbnormal) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/confirm_return";
post_send(self.0, url, data).await
}
pub async fn add_order(&self, data: &AddOrder) -> SdkResult<AddOrderRes> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/add";
post_send(self.0, url, data).await
}
pub async fn add_tip(&self, data: &Tip) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/addtips";
post_send(self.0, url, data).await
}
pub async fn bind_account(&self, delivery_id: &str) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/shop/add";
let data = &serde_json::json!({ "delivery_id": delivery_id });
post_send(self.0, url, data).await
}
pub async fn cancel_order(&self, data: &CancelOrder) -> SdkResult<CancelOrderRes> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/cancel";
post_send(self.0, url, data).await
}
pub async fn get_all_imme_delivery(&self) -> SdkResult<ImmeDeliveryList> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/delivery/getall";
post_send(self.0, url, &()).await
}
pub async fn get_bind_account(&self) -> SdkResult<BindAccountRes> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/shop/get";
post_send(self.0, url, &()).await
}
pub async fn get_order(&self, data: &QueryOrder) -> SdkResult<OrderInfo> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/get";
post_send(self.0, url, data).await
}
pub async fn mock_update_order(&self, data: &MockUpdateOrder) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/test_update_order";
post_send(self.0, url, data).await
}
pub async fn open_delivery(&self) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/open";
post_send(self.0, url, &()).await
}
pub async fn pre_add_order(&self, data: &PreAddOrder) -> SdkResult<PreAddOrderRes> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/pre_add";
post_send(self.0, url, data).await
}
pub async fn pre_cancel_order(&self, data: &CancelOrder) -> SdkResult<CancelOrderRes> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/precancel";
post_send(self.0, url, data).await
}
pub async fn real_mock_update_order(
&self,
data: &RealMockUpdateOrder,
) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/realmock_update_order";
post_send(self.0, url, data).await
}
pub async fn re_order(&self, data: &AddOrder) -> SdkResult<AddOrderRes> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/business/order/readd";
post_send(self.0, url, data).await
}
pub async fn update_order(&self, data: &UpdateOrder) -> SdkResult<ResultCode> {
let url = "https://api.weixin.qq.com/cgi-bin/express/local/delivery/update_order";
post_send(self.0, url, data).await
}
}