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

576 行
22 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\PurchaseGoodsInfo;
use Common\Business\SaleGoods;
use Common\Business\SerialNumberGoods;
use Common\Business\Warehouse;
use Common\Business\WarehouseOperation;
use Common\Business\WarehousingRecord;
use Common\Model\SStockOutGoodsModel;
use Think\Controller;
//[1.7.90]
class WarehousingRecordController extends BaseController
{
/*
* ***********************************************入库参数与方法*********************************************************
* @param $order_number 订单号
* @param $add_time 时间
* @param $supplier_id 供货商id
* @param $warehouse_id 仓库id
*
* function Info 查询供货商与入库仓库映射方法
*/
/*
* ***********************************************查询信息*****************************************************
*/
/*
* 查询供货商与仓库
*/
private function Info($merchant_id)
{
$where['merchantid'] = $merchant_id;
$where['status'] = 1;
$supplier = M('retail_supplier')->field("id,supplier_name")->where($where)->order('id desc')->select();
$map['merchant_id'] = $merchant_id;
$map['status'] = 1;
$fields = "id,name";
$purchase_warehouse = D('PurchaseWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
$this->assign('supplier', json_encode($supplier)); //供货商
$this->assign('purchase_warehouse', json_encode($purchase_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(
'exportOperation' => '/index.php/Retail/WarehousingRecord/export',
'addWarehousing' => '/index.php/Retail/WarehousingRecord/addWarehousing',
'retreatInfo' => '/index.php/Retail/WarehousingRecord/retreatDetails',
'retreat' => '/index.php/Retail/WarehousingRecord/retreat',
'OrderInfo' => '/index.php/Retail/WarehousingRecord/details'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("merchant_userinfo");
$this->Info($user['id']);
$this->display();
}
//入库单列表
public function WarehousingRecordList()
{
$content = I("post.");
$content['merchant_id'] = $this->merchant_id;
$content['operator_type'] = 1;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getMerchantWarehousingOrderList($content);
$this->ajaxReturn($result);
}
/*
* 新增入库单信息
*/
public function addWarehousing()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/WarehousingRecord/goodsList',
'onSubmit' => '/index.php/Retail/WarehousingRecord/WarehouseOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("merchant_userinfo");
$this->Info($user['id']);
$this->goodsClass($user['id']);
$order_number = I('get.order_number'); //采购订单号
$supplier_id = I('get.supplier_id'); //供货商id
if (!empty($order_number) && !empty($supplier_id)) {
$this->assign('order_number', $order_number);
$this->assign('supplier_id', $supplier_id);
$this->assign('type', 1);
$this->assign('source_type', 1);
}
$this->display();
}
//采购入库的串号信息
public function serialList()
{
$data = I('post.');
$data['user_type'] = 3;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->returnableSerialList($data);
$this->ajaxReturn($result);
}
//采购入库的商品列表goodsList
public function goodsList()
{
$data = I('post.');
$data['user_type'] = 3;
$data['merchant_id'] = $this->merchant_id;
$PurchaseClass = new PurchaseGoodsInfo();
$result = $PurchaseClass->warehousePurchaseGoodsList($data);
$this->ajaxReturn($result);
}
//其他入库串号验证
public function serialVerify()
{
$data = I('post.');
$data['user_type'] = 3;
$data['merchant_id'] = $this->merchant_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->singleGoodsVerify($data);
$this->ajaxReturn($result);
}
//其他入库选择的商品列表
public function otherList()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 3;
$data['merchant_id'] = $this->merchant_id;
$SaleClass = new SaleGoods();
$result = $SaleClass->otherGoodsList($data);
$this->ajaxReturn($result);
}
/*
* 退货入库详情
*/
public function retreatDetails()
{
$arr = array(
'exportOperation' => '/index.php/Retail/WarehousingRecord/retreaDetailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
$operator = I('get.operator');
$this->assign('operator', $operator);
$where['id'] = $id;
$info = D('WarehousingRecord')->getFind($where);
//门店退货详情
$info['add_time'] = date('Y-m-d H:i:s', $info['retreat_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
$warehouse_id = D('SStockOutOrder')->getFindField(array('id' => $info['stock_out_id'], 'type' => 1), "warehouse_id");
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $warehouse_id), "name");
$this->assign('id', $id);
$this->assign('info', $info);
$this->assign('store_name', $store_name);
$this->assign('warehouse', $warehouse);
$this->display();
}
//退货详情串号列表
public function retreatDetailsSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$data['serial_type'] = 3;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//退货详情
public function retreatDetailsList()
{
$id = I("post.id");
$where['warehouse_record_id'] = $id;
$where['type'] = 1;
$SStockOutGoodsModel = new SStockOutGoodsModel();
$list = $SStockOutGoodsModel->getSelect($where);
if (!empty($list)) {
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
$val['sku_num'] = round($val['sku_num'], 3);
$val['warehouse_num'] = round($val['stock_num'], 3);
$val['warehouse_price'] = round($val['stock_price'], 2);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
}
$res['data'] = $list;
$res['status'] = 1;
$this->ajaxReturn($res);
}
/*
* 门店退货的商品入库
*/
public function retreat()
{
$arr = array(
'onSubmit' => '/index.php/Retail/WarehousingRecord/retreatOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
$where['id'] = $id;
$info = D('WarehousingRecord')->getFind($where);
$info['add_time'] = date('Y-m-d H:i:s', $info['retreat_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
//门店退货详情
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
$warehouse = D('SaleWarehouse')->getFind(array('id' => $info['warehouse_id']));
$this->assign('id', $id);
$this->assign('info', $info);
$this->assign('warehouse', $warehouse);
$this->assign('store_name', $store_name);
$this->display();
}
//门店退货详情
public function retreatGoodsList()
{
$id = I("post.id");
$where['warehouse_record_id'] = $id;
$where['type'] = 1;
$SStockOutGoodsModel = new SStockOutGoodsModel();
$SerialClass = new SerialNumberGoods();
$list = $SStockOutGoodsModel->getSelect($where);
if (!empty($list)) {
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
$val['sku_num'] = round($val['sku_num'], 3);
$val['stock_num'] = round($val['stock_num'], 3);
$val['warehouse_num'] = round($val['stock_num'], 3);
$val['warehouse_price'] = round($val['stock_price'], 2);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
//串号信息
if($val['serial_number_state'] == 1){
$result = $SerialClass->recordSerialList([
'user_type'=>4,
'serial_type'=>3,
'id'=>$val['id']
]);
$val['serial_list'] = $result['data']['list'];
}
}
}
$res['status'] = 1;
$res['data'] = $list;
$this->ajaxReturn($res);
}
//入库详情
public function details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/WarehousingRecord/detailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I("get.id");
$type = I("get.type");
$operator = I('get.operator');
$supplier_id = I('get.supplier_id');
$this->assign('operator', $operator);
$this->assign('supplier_id', $supplier_id);
$where['id'] = $id;
$info = D('WarehousingRecord')->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 = "其他入库";
break;
case 1:
$stock_name = "采购入库";
break;
case 2:
$stock_name = "补货入库";
break;
case 3:
$stock_name = "盘盈入库";
break;
case 4:
$stock_name = "退货入库";
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
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->display();
}
//入库详情串号列表
public function detailSerialList()
{
$data = I('post.');
$data['user_type'] = 3;
$data['serial_type'] = 2;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
public function DetailsList()
{
$id = I("post.id");
$goodsList = D('WarehousingGoods')->getSelect(array('warehouse_record_id' => $id), $page = '', $limit = '', $fields = '', 'id asc');
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
$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);
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
}
}
$res['status'] = 1;
$res['data'] = $goodsList;
$this->ajaxReturn($res);
}
/*
* *************************************************操作******************************************************
*/
//入库提交
public function WarehouseOperation()
{
$data = I('post.');
$data['merchant_id'] = $this->merchant_id;
$data['operator_id'] = session("jurisdiction_user")['id'];
if ($data['type'] == 1) {
$data['stock'] = 1;
}
$res = A('Api/Inventory')->MerWarehousing($data);
if ($res['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0 后台 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
if ($data['stock'] == 1) {
$desc = '入库单-新增采购入库';//操作行为描述
} else {
$desc = '入库单-新增其他入库';//操作行为描述
}
action_log($source, $type, $request_data, $desc);
}
$this->ajaxReturn($res);
}
//门店退货入库
public function retreatOperation()
{
$data = I('post.');
$data['merchant_id'] = $this->merchant_id;
$data['operator_id'] = session("jurisdiction_user")['id'];
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $data['merchant_id'] . "_warehousing_id_" . $data['id'];
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $data['id']);
}
$WarehouseClass = new WarehouseOperation();
$result = $WarehouseClass->retreatWarehousing($data);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($result);
}
//导出
public function export()
{
$content = I("get.");
$content['merchant_id'] = $this->merchant_id;
$content['operator_type'] = 1;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getMerchantWarehousingOrderList($content);
$fileds_name = "入库单导出";
$arr = array(
array('index', '序号'),
array('operator', '操作人'),
array('add_time', '入库时间'),
array('order_number', '入库单号'),
array('supplier_name', '供应商'),
array('warehouse_name', '入库仓库'),
array('type_name', '入库类型'),
array('goods_species', '应收合计(种)'),
array('money_total', '应收金额'),
array('real_goods_species', '实收合计(种)'),
array('real_money_total', '实收金额'),
array('remarks', '备注'),
array('status_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('WarehousingRecord')->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 = "采购入库";
break;
case 2:
$stock_name = "补货入库";
break;
case 3:
$stock_name = "盘盈入库";
break;
case 4:
$stock_name = "退货入库";
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
break;
}
$goodsList = D('WarehousingGoods')->getSelect(array('warehouse_record_id' => $id), $page = '', $limit = '', $fileds = '', 'id asc');
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
$val['index'] = $key + 1;
$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));
if (!empty($val['build_date'])) {
$val['build_date'] = date('Y-m-d', $val['build_date']);
}
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
}
}
$store_name = $store_name ? $store_name : "";
$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());
if ($type == 4) {
$str[1] = '退货门店:' . $store_name . ' 入库单号:' . $info['order_number'] . " 入库仓库:" . $warehouse . " 入库时间:" . $info['add_time'];
} else {
$str[1] = '入库单号:' . $info['order_number'] . " 入库仓库:" . $warehouse . " 入库时间:" . $info['add_time'];
}
$str[2] = '类型:' . $stock_name . " 合计:" . $info['real_goods_species'] . "种" . " 金额:" . strval($info['real_money_total']);
$str[3] = "备注:" . $info['remarks'];
detailGetExcel($fileds_name, $arr, $goodsList, $str);
}
//门店退货入库详情导出
public function retreaDetailsExport()
{
$id = I('get.id');
$where['id'] = $id;
$info = D('WarehousingRecord')->getFind($where);
//门店退货详情
$info['add_time'] = date('Y-m-d H:i:s', $info['retreat_time']);
$store_name = D('Store')->getStoreName(array('id' => $info['store_id']));
$warehouse_id = D('SStockOutOrder')->getFindField(array('id' => $info['stock_out_id'], 'type' => 1), "warehouse_id");
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $warehouse_id), "name");
//门店退货详情
$map['warehouse_record_id'] = $id;
$map['type'] = 1;
$detailsList = D('SStockOutGoods')->getSelect($map, $page = '', $limit = '');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
$val['sku_num'] = strval(round($val['sku_num'], 3));
$val['warehouse_num'] = strval(round($val['stock_num'], 3));
$val['warehouse_price'] = strval(round($val['stock_price'], 2));
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('warehouse_num', '数量'),
array('warehouse_price', '出库价'),
array('subtotal', '合计'),
array('remarks', '备注'),
);
$str = array();
$str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
$str[1] = '入库单号:' . $info['order_number'] . " 出货仓库:" . $warehouse . " 类型:门店退货入库";
$str[2] = '门店:' . $store_name . " 创建时间:" . $info['add_time'] . " 合计:" . $info['goods_species'] . " 金额:" . strval($info['money_total']);
$str[3] = "备注:" . $info['remarks'];
detailGetExcel($fileds_name, $arr, $detailsList, $str);
}
}