515 行
22 KiB
PHP
可执行文件
515 行
22 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Business;
|
|
|
|
use Api\Controller\InventoryController;
|
|
use Common\Model\RetailCashierModel;
|
|
use Common\Model\RetailStoreModel;
|
|
use Common\Model\RetailSupplierModel;
|
|
use Common\Model\SaleWarehouseModel;
|
|
use Common\Model\SSaleWarehouseModel;
|
|
use Common\Model\SStockOutGoodsModel;
|
|
use Common\Model\SStockOutOrderModel;
|
|
use Common\Model\SSupplierModel;
|
|
use Common\Model\StockOutGoodsModel;
|
|
use Common\Model\StockOutOrderModel;
|
|
|
|
//[1.8.76]
|
|
|
|
/**
|
|
* 出库类
|
|
* Class OutboundOrder
|
|
* @package Common\Business
|
|
* [
|
|
* 商户与门店的出库单的出库详情列表 detailList
|
|
* 获取商户与门店出库单金额统计详情 getStockOrderTotalMoney
|
|
* 商户出库单列表 getMerchantStockOrderList
|
|
* 商户出库单列表的where条件 getMerchantStockListTerm
|
|
* 门店出库单列表 getStoreStockOrderList
|
|
* 门店出库单列表的where条件 getStoreStockListTerm
|
|
* ]
|
|
*/
|
|
class OutboundOrder
|
|
{
|
|
/**
|
|
* 出库单的出库详情列表
|
|
* @param $param
|
|
* [
|
|
* user_type 3商户 4门店
|
|
* store_id
|
|
* id 出库单id
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function detailList($param)
|
|
{
|
|
$where['stock_out_id'] = $param['id'];
|
|
switch ($param['user_type']) {
|
|
case 3:
|
|
$StockOutGoodsModel = new StockOutGoodsModel();
|
|
break;
|
|
case 4:
|
|
$StockOutGoodsModel = new SStockOutGoodsModel();
|
|
//成本价权限
|
|
$StockRecordClass = new StockRecord();
|
|
$stateResult = $StockRecordClass->addStockOutInitial([
|
|
'store_id' => $param['store_id']
|
|
]);
|
|
$cost_price_state = $stateResult['data'];
|
|
$where['type'] = ['in', '0,1,2,3,9'];
|
|
break;
|
|
}
|
|
$list = $StockOutGoodsModel->getSelect($where, '', '', '', 'id asc');
|
|
if (!empty($list)) {
|
|
foreach ($list as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['stock_num'] = round($val['stock_num'], 3);
|
|
$val['subtotal'] = round($val['subtotal'], 2);
|
|
$val['sku_num'] = round($val['sku_num'], 3);
|
|
if ($cost_price_state == 2 && $param['user_type'] == 4) {
|
|
$val['stock_price'] = '***';
|
|
$val['cost_price'] = '***';
|
|
} else {
|
|
$val['stock_price'] = round($val['stock_price'], 2);
|
|
$val['cost_price'] = round($val['cost_price'], 3);
|
|
}
|
|
if (!empty($val['build_date'])) {
|
|
$val['build_date'] = date('Y-m-d', $val['build_date']);
|
|
}
|
|
if ($val['attribute_state'] == 2) {
|
|
$val['goods_code'] = $val['sku_code'];
|
|
$val['goods_number'] = $val['sku_goods_number'];
|
|
}
|
|
}
|
|
}
|
|
return callBack(statusCode()['success'], '查询成功', $list);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取出库单金额统计详情
|
|
* @param $parameter
|
|
* [
|
|
* where 查询条件
|
|
* user_type 3商户 4门店
|
|
* operator_type 1后台 2收银端 3助手端
|
|
* ]
|
|
* @return array
|
|
* [
|
|
* orderCount 订单数
|
|
* goods_species 出库商品种数
|
|
* total_cost_price 出库成本价合计
|
|
* money_total 出库价合计
|
|
* real_goods_species 实收商品种数
|
|
* real_total_cost_money 实收成本价
|
|
* real_money_total 实收价
|
|
* differenceMoney 实收盈亏金额
|
|
* refuse_goods_species 拒收商品种数
|
|
* refuse_total_stock_money 拒收出库价金额
|
|
* refuse_total_cost_money 拒收成本价金额
|
|
* ]
|
|
*/
|
|
public function getStockOrderTotalMoney($parameter)
|
|
{
|
|
switch ($parameter['user_type']) {
|
|
case 3:
|
|
//商户
|
|
$stockOrderModel = new StockOutOrderModel();
|
|
$where = $this->getMerchantStockListTerm($parameter); //获取请求条件
|
|
break;
|
|
case 4:
|
|
//门店
|
|
$stockOrderModel = new SStockOutOrderModel();
|
|
$where = $this->getStoreStockListTerm($parameter); //获取请求条件
|
|
break;
|
|
}
|
|
$TotalList = $stockOrderModel->getSelect($where, '', '', "*", "id desc");
|
|
$orderCount = 0; //订单数
|
|
$goods_species = 0; //出库商品种数
|
|
$total_cost_price = 0; //出库成本价合计
|
|
$money_total = 0; //出库价合计
|
|
$real_goods_species = 0; //实收商品种数
|
|
$real_total_cost_money = 0; //实收成本价
|
|
$real_money_total = 0; //实收价
|
|
$differenceMoney = 0; //实收盈亏金额
|
|
$refuse_goods_species = 0; //拒收商品种数_
|
|
$refuse_total_stock_money = 0; //拒收出库价金额
|
|
$refuse_total_cost_money = 0; //拒收成本价金额
|
|
if ($TotalList) {
|
|
foreach ($TotalList as $va) {
|
|
$orderCount++;
|
|
$goods_species += $va['goods_species'];
|
|
$total_cost_price += $va['total_cost_price'];
|
|
$money_total += $va['money_total'];
|
|
if ($va['warehousing_status'] == 1) {
|
|
$real_goods_species += $va['real_goods_species'];
|
|
$real_money_total += $va['real_money_total'];
|
|
$real_total_cost_money += $va['real_total_cost_money'];
|
|
}
|
|
if ($va['refuse_status'] == 2) {
|
|
$refuse_goods_species += $va['refuse_goods_species'];
|
|
$refuse_total_stock_money += $va['refuse_total_stock_money'];
|
|
$refuse_total_cost_money += $va['refuse_total_cost_money'];
|
|
}
|
|
}
|
|
if ($real_money_total > 0) {
|
|
$differenceMoney = round($real_money_total - $real_total_cost_money, 2);
|
|
}
|
|
}
|
|
$list = array(
|
|
array(
|
|
'orderCount' => $orderCount,
|
|
'goods_species' => $goods_species,
|
|
'total_cost_price' => $total_cost_price,
|
|
'money_total' => $money_total,
|
|
'real_goods_species' => $real_goods_species,
|
|
'real_total_cost_money' => $real_total_cost_money,
|
|
'real_money_total' => $real_money_total,
|
|
'refuse_goods_species' => $refuse_goods_species,
|
|
'refuse_total_stock_money' => $refuse_total_stock_money,
|
|
'refuse_total_cost_money' => $refuse_total_cost_money,
|
|
'differenceMoney' => $differenceMoney,
|
|
)
|
|
);
|
|
return callBack(statusCode()['success'], '查询成功', $list);
|
|
}
|
|
|
|
/**
|
|
* 商户出库单列表
|
|
* @param $parameter
|
|
* [
|
|
* page 分页
|
|
* limit 条数
|
|
* merchant_id
|
|
* order_number 出库订单号
|
|
* add_time 出库时间
|
|
* type 出库类型 0其他出库 1调拨出库 2盘亏出库 3门店申请调拨出库 4退货出库
|
|
* supplier_id 供货商id
|
|
* warehousing_status 0未入库 1已入库
|
|
* operator_type 1后台 2收银端 3助手端
|
|
* ]
|
|
* @return array
|
|
* [
|
|
* list 出库单信息
|
|
* count' 出库单数量
|
|
* ]
|
|
*/
|
|
public function getMerchantStockOrderList($parameter)
|
|
{
|
|
$where = $this->getMerchantStockListTerm($parameter); //获取查询参数
|
|
if (empty($where)) {
|
|
return ['list' => [], 'count' => 0];
|
|
}
|
|
$StockOutOrderModel = new StockOutOrderModel();
|
|
$list = $StockOutOrderModel->getSelect($where, $parameter['page'], $parameter['limit'], "*", "id desc");
|
|
if (!empty($list)) {
|
|
$count = $StockOutOrderModel->getCount($where);
|
|
$SaleWarehouseModel = new SaleWarehouseModel();
|
|
$Supplier = new RetailSupplierModel();
|
|
$Store = new RetailStoreModel();
|
|
$InventoryClass = new InventoryController();
|
|
foreach ($list as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['operator'] = $InventoryClass->OperatorName($val['operator_id']);
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$val['total_cost_price'] = round($val['total_cost_price'], 2);
|
|
$val['money_total'] = round($val['money_total'], 2);
|
|
$val['real_money_total'] = $val['real_money_total'] ? round($val['real_money_total'], 2) : '';
|
|
$val['real_total_cost_money'] = $val['real_total_cost_money'] ? round($val['real_total_cost_money'], 2) : '';
|
|
$val['refuse_total_cost_money'] = $val['refuse_total_cost_money'] ? round($val['refuse_total_cost_money'], 2) : '';
|
|
$val['refuse_total_stock_money'] = $val['refuse_total_stock_money'] ? round($val['refuse_total_stock_money'], 2) : '';
|
|
$val['difference_money'] = '';
|
|
if (!empty($val['real_money_total'])) {
|
|
$val['difference_money'] = round($val['real_money_total'] - $val['real_total_cost_money'], 2);
|
|
}
|
|
$val['warehouse_name'] = $SaleWarehouseModel->getFindField(array('id' => $val['warehouse_id']), "name");
|
|
if (in_array($val['type'], [1, 3])) {
|
|
$val['store_name'] = $Store->getFindField(array('id' => $val['store_id']), "storetag");
|
|
if ($val['warehousing_status'] == 1) {
|
|
$val['warehouse_time'] = date('Y-m-d H:i:s', $val['warehouse_time']);
|
|
$val['real_money_total'] = round($val['real_money_total'], 2);
|
|
$val['warehousing_name'] = "已入库";
|
|
} else {
|
|
if ($val['refuse_status'] == 2) {
|
|
$val['warehouse_time'] = date('Y-m-d H:i:s', $val['refuse_time']);
|
|
}
|
|
$val['warehousing_name'] = "未入库";
|
|
}
|
|
}
|
|
switch ($val['type']) {
|
|
case 0:
|
|
$val['type_name'] = "其他出库";
|
|
break;
|
|
case 1:
|
|
$val['type_name'] = "调拨出库";
|
|
break;
|
|
case 2:
|
|
$val['type_name'] = "盘亏出库";
|
|
break;
|
|
case 3:
|
|
$val['type_name'] = "申请调拨出库";
|
|
break;
|
|
case 4:
|
|
$val['store_name'] = $Supplier->getFindField(array('id' => $val['supplier_id']), "supplier_name");
|
|
$val['type_name'] = "退货出库";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return callBack(statusCode()['success'], '查询成功', [
|
|
'list' => $list ? $list : [],
|
|
'count' => $count ? $count : 0
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 商户出库单列表的where条件
|
|
* @param $parameter
|
|
* [
|
|
* merchant_id
|
|
* page 分页
|
|
* limit 条数
|
|
* order_number 出库订单号
|
|
* add_time 出库时间 web端
|
|
* start_time 出库开始时间 移动端
|
|
* end_time 出库结束时间 移动端
|
|
* type 出库类型 0其他出库 1调拨出库 2盘亏出库 3门店申请调拨出库 4退货出库
|
|
* supplier_id 供货商id
|
|
* warehousing_status 0未入库 1已入库
|
|
* operator_type 1后台 2收银端 3助手端
|
|
* ]
|
|
* @return mixed array
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
public function getMerchantStockListTerm($parameter)
|
|
{
|
|
$order_number = $parameter['order_number'];
|
|
$type = $parameter['type'];
|
|
$supplier_id = $parameter['supplier_id'];
|
|
$warehousing_status = $parameter['warehousing_status'];
|
|
if (!empty($order_number)) {
|
|
$where['order_number'] = array('like', '%' . $order_number . '%');
|
|
}
|
|
switch ($parameter['operator_type']) {
|
|
case 1:
|
|
$add_time = $parameter['add_time'];
|
|
if (!empty($add_time)) {
|
|
if (!is_array($add_time)) {
|
|
$add_time = explode(',', $add_time);
|
|
}
|
|
$start_time = strtotime($add_time[0]);
|
|
$end_time = strtotime($add_time[1]);
|
|
$where['add_time'] = array('between', array($start_time, $end_time));
|
|
}
|
|
break;
|
|
case 3:
|
|
$start_time = $parameter['start_time'];
|
|
$end_time = $parameter['end_time'];
|
|
if (!empty($start_time) && !empty($end_time)) {
|
|
$start_time = strtotime($start_time . "00:00:00");
|
|
$end_time = strtotime($end_time . "23:59:59");
|
|
$where['add_time'] = array('between', array($start_time, $end_time));
|
|
} else if (!empty($start_time)) {
|
|
$start_time = strtotime($start_time . "00:00:00");
|
|
$where['add_time'] = array('gt', $start_time);
|
|
} else if (!empty($end_time)) {
|
|
$end_time = strtotime($end_time . "23:59:59");
|
|
$where['add_time'] = array('lt', $end_time);
|
|
}
|
|
break;
|
|
}
|
|
if ($type != '') {
|
|
$where['type'] = $type;
|
|
}
|
|
if ($warehousing_status != '') {
|
|
$where['warehousing_status'] = $warehousing_status;
|
|
}
|
|
if (!empty($supplier_id)) {
|
|
$where['supplier_id'] = $supplier_id;
|
|
}
|
|
$where['merchant_id'] = $parameter['merchant_id'];
|
|
$where['status'] = isset($parameter['status']) ? $parameter['status'] : 1;
|
|
return $where;
|
|
}
|
|
|
|
/**
|
|
* 门店出库单列表
|
|
* @param $parameter
|
|
* [
|
|
* merchant_id
|
|
* store_id
|
|
* order_number 出库订单号
|
|
* add_time 出库时间 web端
|
|
* start_time 出库开始时间 移动端
|
|
* end_time 出库结束时间 移动端
|
|
* type 出库类型 0其他出库 1向商户退货出库 2盘亏出库 3调拨出库 9向供货商退货出库
|
|
* supplier_id 供货商id
|
|
* warehousing_status 0未入库 1已入库
|
|
* operator_type 1后台 2收银端 3助手端
|
|
* ]
|
|
* @return array
|
|
* [
|
|
* list 出库单列表
|
|
* count 出库单条数
|
|
* ]
|
|
*/
|
|
public function getStoreStockOrderList($parameter)
|
|
{
|
|
$where = $this->getStoreStockListTerm($parameter); //获取出库单条件
|
|
$StockOutOrderModel = new SStockOutOrderModel();
|
|
$list = $StockOutOrderModel->getSelect($where, $parameter['page'], $parameter['limit'], "*", "id desc");
|
|
if (!empty($list)) {
|
|
$count = $StockOutOrderModel->getCount($where);
|
|
$CashierModel = new RetailCashierModel();
|
|
$StoreModel = new RetailStoreModel();
|
|
$SupplierModel = new SSupplierModel();
|
|
$SaleWarehouse = new SSaleWarehouseModel();
|
|
$InventoryClass = new InventoryController();
|
|
foreach ($list as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
if ($val['operator_type'] == 1) {//收银员
|
|
$val['operator'] = $CashierModel->getFindField(array('id' => $val['operator_id']), "name");
|
|
} else {
|
|
$val['operator'] = $InventoryClass->OperatorName($val['operator_id']);
|
|
}
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$val['total_cost_price'] = round($val['total_cost_price'], 2);
|
|
$val['money_total'] = round($val['money_total'], 2);
|
|
$val['real_total_cost_money'] = $val['real_total_cost_money'] ? round($val['real_total_cost_money'], 2) : '';
|
|
$val['real_money_total'] = $val['real_money_total'] ? round($val['real_money_total'], 2) : '';
|
|
$val['refuse_total_cost_money'] = $val['refuse_total_cost_money'] ? round($val['refuse_total_cost_money'], 2) : '';
|
|
$val['refuse_total_stock_money'] = $val['refuse_total_stock_money'] ? round($val['refuse_total_stock_money'], 2) : '';
|
|
if (!empty($val['real_money_total'])) {
|
|
$val['difference_money'] = round($val['real_money_total'] - $val['real_total_cost_money'], 2);
|
|
}
|
|
$val['warehouse_name'] = $SaleWarehouse->getFindField(array('id' => $val['warehouse_id']), "name");
|
|
if ($val['type'] == 1) {
|
|
if (!$val['warehousing_status']) {
|
|
$val['warehousing_name'] = '未入库';
|
|
} else {
|
|
$val['warehousing_name'] = '已入库';
|
|
$val['warehouse_time'] = date('Y-m-d H:i:s', $val['warehouse_time']);
|
|
$val['real_money_total'] = round($val['real_money_total'], 2);
|
|
}
|
|
} else if ($val['type'] == 3) {
|
|
switch ($val['examine_status']) {
|
|
case 0:
|
|
$val['warehousing_name'] = '未审核';
|
|
break;
|
|
case 1:
|
|
if (!$val['warehousing_status']) {
|
|
if ($val['refuse_status'] == 2) {
|
|
$val['warehousing_name'] = '已拒绝';
|
|
} else {
|
|
$val['warehousing_name'] = '未入库';
|
|
}
|
|
} else {
|
|
$val['warehousing_name'] = '已入库';
|
|
$val['warehouse_time'] = date('Y-m-d H:i:s', $val['warehouse_time']);
|
|
$val['real_money_total'] = round($val['real_money_total'], 2);
|
|
}
|
|
break;
|
|
case 2:
|
|
$val['warehousing_name'] = '拒绝';
|
|
break;
|
|
}
|
|
}
|
|
switch ($val['type']) {
|
|
case 0:
|
|
$val['goods_to_name'] = "";
|
|
$val['type_name'] = "其他出库";
|
|
break;
|
|
case 1:
|
|
$val['goods_to_name'] = '商户';
|
|
$val['type_name'] = "退货至商户出库";
|
|
break;
|
|
case 2:
|
|
$val['goods_to_name'] = "";
|
|
$val['type_name'] = "盘亏出库 ";
|
|
break;
|
|
case 3:
|
|
$val['goods_to_name'] = $StoreModel->getFindField(array('id' => $val['transfer_to_store_id']), "storetag");
|
|
$val['type_name'] = "调拨出库 ";
|
|
break;
|
|
case 9:
|
|
$val['goods_to_name'] = $SupplierModel->getFindField(array('id' => $val['supplier_id']), "supplier_name");
|
|
$val['type_name'] = '退货至供货商出库';
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return callBack(statusCode()['success'], '查询成功', [
|
|
'list' => $list ? $list : [],
|
|
'count' => $count ? $count : 0
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 门店查询出库单列表条件
|
|
* @param $parameter
|
|
* [
|
|
* merchant_id
|
|
* store_id
|
|
* order_number 出库订单号
|
|
* add_time 出库时间 web端
|
|
* start_time 出库单开始时间 移动端
|
|
* end_time 出库单结束时间 移动端
|
|
* type 出库类型 0其他出库 1向商户退货出库 2盘亏出库 3调拨出库 9向供货商退货出库
|
|
* supplier_id 供货商id
|
|
* warehousing_status 0未入库 1已入库
|
|
* operator_type 1后台 2收银端 3助手端
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function getStoreStockListTerm($parameter)
|
|
{
|
|
$order_number = $parameter['order_number'];
|
|
$add_time = $parameter['add_time'];
|
|
$start_time = $parameter['start_time'];
|
|
$end_time = $parameter['end_time'];
|
|
$type = $parameter['type'];
|
|
$supplier_id = $parameter['supplier_id'];
|
|
$warehousing_status = $parameter['warehousing_status'];
|
|
if (!empty($order_number)) {
|
|
$where['order_number'] = array('like', '%' . $order_number . '%');
|
|
}
|
|
switch ($parameter['operator_type']) {
|
|
case 1:
|
|
if (!empty($add_time)) {
|
|
if (!is_array($add_time)) {
|
|
$add_time = explode(',', $add_time);
|
|
}
|
|
$start_time = strtotime($add_time[0]);
|
|
$end_time = strtotime($add_time[1]);
|
|
$where['add_time'] = array('between', array($start_time, $end_time));
|
|
}
|
|
break;
|
|
case 3:
|
|
if (!empty($start_time) && !empty($end_time)) {
|
|
$start_time = strtotime($start_time . "00:00:00");
|
|
$end_time = strtotime($end_time . "23:59:59");
|
|
$where['add_time'] = array('between', array($start_time, $end_time));
|
|
} else if (!empty($start_time)) {
|
|
$where['add_time'] = array('gt', strtotime($start_time . "00:00:00"));
|
|
} else if (!empty($end_time)) {
|
|
$where['add_time'] = array('lt', strtotime($end_time . "23:59:59"));
|
|
}
|
|
break;
|
|
}
|
|
if ($type != '') {
|
|
$where['type'] = $type;
|
|
}
|
|
if ($warehousing_status != '') {
|
|
$where['warehousing_status'] = $warehousing_status;
|
|
}
|
|
if (!empty($supplier_id)) {
|
|
$where['supplier_id'] = $supplier_id;
|
|
}
|
|
$where['merchant_id'] = $parameter['merchant_id'];
|
|
$where['store_id'] = $parameter['store_id'];
|
|
$where['status'] = 1;
|
|
return $where;
|
|
}
|
|
} |