文件
mashangyoujiu/Application/Retail/Controller/ExpressController.class.php

911 行
35 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Common\Business\Sell;
use Common\Business\SerialNumberGoods;
use Common\Model\StoreConfigModel;
use Think\Controller;
use Common\Model\ExpressOrderModel;
//[1.9.21]
/**
* 门店快递设置
* Class ExpressController
* @package Retail\Controller
*/
class ExpressController extends BaseController
{
protected $token;//门店授权token
protected $cpCode = '';//物流编码
/**
* 大转盘需要改
*/
public function _initialize()
{
parent::_initialize();
if (empty($this->store_id)) {
if (IS_POST) {
$res = array(
'status' => 0,
'msg' => '您无权访问该接口',
);
$this->ajaxReturn($res);
} else {
session(null);
echo '<script>top.window.location="' . $_SERVER ["SCRIPT_NAME"] . '/Retail/Login/index"</script>';
exit;
}
}
$StoreConfigModel = new StoreConfigModel();
$this->token = $StoreConfigModel->getFindField(array('store_id' => $this->store_id), 'cn_token');
if (I('post.cp_code')) {
$this->cpCode = I('post.cp_code');
}
}
/**
* 基本设置页面
*/
public function set()
{
if (!C('CN_APP_KEY') || !C('CN_APP_SECRET')) {
echo '系统未开启电子面单功能,敬请期待';
} else {
$authorized = empty($this->token) ? 'false' : 'true';//判断是否授权菜鸟物流云
$StoreShippingAddressModel = D('StoreShippingAddress');
$map = array(
'store_id' => $this->store_id,
'state' => 1,
);
$defaultInfo = $StoreShippingAddressModel->getFind($map);//获取门店默认发货地址
if (empty($defaultInfo)) {
$defaultInfo = array(
'cp_code' => '', // varchar(50) DEFAULT NULL COMMENT '物流编码',
'branch_code' => '', // varchar(20) DEFAULT NULL COMMENT '网点code',
'branch_name' => '', // varchar(50) DEFAULT NULL COMMENT '网点名称',
'province' => '', // varchar(50) DEFAULT NULL COMMENT '省',
'city' => '', // varchar(50) DEFAULT NULL COMMENT '市',
'district' => '', // varchar(50) DEFAULT NULL COMMENT '区',
'town' => '', // varchar(255) DEFAULT NULL COMMENT '街道、镇',
'detail' => '', // varchar(255) DEFAULT NULL COMMENT '详细地址',
'template_url' => '', // varchar(255) DEFAULT NULL COMMENT '面单模板地址',
'template_type' => '', // varchar(255) DEFAULT NULL COMMENT '面单模板类型',
'name' => '', // varchar(50) DEFAULT NULL COMMENT '发货人姓名',
'mobile' => '', // varchar(11) DEFAULT NULL COMMENT '发货人手机',
'phone' => '', // varchar(20) DEFAULT NULL COMMENT '发货人固定电话',
);
}
$this->assign('defaultInfo', json_encode($defaultInfo));
$this->assign('authorized', $authorized);
$this->display();
}
}
/**
* 设置默认发货信息
*/
public function saveDefault()
{
$cp_code = I('post.cp_code'); // varchar(50) DEFAULT NULL COMMENT '物流编码',
$branch_code = I('post.branch_code'); // varchar(20) DEFAULT NULL COMMENT '网点code',
$branch_name = I('post.branch_name'); // varchar(50) DEFAULT NULL COMMENT '网点名称',
$province = I('post.province'); // varchar(50) DEFAULT NULL COMMENT '省',
$city = I('post.city'); // varchar(50) DEFAULT NULL COMMENT '市',
$district = I('post.district'); // varchar(50) DEFAULT NULL COMMENT '区',
$town = I('post.town'); // varchar(255) DEFAULT NULL COMMENT '街道、镇',
$detail = I('post.detail'); // varchar(255) DEFAULT NULL COMMENT '详细地址',
$template_url = I('post.template_url'); // varchar(255) DEFAULT NULL COMMENT '面单模板地址',
$template_type = I('post.template_type'); // varchar(255) DEFAULT NULL COMMENT '面单模板类型',
$name = I('post.name'); // varchar(50) DEFAULT NULL COMMENT '发货人姓名',
$mobile = I('post.mobile'); // varchar(11) DEFAULT NULL COMMENT '发货人手机',
$phone = I('post.phone'); // varchar(20) DEFAULT NULL COMMENT '发货人固定电话',
$addItem = array(
'store_id' => $this->store_id,
'state' => 1,
'add_time' => time(),
'cp_code' => $cp_code,
'branch_code' => $branch_code,
'branch_name' => $branch_name,
'province' => $province,
'city' => $city,
'district' => $district,
'town' => $town,
'detail' => $detail,
'template_url' => $template_url,
'template_type' => $template_type,
'name' => $name,
'mobile' => $mobile,
'phone' => $phone,
);
$StoreShippingAddressModel = D('StoreShippingAddress');
$map = array(
'store_id' => $this->store_id,
'state' => 1,
);
$StoreShippingAddressModel->updateOrder($map, array('state' => 0));//把之前的改为删除状态
$add = $StoreShippingAddressModel->addOrder($addItem);
if ($add) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '设置-保存默认发货信息';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '保存成功';
} else {
$res['status'] = 0;
$res['msg'] = '保存失败,请重试';
}
$this->ajaxReturn($res);
}
/**
* 获取商家信息
*/
public function getMerInfo()
{
$CNLogistics = new \Addons\Api\CNLogistics($this->token, $this->cpCode);
$res = $CNLogistics->getMerInfo();
$this->ajaxReturn($res);
}
/**
* 获取云打印标准面单
*/
public function getTemplates()
{
if (empty($this->cpCode)) {
$res['status'] = 0;
$res['msg'] = '请传入物流编号';
$this->ajaxReturn($res);
}
$CNLogistics = new \Addons\Api\CNLogistics($this->token, $this->cpCode);
$res = $CNLogistics->getStandardTemplates();//获取云打印标准面单
if ($res['status'] == 1) {
$res['data'] = $res['data'][0]['standardTemplateDOs'];
}
$this->ajaxReturn($res);
}
/**
* 获取授权链接
*/
public function getAuthCode()
{
$key = 'auth.store: ' . $this->store_id;
$key = substr(md5($key), 8, 16);
S($key, $this->store_id, 300);
$appKey = C('CN_APP_KEY');
$ext = 'type/2:id/' . $key;//type==2代表门店授权 1商户授权(预留)
$redirect_url = getServerUrl() . '/index.php/cn_auth_callback';
$auth_url = "https://lcp.cloud.cainiao.com/permission/isv/grantpage_tb.do?isvAppKey={$appKey}&ext={$ext}&redirectUrl={$redirect_url}";
$res['status'] = 1;
$res['msg'] = '获取成功';
$res['auth_url'] = $auth_url;
$this->ajaxReturn($res);
}
/**
* 大转盘需要改
* 发货页面
*/
public function send_goods()
{
$cnLogisticsState = 'true';
if (!C('CN_APP_KEY') || !C('CN_APP_SECRET')) {
$cnLogisticsState = 'false';
}
$kd100State = 'true';
// if (!C('KD100_CUSTOMER') || !C('KD100_KEY')) {
// $kd100State = 'false';
// }
$id = I('get.id');
$BillModel = D('RetailBillOrder');
$OnlineModel = D('RetailBillOnline');
$map = array(
'b.' . $BillModel::ID => $id,
'b.' . $BillModel::TYPE => 1,
'b.' . $BillModel::ORDER_TYPE => array('in', '1,3'),
'b.' . $BillModel::REFUND_STATUS => array('in', '0,5'),
'o.' . $OnlineModel::PICKUP_TYPE => array('in', '2,3'),
'o.' . $OnlineModel::DELIVERY_TYPE => 1,
'o.' . $OnlineModel::STATUS => 1,
);
$fields = array(
'b.' . $BillModel::ID,
'b.' . $BillModel::ORDER_NO,
'o.' . $OnlineModel::USER_NAME,
'o.' . $OnlineModel::USER_PHONE,
'o.' . $OnlineModel::USER_ADDRESS,
);
$bill_order = $BillModel->getOrderLinkFind($map, $fields);
if (!empty($bill_order)) {
$StoreShippingAddressModel = D('StoreShippingAddress');
$map = array(
'store_id' => $this->store_id,
'state' => 1,
);
$default_sender = $StoreShippingAddressModel->getFind($map);//获取门店默认发货地址
$default_sender['goods_name'] = '';
$default_sender['goods_count'] = '';
$default_sender['goods_weight'] = '';
$default_sender['goods_volume'] = '';
$authorized = empty($this->token) ? 'false' : 'true';//判断是否授权菜鸟物流云
$bill = array(
'id' => $id,
'order_no' => $bill_order[$BillModel::ORDER_NO],
'receiving_name' => $bill_order[$OnlineModel::USER_NAME],
'receiving_phone' => $bill_order[$OnlineModel::USER_PHONE],
'receiving_address' => $bill_order[$OnlineModel::USER_ADDRESS],
);
$this->assign('bill', json_encode($bill));
$this->assign('authorized', $authorized);
$this->assign('default_sender', $default_sender ? json_encode($default_sender) : json_encode(array()));
$this->assign('cnLogisticsState', $cnLogisticsState);
$this->assign('kd100State', $kd100State);
$this->display();
} else {
echo '未查询到该订单或订单已发货';
}
}
/**
* 获取物流公司列表
*/
public function getExpress()
{
$page = I('post.page') ? I('post.page') : 1;
$keyword = I('post.keyword');
$limit = 20;
if (!empty($keyword)) {
$map = array(
'kd_name' => array('like', "%{$keyword}%"),
);
$list = M('express')->where($map)->page($page, $limit)->order('id asc')->select();
} else {
$list = M('express')->page($page, $limit)->order('id asc')->select();
}
if (!empty($list)) {
$res['data'] = $list;
$res['status'] = 1;
$res['msg'] = '获取成功';
} else {
$res['status'] = 0;
$res['msg'] = '暂无数据';
}
$this->ajaxReturn($res);
}
/**
* 大转盘需要改
* 提交直接填写订单号发货信息
*/
public function directSetOrderNo()
{
$bill_id = I('post.bill_id');
$express_no = I('post.express_no');
$express_name = I('post.express_name');
$express_code = I('post.express_code');
if (empty($bill_id) || empty($express_no) || empty($express_name) || empty($express_code)) {
$res['status'] = 0;
$res['msg'] = '请完善发货信息';
$this->ajaxReturn($res);
}
$BillModel = D('RetailBillOrder');
$OnlineModel = D('RetailBillOnline');
$map = array(
'b.' . $BillModel::ID => $bill_id,
'b.' . $BillModel::TYPE => 1,
'b.' . $BillModel::ORDER_TYPE => array('in', '1,3'),
'b.' . $BillModel::REFUND_STATUS => array('in', '0,5'),
'o.' . $OnlineModel::PICKUP_TYPE => array('in', '2,3'),
'o.' . $OnlineModel::DELIVERY_TYPE => 1,
'o.' . $OnlineModel::STATUS => 1,
);
$bill_order = $BillModel->getOrderLinkFind($map);
if (empty($bill_order)) {
$res['status'] = 0;
$res['msg'] = '未查询到该订单或订单已发货';
$this->ajaxReturn($res);
}
$item = array(
'type' => 2,
'express_no' => $express_no,
'express_name' => $express_name,
'express_code' => $express_code,
'bill_id' => $bill_id,
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id,
'uid' => $bill_order[$BillModel::UID],
'bill_order' => $bill_order,
'platform_type' => $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1
);
$res = A('Api/Express')->toSendGoods($item);
$this->ajaxReturn($res);
}
/**
* 大转盘需要改
* 电子面单取号
*/
public function getExpressCode()
{
$bill_id = I('post.bill_id');
$mobile = I('post.mobile');
$phone = I('post.phone');
$name = I('post.name');
$goods_name = I('post.goods_name');
$goods_count = I('post.goods_count');
$goods_weight = I('post.goods_weight');
$goods_volume = I('post.goods_volume');
$express_code = I('post.express_code');
$express_name = I('post.express_name');
if (empty($name)) {
$res['status'] = 0;
$res['msg'] = '请填写发货人姓名';
$this->ajaxReturn($res);
}
if (empty($mobile) && empty($phone)) {
$res['status'] = 0;
$res['msg'] = '发货人手机号和固定电话不能同时为空';
$this->ajaxReturn($res);
}
if (empty($goods_name)) {
$res['status'] = 0;
$res['msg'] = '请填写物品名称';
$this->ajaxReturn($res);
}
if (empty($goods_count)) {
$res['status'] = 0;
$res['msg'] = '请填写物品数量';
$this->ajaxReturn($res);
}
if (empty($goods_weight)) {
$res['status'] = 0;
$res['msg'] = '请填写物品重量';
$this->ajaxReturn($res);
}
if (empty($goods_volume)) {
$res['status'] = 0;
$res['msg'] = '请填写物品体积';
$this->ajaxReturn($res);
}
if (empty($express_code)) {
$res['status'] = 0;
$res['msg'] = '请选择物流公司';
$this->ajaxReturn($res);
}
$StoreShippingAddressModel = D('StoreShippingAddress');
$map = array(
'store_id' => $this->store_id,
'state' => 1,
);
$defaultInfo = $StoreShippingAddressModel->getFind($map);//获取门店默认发货地址
if (empty($defaultInfo)) {
$res['status'] = 0;
$res['msg'] = '门店未设置发货地址,请先设置发货地址';
$this->ajaxReturn($res);
}
$BillModel = D('RetailBillOrder');
$OnlineModel = D('RetailBillOnline');
$map = array(
'b.' . $BillModel::ID => $bill_id,
'b.' . $BillModel::TYPE => 1,
'b.' . $BillModel::ORDER_TYPE => array('in', '1,3'),
'b.' . $BillModel::REFUND_STATUS => array('in', '0,5'),
'o.' . $OnlineModel::PICKUP_TYPE => array('in', '2,3'),
'o.' . $OnlineModel::DELIVERY_TYPE => 1,
'o.' . $OnlineModel::STATUS => array('eq', 1),
);
$fields = array(
'b.' . $BillModel::ID,
'b.' . $BillModel::ORDER_NO,
'b.' . $BillModel::REFUND_NO,
'b.' . $BillModel::ORDER_TYPE,
'b.' . $BillModel::UID,
'o.' . $OnlineModel::USER_NAME,
'o.' . $OnlineModel::USER_PHONE,
'o.' . $OnlineModel::USER_ADDRESS,
'b.third_order',
);
$bill_order = $BillModel->getOrderLinkFind($map, $fields);
$order_no = $bill_order[$BillModel::ORDER_NO];
//发货人信息
$sender = array(
'city' => $defaultInfo['city'],//城市
'detail' => $defaultInfo['detail'],//详细地址
'district' => $defaultInfo['district'],//区县
'province' => $defaultInfo['province'],//省
'town' => $defaultInfo['town'],//街道
'mobile' => $mobile,//手机号码(手机号和固定电话不能同时为空)
'name' => $name,//姓名
'phone' => $phone,//固定电话(手机号和固定电话不能同时为空)
'goods_name' => $goods_name,//物品名称
'goods_count' => $goods_count,//物品数量
'goods_weight' => $goods_weight,//物品重量
'goods_volume' => $goods_volume,//物品重量
'template_url' => $defaultInfo['template_url'],//物品重量
'user_id' => $this->store_id,//物品重量
);
//收货人信息
$address = $bill_order[$OnlineModel::USER_ADDRESS];
$direct = array('北京', '天津', '上海', '重庆');//直辖市
$temp = explode('省', $address);
if (count($temp) >= 2) {
$address = $temp[1];//去除省份
$province = in_array($temp[0], $direct) ? $temp[0] : ($temp[0] . '省');
}
$temp = explode('市', $address);
if (in_array($temp[0], $direct)) {
$province = $temp[0];
}
$city = $temp[0] . '市';
$address = str_replace($city, '', $address);//去除市
$temp = explode('区', $address);
$district = $temp[0] . '区';
$detail = str_replace($district, '', $address);//去除区
$recipient = array(
'province' => $province,//省
'city' => $city,//城市
'district' => $district,//区县
'detail' => $detail,//详细地址
'town' => '',//街道
'mobile' => $bill_order[$OnlineModel::USER_PHONE],//手机号码(手机号和固定电话不能同时为空)
'name' => $bill_order[$OnlineModel::USER_NAME],//姓名
'phone' => '',//固定电话(手机号和固定电话不能同时为空)
);
// exit;
$addItem = array(
'store_id' => $this->store_id,//'门店id',
'cp_code' => $this->cpCode,//'物流公司编码',
'branch_code' => $defaultInfo['branch_code'],//'网点code',
'branch_name' => $defaultInfo['branch_name'],//'网点名称',
'sender_name' => $sender['name'],//'发货人姓名',
'sender_mobile' => $sender['mobile'],//'发货人手机',
'sender_phone' => $sender['phone'],//'发货人固定电话',
'sender_address' => $sender['province'] . $sender['city'] . $sender['district'] . $sender['town'] . $sender['detail'],//'发货地址',
'goods_name' => $sender['goods_name'],//'商品名称',
'goods_count' => $sender['goods_count'],//'商品数量',
'goods_weight' => $sender['goods_weight'],//'商品重量 单位g',
'goods_volume' => $sender['goods_volume'],//'商品体积 单位ml',
'recipient_name' => $recipient['name'],//'收件人姓名',
'recipient_mobile' => $recipient['mobile'],//'收件人手机号',
'recipient_phone' => $recipient['phone'],//'收件人固定电话',
'recipient_address' => $bill_order[$OnlineModel::USER_ADDRESS],//'收件人地址',
'template_url' => $sender['template_url'],//'面单模板地址',
'status' => 1,//'1正常 0取消',
'state' => 0,//'1正常 0删除',
'add_time' => time(),//'创建时间',
);
$CNLogisticsOrderModel = D('CNLogisticsOrder');
$logistics_id = $CNLogisticsOrderModel->addOrder($addItem);
if ($logistics_id) {
$CNLogistics = new \Addons\Api\CNLogistics($this->token, $this->cpCode);
$res = $CNLogistics->getExpressCode($sender, $recipient, $order_no);
if ($res['status'] == 1) {
$upItem = array(
'waybill_code' => $res['waybillCloudPrintResponseList'][0]['waybillCode'],//'电子面单号',
'print_data' => $res['waybillCloudPrintResponseList'][0]['printData'],//'面单模板打印数据',
'status' => 1,//'1正常 0取消',
'state' => 1,//'1正常 0删除',
);
$CNLogisticsOrderModel->updateOrder(array('id' => $logistics_id), $upItem);
$item = array(
'type' => 1,
'express_no' => $upItem['waybill_code'],
'express_name' => $express_name,
'express_code' => $express_code,
'bill_id' => $bill_id,
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id,
'logistics_id' => $logistics_id,
'uid' => $bill_order[$BillModel::UID],
'bill_order' => $bill_order,
'platform_type' => $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1
);
$res = A('Api/Express')->toSendGoods($item);
$res['status'] == 1 && $res['msg'] = '取号成功,请前往“设置->电子面单->面单列表打印电子面单”';
}
} else {
$res['status'] = 0;
$res['msg'] = '系统发生错误';
}
$this->ajaxReturn($res);
}
/**
* 大转盘需要改
* 查看物流页面
*/
public function see_logistics()
{
// if (!C('KD100_CUSTOMER') || !C('KD100_KEY')) {
// echo '系统未开启快递100查询物流功能,敬请期待';
// exit;
// }
$id = I('get.id');
$res = A('Api/Express')->getExpressInfo($id);
// if ($res['status'] == 1) {
$BillModel = D('RetailBillOrder');
$OnlineModel = D('RetailBillOnline');
$map = array(
'b.' . $BillModel::ID => $id,
'b.' . $BillModel::TYPE => 1,
'b.' . $BillModel::ORDER_TYPE => 1,
'b.' . $BillModel::REFUND_STATUS => 0,
'o.' . $OnlineModel::PICKUP_TYPE => array('in', '2,3'),
'o.' . $OnlineModel::DELIVERY_TYPE => 4,
'o.' . $OnlineModel::STATUS => array('neq', 1),
);
$bill_order = $BillModel->getOrderLinkFind($map);
$res['data']['order_no'] = $bill_order[$BillModel::ORDER_NO];;
$res['data']['receiving_name'] = $bill_order[$OnlineModel::USER_NAME];
$res['data']['receiving_phone'] = $bill_order[$OnlineModel::USER_PHONE];
$res['data']['receiving_address'] = $bill_order[$OnlineModel::USER_ADDRESS];
$this->assign('logistics', json_encode($res['data']));
$this->display();
// } else {
// echo $res['msg'];
// }
}
public function expressNoSave()
{
$post = I("post.");
$param = [
'id',//主键id
'expressNo',//物流单号
'expressName',//物流名称
'expressCode',//快递公司编码
];
foreach ($param as $value) {
$isData = array_key_exists($value, $post);
if ($isData === false) {
$message = "缺少参数 '" . $value . "'";
$res = callBack(statusCode()['error'], $message);
$this->ajaxReturn($res);
}
}
if ($post['id'] == '' || $post['expressNo'] == '' || $post['expressName'] == '' || $post['expressCode'] == '') {
$res = callBack(statusCode()['error'], '物流单号不能为空');
$this->ajaxReturn($res);
}
$expressNo = trim($post['expressNo']);
//验证快递单号,长度不超过30位的数字和字母
if (!preg_match('/^[_0-9a-zA-Z]{1,30}$/i', $expressNo)) {
$res = callBack(statusCode()['error'], '请输入长度不超过30位的规范快递单号');
$this->ajaxReturn($res);
}
$where = [
'bill_id' => $post['id'],
'order_type' => 1,//order_type为1时 关联订单bill_order表id
];
$save = [
'express_no' => $expressNo,
'express_name' => $post['expressName'],
'express_code' => $post['expressCode'],
];
$expressOrderModel = new ExpressOrderModel();
$data = $expressOrderModel->updateOrder($where, $save);
if ($data === false) {
$res = callBack(statusCode()['error'], '失败');
} else {
$res = callBack(statusCode()['success'], '成功');
}
$this->ajaxReturn($res);
}
/**
* 直接填写token
*/
public function setToken()
{
$token = I('post.token');
$StoreConfigModel = D('StoreConfig');
$map = array('store_id' => $this->store_id);
$item = array(
'cn_token' => $token,
);
$old = $StoreConfigModel->getFind($map);
if (empty($old)) {
$item['store_id'] = $this->store_id;
$update = $StoreConfigModel->addOrder($item);
} else if ($token == $old['cn_token']) {
$update = true;
} else {
$update = $StoreConfigModel->updateOrder($map, $item);
}
if ($update) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '设置-重新填写token';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '保存成功';
} else {
$res['status'] = 0;
$res['msg'] = '保存失败';
}
$this->ajaxReturn($res);
}
/**
* 电子面单列表
*/
public function order()
{
if (!C('CN_APP_KEY') || !C('CN_APP_SECRET')) {
echo '系统未开启电子面单功能,敬请期待';
} else {
$arr = array(
'printFaceSheet' => '/index.php/Retail/Express/printFaceSheet',
'cancelExpress' => '/index.php/Retail/Express/cancelExpress',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
}
/**
* 获取电子面单列表
*/
public function getExpressList()
{
$waybill_code = I('post.waybill_code');
$express_type = I('post.express_type');
$time = I('post.time');
$CNLogisticsOrderModel = D('CNLogisticsOrder');
$map = array(
'state' => 1,
'store_id' => $this->store_id,
);
if (!empty($waybill_code)) {
$map['waybill_code'] = $waybill_code;
}
if (!empty($express_type)) {
$map['status'] = $express_type == 1 ? 1 : 0;
}
if (!empty($time)) {
$start_time = strtotime($time[0]);
$end_time = strtotime($time[1]);
$map['add_time'] = array('between', array($start_time, $end_time));
}
$fields = array(
'id',// 'id',
'cp_code',// '物流公司编码',
'branch_code',// '网点code',
'branch_name',// '网点名称',
'sender_name',// '发货人姓名',
'sender_mobile',// '发货人手机',
'sender_phone',// '发货人固定电话',
'sender_address',// '发货地址',
'goods_name',// '商品名称',
'goods_count',// '商品数量',
'goods_weight',// '商品重量 单位g',
'goods_volume',// '商品体积 单位ml',
'recipient_name',// '收件人姓名',
'recipient_mobile',//'收件人手机号',
'recipient_phone',// '收件人固定电话',
'recipient_address',// '收件人地址',
'waybill_code',//'电子面单号',
'status',// '1正常 0取消',
'add_time',// '创建时间',
'cancel_time',// '取消时间',
);
$list = $CNLogisticsOrderModel->getSelect($map, $fields);
$res['status'] = 1;
if (!empty($list)) {
foreach ($list as &$value) {
$value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
if (!empty($value['cancel_time'])) {
$value['cancel_time'] = date('Y-m-d H:i:s', $value['cancel_time']);
}
}
$res['msg'] = '获取成功';
} else {
$res['msg'] = '暂无数据';
}
$res['data'] = $list;
$this->ajaxReturn($res);
}
/**
* 电子面单取消
*/
public function cancelExpress()
{
$id = I('post.id');//电子面单id
if (empty($id)) {
$res['status'] = 0;
$res['msg'] = '请选择要取消的电子面单';
$this->ajaxReturn($res);
}
$CNLogisticsOrderModel = D('CNLogisticsOrder');
$map = array(
'state' => 1,
'store_id' => $this->store_id,
'id' => $id,
);
$order = $CNLogisticsOrderModel->getFind($map);
if (empty($order)) {
$res['status'] = 0;
$res['msg'] = '您要取消的面单不存在,请确认参数';
$this->ajaxReturn($res);
}
$CNLogistics = new \Addons\Api\CNLogistics($this->token, $order['cp_code']);
$res = $CNLogistics->cancelExpress($order['waybill_code']);
if ($res['status'] == 1) {
if ($res['success'] == 'true' && $res['discardResult'] == 'true') {
$updateItem = array(
'status' => 0,
);
$CNLogisticsOrderModel->updateOrder($map, $updateItem);
$this->cancelOrder($id);
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '面单列表-取消面单';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['msg'] = '取消成功';
} else {
$res['status'] = 0;
$res['msg'] = $res['errorMsg'] ? $res['errorMsg'] : '取消失败';
}
} else {
$res['status'] = 0;
$res['msg'] = $res['errorMsg'] ? $res['errorMsg'] : '取消失败';
}
$this->ajaxReturn($res);
}
/**
* 取下电子免单订单修改
* $param $id 电子免单id
*/
protected function cancelOrder($id)
{
$bill_id = D("ExpressOrder")->getFindField(array('logistics_id' => $id), "bill_id");
$order_no = D("RetailBillOrder")->getFindField(array('id' => $bill_id), "order_no");
$parameter = array(
'order_no' => $order_no,
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id
);
$res = A("Api/Delivery")->cancelDelivery($parameter);
return $res;
}
/**
* 获取打印面单参数
*/
public function printFaceSheet()
{
$id = I('post.id');//电子面单id
if (empty($id)) {
$res['status'] = 0;
$res['msg'] = '请选择要打印的电子面单';
$this->ajaxReturn($res);
}
$CNLogisticsOrderModel = D('CNLogisticsOrder');
$map = array(
'state' => 1,
'store_id' => $this->store_id,
'id' => $id,
);
$fields = array(
'id',
'store_id',
'template_url',
'cp_code',
'print_data',
'waybill_code',
);
$order = $CNLogisticsOrderModel->getFind($map, $fields);
if (!empty($order)) {
$res['data'] = $order;
$res['status'] = 1;
$res['msg'] = '获取成功';
} else {
$res['status'] = 0;
$res['msg'] = '您要打印的面单不存在,请确认参数';
}
$this->ajaxReturn($res);
}
/**
* 删除电子面单记录
*/
public function delExpress()
{
$id = I('post.id');//电子面单id
if (empty($id)) {
$res['status'] = 0;
$res['msg'] = '请选择要删除的电子面单';
$this->ajaxReturn($res);
}
$CNLogisticsOrderModel = D('CNLogisticsOrder');
$map = array(
'state' => 1,
'store_id' => $this->store_id,
'id' => $id,
);
$order = $CNLogisticsOrderModel->getFind($map);
if (!empty($order)) {
if ($order['status'] != 1) {
$update = array(
'state' => 0
);
$CNLogisticsOrderModel->updateOrder($map, $update);
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '面单列表-删除';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '删除成功';
} else {
$res['status'] = 0;
$res['msg'] = '操作有误:只能删除已取消的记录';
}
} else {
$res['status'] = 0;
$res['msg'] = '您要删除的面单不存在,请确认参数';
}
$this->ajaxReturn($res);
}
//商品信息
public function orderInfo()
{
$data = I('post.');
$SellClass = new Sell();
$result = $SellClass->sellList($data);
$this->ajaxReturn($result);
}
//串号商品查询
public function searchSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->searchWarehouseSerial($data);
$this->ajaxReturn($result);
}
//配送前确认商品信息confirmDistributionGoods
public function confirmDistributionGoods()
{
$data = I('post.');
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['type'] = 1;
$SellClass = new Sell();
$result = $SellClass->confirmSellGoods($data);
$this->ajaxReturn($result);
}
}