chore(src): 所有代码上传

This commit is contained in:
2025-12-02 15:36:42 +08:00
parent ce8e59902c
commit eb79ad260c
669 changed files with 86838 additions and 87639 deletions

View File

@@ -1,246 +1,238 @@
<?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;
}
<?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

@@ -1,268 +1,260 @@
<?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 ]);
}
<?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

@@ -1,175 +1,167 @@
<?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;
}
<?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

@@ -1,264 +1,256 @@
<?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;
}
<?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

@@ -1,135 +1,127 @@
<?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);
}
<?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

@@ -1,127 +1,119 @@
<?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;
}
<?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

@@ -1,160 +1,169 @@
<?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);
}
<?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 = '', $save_trace = false)
{
$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)) {
//商品名称或者图片中有逗号特殊处理
$normal_key = 0;
foreach($temp_array as $key=>$val){
if(preg_match("/^\d+:\d+:/", $val)){
$normal_key = $key;
}else{
$temp_array[$normal_key] .=','.$val;
unset($temp_array[$key]);
}
}
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' ] ];
}
}
if(!empty($v['trace'])){
$list[ $k ][ 'trace' ] = json_decode($v['trace'], true);
}else{
$trace_list = $trace_model->trace($v[ 'delivery_no' ], $v[ 'express_company_id' ], $v[ 'site_id' ], $mobile);
$list[ $k ][ 'trace' ] = $trace_list[ 'data' ];
if($save_trace){
model('express_delivery_package')->update(['trace' => json_encode($trace_list['data'], JSON_UNESCAPED_UNICODE)], [['id', '=', $v['id']]]);
}
}
}
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

@@ -1,222 +1,214 @@
<?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);
}
<?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

@@ -1,86 +1,78 @@
<?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);
}
<?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

@@ -1,93 +1,85 @@
<?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' ]);
}
}
<?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' ]);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,108 +1,100 @@
<?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);
}
<?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

@@ -1,86 +1,78 @@
<?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' ]);
}
}
<?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' => $result['message'] ?? '抱歉,暂无物流记录' ];
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' ]);
}
}
}