550 行
22 KiB
PHP
可执行文件
550 行
22 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\OutboundOrder;
|
||
use Common\Business\SaleGoods;
|
||
use Common\Business\SerialNumberGoods;
|
||
use Common\Model\SaleMGoodsModel;
|
||
use Common\Model\SaleWarehouseModel;
|
||
use Common\Model\StockOutGoodsModel;
|
||
use Common\Model\StockOutOrderModel;
|
||
use Common\Model\SWarehousingGoodsModel;
|
||
use Common\Model\WarehousingGoodsModel;
|
||
use Think\Controller;
|
||
use Common\Business\RefuseWarehousing;
|
||
|
||
//[1.7.90]
|
||
class StockOutOrderController extends BaseController
|
||
{
|
||
/*
|
||
* ***********************************************出库参数与方法*********************************************************
|
||
* @param $order_number 订单号
|
||
* @param $add_time 时间
|
||
*@param $warehouse_id 仓库id
|
||
* function Info 查询出库仓库映射方法
|
||
*/
|
||
/*
|
||
* ***********************************************查询信息*****************************************************
|
||
*/
|
||
/*
|
||
* 查询供货商与仓库
|
||
*/
|
||
private function Info($merchant_id)
|
||
{
|
||
$map['merchant_id'] = $merchant_id;
|
||
$map['status'] = 1;
|
||
$fields = "id,name";
|
||
$warehouse = D('SaleWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
|
||
$where = array(
|
||
'merchantid' => $merchant_id,
|
||
'state' => 0,
|
||
'supplier_type' => 1
|
||
);
|
||
$store = D('RetailStore')->getSelect($where, "id,storetag");
|
||
$wap['merchantid'] = $merchant_id;
|
||
$wap['status'] = 1;
|
||
$supplier = D("Supplier")->getSelect($wap, $page = '', $limit = '', "id,supplier_name");
|
||
$this->assign('warehouse', json_encode($warehouse)); //销售仓库
|
||
$this->assign('store', json_encode($store));
|
||
$this->assign("supplier", json_encode($supplier));
|
||
}
|
||
|
||
/*
|
||
* 商品分类
|
||
*/
|
||
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(
|
||
'exportOperation' => '/index.php/Retail/StockOutOrder/export',
|
||
'addStockOut' => '/index.php/Retail/StockOutOrder/addStockOut',
|
||
'OrderInfo' => '/index.php/Retail/StockOutOrder/details',
|
||
'warehousingInfo' => '/index.php/Retail/StockOutOrder/warehousingInfo',
|
||
'refuse_info' => '/index.php/Retail/StockOutOrder/refuseInfo'
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$user = session("merchant_userinfo");
|
||
$this->Info($user['id']);
|
||
$supplier = D("Supplier")->getSelect(array('merchantid' => $user['id'], 'status' => 1), $page = '', $limit = '', "id,supplier_name");
|
||
$this->assign('supplier', json_encode($supplier));
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//出库单列表
|
||
public function stockOrderList()
|
||
{
|
||
$content = I("post.");
|
||
$content['merchant_id'] = $this->merchant_id;
|
||
$content['operator_type'] = 1;
|
||
$outboundOrder = new OutboundOrder();
|
||
$result = $outboundOrder->getMerchantStockOrderList($content); //出库单列表
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//出库单金额统计
|
||
public function stockOrderTotal()
|
||
{
|
||
$content = I("post.");
|
||
$content['merchant_id'] = $this->merchant_id;
|
||
$content['user_type'] = 3;
|
||
$content['operator_type'] = 1;
|
||
$outboundOrder = new OutboundOrder();
|
||
$result = $outboundOrder->getStockOrderTotalMoney($content);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/*
|
||
* 新增出库单信息
|
||
*/
|
||
public function addStockOut()
|
||
{
|
||
$arr = array(
|
||
'goodsChoice' => '/index.php/Retail/StockOutOrder/goodsList',
|
||
'onSubmit' => '/index.php/Retail/StockOutOrder/StockOutOperation'
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$user = session("merchant_userinfo");
|
||
$this->Info($user['id']);
|
||
$this->goodsClass($user['id']);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//串号列表
|
||
public function serialList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->warehouseSerialList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//出库时仓库商品状态明细
|
||
public function goodsList()
|
||
{
|
||
$data = I('post.');
|
||
$data['operator_type'] = 1;
|
||
$data['user_type'] = 3;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$SaleGoodsClass = new SaleGoods();
|
||
$result = $SaleGoodsClass->warehouseSearchGoods($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/*
|
||
* 出库单详情
|
||
*/
|
||
public function details()
|
||
{
|
||
$arr = array(
|
||
'exportOperation' => '/index.php/Retail/StockOutOrder/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('StockOutOrder')->getFind($where);
|
||
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
|
||
$info['remarks'] = str_replace("\n", "", $info['remarks']);
|
||
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
|
||
switch ($type) {
|
||
case 0:
|
||
$stock_name = "其他出库";
|
||
$store_name = '';
|
||
break;
|
||
case 1:
|
||
$stock_name = "调拨出库";
|
||
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
|
||
break;
|
||
case 2:
|
||
$stock_name = "盘亏出库";
|
||
break;
|
||
case 3:
|
||
$stock_name = "申请调拨出库";
|
||
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
|
||
break;
|
||
case 4:
|
||
$stock_name = "退货出库";
|
||
$store_name = D("Supplier")->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('store_name', $store_name);
|
||
$this->assign('stock_name', $stock_name);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//出库记录串号列表
|
||
public function detailSerialList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$data['serial_type'] = 3;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->recordSerialList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//出库详情
|
||
public function detailsList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$OutboundOrderClass = new OutboundOrder();
|
||
$result = $OutboundOrderClass->detailList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/*
|
||
* 门店入库详情
|
||
*/
|
||
public function warehousingInfo()
|
||
{
|
||
$arr = array(
|
||
'exportOperation' => '/index.php/Retail/StockOutOrder/warehouseExport',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$id = I("get.id");
|
||
$warehouse_record_id = D('StockOutOrder')->getFindField(array('id' => $id), "warehouse_record_id");
|
||
$storeWarehouseInfo = D('SWarehousingRecord')->getFind(array('id' => $warehouse_record_id));
|
||
$storeWarehouseInfo['add_time'] = date('Y-m-d H:i:s', $storeWarehouseInfo['add_time']);
|
||
$storeWarehouseInfo['remarks'] = str_replace("\n", "", $storeWarehouseInfo['remarks']);
|
||
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $storeWarehouseInfo['warehouse_id']), "name");
|
||
$store_name = D('Store')->getStoreName(array('id' => $storeWarehouseInfo['store_id']));
|
||
$this->assign('info', $storeWarehouseInfo);
|
||
$this->assign('warehouse', $warehouse);
|
||
$this->assign('store_name', $store_name);
|
||
$this->assign('id', $warehouse_record_id);
|
||
$this->assign('stock_id', $id);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//调拨出库的入库详情的串号列表
|
||
public function warehousingSerial()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 4;
|
||
$data['serial_type'] = 2;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->recordSerialList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//调拨出库的入库详情
|
||
public function warehousingList()
|
||
{
|
||
$id = I("post.id");
|
||
$SWarehousingGoodsModel = new SWarehousingGoodsModel();
|
||
$goodsList = $SWarehousingGoodsModel->getSelect(array('warehouse_record_id' => $id));
|
||
if (!empty($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;
|
||
if (!empty($val['build_date'])) {
|
||
$val['build_date'] = date('Y-m-d', $val['build_date']);
|
||
}
|
||
$val['sku_num'] = round($val['sku_num'], 3);
|
||
$val['warehouse_num'] = round($val['warehouse_num'], 3);
|
||
$val['warehouse_price'] = round($val['warehouse_price'], 2);
|
||
$val['subtotal'] = round($val['subtotal'], 2);
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['data'] = $goodsList;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//拒收详情页
|
||
public function refuseInfo()
|
||
{
|
||
$arr = array(
|
||
'exportOperation' => '/index.php/Retail/StockOutOrder/refuseLisExport',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$id = I("get.id");
|
||
$refuseInfo = new RefuseWarehousing();
|
||
$info = $refuseInfo->merchantStockOrderRefuseInfo($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, 1);
|
||
$result = ['status' => 1, 'message' => '查询成功', 'data' => ['list' => $list]];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/*
|
||
* *************************************************操作******************************************************
|
||
*/
|
||
//出库提交
|
||
public function StockOutOperation()
|
||
{
|
||
$data = I("post.");
|
||
$data['operator_id'] = session("jurisdiction_user")['id'];
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$res = A("Api/Inventory")->MerStockOut($data);
|
||
if ($res['status'] == 1) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '出库单-新增';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
|
||
//商品出库明细库存减少(已作废)
|
||
public function WarehouseReduce($where, $total_num)
|
||
{
|
||
$ware_goods = D('WarehousingGoods')->getSelect($where, $page = '', $limit = '', "id,surplus_num", "id asc");
|
||
if ($ware_goods) {
|
||
$stock_arr = array();
|
||
foreach ($ware_goods as $k => &$v) {
|
||
$ware_push = array();
|
||
if ($v['surplus_num'] >= $total_num) {
|
||
$ware_push['id'] = $v['id'];
|
||
$ware_push['num'] = $total_num;
|
||
array_push($stock_arr, $ware_push);
|
||
break;
|
||
} else {
|
||
$ware_push['id'] = $v['id'];
|
||
$ware_push['num'] = $v['surplus_num'];
|
||
array_push($stock_arr, $ware_push);
|
||
$total_num = round($total_num - $v['surplus_num'], 3);
|
||
}
|
||
}
|
||
if ($stock_arr) {
|
||
foreach ($stock_arr as $tkey => &$tval) {
|
||
D('WarehousingGoods')->updateSetDec(array('id' => $tval['id']), "surplus_num", $tval['num']);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//导出
|
||
public function export()
|
||
{
|
||
$content = I("get.");
|
||
$content['merchant_id'] = $this->merchant_id;
|
||
$content['operator_type'] = 1; //web端
|
||
$outboundOrder = new OutboundOrder();
|
||
$result = $outboundOrder->getMerchantStockOrderList($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('store_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('StockOutOrder')->getFind($where);
|
||
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
|
||
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
|
||
switch ($type) {
|
||
case 0:
|
||
$stock_name = "其他出库";
|
||
break;
|
||
case 1:
|
||
$stock_name = "调拨出库";
|
||
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
|
||
break;
|
||
case 2:
|
||
$stock_name = "盘亏出库";
|
||
break;
|
||
case 3:
|
||
$stock_name = "申请调拨出库";
|
||
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
|
||
break;
|
||
case 4:
|
||
$stock_name = "退货出库";
|
||
$store_name = D("Supplier")->getFindField(array('id' => $info['supplier_id']), "supplier_name");
|
||
break;
|
||
}
|
||
$store_name = $store_name ? $store_name : "";
|
||
$map['stock_out_id'] = $id;
|
||
$detailsList = D('StockOutGoods')->getSelect($map, $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));
|
||
$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 (!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'];
|
||
}
|
||
}
|
||
}
|
||
$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());
|
||
$str[1] = '出库单号:' . $info['order_number'] . " 出货仓库:" . $warehouse . " 类型:" . $stock_name;
|
||
if ($type == 1 || $type == 3 || $type == 4) {
|
||
$str[2] = '货至:' . $store_name . " 出库时间:" . $info['add_time'] . " 合计:" . $info['goods_species'] . " 金额:" . strval($info['money_total']);
|
||
} else {
|
||
$str[2] = "出库时间:" . $info['add_time'] . " 合计:" . $info['goods_species'] . " 金额:" . strval($info['money_total']);
|
||
}
|
||
$str[3] = "备注:" . $info['remarks'];
|
||
detailGetExcel($fileds_name, $arr, $detailsList, $str);
|
||
}
|
||
|
||
//门店入库详情导出
|
||
public function warehouseExport()
|
||
{
|
||
$id = I("get.id");
|
||
$storeWarehouseInfo = D('SWarehousingRecord')->getFind(array('id' => $id));
|
||
$storeWarehouseInfo['add_time'] = date('Y-m-d H:i:s', $storeWarehouseInfo['add_time']);
|
||
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $storeWarehouseInfo['warehouse_id']), "name");
|
||
$store_name = D('Store')->getStoreName(array('id' => $storeWarehouseInfo['store_id']));
|
||
$goodsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $storeWarehouseInfo['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;
|
||
if (!empty($val['build_date'])) {
|
||
$val['build_date'] = date('Y-m-d', $val['build_date']);
|
||
}
|
||
$val['sku_num'] = strval(round($val['sku_num'], 3));
|
||
$val['warehouse_num'] = strval(round($val['warehouse_num'], 3));
|
||
$val['warehouse_price'] = strval(round($val['warehouse_price'], 2));
|
||
$val['subtotal'] = strval(round($val['subtotal'], 2));
|
||
}
|
||
}
|
||
$fileds_name = "出库单详情导出";
|
||
$arr = array(
|
||
array('index', '序号'),
|
||
array('goods_name', '商品名称'),
|
||
array('sku_name', '规格'),
|
||
array('goods_number', '货号'),
|
||
array('goods_code', '条码'),
|
||
array('company', '单位'),
|
||
array('build_date', '生产日期'),
|
||
array('quality_guarantee_period', '保质期'),
|
||
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] = '入库单号:' . $storeWarehouseInfo['order_number'] . " 门店:" . $store_name . " 入库仓库:" . $warehouse;
|
||
$str[2] = '入库时间:' . $storeWarehouseInfo['add_time'] . " 合计:" . $storeWarehouseInfo['real_goods_species'] . " 金额:" . strval($storeWarehouseInfo['real_money_total']);
|
||
$str[3] = "备注:" . $storeWarehouseInfo['remarks'];
|
||
detailGetExcel($fileds_name, $arr, $goodsList, $str);
|
||
}
|
||
|
||
/**
|
||
* 拒收商品信息导出
|
||
*/
|
||
public function refuseLisExport()
|
||
{
|
||
$id = I("get.id");
|
||
$refuse = new RefuseWarehousing();
|
||
$refuse->merchantRefuseInfoExport($id, 1);
|
||
}
|
||
} |