418 行
15 KiB
PHP
可执行文件
418 行
15 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Retail\Controller;
|
|
|
|
use Common\Business\InventoryOperation;
|
|
use Common\Business\InventoryRecord;
|
|
use Common\Business\SaleGoods;
|
|
use Common\Business\SerialNumberGoods;
|
|
use Think\Controller;
|
|
|
|
//[1.7.90]
|
|
class InventoryController 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);
|
|
$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(
|
|
'addInventoryOrder' => '/index.php/Retail/Inventory/addInventory',
|
|
'OrderInfo' => '/index.php/Retail/Inventory/details',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$user = session("merchant_userinfo");
|
|
// $this->Info($user['id']);
|
|
$this->display();
|
|
}
|
|
|
|
/*盘点单列表
|
|
* @param $where['status'] 0盘点失败 1盘点成功
|
|
*/
|
|
public function InventoryList()
|
|
{
|
|
$user = session("merchant_userinfo");
|
|
$content = I("post.");
|
|
$page = $content['page'];
|
|
$limit = $content['limit'];
|
|
$order_number = $content['order_number'];
|
|
$add_time = $content['add_time'];
|
|
if (!empty($order_number)) {
|
|
$where['order_number'] = array('like', '%' . $order_number . '%');
|
|
}
|
|
if (!empty($add_time)) {
|
|
$start_time = strtotime($add_time[0]);
|
|
$end_time = strtotime($add_time[1]);
|
|
$where['add_time'] = array('between', array($start_time, $end_time));
|
|
}
|
|
$where['merchant_id'] = $user['id'];
|
|
$where['status'] = array('in', '1,2');
|
|
$info = D('InventoryOrder')->getSelect($where, $page, $limit, $field = "*", $order = "id desc");
|
|
if ($info) {
|
|
$count = D('InventoryOrder')->getCount($where);
|
|
foreach ($info as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
switch ($val['status']) {
|
|
case 1:
|
|
$val['status_name'] = '完成';
|
|
break;
|
|
case 2:
|
|
$val['status_name'] = '进行中';
|
|
break;
|
|
default:
|
|
$val['status_name'] = '失败';
|
|
break;
|
|
}
|
|
$val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']);
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$val['amount'] = round($val['amount'], 2);
|
|
$val['quantity'] = round($val['quantity'], 3);
|
|
$val['warehouse_name'] = D('SaleWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name");
|
|
}
|
|
} else {
|
|
$info = array();
|
|
$count = 0;
|
|
}
|
|
$res['status'] = 1;
|
|
$res['data'] = $info;
|
|
$res['msg'] = '查询成功';
|
|
$res['count'] = $count;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/*
|
|
* 新增盘点单信息
|
|
*/
|
|
public function addInventory()
|
|
{
|
|
$arr = array(
|
|
'goodsChoice' => '/index.php/Retail/Inventory/goodsList',
|
|
'onSubmit' => '/index.php/Retail/Inventory/InventoryOperation',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$inventory_id = I("get.inventory_id");
|
|
$this->assign('inventory_id', $inventory_id ? $inventory_id : '');
|
|
$showSystemNum = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'is_check_show_invenum');
|
|
$this->assign('showSystemNum', $showSystemNum);
|
|
$user = session("merchant_userinfo");
|
|
$this->Info($user['id']);
|
|
$this->goodsClass($user['id']);
|
|
$this->display();
|
|
}
|
|
|
|
|
|
//草稿箱商品信息
|
|
public function draftsList()
|
|
{
|
|
$data = I('post.');
|
|
$data['user_type'] = 3;
|
|
$InventoryRecordClass = new InventoryRecord();
|
|
$result = $InventoryRecordClass->keepInventory($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
//盘点时仓库商品状态明细
|
|
public function goodsList()
|
|
{
|
|
$data = I('post.');
|
|
$data['operator_type'] = 1;
|
|
$data['user_type'] = 3;
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$SaleClass = new SaleGoods();
|
|
$result = $SaleClass->InventorySearchGoods($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
//盘点单详情
|
|
public function details()
|
|
{
|
|
$arr = array(
|
|
'exportOperation' => '/index.php/Retail/Inventory/detailsExport',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$id = I('get.id');
|
|
$operator = I('get.operator');
|
|
$this->assign('operator', $operator);
|
|
$status = I('get.status');
|
|
$status = $status ? $status : '';
|
|
$where['id'] = $id;
|
|
$info = D('InventoryOrder')->getFind($where);
|
|
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
|
|
$info['quantity'] = round($info['quantity'], 3);
|
|
$info['remarks'] = str_replace("\n", "", $info['remarks']);
|
|
switch ($info['status']) {
|
|
case 1:
|
|
$info['type_name'] = '盘点完成';
|
|
break;
|
|
case 2:
|
|
$info['type_name'] = '进行中';
|
|
break;
|
|
case 0:
|
|
$info['type_name'] = '盘点失败';
|
|
break;
|
|
}
|
|
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
|
|
$this->assign('id', $id);
|
|
$this->assign('info', $info);
|
|
$this->assign('warehouse', $warehouse);
|
|
$this->assign('status', $status);
|
|
$this->display();
|
|
}
|
|
|
|
|
|
//盘点记录的串号列表
|
|
public function detailsSerial()
|
|
{
|
|
$data = I('post.');
|
|
$data['user_type'] = 3;
|
|
$data['serial_type'] = 4;
|
|
$SerialClass = new SerialNumberGoods();
|
|
$result = $SerialClass->recordSerialList($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 盘点单详情列表
|
|
* id 盘点单id
|
|
*/
|
|
public function detailsList()
|
|
{
|
|
$param = [
|
|
'user_type' => 3,
|
|
'order_id' => I("post.id"),
|
|
'type' => I("post.status"),
|
|
];
|
|
$InventoryRecordClass = new InventoryRecord();
|
|
$result = $InventoryRecordClass->goodsRecordList($param);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
/*
|
|
* *************************************************操作******************************************************
|
|
*/
|
|
|
|
|
|
//删除商品记录
|
|
public function removeGoods()
|
|
{
|
|
$param = [
|
|
'user_type' => 3,
|
|
'order_id' => I("post.inventory_id"),
|
|
'inventory_goods_id' => I("post.inventory_goods_id")
|
|
];
|
|
$InventoryClass = new InventoryOperation();
|
|
$result = $InventoryClass->deleteGoodsRecord($param);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
//串号验证
|
|
public function serialVerify()
|
|
{
|
|
$data = I('post.');
|
|
$data['user_type'] = 3;
|
|
$data['operator_type'] = 1;
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$SerialClass = new SerialNumberGoods();
|
|
$result = $SerialClass->inventorySerialVerify($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
//盘点提交
|
|
public function InventoryOperation()
|
|
{
|
|
$goodsList = I("post.goodsList");
|
|
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
|
|
$param = [
|
|
'operator_type' => 1,
|
|
'user_type' => 3,
|
|
'merchant_id' => $this->merchant_id,
|
|
'operator_id' => session("jurisdiction_user")['id'],
|
|
'order_id' => I("post.inventory_id"),
|
|
'goodsList' => $goodsList,
|
|
'submit_type' => I("post.status"),
|
|
'remarks' => I("post.remarks")
|
|
];
|
|
$InventoryClass = new InventoryOperation();
|
|
$result = $InventoryClass->storeReal($param);
|
|
if ($result['status'] == 1) {
|
|
//操作日志记录
|
|
$source = 0;//请求来源: 0pc系统 1小助手
|
|
$type = 3; //商户
|
|
$request_data = json_encode($_POST);//请求参数 json数据
|
|
switch ($param['submit_type']) {
|
|
case 1:
|
|
$desc = '盘点管理-盘点提交';//操作行为描述
|
|
break;
|
|
case 2:
|
|
$desc = '盘点管理-盘点保存草稿箱';//操作行为描述
|
|
break;
|
|
}
|
|
action_log($source, $type, $request_data, $desc);
|
|
}
|
|
$result['msg'] = isset($result['message']) ? $result['message'] : $result['msg'];
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 盘点单导出
|
|
*/
|
|
public function export()
|
|
{
|
|
$user = session("merchant_userinfo");
|
|
$content = I("get.");
|
|
$order_number = $content['order_number'];
|
|
$add_time = $content['add_time'];
|
|
if (!empty($order_number)) {
|
|
$where['order_number'] = array('like', $order_number . '%');
|
|
}
|
|
if (!empty($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));
|
|
}
|
|
$where['merchant_id'] = $user['id'];
|
|
$where['status'] = array('in', '1,2');
|
|
$info = D('InventoryOrder')->getSelect($where);
|
|
if ($info) {
|
|
foreach ($info as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']);
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$val['amount'] = round($val['amount'], 2);
|
|
$val['quantity'] = round($val['quantity'], 3);
|
|
$val['warehouse_name'] = D('SaleWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name");
|
|
switch ($val['status']) {
|
|
case 1:
|
|
$val['status_name'] = '完成';
|
|
break;
|
|
case 2:
|
|
$val['status_name'] = '进行中';
|
|
break;
|
|
default:
|
|
$val['status_name'] = '失败';
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
$info = array();
|
|
}
|
|
$fileds_name = "盘点单导出";
|
|
$arr = array(
|
|
array('index', '序号'),
|
|
array('order_number', '盘点单号'),
|
|
array('warehouse_name', '盘点仓库'),
|
|
array('operator', '操作人'),
|
|
array('add_time', '盘点时间'),
|
|
array('goods_species', '商品总种类'),
|
|
array('quantity', '盈亏数量'),
|
|
array('amount', '盈亏金额'),
|
|
array('remarks', '备注'),
|
|
array('status_name', '状态'),
|
|
);
|
|
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
|
|
getExcel($fileds_name, $arr, $info, $str);
|
|
}
|
|
|
|
//详情导出
|
|
public function detailsExport()
|
|
{
|
|
$id = I('get.id');
|
|
$status = I('get.status');
|
|
$where['id'] = $id;
|
|
$info = D('InventoryOrder')->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");
|
|
$map['state'] = 1;
|
|
$map['inventory_order_id'] = $id;
|
|
if ($status != '') {
|
|
$map['type'] = $status;
|
|
}
|
|
$detailsList = D('InventoryGoods')->getSelect($map, $page = '', $limit = '');
|
|
$goods_species = 0;
|
|
$quantity = 0;
|
|
$amount = 0;
|
|
if ($detailsList) {
|
|
foreach ($detailsList as $key => &$val) {
|
|
$goods_species += 1;
|
|
$quantity += $val['num'];
|
|
$amount += $val['subtotal'];
|
|
$val['index'] = $key + 1;
|
|
$val['inventory_num'] = round($val['inventory_num'], 3);
|
|
$val['cost_price'] = round($val['cost_price'], 2);
|
|
$val['subtotal'] = round($val['subtotal'], 2);
|
|
$val['sku_num'] = round($val['sku_num'], 3);
|
|
$val['goods_num'] = round($val['goods_num'], 3);
|
|
$val['num'] = round($val['num'], 3);
|
|
if ($val['attribute_state'] == 2) {
|
|
$val['goods_code'] = $val['sku_code'];
|
|
$val['goods_number'] = $val['sku_goods_number'];
|
|
}
|
|
}
|
|
}
|
|
$goods_species = round($goods_species);
|
|
$quantity = round($quantity, 3);
|
|
$amount = round($amount, 2);
|
|
$fileds_name = "盘点详情导出";
|
|
$arr = array(
|
|
array('index', '序号'),
|
|
array('goods_name', '商品名称'),
|
|
array('sku_name', '规格'),
|
|
array('goods_number', '货号'),
|
|
array('goods_code', '条码'),
|
|
array('company', '单位'),
|
|
array('sku_num', '规格基数'),
|
|
array('cost_price', '成本价'),
|
|
array('goods_num', '原库存'),
|
|
array('inventory_num', '盘点数量'),
|
|
array('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 . " 盘点时间:" . $info['add_time'];
|
|
$str[2] = '合计:' . $goods_species . " 盈亏数量:" . $quantity . " 金额:" . $amount;
|
|
$str[3] = "备注:" . $info['remarks'];
|
|
detailGetExcel($fileds_name, $arr, $detailsList, $str);
|
|
}
|
|
} |