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

672 行
28 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\OutboundOrder;
use Common\Business\RefuseWarehousing;
use Common\Business\SaleGoods;
use Common\Business\SerialNumberGoods;
use Common\Business\StockRecord;
use Common\Model\RetailStoreModel;
use Common\Model\SSaleMGoodsModel;
use Common\Model\SStockGoodsSerialModel;
use Common\Model\SStockOutGoodsModel;
use Common\Model\SStockOutOrderModel;
use Common\Model\SWarehouseGoodsSerialModel;
use Common\Model\SWarehousingGoodsModel;
use Think\Controller;
//[1.7.90]
class SStockOutOrderController extends BaseController
{
/*
* ***********************************************出库参数与方法*********************************************************
* @param $order_number 订单号
* @param $add_time 时间
*@param $warehouse_id 仓库id
* function Info 查询出库仓库映射方法
*/
/*
* ***********************************************查询信息*****************************************************
*/
/*
* 查询与仓库
*/
private function Info($merchant_id, $store_id)
{
$map['merchant_id'] = $merchant_id;
$map['status'] = 1;
$map['store_id'] = $store_id;
$fields = "id,name";
$warehouse = D('SSaleWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
$this->assign('warehouse', json_encode($warehouse));
}
/*
* 商品分类
*/
private function goodsClass($merchant_id)
{
$class_name = M('retail_goods_class')->where(array('merchantid' => $merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
$this->assign('goodsClass1', json_encode($class_name));
}
/*
* 出单信息
*/
public function index()
{
$arr = array(
'addStockOut' => '/index.php/Retail/SStockOutOrder/addStockOut',
'exportOperation' => '/index.php/Retail/SStockOutOrder/export',
'OrderInfo' => '/index.php/Retail/SStockOutOrder/details',
'warehouseInfo' => '/index.php/Retail/SStockOutOrder/warehouseInfo',
'refuseInfo' => '/index.php/Retail/SStockOutOrder/refuseInfo'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$store_id = session("storeid");
$this->Info($user['merchantid'], $store_id);
$supplier = D("SSupplier")->getSelect(array('merchant_id' => $user['merchantid'], 'store_id' => $store_id, 'status' => 1), $page = '', $limit = '', "id,supplier_name");
$this->assign('supplier', json_encode($supplier));
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//出库单列表
public function stockOrderList()
{
$content = I("post.");
$content['merchant_id'] = $this->merchant_id;
$content['store_id'] = $this->store_id;
$content['operator_type'] = 1;
$outboundOrder = new OutboundOrder();
$result = $outboundOrder->getStoreStockOrderList($content); //获取列表
$this->ajaxReturn($result);
}
//出库单金额统计
public function stockOrderTotal()
{
$content = I("post.");
$content['merchant_id'] = $this->merchant_id;
$content['store_id'] = $this->store_id;
$content['operator_type'] = 1;
$content['user_type'] = 4;
$outboundOrder = new OutboundOrder();
$result = $outboundOrder->getStockOrderTotalMoney($content); //出库金额统计列表
$this->ajaxReturn($result);
}
/*
* 新增出库单信息
*/
public function addStockOut()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/SStockOutOrder/goodsList',
'onSubmit' => '/index.php/Retail/SStockOutOrder/StockOutOperation'
);
$authArr = checkFunction($arr);
$store_id = $this->store_id;
$id = I('get.stock_order_id'); //出库单id
$this->goodsClass($this->merchant_id); //分类查询
if (!empty($id)) {
$type = 3; //调拨出库
$store_status = true;
$SStockOutOrderModel = new SStockOutOrderModel();
$StockOrderInfo = $SStockOutOrderModel->getFieldInfo(array('id' => $id), "transfer_to_store_id,order_number");
$transfer_to_store_id = $StockOrderInfo['transfer_to_store_id'];
$order_number = $StockOrderInfo['order_number'];
$StoreModel = new RetailStoreModel();
$store = $StoreModel->getSelect(array('id' => $transfer_to_store_id));
//门店间调拨审核拒绝继续调拨
$SStockOutGoodsModel = new SStockOutGoodsModel();
$goodsList = $SStockOutGoodsModel->getSelect(array('stock_out_id' => $id), '', '', "*", 'id asc');
if (!empty($goodsList)) {
$SSaleMGoodsModel = new SSaleMGoodsModel();
$SStockGoodsSerialModel = new SStockGoodsSerialModel();
$SWarehouseGoodsSerialModel = new SWarehouseGoodsSerialModel();
foreach ($goodsList as $key => &$val) {
$val['index'] = $key + 1;
$val['stock_id'] = $val['id'];
$goods_info = $SSaleMGoodsModel->getFieldInfo(array('goods_id' => $val['goods_id'], 'sku_id' => $val['sku_id']), "goods_num,id");
$val['id'] = $goods_info['id'];
$val['goods_num'] = round($goods_info['goods_num'], 3);
$val['output_num'] = round($val['stock_num'], 3);
//串号信息
if ($val['serial_number_state'] == 1) {
$serialList = $SStockGoodsSerialModel->getSelect([
'outside_id' => $val['id']
], '', '', 'main_serial_number,auxiliary_serial_number_one,auxiliary_serial_number_two');
if (!empty($serialList)) {
foreach ($serialList as &$v) {
$where = [
'store_id' => $store_id,
'merchant_id' => $this->merchant_id,
'goods_id' => $val['goods_id'],
'main_serial_number' => $v['main_serial_number'],
'num' => ['gt', 0]
];
if ($val['sku_id']) {
$where['sku_id'] = $val['sku_id'];
}
$v['id'] = $SWarehouseGoodsSerialModel->basisOrderGetFindField($where, 'id', 'id desc');
}
$val['serial_list'] = $serialList;
}
}
}
}
} else {
$store_map = array(
'merchantid' => $this->merchant_id,
'state' => 0,
'id' => array('neq', $store_id),
'supplier_type' => 1
);
$store = D('RetailStore')->getSelect($store_map);
}
//供货商
$supplier = D("SSupplier")->getSelect(array('store_id' => $store_id, 'status' => 1), $page = '', $limit = '', "id,supplier_name");
$goodsList = $goodsList ? $goodsList : array(); //出库单商品明细
$id = $id ? $id : 0; //出库单id
$order_number = $order_number ? $order_number : ""; //出库订单号
$type = $type ? $type : ''; //出库类型
$store_status = $store_status ? $store_status : false; //门店显示
$transfer_to_store_id = $transfer_to_store_id ? $transfer_to_store_id : ""; //调拨的目标门店id
$this->assign('authArr', $authArr);
$this->assign('id', $id);
$this->assign('order_number', $order_number);
$this->assign('type', $type);
$this->assign('store_status', $store_status);
$this->assign('transfer_to_store_id', $transfer_to_store_id);
$this->assign("goodsList", json_encode($goodsList));
$this->assign('store', json_encode($store));
$this->assign("supplier", json_encode($supplier));
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->display();
}
//出库页面数据初始化
public function addStockOutInitial()
{
$StockRecordClass = new StockRecord();
$result = $StockRecordClass->addStockOutInitial([
'store_id' => $this->store_id
]);
$this->ajaxReturn($result);
}
//串号列表
public function serialList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->warehouseSerialList($data);
$this->ajaxReturn($result);
}
//出库时仓库商品状态明细
public function goodsList()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$SaleGoodsClass = new SaleGoods();
$result = $SaleGoodsClass->warehouseSearchGoods($data);
$this->ajaxReturn($result);
}
/*
* 出库单详情
*/
public function details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SStockOutOrder/detailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
$type = I("get.type");
$operator = I('get.operator');
$this->assign('operator', $operator);
$where['id'] = $id;
$info = D('SStockOutOrder')->getFind($where);
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
switch ($type) {
case 0:
$stock_name = "其他出库";
break;
case 1:
$stock_name = "退货至商户出库";
break;
case 2:
$stock_name = "盘亏出库";
break;
case 3:
$stock_name = "调拨出库";
$store_name = D('Store')->getStoreName(array('id' => $info['transfer_to_store_id']));
break;
case 9:
$stock_name = "退货至供货商出库";
$store_name = D("SSupplier")->getFindField(array('id' => $info['supplier_id']), "supplier_name");
break;
}
$store_name = $store_name ? $store_name : "";
$this->assign('id', $id);
$this->assign('type', $type);
$this->assign('info', $info);
$this->assign('warehouse', $warehouse);
$this->assign('stock_name', $stock_name);
$this->assign('store_name', $store_name);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//出库记录串号列表
public function detailSerialList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['serial_type'] = 3;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//出库详情
public function detailsList()
{
$data = I('post.');
$data['user_type'] = 4;
$OutboundOrderClass = new OutboundOrder();
$result = $OutboundOrderClass->detailList($data);
$this->ajaxReturn($result);
}
/*
* 商户入库详情
*/
public function warehouseInfo()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SStockOutOrder/warehouseInfoExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I("get.id");
$type = I("get.type");
$goods_to_name = I("get.goods_to_name");
$transfer_to_store_id = I('get.transfer_to_store_id');
$m_warehouse_id = D('SStockOutGoods')->getFindField(array('stock_out_id' => $id), "warehouse_record_id");
if ($type == 1) {
//商户入库
$mWarehouseInfo = D('WarehousingRecord')->getFind(array('id' => $m_warehouse_id));
$mWarehouseInfo['add_time'] = date('Y-m-d H:i:s', $mWarehouseInfo['add_time']);
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $mWarehouseInfo['warehouse_id']), "name");
} else if ($type == 3) {
//门店入库
$mWarehouseInfo = D('SWarehousingRecord')->getFind(array('id' => $m_warehouse_id));
$mWarehouseInfo['add_time'] = date('Y-m-d H:i:s', $mWarehouseInfo['add_time']);
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $mWarehouseInfo['warehouse_id']), "name");
}
$mWarehouseInfo['remarks'] = str_replace("\n", "", $mWarehouseInfo['remarks']);
$this->assign('info', $mWarehouseInfo);
$this->assign('goods_to_name', $goods_to_name);
$this->assign('warehouse', $warehouse);
$this->assign('id', $m_warehouse_id);
$this->assign('stock_id', $id);
$this->assign('type', $type);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//调拨出库的入库详情的串号列表
public function warehousingSerial()
{
$data = I('post.');
if ($data['type'] == 1) {
$data['user_type'] = 3;
} else {
$data['user_type'] = 4;
}
unset($data['type']);
$data['serial_type'] = 2;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
public function WarehouseInfoList()
{
$id = I("post.id");
$type = I("post.type");
if ($type == 1) {
//商户入库
$goodsList = D('WarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
} else if ($type == 3) {
//门店入库
$goodsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
}
$StockRecordClass = new StockRecord();
$stateResult = $StockRecordClass->addStockOutInitial([
'store_id' => $this->store_id
]);
$cost_price_state = $stateResult['data'];
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
$val['index'] = $key + 1;
$val['sku_num'] = round($val['sku_num'], 3);
$val['warehouse_num'] = round($val['warehouse_num'], 3);
if ($cost_price_state == 2) {
$val['warehouse_price'] = '***';
} else {
$val['warehouse_price'] = round($val['warehouse_price'], 2);
}
$val['subtotal'] = round($val['subtotal'], 2);
}
}
$res['status'] = 1;
$res['data'] = $goodsList;
$this->ajaxReturn($res);
}
/*
* *************************************************操作******************************************************
*/
/*门店出库操作
* @param $merchant_id 商户id
* @param $store_id 门店id
* @param $operator_id 操作人id
* @param $user_type 1商户 2门店 3收银员
* @param $warehouse_id 出库仓库id
* @param $remarks 备注
* @param $type 0其他出库 1向商户退货出库 2盘亏出库 3调拨出库
* @param $goodsList 出库商品
* @param $transfer_id 调拨至目标门店id
*/
public function StockOutOperation()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['operator_id'] = session("jurisdiction_user")['id'];
$result = A('Api/Inventory')->stockOut($data);
if ($result['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '出库单-新增';//操作行为描述
action_log($source, $type, $request_data, $desc);
}
$this->ajaxReturn($result);
}
//导出
public function export()
{
$content = I("get.");
$content['merchant_id'] = session("ls_userinfo")['merchantid'];
$content['store_id'] = session("storeid");
$content['operator_type'] = 1; //web端
$outboundOrder = new OutboundOrder();
$result = $outboundOrder->getStoreStockOrderList($content);
$fileds_name = "出库单导出";
$arr = array(
array('index', '序号'),
array('operator', '操作人'),
array('add_time', '出库时间'),
array('warehouse_time', '入库时间'),
array('order_number', '出库单号'),
array('warehouse_name', '出库仓库'),
array('type_name', '出库类型'),
array('goods_to_name', '货至'),
array('goods_species', '出库商品种数'),
array('total_cost_price', '出库成本价'),
array('money_total', '出库价'),
array('real_goods_species', '实收商品种数'),
array('real_total_cost_money', '实收成本价'),
array('real_money_total', '实收金额'),
array('difference_money', '实收盈亏金额'),
array('refuse_goods_species', '拒收商品种数'),
array('refuse_total_cost_money', '拒收成本价'),
array('refuse_total_stock_money', '拒收出库价'),
array('remarks', '备注'),
array('warehousing_name', '货至状态'),
);
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
getExcel($fileds_name, $arr, $result['data']['list'], $str);
}
//出库导出
public function detailsExport()
{
$id = I('get.id');
$type = I("get.type");
$where['id'] = $id;
$info = D('SStockOutOrder')->getFind($where);
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
switch ($type) {
case 0:
$stock_name = "其他出库";
break;
case 1:
$stock_name = "退货至商户出库";
break;
case 2:
$stock_name = "盘亏出库";
break;
case 3:
$stock_name = "调拨出库";
$store_name = D('Store')->getStoreName(array('id' => $info['transfer_to_store_id']));
break;
case 9:
$stock_name = "退货至供货商出库";
$store_name = D("SSupplier")->getFindField(array('id' => $info['supplier_id']), "supplier_name");
break;
}
$store_name = $store_name ? $store_name : "";
$where = array();
$where['stock_out_id'] = $id;
$detailsList = D('SStockOutGoods')->getSelect($where, $page = '', $limit = '', $fields = '', 'id asc');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
$val['stock_num'] = strval(round($val['stock_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['stock_price'] = "***";
$val['subtotal'] = "***";
} else {
$val['stock_price'] = strval(round($val['stock_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
$val['sku_num'] = strval(round($val['sku_num'], 3));
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
$val['build_date'] = $val['build_date'] ? date('Y-m-d', $val['build_date']) : '';
}
}
if (self::$showPrice == 2 && self::$identity == 2) {
$info['money_total'] = "***";
}
$fileds_name = "出库详情导出";
$arr = array(
array('index', '序号'),
array('goods_name', '商品名称'),
array('sku_name', '规格'),
array('goods_number', '货号'),
array('goods_code', '条码'),
array('company', '单位'),
array('sku_num', '规格基数'),
array('build_date', '生产日期'),
array('quality_guarantee_period', '保质期'),
array('stock_price', '出库价'),
array('stock_num', '数量'),
array('subtotal', '合计'),
array('remarks', '备注'),
);
$str = array();
$str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
if ($type == 3 || $type == 9) {
$str[1] = '出库单号:' . $info['order_number'] . ' 出货仓库:' . $warehouse . " 类型:" . $stock_name . " 货至:" . $store_name;
} else {
$str[1] = '出库单号:' . $info['order_number'] . " 出货仓库:" . $warehouse . " 类型:" . $stock_name;
}
$str[2] = '出库时间:' . $info['add_time'] . " 合计:" . $info['goods_species'] . "种" . " 金额:" . strval($info['money_total']);
$str[3] = "备注:" . $info['remarks'];
detailGetExcel($fileds_name, $arr, $detailsList, $str);
}
//导出
public function warehouseInfoExport()
{
$id = I("get.id");
$type = I("get.type");
if ($type == 1) {
//退货出库
$mWarehouseInfo = D('WarehousingRecord')->getFind(array('id' => $id));
$mWarehouseInfo['add_time'] = date('Y-m-d H:i:s', $mWarehouseInfo['add_time']);
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $mWarehouseInfo['warehouse_id']), "name");
} else if ($type == 3) {
//调拨出库
$mWarehouseInfo = D('SWarehousingRecord')->getFind(array('id' => $id));
$mWarehouseInfo['add_time'] = date('Y-m-d H:i:s', $mWarehouseInfo['add_time']);
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $mWarehouseInfo['warehouse_id']), "name");
}
if ($type == 1) {
//退货出库
$goodsList = D('WarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
} else if ($type == 3) {
//调拨出库
$goodsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
}
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
$val['index'] = $key + 1;
$val['sku_num'] = strval(round($val['sku_num'], 3));
$val['warehouse_num'] = strval(round($val['warehouse_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['warehouse_price'] = "***";
$val['subtotal'] = "***";
} else {
$val['warehouse_price'] = strval(round($val['warehouse_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
}
}
if (self::$showPrice == 2 && self::$identity == 2) {
$mWarehouseInfo['real_money_total'] = "***";
}
$fileds_name = "入库详情导出";
$arr = array(
array('index', '序号'),
array('goods_name', '商品名称'),
array('sku_name', '规格'),
array('goods_number', '货号'),
array('goods_code', '条码'),
array('company', '单位'),
array('sku_num', '规格基数'),
array('warehouse_price', '入库价'),
array('warehouse_num', '数量'),
array('subtotal', '合计'),
array('remarks', '备注'),
);
$str = array();
$str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
$str[1] = '入库单号:' . $mWarehouseInfo['order_number'] . " 入库仓库:" . $warehouse . " 入库时间:" . $mWarehouseInfo['add_time'];
$str[2] = "合计:" . $mWarehouseInfo['real_goods_species'] . "种" . " 金额:" . strval($mWarehouseInfo['real_money_total']);
$str[3] = "备注:" . $mWarehouseInfo['remarks'];
detailGetExcel($fileds_name, $arr, $goodsList, $str);
}
//拒收详情
public function refuseInfo()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SStockOutOrder/refuseLisExport',
);
$authArr = checkFunction($arr);
$id = I("get.id");
$refuseInfo = new RefuseWarehousing();
$info = $refuseInfo->storeStockOrderRefuseInfo($id); //拒收详情
$this->assign('authArr', $authArr);
$this->assign('global_store_jurisdiction', session("identity"));
$this->assign('identity', session("global_store_jurisdiction"));
$this->assign('id', $id);
$this->assign('info', $info);
$this->display();
}
//拒收商品的串号列表
public function refuseSerial()
{
$data = I('post.');
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->refuseSerialList($data);
$this->ajaxReturn($result);
}
//拒收列表
public function refuseList()
{
$id = I("post.id");
$refuse = new RefuseWarehousing();
$list = $refuse->refuseOrderList($id, 2);
$result = ['status' => 1, 'message' => '查询成功', 'data' => ['list' => $list]];
$this->ajaxReturn($result);
}
//拒收导出
public function refuseLisExport()
{
$id = I("get.id");
$refuse = new RefuseWarehousing();
$refuse->merchantRefuseInfoExport($id, 2);
}
}