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

489 行
19 KiB
PHP
可执行文件

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

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

<?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 SInventoryController extends BaseController
{
/*
* ***********************************************盘点参数与方法*********************************************************
* @param $order_number 订单号
* @param $add_time 时间
*@param $warehouse_id 仓库id
* function Info 查询盘点仓库映射方法
*/
static $showPrice;
static $identity;
static $global_store_jurisdiction;
public function _initialize()
{
parent::_initialize();
self::$showPrice = session('global_store_jurisdiction')['showpurch_price'];
self::$identity = session("identity");
self::$global_store_jurisdiction = session('global_store_jurisdiction');
}
/*
* ***********************************************查询信息*****************************************************
*/
/*
* 查询仓库
*/
private function Info($merchant_id, $store_id)
{
$map['merchant_id'] = $merchant_id;
$map['store_id'] = $store_id;
$map['status'] = 1;
$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(
'addInventoryOrder' => '/index.php/Retail/SInventory/addInventory',
'exportOperation' => '/index.php/Retail/SInventory/export',
'OrderInfo' => '/index.php/Retail/SInventory/details'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$merchant_id = $user['merchantid'];
$store_id = session("storeid");
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
public function InventoryList()
{
$user = session("ls_userinfo");
$merchant_id = $user['merchantid'];
$store_id = session("storeid");
$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'] = $merchant_id;
$where['store_id'] = $store_id;
$where['status'] = array('in', '1,2');
$info = D('SInventoryOrder')->getSelect($where, $page, $limit, $field = "*", $order = "id desc");
if ($info) {
$count = D('SInventoryOrder')->getCount($where);
foreach ($info as $key => &$val) {
$val['index'] = $key + 1;
if ($val['operator_type'] == 1) {//收银员
$val['operator'] = D('Cashier')->getFindField(array('id' => $val['operator_id']), "name");
} else {
$val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']);
}
switch ($val['status']) {
case 1:
$val['status_name'] = '完成';
break;
case 2:
$val['status_name'] = '进行中';
break;
default:
$val['status_name'] = '失败';
break;
}
$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('SSaleWarehouse')->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/SInventory/goodsList',
'onSubmit' => '/index.php/Retail/SInventory/InventoryOperation'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$merchant_id = $this->merchant_id;
$store_id = $this->store_id;
$this->Info($merchant_id, $store_id);
$this->goodsClass($merchant_id);
$inventory_id = I('get.inventory_order_id');
$showSystemNum = D('StoreConfig')->getFindField(['store_id' => $this->store_id], 'is_check_show_invenum');
$this->assign('showSystemNum', $showSystemNum);
$this->assign('inventory_id', $inventory_id ? $inventory_id : '');
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign("supplier_type", session('ls_userinfo')['supplier_type']);
$this->display();
}
//草稿箱商品信息
public function draftsList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['store_id'] = $this->store_id;
$data['supplier_type'] = $this->role_info['supplier_type'];
$InventoryRecordClass = new InventoryRecord();
$result = $InventoryRecordClass->keepInventory($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;
$SaleClass = new SaleGoods();
$result = $SaleClass->InventorySearchGoods($data);
$this->ajaxReturn($result);
}
/*
* 盘点单详情
*/
public function details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SInventory/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('SInventoryOrder')->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 0:
$info['type_name'] = "盘点失败";
break;
case 1:
$info['type_name'] = "盘点完成";
break;
case 2:
$info['type_name'] = "进行中";
break;
}
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
$this->assign('supplier_type', session('ls_userinfo')['supplier_type']);
$this->assign('id', $id);
$this->assign('info', $info);
$this->assign('warehouse', $warehouse);
$this->assign('status', $status);
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//盘点记录的串号列表
public function detailsSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$data['serial_type'] = 4;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//盘点商品记录
public function detailsList()
{
$param = [
'user_type' => 4,
'order_id' => I("post.id"),
'type' => I("post.status"),
'purchase_price_state' => session('global_store_jurisdiction')['showpurch_price'],
'supplier_type' => session('ls_userinfo')['supplier_type']
];
$InventoryRecordClass = new InventoryRecord();
$result = $InventoryRecordClass->goodsRecordList($param);
$this->ajaxReturn($result);
}
/*
* *************************************************操作******************************************************
*/
public function removeGoods()
{
$param = [
'user_type' => 4,
'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'] = 4;
$data['operator_type'] = 1;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->inventorySerialVerify($data);
$this->ajaxReturn($result);
}
/*门店盘点
* @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 $goodsList 盘点商品
*@param $status 盘点状态 0失败 1完成盘点 2进行中(保存到草稿箱)
*@param $inventory_order_id 原盘点单id
*/
public function InventoryOperation()
{
$goodsList = I("post.goodsList");
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
$param = [
'operator_type' => 1,
'user_type' => 4,
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id,
'operator_id' => session("jurisdiction_user")['id'],
'supplier_type' => session('ls_userinfo')['supplier_type'], //1普通供货商 2寄售供货商
'order_id' => I("post.inventory_id") ? I("post.inventory_id") : null,
'goodsList' => $goodsList,
'submit_type' => I("post.status") ? I("post.status") : 1,
'remarks' => I("post.remarks"),
];
$InventoryClass = new InventoryOperation();
$result = $InventoryClass->storeReal($param);
if ($result['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0 后台系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$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);
}
$this->ajaxReturn($result);
}
//导出
public function export()
{
$user = session("ls_userinfo");
$merchant_id = $user['merchantid'];
$store_id = session("storeid");
$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'] = $merchant_id;
$where['store_id'] = $store_id;
$where['status'] = array('in', '1,2');
$info = D('SInventoryOrder')->getSelect($where);
if ($info) {
foreach ($info as $key => &$val) {
$val['index'] = $key + 1;
if ($val['operator_type'] == 1) {//收银员
$val['operator'] = D('Cashier')->getFindField(array('id' => $val['operator_id']), "name");
} else {
$val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']);
}
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
if (self::$showPrice == 2 && self::$identity == 2) {
$val['amount'] = "***";
} else {
$val['amount'] = round($val['amount'], 2);
}
$val['quantity'] = round($val['quantity'], 3);
$val['warehouse_name'] = D('SSaleWarehouse')->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()
{
$global_store_jurisdiction = session('global_store_jurisdiction');
$id = I('get.id');
$status = I('get.status');
$where['id'] = $id;
$info = D('SInventoryOrder')->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");
$map['state'] = 1;
$map['inventory_order_id'] = $id;
if ($status != '') {
$map['type'] = $status;
}
$detailsList = D('SInventoryGoods')->getSelect($map);
$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);
if (self::$showPrice == 2 && self::$identity == 2) {
$val['cost_price'] = "***";
$val['subtotal'] = "***";
} else {
$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'];
}
if (session('ls_userinfo')['supplier_type'] == 2 && !empty($val['purchase_order_id'])) {
$val['purchase_order_number'] = D('SPurchaseOrder')->getFindField(array('id' => $val['purchase_order_id']), "order_number");
}
}
}
$goods_species = round($goods_species); //商品种数
$quantity = round($quantity, 3); // 盈亏数量
$amount = round($amount, 2); //盈亏金额
if (self::$showPrice == 2 && self::$identity == 2) {
$amount = '***';
}
$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', '备注'),
);
if (session('ls_userinfo')['supplier_type'] == 2) {
$arr[12] = array('purchase_order_number', '批次号');
$arr[13] = 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);
}
}