This commit is contained in:
2025-10-29 15:32:26 +08:00
parent d90614805b
commit b7462657cd
78921 changed files with 2753938 additions and 71 deletions

View File

@@ -0,0 +1,246 @@
<?php
/**
*/
namespace app\model\express;
use app\model\store\Store;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 配送配置
*/
class Config extends BaseModel
{
/*********************************************************************** 物流配送 start ***********************************************************************/
/**
* 物流配送配置
* @param $site_id
* @return \multitype
*/
public function getExpressConfig($site_id)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_CONFIG' ] ]);
if (empty($res[ 'data' ][ 'value' ])) {
$res[ 'data' ][ 'value' ] = [
'express_name' => '快递发货'
];
}
return $res;
}
/**
* 设置物流配送配置
* @param $data
* @param $is_use
* @param $site_id
* @return array
*/
public function setExpressConfig($data, $is_use, $site_id)
{
if ($site_id === '') {
return $this->error('', 'REQUEST_SITE_ID');
}
$config = new ConfigModel();
$res = $config->setConfig($data, '物流配送设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_CONFIG' ] ]);
return $res;
}
/*********************************************************************** 物流配送 end ***********************************************************************/
/*********************************************************************** 门店自提 start ***********************************************************************/
/**
* 门店自提配置
* @param $site_id
* @return \multitype
*/
public function getStoreConfig($site_id)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_STORE_CONFIG' ] ]);
if (empty($res[ 'data' ][ 'value' ])) {
$res[ 'data' ][ 'value' ] = [
'store_name' => '门店自提'
];
}
return $res;
}
/**
* 设置门店自提配置
* @param $data
* @param $is_use
* @param $site_id
* @return array
*/
public function setStoreConfig($data, $is_use, $site_id)
{
if ($site_id === '') {
return $this->error('', 'REQUEST_SITE_ID');
}
if ($is_use == 1) {
$store_model = new Store();
$check_result = $store_model->checkIscanStoreTrade($site_id);
if ($check_result[ 'code' ] < 0)
return $check_result;
}
$config = new ConfigModel();
$res = $config->setConfig($data, '门店自提配置设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_STORE_CONFIG' ] ]);
return $res;
}
/**
* 设置门店自提开关
* @param $is_use
* @param $site_id
* @param string $app_module
* @return array
*/
public function setStoreIsuse($is_use, $site_id, $app_module = 'shop')
{
if ($site_id === '') {
return $this->error('', 'REQUEST_SITE_ID');
}
if ($is_use == 1) {
$store_model = new Store();
$check_result = $store_model->checkIscanStoreTrade($site_id);
if ($check_result[ 'code' ] < 0)
return $check_result;
}
$config = new ConfigModel();
$res = $config->modifyConfigIsUse($is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'EXPRESS_STORE_CONFIG' ] ]);
return $res;
}
/*********************************************************************** 门店自提 end ***********************************************************************/
/*********************************************************************** 外卖配送 start ***********************************************************************/
/**
* 外卖配送配置
* @param $site_id
* @return array
*/
public function getLocalDeliveryConfig($site_id)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_LOCAL_DELIVERY_CONFIG' ] ]);
if (empty($res[ 'data' ][ 'value' ])) {
$res[ 'data' ][ 'value' ] = [
'local_name' => '同城配送'
];
}
return $res;
}
/**
* 设置外卖配送配置
* @param $data
* @param $is_use
* @param $site_id
* @return array
*/
public function setLocalDeliveryConfig($data, $is_use, $site_id)
{
if ($site_id === '') {
return $this->error('', '缺少必须参数站点id');
}
if ($is_use == 1) {
$local_model = new Local();
$check_result = $local_model->checkIsCanTradeLocal($site_id);
if ($check_result[ 'code' ])
return $check_result;
}
$config = new ConfigModel();
$res = $config->setConfig($data, '同城配送配置设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'EXPRESS_LOCAL_DELIVERY_CONFIG' ] ]);
return $res;
}
/*********************************************************************** 外卖配送 end ***********************************************************************/
/**
* 外卖配送配置
* @param $site_id
* @return array
*/
public function getDeliverTypeSort($site_id)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'DELIVERY_SORT_CONFIG' ] ]);
if (empty($res[ 'data' ][ 'value' ])) {
$res[ 'data' ][ 'value' ] = [
'deliver_type' => 'local,express,store'
];
}
return $res;
}
public function setDeliverTypeSort($data, $site_id)
{
if ($site_id === '') {
return $this->error('', '缺少必须参数站点id');
}
$config = new ConfigModel();
$res = $config->setConfig($data, '配置方式排序设置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'DELIVERY_SORT_CONFIG' ] ]);
return $res;
}
/**
* 配送方式列表
* @param $site_id
* @return array
*/
public function getExpressTypeList($site_id)
{
//外卖配送
$local = $this->getLocalDeliveryConfig($site_id)[ 'data' ][ 'value' ] ?? [];
$store = $this->getStoreConfig($site_id)[ 'data' ][ 'value' ] ?? [];
$express = $this->getExpressConfig($site_id)[ 'data' ][ 'value' ] ?? [];
return [ 'express' => $express[ 'express_name' ], 'store' => $store[ 'store_name' ], 'local' => $local[ 'local_name' ] ];
}
/**
* 获取已启用的配送方式
* @param $site_id
* @return array
*/
public function getEnabledExpressType($site_id)
{
$local = $this->getLocalDeliveryConfig($site_id)[ 'data' ];
$store = $this->getStoreConfig($site_id)[ 'data' ];
$express = $this->getExpressConfig($site_id)[ 'data' ];
$express_type = [];
if ($express[ 'is_use' ]) {
$express_type[ 'express' ] = [
'name' => $express[ 'value' ][ 'express_name' ],
'icon' => 'iconwuliu',
'desc' => '支持' . $express[ 'value' ][ 'express_name' ] . '的商品在购买后将会通过快递的方式进行配送,可在订单中查看物流信息'
];
}
if ($store[ 'is_use' ]) {
$express_type[ 'store' ] = [
'name' => $store[ 'value' ][ 'store_name' ],
'icon' => 'icondianpu',
'desc' => '支持' . $store[ 'value' ][ 'store_name' ] . '的商品在购买后用户可自行到下单时所选择的自提点进行提货'
];
}
if ($local[ 'is_use' ]) {
$express_type[ 'local' ] = [
'name' => $local[ 'value' ][ 'local_name' ],
'icon' => 'iconwaimaifuwu',
'desc' => '支持' . $local[ 'value' ][ 'local_name' ] . '的商品在购买后平台将安排配送人员配送到用户指定的收货地点'
];
}
return $express_type;
}
}

View File

@@ -0,0 +1,268 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
/**
* 物流配送
*/
class Express extends BaseModel
{
const express_type = [
'express' => [ 'name' => 'express', 'title' => '物流配送' ],
'store' => [ 'name' => 'store', 'title' => '门店自提' ],
'local' => [ 'name' => 'local', 'title' => '外卖配送' ],
];
/**
* 计算费用
* @param $shop_goods
* @param $data
* @return array
*/
public function calculate($param)
{
/** @var \app\model\order\OrderCreate $order_object */
$order_object = $param['order_object'];
if (empty($order_object->delivery[ 'member_address' ])) {
return $this->error([], '请选择物流配送地址');
}
$site_id = $order_object->site_id;
//模板分组
$template_array = [];
foreach ($order_object->goods_list as $k => $v) {
if ($v[ 'is_free_shipping' ] == 1) {
continue;
}
if (isset($template_array[ $v[ 'shipping_template' ] ])) {
$template_array[ $v[ 'shipping_template' ] ] = [
'num' => $template_array[ $v[ 'shipping_template' ] ][ 'num' ] + $v[ 'num' ],
'weight' => $template_array[ $v[ 'shipping_template' ] ][ 'weight' ] + $v[ 'weight' ] * $v[ 'num' ],
'volume' => $template_array[ $v[ 'shipping_template' ] ][ 'volume' ] + $v[ 'volume' ] * $v[ 'num' ],
'goods_money' => $template_array[ $v[ 'shipping_template' ] ][ 'goods_money' ] + $v[ 'goods_money' ],
];
} else {
$template_array[ $v[ 'shipping_template' ] ] = [
'num' => $v[ 'num' ],
'weight' => $v[ 'weight' ] * $v[ 'num' ],
'volume' => $v[ 'volume' ] * $v[ 'num' ],
'goods_money' => $v[ 'goods_money' ]
];
}
}
$express_template = new ExpressTemplate();
$price = 0;
foreach ($template_array as $k_template => $v_template) {
if ($k_template == 0) {
//默认模板
$template_info = $express_template->getDefaultTemplate($site_id);
} else {
//如果选择的模板已经不存在(可能不存在),
//默认模板
$template_info = $express_template->getExpressTemplateInfo($k_template, $site_id);
}
//判断模板是否配置完善
if (empty($template_info[ 'data' ])) {
// continue;
return $this->error([], 'TEMPLATE_EMPTY');
}
$template_info = $template_info[ 'data' ];
$appoint_free_shipping = $template_info[ 'appoint_free_shipping' ] ?? 0;
$is_exist_free = false;
if ($appoint_free_shipping == 1) {
$item_num = $v_template[ 'num' ];
$item_goods_money = $v_template[ 'goods_money' ];
//免邮区域模板
$free_template_list = $template_info[ 'shipping_template_item' ];
foreach ($free_template_list as $free_k => $free_v) {
//判断是否有适配的区域模板
if (strpos($free_v[ 'area_ids' ], '"' . $order_object->delivery[ 'member_address' ][ 'district_id' ] . '"') !== false) {
$item_snum = $free_v[ 'snum' ];//条件(件数)
$item_sprice = $free_v[ 'sprice' ];//条件 商品总额
if ($item_sprice <= $item_goods_money && $item_snum <= $item_num) {//满足包邮条件,免邮
$is_exist_free = true;
// continue 2;
}
}
}
}
if (!$is_exist_free) {
//开始计算
$is_exist_template = false;
foreach ($template_info[ 'template_item' ] as $k_item => $v_item) {
if (strpos($v_item[ 'area_ids' ], '"' . $order_object->delivery[ 'member_address' ][ 'district_id' ] . '"') !== false) {
$is_exist_template = true;
//运算方式
switch ( $template_info[ 'fee_type' ] ) {
case 1:
$tag = $v_template[ 'weight' ];
break;
case 2:
$tag = $v_template[ 'volume' ];
break;
case 3:
$tag = $v_template[ 'num' ];
break;
default:
break;
}
//开始计算
if ($template_info[ 'fee_type' ] == 1 && $tag == 0) {
$price += 0.0;
} else {
if ($tag <= $v_item[ 'snum' ]) {
$price += $v_item[ 'sprice' ];
} else {
$ext_tag = $tag - $v_item[ 'snum' ];
if ($v_item[ 'xnum' ] == 0) {
$v_item[ 'xnum' ] = 1;
}
if (( $ext_tag * 100 ) % ( $v_item[ 'xnum' ] * 100 ) == 0) {
$ext_data = $ext_tag / $v_item[ 'xnum' ];
} else {
$ext_data = floor($ext_tag / $v_item[ 'xnum' ]) + 1;
}
$price += $v_item[ 'sprice' ] + $ext_data * $v_item[ 'xprice' ];
}
}
break;
}
}
if ($is_exist_template == false) {
return $this->error('', 'TEMPLATE_AREA_EXIST');
}
}
}
return $this->success([ 'delivery_fee' => $price ]);
}
/**
* 区域是否支持配送
* @param $area_id
* @param $site_id
* @return array
*/
public function isSupportDelivery($area_id, $site_id)
{
$condition = array (
[ 'ati.area_ids', 'like', '"' . $area_id . '"' ],
[ 'et.site_id', '=', $site_id ]
);
$alias = 'ati';
$join = [
[
'express_template et',
'et.template_id = ati.template_id',
'left'
]
];
$field = 'ati.template_id';
$list = model('express_template_item')->getList($condition, $field, '', $alias, $join);
if (empty($list)) {
return $this->error('', 'TEMPLATE_AREA_EXIST');
} else {
return $this->success();
}
}
/**
* 积分兑换计算费用
* @param $goods_info
* @param $data
* @return array
*/
public function pointExchangeCalculate($goods_info, $data)
{
$num = $data[ 'num' ];
if ($goods_info[ 'is_free_shipping' ] == 1) {
return $this->success([ 'delivery_fee' => 0 ]);
}
$template_data = [
'num' => $num,
'weight' => $goods_info[ 'weight' ] * $num,
'volume' => $goods_info[ 'volume' ] * $num
];
$express_template = new ExpressTemplate();
$price = 0;
if ($goods_info[ 'shipping_template' ] == 0) {
//默认模板
$template_info = $express_template->getDefaultTemplate($data[ 'site_id' ]);
} else {
//默认模板
$template_info = $express_template->getExpressTemplateInfo($goods_info[ 'shipping_template' ], $data[ 'site_id' ]);
}
//判断模板是否配置完善
if (empty($template_info[ 'data' ])) {
return $this->error([], 'TEMPLATE_EMPTY');
}
$template_info = $template_info[ 'data' ];
//开始计算
$is_exist_template = false;
foreach ($template_info[ 'template_item' ] as $k_item => $v_item) {
if (strpos($v_item[ 'area_ids' ], '"' . $data[ 'member_address' ][ 'district_id' ] . '"') !== false) {
$is_exist_template = true;
//运算方式
switch ( $template_info[ 'fee_type' ] ) {
case 1:
$tag = $template_data[ 'weight' ];
break;
case 2:
$tag = $template_data[ 'volume' ];
break;
case 3:
$tag = $template_data[ 'num' ];
break;
}
//开始计算
if ($tag <= $v_item[ 'snum' ]) {
$price += $v_item[ 'sprice' ];
} else {
$ext_tag = $tag - $v_item[ 'snum' ];
if ($v_item[ 'xnum' ] == 0) {
$v_item[ 'xnum' ] = 1;
}
if (( $ext_tag * 100 ) % ( $v_item[ 'xnum' ] * 100 ) == 0) {
$ext_data = $ext_tag / $v_item[ 'xnum' ];
} else {
$ext_data = floor($ext_tag / $v_item[ 'xnum' ]) + 1;
}
$price += $v_item[ 'sprice' ] + $ext_data * $v_item[ 'xprice' ];
}
break;
}
}
if ($is_exist_template == false) {
return $this->error('', 'TEMPLATE_AREA_EXIST');
}
return $this->success([ 'delivery_fee' => $price ]);
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
/**
* 物流公司
*/
class ExpressCompany extends BaseModel
{
/**
* 添加店铺物流公司
* @param $data
* @return array
*/
public function addExpressCompany($data)
{
$data[ 'create_time' ] = time();
$data[ 'modify_time' ] = time();
$company_template = new ExpressCompanyTemplate();
$company_info = $company_template->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ]);
$data[ 'company_name' ] = $company_info[ 'data' ][ 'company_name' ];
$data[ 'logo' ] = $company_info[ 'data' ][ 'logo' ];
$data[ 'express_no' ] = $company_info[ 'data' ][ 'express_no' ];
$brand_id = model('express_company')->add($data);
return $this->success($brand_id);
}
/**
* 修改店铺物流公司
* @param $data
* @param $condition
* @return array
*/
public function editExpressCompany($data, $condition)
{
$data[ 'modify_time' ] = time();
$res = model('express_company')->update($data, $condition);
return $this->success($res);
}
/**
* 删除店铺物流公司
* @param $condition
* @return array
*/
public function deleteExpressCompany($condition)
{
$res = model('express_company')->delete($condition);
return $this->success($res);
}
/**
* 获取店铺物流公司信息
* @param $condition
* @param string $field
* @return array
*/
public function getExpressCompanyInfo($condition, $field = 'id, site_id, company_id, express_no, content_json, background_image, font_size, width, height, create_time, modify_time, scale')
{
$res = model('express_company')->getInfo($condition, $field);
if (!empty($res)) {
if (empty($res[ 'content_json' ])) {
$res[ 'content_json' ] = json_encode($this->getPrintItemList());
}
}
return $this->success($res);
}
/**
* 获取店铺物流公司列表
* @param array $condition
* @param string $field
* @param string $order
* @param string $alias
* @param array $join
* @param string $group
* @param null $limit
* @return array
*/
public function getExpressCompanyList($condition = [], $field = 'id, site_id, company_id, express_no, content_json, background_image, font_size, width, height, create_time, modify_time, scale, company_name', $order = '', $alias = '', $join = [], $group = '', $limit = null)
{
$list = model('express_company')->getList($condition, $field, $order, $alias, $join, $group, $limit);
return $this->success($list);
}
/**
* 获取店铺物流公司分页列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return array
*/
public function getExpressCompanyPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = 'id, site_id, company_id,express_no, content_json, background_image, font_size, width, height, create_time, modify_time, scale')
{
$list = model('express_company')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/**
* 获取打印项
* @return array
*/
public function getPrintItemList()
{
$data = [
[
'item_name' => 'order_no',
'item_title' => '订单编号',
],
[
'item_name' => 'sender_company',
'item_title' => '发件人公司',
],
[
'item_name' => 'sender_name',
'item_title' => '发件人姓名',
],
[
'item_name' => 'sender_address',
'item_title' => '发件人地址',
],
[
'item_name' => 'sender_phone',
'item_title' => '发件人电话',
],
[
'item_name' => 'sender_post_code',
'item_title' => '发件人邮编',
],
[
'item_name' => 'receiver_name',
'item_title' => '收件人姓名',
],
[
'item_name' => 'receiver_address',
'item_title' => '收件人地址',
],
[
'item_name' => 'receiver_phone',
'item_title' => '收件人电话',
],
[
'item_name' => 'receiver_post_code',
'item_title' => '收件人邮编',
],
[
'item_name' => 'logistics_number',
'item_title' => '货到付款物流编号',
],
[
'item_name' => 'collection_payment',
'item_title' => '代收金额',
],
[
'item_name' => 'remark',
'item_title' => '备注',
],
];
return $data;
}
}

View File

@@ -0,0 +1,264 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
/**
* 系统物流公司
*/
class ExpressCompanyTemplate extends BaseModel
{
/***************************************************************** 系统物流公司start **********************************************************************/
/**
* 添加系统物流公司
* @param unknown $data
*/
public function addExpressCompanyTemplate($data)
{
$id = model('express_company_template')->add($data);
return $this->success($id);
}
/**
* 添加多个系统物流公司
* @param unknown $data
*/
public function addExpressCompanyTemplateList($data)
{
$id = model('express_company_template')->addList($data);
return $this->success($id);
}
/**
* 修改系统物流公司
* @param $data
* @return array
*/
public function editExpressCompanyTemplate($data)
{
$res = model('express_company_template')->update($data, [ [ 'company_id', '=', $data[ 'company_id' ] ], [ 'site_id', '=', $data[ 'site_id' ] ] ]);
return $this->success($res);
}
/**
* 删除系统物流公司
* @param array $condition
*/
public function deleteExpressCompanyTemplate($condition)
{
$res = model('express_company_template')->delete($condition);
return $this->success($res);
}
/**
* 获取物流公司信息
* @param array $condition
* @param string $field
*/
public function getExpressCompanyTemplateInfo($condition, $field = '*')
{
$res = model('express_company_template')->getInfo($condition, $field);
if (!empty($res)) {
if (empty($res[ 'content_json' ])) {
$res[ 'content_json' ] = json_encode($this->getPrintItemList());
}
}
return $this->success($res);
}
/**
* 获取物流公司列表
* @param array $condition
* @param string $field
* @param string $order
* @param string $limit
*/
public function getExpressCompanyTemplateList($condition = [], $field = '*', $order = '', $limit = null)
{
$list = model('express_company_template')->getList($condition, $field, $order, '', '', '', $limit);
return $this->success($list);
}
/**
* 获取物流公司分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getExpressCompanyTemplatePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
{
$list = model('express_company_template')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/**
* 修改物流公司排序
* @param $sort
* @param $company_id
* @return array|\multitype
*/
public function modifyExpressCompanyTemplateSort($sort, $company_id)
{
$res = model('express_company_template')->update([ 'sort' => $sort ], [ [ 'company_id', '=', $company_id ] ]);
return $this->success($res);
}
/***************************************************************** 系统物流公司end **********************************************************************/
/***************************************************************** 店铺物流公司start **********************************************************************/
/**
* 添加店铺物流公司
* @param unknown $data
*/
public function addExpressCompanyTemplateShop($data)
{
$data[ 'create_time' ] = time();
$data[ 'modify_time' ] = time();
$company_info = $this->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ]);
$data[ 'company_name' ] = $company_info[ 'data' ][ 'company_name' ];
$brand_id = model('express_company_template_shop')->add($data);
return $this->success($brand_id);
}
/**
* 修改店铺物流公司
* @param unknown $data
* @return multitype:string
*/
public function editExpressCompanyTemplateShop($data, $condition)
{
$data[ 'modify_time' ] = time();
$res = model('express_company_template_shop')->update($data, $condition);
return $this->success($res);
}
/**
* 删除店铺物流公司
* @param unknown $condition
*/
public function deleteExpressCompanyTemplateShop($condition)
{
$res = model('express_company_template_shop')->delete($condition);
return $this->success($res);
}
/**
* 获取店铺物流公司信息
* @param unknown $condition
* @param string $field
*/
public function getExpressCompanyTemplateShopInfo($condition, $field = 'id, site_id, company_id, content_json, background_image, font_size, width, height, create_time, modify_time, scale')
{
$res = model('express_company_template_shop')->getInfo($condition, $field);
if (!empty($res)) {
if (empty($res[ 'content_json' ])) {
$res[ 'content_json' ] = json_encode($this->getPrintItemList());
}
}
return $this->success($res);
}
/**
* 获取店铺物流公司列表
* @param array $condition
* @param string $field
* @param string $order
* @param string $limit
*/
public function getExpressCompanyTemplateShopList($condition = [], $field = 'company_id as id, site_id, company_id, content_json, background_image, font_size, width, height, create_time, modify_time, scale, company_name', $order = '', $limit = null)
{
$list = model('express_company_template')->getList($condition, $field, $order, '', '', '', $limit);
return $this->success($list);
}
/**
* 获取店铺物流公司分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getExpressCompanyTemplateShopPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = 'id, site_id, company_id, content_json, background_image, font_size, width, height, create_time, modify_time, scale')
{
$list = model('express_company_template_shop')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/***************************************************************** 店铺物流公司end **********************************************************************/
/**
* 获取打印项
* @return array
*/
public function getPrintItemList()
{
$data = [
[
'item_name' => 'order_no',
'item_title' => '订单编号',
],
[
'item_name' => 'sender_company',
'item_title' => '发件人公司',
],
[
'item_name' => 'sender_name',
'item_title' => '发件人姓名',
],
[
'item_name' => 'sender_address',
'item_title' => '发件人地址',
],
[
'item_name' => 'sender_phone',
'item_title' => '发件人电话',
],
[
'item_name' => 'sender_post_code',
'item_title' => '发件人邮编',
],
[
'item_name' => 'receiver_name',
'item_title' => '收件人姓名',
],
[
'item_name' => 'receiver_address',
'item_title' => '收件人地址',
],
[
'item_name' => 'receiver_phone',
'item_title' => '收件人电话',
],
[
'item_name' => 'receiver_post_code',
'item_title' => '收件人邮编',
],
[
'item_name' => 'logistics_number',
'item_title' => '货到付款物流编号',
],
[
'item_name' => 'collection_payment',
'item_title' => '代收金额',
],
[
'item_name' => 'remark',
'item_title' => '备注',
],
];
return $data;
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
/**
* 配送员信息
*/
class ExpressDeliver extends BaseModel
{
/**
* 获取配送员分页列表
* @param $condition
* @param $field
* @param $order
* @param $page
* @param $page_size
* @return array
*/
public function getDeliverPageLists($condition, $field, $order, $page, $page_size)
{
$list = model('express_deliver')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/**
* 获取配送员列表
* @param $condition
* @param string $field
* @return array
*/
public function getDeliverLists($condition, $field = '*')
{
$list = model('express_deliver')->getList($condition, $field);
return $this->success($list);
}
/**
* 添加配送员
* @param $data
* @return array
*/
public function addDeliver($data)
{
if (empty($data[ 'deliver_name' ])) {
return $this->error('', '配送员姓名不能为空!');
}
if (empty($data[ 'deliver_mobile' ])) {
return $this->error('', '配送员手机号不能为空!');
}
$data[ 'create_time' ] = time();
$result = model('express_deliver')->add($data);
return $this->success($result);
}
/**
* 编辑配送员
* @param $data
* @param $deliver_id
* @return array
*/
public function editDeliver($data, $deliver_id)
{
if (empty($data[ 'deliver_name' ])) {
return $this->error('', '配送员姓名不能为空!');
}
if (empty($data[ 'deliver_mobile' ])) {
return $this->error('', '配送员手机号不能为空!');
}
$data[ 'modify_time' ] = time();
$condition = [
[ 'deliver_id', '=', $deliver_id ],
[ 'site_id', '=', $data[ 'site_id' ] ]
];
if (isset($data[ 'store_id' ])) {
$condition[] = [ 'store_id', '=', $data[ 'store_id' ] ];
}
$result = model('express_deliver')->update($data, $condition);
return $this->success($result);
}
/**
* 删除配送员
* @param $deliver_id
* @param $site_id
* @param int $store_id
* @return array
*/
public function deleteDeliver($deliver_id, $site_id, $store_id = 0)
{
$condition = [
[ 'deliver_id', 'in', $deliver_id ],
[ 'site_id', '=', $site_id ]
];
if ($store_id > 0) {
$condition[] = [ 'store_id', '=', $store_id ];
}
$result = model('express_deliver')->delete($condition);
return $this->success($result);
}
/**
* 配送员信息
* @param $deliver_id
* @param $site_id
* @param int $store_id
* @return array
*/
public function getDeliverInfo($deliver_id, $site_id, $store_id = 0)
{
$condition = [
[ 'deliver_id', '=', $deliver_id ],
[ 'site_id', '=', $site_id ]
];
if ($store_id > 0) {
$condition[] = [ 'store_id', '=', $store_id ];
}
$info = model('express_deliver')->getInfo($condition, 'deliver_name,deliver_mobile,create_time,modify_time,deliver_id');
return $this->success($info);
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
*/
namespace app\model\express;
use addon\electronicsheet\model\ExpressElectronicsheet;
use app\model\member\Member;
use app\model\BaseModel;
/**
* 物流配送
*/
class ExpressDelivery extends BaseModel
{
/**
* 物流配送
* @param $param
* @return array|int|string
*/
public function delivery($param)
{
$order_id = $param[ 'order_id' ] ?? 0; // 订单id
$order_goods_id_array = $param[ 'order_goods_id_array' ];
$goods_id_array = $param[ 'goods_id_array' ];
$delivery_type = $param[ 'delivery_type' ]; // 物流方式 1 物流配送 0 无需物流
$delivery_no = $param[ 'delivery_no' ] ?? ''; // 物流单号
$member_id = $param[ 'member_id' ];
$site_id = $param[ 'site_id' ];
$member_model = new Member();
$member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname');
$member_info = $member_info_result[ 'data' ];
if ($param[ 'type' ] == 'manual') {
$express_company_id = $param[ 'express_company_id' ] ?? 0;
$express_company_name = '';
if ($express_company_id > 0) {
$express_company_info = model('express_company')->getInfo([ [ 'company_id', '=', $express_company_id ] ], 'company_name');
$express_company_name = $express_company_info[ 'company_name' ];
}
$template_id = 0;
$template_name = '';
//查询物流单号是否已存在,如果存在就合并入已存在的数据(手动发货才会合并)
$condition = array (
[ 'site_id', '=', $site_id ],
[ 'delivery_no', '=', $delivery_no ],
[ 'order_id', '=', $order_id ],
[ 'delivery_type', '=', $delivery_type ],
[ 'express_company_id', '=', $express_company_id ],
[ 'member_id', '=', $member_id ]
);
$info = model('express_delivery_package')->getInfo($condition, '*');
if (!empty($info)) {
$temp_order_goods_id_arr = explode(',', $info[ 'order_goods_id_array' ]);
$temp_goods_id_arr = explode(',', $info[ 'goods_id_array' ]);
$order_goods_id_array = implode(',', array_unique(array_merge($temp_order_goods_id_arr, $order_goods_id_array)));
$goods_id_array = implode(',', array_merge($temp_goods_id_arr, $goods_id_array));
$data = array (
'order_goods_id_array' => $order_goods_id_array,
'goods_id_array' => $goods_id_array,
);
$result = model('express_delivery_package')->update($data, $condition);
return $this->success($result);
}
} else {
$delivery_type = 1;
//获取模板信息
$template_model = new ExpressElectronicsheet();
$template_info = $template_model->getExpressElectronicsheetInfo(
[
[ 'id', '=', $param[ 'template_id' ] ],
[ 'site_id', '=', $site_id ]
],
'template_name,company_id,company_name'
);
$template_id = $param[ 'template_id' ];
$template_name = $template_info[ 'data' ][ 'template_name' ];
$express_company_id = $template_info[ 'data' ][ 'company_id' ];
$express_company_name = $template_info[ 'data' ][ 'company_name' ];
}
if ($delivery_type > 0) {
$count = model('express_delivery_package')->getCount([ [ 'site_id', '=', $site_id ], [ 'order_id', '=', $order_id ], [ 'delivery_type', '=', $delivery_type ] ]);
$num = $count + 1;
$package_name = '包裹' . $num;
} else {
$package_name = '无需物流';
}
$express_company_info = model('express_company_template')->getInfo([ [ 'company_id', '=', $express_company_id ] ], 'logo');
$express_company_image = empty($express_company_info) ? '' : $express_company_info[ 'logo' ];
$data = array (
'order_id' => $order_id,
'order_goods_id_array' => implode(',', $order_goods_id_array),
'goods_id_array' => implode(',', $goods_id_array),
'delivery_no' => $delivery_no,
'site_id' => $site_id,
'member_id' => $member_id,
'member_name' => $member_info[ 'nickname' ] ?? '',
'delivery_type' => $delivery_type,
'express_company_id' => $express_company_id,
'express_company_name' => $express_company_name,
'package_name' => $package_name,
'delivery_time' => time(),
'express_company_image' => $express_company_image,
'type' => $param[ 'type' ],
'template_id' => $template_id,
'template_name' => $template_name
);
$result = model('express_delivery_package')->add($data);
return $result;
}
}

View File

@@ -0,0 +1,160 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
use app\model\order\OrderCommon;
/**
* 物流配送
*/
class ExpressPackage extends BaseModel
{
/**
* 修改物流单号和物流公司
* @param $data
* @return array
*/
public function editOrderExpressDeliveryPackage($data)
{
$order_common_model = new OrderCommon();
//订单状态
$order_status = model('order')->getValue([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'order_id', '=', $data[ 'order_id' ] ] ], 'order_status');
if (empty($order_status)) {
return $this->error('', '订单不存在');
}
if (!in_array($order_status, [ $order_common_model::ORDER_PAY, $order_common_model::ORDER_DELIVERY ])) {
return $this->error('', '订单已收货或已完成');
}
//包裹信息
$package_count = model('express_delivery_package')->getCount(
[
[ 'site_id', '=', $data[ 'site_id' ] ], [ 'order_id', '=', $data[ 'order_id' ] ], [ 'id', '=', $data[ 'package_id' ] ]
]
);
if ($package_count == 0) {
return $this->error('', '包裹信息不存在');
}
model('express_delivery_package')->startTrans();
try {
if ($data[ 'delivery_type' ] == 0) {
$data[ 'express_company_id' ] = 0;
$data[ 'delivery_no' ] = '';
$express_company_name = '';
$express_company_image = '';
} else {
if ($data[ 'express_company_id' ] == '') {
return $this->error('', '物流公司不能为空');
}
if ($data[ 'delivery_no' ] == '') {
return $this->error('', '物流单号不能为空');
}
//获取物流公司名称
$express_company_info = model('express_company_template')->getInfo([ [ 'company_id', '=', $data[ 'express_company_id' ] ] ], 'company_name,logo');
$express_company_name = $express_company_info[ 'company_name' ];
$express_company_image = $express_company_info[ 'logo' ];
}
$condition = [
[ 'site_id', '=', $data[ 'site_id' ] ], [ 'order_id', '=', $data[ 'order_id' ] ], [ 'id', '=', $data[ 'package_id' ] ]
];
model('express_delivery_package')->update(
[
'delivery_type' => $data[ 'delivery_type' ],
'express_company_id' => $data[ 'express_company_id' ],
'express_company_name' => $express_company_name,
'delivery_no' => $data[ 'delivery_no' ],
'express_company_image' => $express_company_image
], $condition
);
model('express_delivery_package')->commit();
return $this->success();
} catch (\Exception $e) {
model('express_delivery_package')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 获取物流包裹列表
* @param $condition
* @param string $field
* @return array
*/
public function getExpressDeliveryPackageList($condition, $field = '*')
{
$list = model('express_delivery_package')->getList($condition, $field);
return $this->success($list);
}
/**
* 获取包裹信息
* @param $condition
* @param string $mobile
* @return mixed
*/
public function package($condition, $mobile = '')
{
$list_result = $this->getExpressDeliveryPackageList($condition);
$list = $list_result[ 'data' ];
$trace_model = new Trace();
foreach ($list as $k => $v) {
$temp_array = explode(',', $v[ 'goods_id_array' ]);
if (!empty($temp_array)) {
foreach ($temp_array as $temp_k => $temp_v) {
$temp_str = str_replace('http://', 'http//', $temp_v);
$temp_str = str_replace('https://', 'https//', $temp_str);
$temp_item = explode(':', $temp_str);
$sku_image = str_replace('https//', 'https://', $temp_item[ '3' ]);
$sku_image = str_replace('http//', 'http://', $sku_image);
$list[ $k ][ 'goods_list' ][] = [ 'sku_name' => $temp_item[ '2' ], 'num' => $temp_item[ '1' ], 'sku_image' => $sku_image, 'sku_id' => $temp_item[ '0' ] ];
}
}
$trace_list = $trace_model->trace($v[ 'delivery_no' ], $v[ 'express_company_id' ], $v[ 'site_id' ], $mobile);
$list[ $k ][ 'trace' ] = $trace_list[ 'data' ];
}
return $list;
}
/**
* 获取订单分页列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return array
*/
public function getExpressDeliveryPackagePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
{
$order_list = model('order')->pageList($condition, $field, $order, $page, $page_size);
if (!empty($order_list[ 'list' ])) {
foreach ($order_list[ 'list' ] as $k => $v) {
$order_goods_list = model('order_goods')->getList([
'order_id' => $v[ 'order_id' ]
]);
foreach ($order_goods_list as $ck => $cv) {
$order_goods_list[ $ck ][ 'num' ] = numberFormat($order_goods_list[ $ck ][ 'num' ]);
}
$order_list[ 'list' ][ $k ][ 'order_goods' ] = $order_goods_list;
}
}
return $this->success($order_list);
}
}

View File

@@ -0,0 +1,222 @@
<?php
/**
*/
namespace app\model\express;
use think\facade\Cache;
use app\model\BaseModel;
/**
* 运费模板
*/
class ExpressTemplate extends BaseModel
{
/**
* 添加运费模板控制每个站点最多10条
* @param $data
* @param $items
* @param $shipping_items
* @return array
*/
public function addExpressTemplate($data, $items, $shipping_items)
{
$count = model('express_template')->getCount([ 'site_id' => $data[ 'site_id' ] ]);
if ($count >= 10) {
return $this->error('', 'TEMPLATE_TO_LONG');
}
if ($data[ 'is_default' ] == 1) {
model('express_template')->update([ 'is_default' => 0 ], [ 'site_id' => $data[ 'site_id' ] ]);
}
if (empty($data[ 'appoint_free_shipping' ])) {
$data[ 'shipping_surplus_area_ids' ] = '';
$shipping_items = [];
}
//模板基础信息
$data[ 'create_time' ] = time();
$template_id = model('express_template')->add($data);
//具体模板信息
foreach ($items as $k => $v) {
$data_item = $v;
$data_item[ 'template_id' ] = $template_id;
$data_item[ 'fee_type' ] = $data[ 'fee_type' ];
if ($data_item[ 'area_ids' ] && $data_item[ 'area_names' ]) {
model('express_template_item')->add($data_item);
}
}
foreach ($shipping_items as $k => $v) {
$data_item = $v;
$data_item[ 'template_id' ] = $template_id;
if ($data_item[ 'area_ids' ] && $data_item[ 'area_names' ]) {
model('express_template_free_shipping')->add($data_item);
}
}
return $this->success($template_id);
}
/**
* 修改系统运费模板
* @param $data
* @param $items
* @param $shipping_items
* @return array
*/
public function editExpressTemplate($data, $items, $shipping_items)
{
//设置默认
if ($data[ 'is_default' ] == 1) {
model('express_template')->update([ 'is_default' => 0 ], [ 'site_id' => $data[ 'site_id' ] ]);
}
$data[ 'modify_time' ] = time();
$res = model('express_template')->update($data, [ [ 'template_id', '=', $data[ 'template_id' ] ] ]);
if (empty($data[ 'appoint_free_shipping' ])) {
$data[ 'shipping_surplus_area_ids' ] = '';
$shipping_items = [];
}
//具体模板信息
model('express_template_item')->delete([ [ 'template_id', '=', $data[ 'template_id' ] ] ]);
foreach ($items as $k => $v) {
$data_item = $v;
$data_item[ 'template_id' ] = $data[ 'template_id' ];
$data_item[ 'fee_type' ] = $data[ 'fee_type' ];
if ($data_item[ 'area_ids' ] && $data_item[ 'area_names' ]) {
model('express_template_item')->add($data_item);
}
}
//具体模板信息
model('express_template_free_shipping')->delete([ [ 'template_id', '=', $data[ 'template_id' ] ] ]);
foreach ($shipping_items as $k => $v) {
$data_item = $v;
$data_item[ 'template_id' ] = $data[ 'template_id' ];
if ($data_item[ 'area_ids' ] && $data_item[ 'area_names' ]) {
model('express_template_free_shipping')->add($data_item);
}
}
return $this->success($res);
}
/**
* 删除系统运费模板
* @param int $template_id
*/
public function deleteExpressTemplate($template_id, $site_id)
{
$res = model('express_template')->delete([ [ 'template_id', 'in', $template_id ], [ 'site_id', '=', $site_id ] ]);
if ($res) {
model('express_template_item')->delete([ [ 'template_id', 'in', $template_id ] ]);
model('express_template_free_shipping')->delete([ [ 'template_id', 'in', $template_id ] ]);
}
return $this->success($res);
}
/**
* 设置默认运费模板
* @param int $template_id
*/
public function updateDefaultExpressTemplate($template_id, $is_default, $site_id)
{
if ($is_default == 1) {
model('express_template')->update([ 'is_default' => 0 ], [ 'site_id' => $site_id ]);
}
$res = model('express_template')->update([ 'is_default' => 1 ], [ 'template_id' => $template_id ]);
return $this->success($res);
}
/**
* 获取运费模板信息
* @param $template_id
* @param $site_id
* @return array
*/
public function getExpressTemplateInfo($template_id, $site_id)
{
$res = model('express_template')->getInfo([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $site_id ] ], 'template_id, site_id, template_name, fee_type, create_time, modify_time, is_default, surplus_area_ids, appoint_free_shipping, shipping_surplus_area_ids');
if ($res) {
$res[ 'template_item' ] = model('express_template_item')->getList([ [ 'template_id', '=', $template_id ] ], '*');
$res[ 'shipping_template_item' ] = model('express_template_free_shipping')->getList([ [ 'template_id', '=', $template_id ] ], '*');
}
return $this->success($res);
}
/**
* 获取默认运费模板
* @param $site_id
* @return array
*/
public function getDefaultTemplate($site_id)
{
$res = model('express_template')->getInfo([ [ 'is_default', '=', 1 ], [ 'site_id', '=', $site_id ] ], 'template_id, site_id, template_name, fee_type, create_time, modify_time, is_default');
if ($res) {
$res[ 'template_item' ] = model('express_template_item')->getList([ [ 'template_id', '=', $res[ 'template_id' ] ] ], '*');
$res[ 'shipping_template_item' ] = model('express_template_free_shipping')->getList([ [ 'template_id', '=', $res[ 'template_id' ] ] ], '*');
}
return $this->success($res);
}
/**
* 获取运费模板列表(主表查询)
* @param array $condition
* @param string $field
* @param string $order
* @param string $limit
*/
public function getExpressTemplateList($condition = [], $field = 'template_id, site_id, template_name, fee_type, create_time, modify_time, is_default', $order = '', $limit = null)
{
$list = model('express_template')->getList($condition, $field, $order, '', '', '', $limit);
return $this->success($list);
}
/**
* 获取运费模板列表(主表查询)
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return array
*/
public function getExpressTemplatePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = 'template_id, site_id, template_name, fee_type, create_time, modify_time, is_default')
{
$list = model('express_template')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/**
* 获取运费模板地域运费列表(主表查询)
* @param array $condition
* @param string $field
* @param string $order
* @param string $limit
*/
public function getExpressTemplateItemList($condition = [], $field = '*', $order = '', $limit = null)
{
$data = json_encode([ $condition, $field, $order, $limit ]);
$cache = Cache::get("express_template_getExpressTemplateItemList_" . $data);
if (!empty($cache)) {
return $this->success($cache);
}
$list = model('express_template_item')->getList($condition, $field, $order, '', '', '', $limit);
Cache::tag("express_template_")->set("express_template_getExpressTemplateItemList_" . $data, $list);
return $this->success($list);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
*/
namespace app\model\express;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
use extend\Kd100 as Kd100Extend;
/**
* 快递100
*/
class Kd100 extends BaseModel
{
/*********************************************************************** 快递100 start ***********************************************************************/
/**
* 快递100配置
* @param $site_id
* @return \multitype
*/
public function getKd100Config($site_id)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'app_module', '=', 'shop' ], [ 'site_id', '=', $site_id ], [ 'config_key', '=', 'EXPRESS_KD100_CONFIG' ] ]);
return $res;
}
/**
* 设置物流配送配置
* @param $data
* @param $is_use
* @param $site_id
* @return \multitype
*/
public function setKd100Config($data, $is_use, $site_id)
{
if ($is_use > 0) {
$this->modifyStatus(0, $site_id);
}
$config = new ConfigModel();
$res = $config->setConfig($data, '快递100设置', $is_use, [ [ 'app_module', '=', 'shop' ], [ 'site_id', '=', $site_id ], [ 'config_key', '=', 'EXPRESS_KD100_CONFIG' ] ]);
return $res;
}
/**
* 开关状态
* @param $is_use
* @param $site_id
* @return array
*/
public function modifyStatus($is_use, $site_id)
{
$config = new ConfigModel();
$res = $config->modifyConfigIsUse($is_use, [ [ 'app_module', '=', 'shop' ], [ 'site_id', '=', $site_id ], [ 'config_key', '=', 'EXPRESS_KD100_CONFIG' ] ]);
return $res;
}
/*********************************************************************** 快递100 end ***********************************************************************/
/**
* 查询物流轨迹 并且转化为兼容数据结构
* @param $code
* @param $express_no
* @param $phone
* @param $site_id
* @return array
*/
public function trace($code, $express_no, $phone, $site_id)
{
$config_result = $this->getKd100Config($site_id);
$config = $config_result[ 'data' ];
if ($config[ 'is_use' ] == 0)
return $this->error();
$kd100_extend = new Kd100Extend($config[ 'value' ]);
$result = $kd100_extend->getExpressTracesEnterpriseEdition($express_no, $code, $phone);
return $this->success($result);
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
*/
namespace app\model\express;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
use extend\Kdbird as KdbirdExtend;
/**
* 快递鸟
*/
class Kdbird extends BaseModel
{
/*********************************************************************** 快递100 start ***********************************************************************/
/**
* 快递鸟配置
* @param $site_id
* @return \multitype
*/
public function getKdbirdConfig($site_id)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'app_module', '=', 'shop' ], [ 'site_id', '=', $site_id ], [ 'config_key', '=', 'EXPRESS_KDBIRD_CONFIG' ] ]);
if (empty($res[ 'data' ][ 'value' ][ 'status' ])) {
$res[ 'data' ][ 'value' ][ 'status' ] = 0;
}
return $res;
}
/**
* 设置物流配送配置
* @param $data
* @param $is_use
* @param $site_id
* @return \multitype
*/
public function setKdbirdConfig($data, $is_use, $site_id)
{
if ($is_use > 0) {
$this->modifyStatus(0, $site_id);
}
$config = new ConfigModel();
$res = $config->setConfig($data, '快递鸟设置', $is_use, [ [ 'app_module', '=', 'shop' ], [ 'site_id', '=', $site_id ], [ 'config_key', '=', 'EXPRESS_KDBIRD_CONFIG' ] ]);
return $res;
}
/**
* 开关状态
* @param $is_use
* @param $site_id
* @return array
*/
public function modifyStatus($is_use, $site_id)
{
$config = new ConfigModel();
$res = $config->modifyConfigIsUse($is_use, [ [ 'app_module', '=', 'shop' ], [ 'site_id', '=', $site_id ], [ 'config_key', '=', 'EXPRESS_KDBIRD_CONFIG' ] ]);
return $res;
}
/*********************************************************************** 快递100 end ***********************************************************************/
/**
* 查询物流轨迹 并且转化为兼容数据结构
* @param $code
* @param $express_no
* @param $site_id
* @param $mobile
* @return array
*/
public function trace($code, $express_no, $site_id, $mobile)
{
$config_result = $this->getKdbirdConfig($site_id);
$config = $config_result[ 'data' ];
if ($config[ 'is_use' ] == 0) return $this->error();
$kd100_extend = new KdbirdExtend($config[ 'value' ]);
$result = $kd100_extend->orderTracesSubByJson($express_no, $code, $mobile);
if (isset($result[ 'success' ]) && $result[ 'success' ]) {
return $this->success($result);
} else {
return $this->error($result, $result[ 'reason' ]);
}
}
}

View File

@@ -0,0 +1,673 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
use app\model\shop\Shop;
use app\model\store\Store;
/**
* 外卖配送
*/
class Local extends BaseModel
{
/**
* 添加站点外卖配送配置
* @param $data
* @return array
*/
public function addLocal($data)
{
$id = model('local')->add($data);
return $this->success($id);
}
/**
* 修改站点外卖配送配置
* @param $data
* @param $condition
* @return array
*/
public function editLocal($data, $condition)
{
$res = model('local')->update($data, $condition);
return $this->success($res);
}
/**
* 删除站点外卖配送 (通常删除站点会用到)
* @param $condition
* @return array
*/
public function deleteLocal($condition)
{
$res = model('local')->delete($condition);
return $this->success($res);
}
/**
* 获取站点外卖配送信息
* @param $condition
* @param string $field
* @return array
*/
public function getLocalInfo($condition, $field = '*')
{
$check_condition = array_column($condition, 2, 0);
$site_id = $check_condition['site_id'] ?? '';
$store_id = $check_condition['store_id'] ?? 0;
$info = model('local')->getInfo($condition, $field);
if (empty($info)) {
$local_data = array (
'site_id' => $site_id,
'store_id' => $store_id,
'update_time' => time()
);
$this->addLocal($local_data);
$info = model('local')->getInfo($condition, $field);
}
if (!empty($info)) {
$local_area_array = [];
if (!empty($info[ 'local_area_json' ])) {
$local_area_array = json_decode($info[ 'local_area_json' ], true);
}
$info[ 'local_area_array' ] = $local_area_array;
$time_week = [];
if (!empty($info[ 'time_week' ])) {
$time_week = explode(',', $info[ 'time_week' ]);
}
$info[ 'time_week' ] = $time_week;
$area_array = [];
if (!empty($info[ 'area_array' ])) {
$area_array = explode(',', $info[ 'area_array' ]);
}
$info[ 'area_array' ] = $area_array;
if (empty($info[ 'delivery_time' ])) {
$info[ 'delivery_time' ] = [
[ 'start_time' => $info[ 'start_time' ], 'end_time' => $info[ 'end_time' ] ]
];
} else {
$info[ 'delivery_time' ] = json_decode($info[ 'delivery_time' ], true);
}
}
return $this->success($info);
}
/**
* 获取站点外卖配送列表
* @param array $condition
* @param string $field
* @param string $order
* @param null $limit
* @return array
*/
public function getLocalList($condition = [], $field = '*', $order = '', $limit = null)
{
$list = model('local')->getList($condition, $field, $order, '', '', '', $limit);
return $this->success($list);
}
/**
* 获取站点外卖配送分页列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return array
*/
public function getLocalPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
{
$list = model('local')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/**
* 计算费用
* @param $shop_goods
* @param $data
* @return array
*/
public function calculate($params)
{
/** @var \app\model\order\OrderCreate $order_object */
$order_object = $params['order_object'];
$site_id = $order_object->site_id;
$local_condition = array (
[ 'site_id', '=', $site_id ]
);
$store_id = $order_object->store_id ?? 0;
//todo 应该判断一下是否有门店运营插件
if (!addon_is_exit('store')) {
$store_id = 0;
}
if ($store_id > 0) $local_condition[] = [ 'store_id', '=', $store_id ];
$local_info = $this->getLocalInfo($local_condition)[ 'data' ];
if (empty($local_info)) return $this->error('', '没有可以配送的门店');
$start_price_error = 0;//起送价错误
$distance_error = 0;//配送距离错误
$time_error = 0;
$error_code = 12;
if (empty($order_object->delivery[ 'member_address' ])) {
return $this->error([ 'code' => $error_code ], '请选择同城配送地址');
}
$error = '所选地址无法配送';
//判断时间 是否在时间段内
if ($local_info[ 'time_is_open' ] == 1) {
if($local_info[ 'time_type' ] == 1){
$week = date('w');
if (in_array($week, $local_info[ 'time_week' ])) {
}else {
$time_error++;
$error = '配送时间不在营业时间内';
}
}
$time = $order_object->delivery['buyer_ask_delivery_time'];
if ($time == 0) {
$time_error++;
$error = '请选择配送时间';
}
}
if ($store_id == 0) {
$shop_model = new Shop();
$shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ] ?? [];
} else {
$store_model = new Store();
$shop_info = $store_model->getStoreInfo([ [ 'site_id', '=', $site_id ], [ 'store_id', '=', $store_id ] ])[ 'data' ] ?? [];
}
$is_delivery = false;
$start_money_array = [];
if ($local_info[ 'area_type' ] == 1 || $local_info[ 'area_type' ] == 2) {
if ($order_object->delivery[ 'member_address' ][ 'longitude' ] == 0 && $order_object->delivery[ 'member_address' ][ 'latitude' ] == 0) {
return $this->error([ 'code' => $error_code ], '当前配送地址没有配置定位坐标');
}
$shop_longitude = $shop_info[ 'longitude' ];
$shop_latitude = $shop_info[ 'latitude' ];
$longitude = $order_object->delivery[ 'member_address' ][ 'longitude' ];
$latitude = $order_object->delivery[ 'member_address' ][ 'latitude' ];
if ($local_info[ 'area_type' ] == 1) {
$distance = $this->getDistance($latitude, $longitude, $shop_latitude, $shop_longitude);
if ($distance <= $local_info[ 'start_distance' ]) {//是否在起送距离以内
$delivery_money = $local_info[ 'start_delivery_money' ];
} else {
$diff_distance = $distance - $local_info[ 'start_distance' ];//减去起送距离 求得差
if ($local_info[ 'continued_distance' ] == 0) return $this->error([ 'code' => $error_code ], '当前配送地址不支持配送');
$delivery_money = $local_info[ 'start_delivery_money' ] + ceil($diff_distance / $local_info[ 'continued_distance' ]) * $local_info[ 'continued_delivery_money' ];
}
} else {
$delivery_money_array = [];
}
$local_area_array = $local_info[ 'local_area_array' ];
if (!empty($local_area_array)) {
foreach ($local_area_array as $k => $v) {
//起送价是否满足
if ($order_object->goods_money >= $v[ 'start_price' ]) {
$path = $v[ 'path' ];
if ($v[ 'rule_type' ] == 'circle') {//半径
$item_longitude = $path[ 'center' ][ 'longitude' ];
$item_latitude = $path[ 'center' ][ 'latitude' ];
$radius = $path[ 'radius' ];
$item_distance = $this->getDistance($latitude, $longitude, $item_latitude, $item_longitude);
//判断有无超出范围
if ($item_distance <= $radius / 1000) {
$is_delivery = true;
if ($local_info[ 'area_type' ] == 2) {
//非半径 配送费是取设置的
$delivery_money_array[] = $v[ 'delivery_money' ];
}
} else {
$distance_error++;
}
} else if ($v[ 'rule_type' ] == 'polygon') {//多边形
$point = array (
'latitude' => $latitude,
'longitude' => $longitude,
);
//判断坐标是否在多边形内
if (is_point_in_polygon($point, $path)) {
$is_delivery = true;
if ($local_info[ 'area_type' ] == 2) {
//非半径 配送费是取设置的
$delivery_money_array[] = $v[ 'delivery_money' ];
}
} else {
$distance_error++;
}
}
} else {
$start_money_array[] = $v[ 'start_price' ];
$start_price_error++;
}
}
//区域配送 存在相交的区域,以配送费低的区域价格来计算
if ($local_info[ 'area_type' ] == 2) {
if (!empty($delivery_money_array)) {
$delivery_money = min($delivery_money_array);
}
}
}
} else {
//行政区域配送
if ($order_object->goods_money >= $local_info[ 'start_money' ]) {
$district_id = $order_object->delivery[ 'member_address' ][ 'district_id' ];//区县地域id
$area_array = $local_info[ 'area_array' ];
if (in_array($district_id, $area_array)) {
//启用阶梯价 的话 也是必须要具体坐标的
if ($local_info[ 'is_open_step' ] == 1) {
if ($order_object->delivery[ 'member_address' ][ 'longitude' ] == 0 && $order_object->delivery[ 'member_address' ][ 'latitude' ] == 0) {
return $this->error([ 'code' => $error_code ], '当前配送地址没有配置定位坐标');
}
$is_delivery = true;
$shop_longitude = $shop_info[ 'longitude' ];
$shop_latitude = $shop_info[ 'latitude' ];
$longitude = $order_object->delivery[ 'member_address' ][ 'longitude' ];
$latitude = $order_object->delivery[ 'member_address' ][ 'latitude' ];
$distance = $this->getDistance($latitude, $longitude, $shop_latitude, $shop_longitude);
if ($distance <= $local_info[ 'start_distance' ]) {//是否在起送距离以内
$delivery_money = $local_info[ 'start_delivery_money' ];
} else {
$diff_distance = $distance - $local_info[ 'start_distance' ];//减去起送距离 求得差
$delivery_money = $local_info[ 'start_delivery_money' ] + ceil($diff_distance / $local_info[ 'continued_distance' ]) * $local_info[ 'continued_delivery_money' ];
}
} else {
$is_delivery = true;
$delivery_money = $local_info[ 'delivery_money' ];
}
} else {
$distance_error++;//配送距离错误
}
} else {
$start_price_error++;//起送价错误
$start_money_array[] = $local_info[ 'start_money' ];
}
}
if ($is_delivery) {
if ($delivery_money > 0) {
$man_type = $local_info[ 'man_type' ];
$man_money = $local_info[ 'man_money' ];
switch ( $man_type ) {
case 'free':
if ($order_object->goods_money >= $man_money) {
$delivery_money = 0;
}
break;
case 'discount':
if ($order_object->goods_money >= $man_money) {
$man_discount = $local_info[ 'man_discount' ];
$delivery_money -= $man_discount;
$delivery_money = max($delivery_money, 0);
}
break;
}
}
$return_result = array (
'delivery_money' => $delivery_money,
);
if ($time_error > 0) {
$return_result[ 'code' ] = 1;
$return_result[ 'error' ] = $error;
}
return $this->success($return_result);
} else {
if ($distance_error > 0) {
$error = '当前地址不在该门店配送区域,请重新选择可配送该区域的门店';
$error_code = 10;
} else if ($start_price_error > 0 && !isset($order_object->delivery[ 'unlimited_start_money' ])) {//todo 这儿要定义不限制起送价
$error = '当前商品金额尚不满足商家配送的最低起送价格';
$error_code = 11;
}
return $this->error([ 'code' => $error_code, 'start_money_array' => $start_money_array ], $error);
}
}
/**
* 区域是否支持配送
* @param $data
* @return array
*/
public function isSupportDelivery($data)
{
$local_condition = array (
[ 'site_id', '=', $data[ 'site_id' ] ],
);
if (!empty($data[ 'store_id' ])) $local_condition[] = [ 'store_id', '=', $data[ 'store_id' ] ];
$local_info = $this->getLocalInfo($local_condition)[ 'data' ];
$distance_error = 0;//配送距离错误
$error_code = 12;
$is_delivery = false;
if ($local_info[ 'area_type' ] == 1 || $local_info[ 'area_type' ] == 2) {
if ($data[ 'longitude' ] == 0 && $data[ 'latitude' ] == 0) {
return $this->error([ 'code' => $error_code ], '超出配送范围');
}
$longitude = $data[ 'longitude' ];
$latitude = $data[ 'latitude' ];
$local_area_array = $local_info[ 'local_area_array' ];
if (!empty($local_area_array)) {
foreach ($local_area_array as $k => $v) {
$path = $v[ 'path' ];
if ($v[ 'rule_type' ] == 'circle') {//半径
$item_longitude = $path[ 'center' ][ 'longitude' ];
$item_latitude = $path[ 'center' ][ 'latitude' ];
$radius = $path[ 'radius' ];
$item_distance = $this->getDistance($latitude, $longitude, $item_latitude, $item_longitude);
//判断有无超出范围
if ($item_distance <= $radius / 1000) {
$is_delivery = true;
} else {
$distance_error++;
}
} else if ($v[ 'rule_type' ] == 'polygon') {//多边形
$point = array (
'latitude' => $latitude,
'longitude' => $longitude,
);
//判断坐标是否在多边形内
if (is_point_in_polygon($point, $path)) {
$is_delivery = true;
} else {
$distance_error++;
}
}
}
}
} else {
//行政区域配送
$district_id = $data[ 'district_id' ];//区县地域id
$area_array = $local_info[ 'area_array' ];
if (in_array($district_id, $area_array)) {
//启用阶梯价 的话 也是必须要具体坐标的
if ($local_info[ 'is_open_step' ] == 1) {
if ($data[ 'longitude' ] == 0 && $data[ 'latitude' ] == 0) {
return $this->error([ 'code' => $error_code ], '超出配送范围');
}
$is_delivery = true;
} else {
$is_delivery = true;
}
} else {
$distance_error++;//配送距离错误
}
}
if (!$is_delivery && $distance_error) {
$error = '超出配送范围';
return $this->error([ 'code' => $error_code ], $error);
}
return $this->success(1);
}
/**
* 判断可用的区域
* @param $type
* @param $latlng
* @param $range
*/
public function getWithAreaList($type, $latlng, $range)
{
}
/**
* 求两个已知经纬度之间的距离,单位为km
* @param lng1,lng2 经度
* @param lat1,lat2 纬度
* @return float 距离单位为km
**/
public function getDistance($lat1, $lng1, $lat2, $lng2)
{
//将角度转为狐度
$radLat1 = deg2rad($lat1);//deg2rad()函数将角度转换为弧度
$radLat2 = deg2rad($lat2);
$radLng1 = deg2rad($lng1);
$radLng2 = deg2rad($lng2);
$a = $radLat1 - $radLat2;
$b = $radLng1 - $radLng2;
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6371;
return round($s, 1);
}
/**
* 积分兑换计算费用
* @param $goods_info
* @param $data
* @return array
*/
public function pointExchangeCalculate($goods_info, $data)
{
$local_condition = array (
[ 'site_id', '=', $data[ 'site_id' ] ]
);
if (isset($data[ 'delivery' ][ 'store_id' ])) $local_condition[] = [ 'store_id', '=', $data[ 'delivery' ][ 'store_id' ] ];
$local_info = $this->getLocalInfo($local_condition)[ 'data' ];
if (empty($local_info)) return $this->error('', '没有可以配送的门店');
$start_price_error = 0;//起送价错误
$distance_error = 0;//配送距离错误
$time_error = 0;
$error_code = 12;
$error = '';
//判断时间 是否在时间段内
if ($local_info[ 'time_is_open' ] == 1) {
$week = date('w');
if (in_array($week, $local_info[ 'time_week' ])) {
$time = $goods_info[ 'buyer_ask_delivery_time' ];
if ($time == 0) {
$time_error++;
$error = '请选择配送时间';
}
}else {
$time_error++;
$error = '配送时间不在营业时间内';
}
}
$shop_model = new Shop();
$shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $data[ 'site_id' ] ] ])[ 'data' ];
$is_delivery = false;
$start_money_array = [];
if ($local_info[ 'area_type' ] == 1 || $local_info[ 'area_type' ] == 2) {
if (empty($data[ 'member_address' ])) {
return $this->error([ 'code' => $error_code ], '请设置配送地址');
}
if ($data[ 'member_address' ][ 'longitude' ] == 0 && $data[ 'member_address' ][ 'latitude' ] == 0) {
return $this->error([ 'code' => $error_code ], '当前配送地址没有配置定位坐标');
}
$shop_longitude = $shop_info[ 'longitude' ];
$shop_latitude = $shop_info[ 'latitude' ];
$longitude = $data[ 'member_address' ][ 'longitude' ];
$latitude = $data[ 'member_address' ][ 'latitude' ];
if ($local_info[ 'area_type' ] == 1) {
$distance = $this->getDistance($latitude, $longitude, $shop_latitude, $shop_longitude);
if ($distance <= $local_info[ 'start_distance' ]) {//是否在起送距离以内
$delivery_money = $local_info[ 'start_delivery_money' ];
} else {
$diff_distance = $distance - $local_info[ 'start_distance' ];//减去起送距离 求得差
$delivery_money = $local_info[ 'start_delivery_money' ] + ceil($diff_distance / $local_info[ 'continued_distance' ]) * $local_info[ 'continued_delivery_money' ];
}
} else {
$delivery_money_array = [];
}
$local_area_array = $local_info[ 'local_area_array' ];
if (!empty($local_area_array)) {
foreach ($local_area_array as $k => $v) {
//起送价是否满足
if ($data[ 'exchange_info' ][ 'price' ] >= $v[ 'start_price' ]) {
$path = $v[ 'path' ];
if ($v[ 'rule_type' ] == 'circle') {//半径
$item_longitude = $path[ 'center' ][ 'longitude' ];
$item_latitude = $path[ 'center' ][ 'latitude' ];
$radius = $path[ 'radius' ];
$item_distance = $this->getDistance($latitude, $longitude, $item_latitude, $item_longitude);
//判断有无超出范围
if ($item_distance <= $radius / 1000) {
$is_delivery = true;
if ($local_info[ 'area_type' ] == 2) {
// //非半径 配送费是取设置的
$delivery_money_array[] = $v[ 'delivery_money' ];
}
} else {
$distance_error++;
}
} else if ($v[ 'rule_type' ] == 'polygon') {//多边形
$point = array (
'latitude' => $latitude,
'longitude' => $longitude,
);
//判断坐标是否在多边形内
if (is_point_in_polygon($point, $path)) {
$is_delivery = true;
if ($local_info[ 'area_type' ] == 2) {
//非半径 配送费是取设置的
$delivery_money_array[] = $v[ 'delivery_money' ];
}
} else {
$distance_error++;
}
}
} else {
$start_money_array[] = $v[ 'start_price' ];
$start_price_error++;
}
}
//区域配送 存在相交的区域,以配送费低的区域价格来计算
if ($local_info[ 'area_type' ] == 2) {
if (!empty($delivery_money_array)) {
$delivery_money = min($delivery_money_array);
}
}
}
} else {
//行政区域配送
if ($data[ 'exchange_info' ][ 'price' ] >= $local_info[ 'start_money' ]) {
$district_id = $data[ 'member_address' ][ 'district_id' ];//区县地域id
$area_array = $local_info[ 'area_array' ];
if (in_array($district_id, $area_array)) {
//启用阶梯价 的话 也是必须要具体坐标的
if ($local_info[ 'is_open_step' ] == 1) {
if ($data[ 'member_address' ][ 'longitude' ] == 0 && $data[ 'member_address' ][ 'latitude' ] == 0) {
return $this->error([ 'code' => $error_code ], '当前配送地址没有配置定位坐标');
}
$is_delivery = true;
$shop_longitude = $shop_info[ 'longitude' ];
$shop_latitude = $shop_info[ 'latitude' ];
$longitude = $data[ 'member_address' ][ 'longitude' ];
$latitude = $data[ 'member_address' ][ 'latitude' ];
$distance = $this->getDistance($latitude, $longitude, $shop_latitude, $shop_longitude);
if ($distance <= $local_info[ 'start_distance' ]) {//是否在起送距离以内
$delivery_money = $local_info[ 'start_delivery_money' ];
} else {
$diff_distance = $distance - $local_info[ 'start_distance' ];//减去起送距离 求得差
$delivery_money = $local_info[ 'start_delivery_money' ] + ceil($diff_distance / $local_info[ 'continued_distance' ]) * $local_info[ 'continued_delivery_money' ];
}
} else {
$is_delivery = true;
$delivery_money = $local_info[ 'delivery_money' ];
}
} else {
$distance_error++;//配送距离错误
}
} else {
$start_price_error++;//起送价错误
$start_money_array[] = $local_info[ 'start_money' ];
}
}
if ($is_delivery) {
$return_result = array (
'delivery_money' => $delivery_money,
'start_money_array' => $start_money_array,
);
if ($time_error > 0) {
$return_result[ 'code' ] = 1;
$return_result[ 'error' ] = $error;
}
return $this->success($return_result);
} else {
if ($distance_error > 0) {
$error = '当前地址不在该门店配送区域,请重新选择可配送该区域的门店';
$error_code = 10;
} else if ($start_price_error > 0) {
$error = '当前商品金额尚不满足商家配送的最低起送价格';
$error_code = 11;
}
return $this->error([ 'code' => $error_code ], $error);
}
}
/**
* 核验是否可以开启本地配送
* @param $site_id
* @return array
*/
public function checkIsCanTradeLocal($site_id)
{
$store = new Store();
$default_store = $store->getStoreInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'store_id')[ 'data' ] ?? [];
$store_id = $default_store[ 'store_id' ] ?? 0;
$local_info = $this->getLocalInfo([ [ 'site_id', '=', $site_id ], [ 'store_id', '=', $store_id ] ])[ 'data' ] ?? [];
if (empty($local_info))
return $this->error([], '您未完成起送金额、配送费 、配送区域等同城送配置项设置,需设置并提交保存后,才能开启同城配送开关。');
//判断配置有没有配置完善
$local_area_array = $local_info[ 'local_area_array' ];
$area_array = $local_info[ 'area_array' ];
if (empty($local_area_array) && empty($area_array))
return $this->error([], '您未完成起送金额、配送费 、配送区域等同城送配置项设置,需设置并提交保存后,才能开启同城配送开关。');
return $this->success();
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
use app\model\member\Member;
/**
* 外卖配送
*/
class LocalPackage extends BaseModel
{
/**
* 获取外卖配送包裹列表
* @param $condition
* @param string $field
* @return array
*/
public function getLocalDeliveryPackageList($condition, $field = '*')
{
$list = model('local_delivery_package')->getList($condition, $field);
return $this->success($list);
}
/**
* 获取包裹信息
* @param $condition
* @return array
*/
public function package($condition)
{
$info = model('local_delivery_package')->getInfo($condition, '*');
return $this->success($info);
}
/**
* 外卖配送
*/
public function delivery($param)
{
$order_id = $param[ 'order_id' ] ?? 0;//订单id
$order_goods_id_array = $param[ 'order_goods_id_array' ];
$goods_id_array = $param[ 'goods_id_array' ];
$delivery_type = $param[ 'delivery_type' ];//物流方式 1 物流配送 0 无需物流
$delivery_no = $param[ 'delivery_no' ] ?? '';//物流单号
$member_id = $param[ 'member_id' ];
$site_id = $param[ 'site_id' ];
$member_model = new Member();
$member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname');
$member_info = $member_info_result[ 'data' ] ?? [];
//查询物流单号是否已存在,如果存在就合并入已存在的数据
$condition = array (
[ 'site_id', '=', $site_id ],
[ 'delivery_no', '=', $delivery_no ],
[ 'order_id', '=', $order_id ],
[ 'delivery_type', '=', $delivery_type ],
[ 'member_id', '=', $member_id ]
);
$info = model('local_delivery_package')->getInfo($condition, '*');
if (empty($info)) {
if ($delivery_type > 0) {
$count = model('local_delivery_package')->getCount([ [ 'site_id', '=', $site_id ], [ 'order_id', '=', $order_id ], [ 'delivery_type', '=', $delivery_type ] ]);
$num = $count + 1;
$package_name = '包裹' . $num;
} else {
$package_name = '商家自配送';
}
$data = array (
'order_id' => $order_id,
'order_goods_id_array' => implode(',', $order_goods_id_array),
'goods_id_array' => implode(',', $goods_id_array),
'delivery_no' => $delivery_no,
'site_id' => $site_id,
'member_id' => $member_id,
'member_name' => $member_info[ 'nickname' ] ?? '',
'delivery_type' => $delivery_type,
'package_name' => $package_name,
'delivery_time' => time(),
'deliverer' => $param[ 'deliverer' ] ?? '',
'deliverer_mobile' => $param[ 'deliverer_mobile' ] ?? '',
);
$result = model('local_delivery_package')->add($data);
} else {
$temp_order_goods_id_arr = explode(',', $info[ 'order_goods_id_array' ]);
$temp_goods_id_arr = explode(',', $info[ 'goods_id_array' ]);
$order_goods_id_array = implode(',', array_unique(array_merge($temp_order_goods_id_arr, $order_goods_id_array)));
$goods_id_array = implode(',', array_merge($temp_goods_id_arr, $goods_id_array));
$data = array (
'order_goods_id_array' => $order_goods_id_array,
'goods_id_array' => $goods_id_array,
);
$result = model('local_delivery_package')->update($data, $condition);
}
return $this->success($result);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
*/
namespace app\model\express;
use app\model\BaseModel;
/**
* 物流配送
*/
class Trace extends BaseModel
{
/**
* 物流跟踪信息
* @param $code
* @param $company_id
* @param $site_id
* @param $mobile
* @return array|mixed|void
*/
public function trace($code, $company_id, $site_id, $mobile)
{
// $result = array(
// 'success' => true,//成功与否
// 'reason' => '',//错误原因
// 'status' => '1',//物流状态:0-无轨迹,1-已揽收, 2-在途中 201-到达派件城市3-签收,4-问题件
// 'status_name' => '已揽收',//物流状态名称:0-无轨迹,1-已揽收, 2-在途中 201-到达派件城市3-签收,4-问题件,
// 'shipper_code' => 'SH',//快递公司编码
// 'logistic_code' => $code,//物流运单号
// 'list' => array(
// [
// 'datetime' => '2015-03-08 01:15:00',
// 'remark' => '离开广州市 发往北京市(经转)',
// ]
// )
// );
$express_company_model = new ExpressCompanyTemplate();
$company_info_result = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $company_id ] ]);
if (empty($company_info_result[ 'data' ]))
return $this->success([ 'success' => false, 'reason' => '物流公司信息不完整!' ]);
$company_info_result[ 'data' ][ 'site_id' ] = $site_id;
$result = $this->getTrace([ 'code' => $code, 'express_no_data' => $company_info_result[ 'data' ], 'mobile' => $mobile ]);
if (empty($result)) {
$data = [ 'success' => false, 'reason' => '抱歉,没有启用的物流方式' ];
return $this->success($data);
}
if ($result[ 'code' ] < 0 || empty($result[ 'data' ])) {
$data = [ 'success' => false, 'reason' => '抱歉,暂无物流记录' ];
return $this->success($data);
}
return $result;
}
public function getTrace($data)
{
$express_no_data = $data[ "express_no_data" ];
$kd100_model = new Kd100();
$kd100_config = $kd100_model->getKd100Config($express_no_data[ "site_id" ]);
if ($kd100_config[ "data" ][ "is_use" ]) {
$express_no = $express_no_data[ "express_no_kd100" ];
return $kd100_model->trace($data[ "code" ], $express_no, $data[ 'mobile' ], $express_no_data[ "site_id" ]);
}
$kdbird_model = new Kdbird();
$kdbird_config = $kdbird_model->getKdbirdConfig($express_no_data[ "site_id" ]);
if ($kdbird_config[ "data" ][ "is_use" ]) {
$express_no = $express_no_data[ "express_no" ];
return $kdbird_model->trace($data[ "code" ], $express_no, $express_no_data[ "site_id" ], $data[ 'mobile' ]);
}
}
}