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

1001 行
44 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\CacheHandle;
use Common\Business\InventorySet;
use Common\Business\PurchaseOrder;
use Common\Business\SaleGoods;
use Common\Business\SerialNumberGoods;
use Think\Controller;
use Common\Business\PurchaseGoodsInfo;
//[1.8.49]
/**
* Class SPurchaseOrderController
* @package Retail\Controller
*/
class SPurchaseOrderController extends BaseController
{
/*
* ***********************************************采购订单参数与方法*********************************************************
* @param $order_number 订单号
* @param $add_time 采购时间
* @param $supplier_id 供货商id
* @param $warehouse_id 仓库id
*
* function Info 查询供货商与采购仓库映射方法
*/
/*
* ***********************************************查询信息*****************************************************
*/
private function Info($merchant_id, $store_id)
{
$where['merchant_id'] = $merchant_id;
$where['store_id'] = $store_id;
$where['status'] = 1;
$supplier = D('SSupplier')->getSelect($where, $page = '', $limit = '', "id,supplier_name");
$map['merchant_id'] = $merchant_id;
$map['status'] = 1;
$map['store_id'] = $store_id;
$fields = "id,name";
$warehouse = D('SPurchaseWarehouse')->getSelect($map, $page = '', $limit = '', $fields, $order = 'default_state desc');
$this->assign('supplier', json_encode($supplier));
$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));
}
/*
* 规格信息已作废
*/
private function getMGoodsSkuInfo($goods_id)
{
$skuList = M('retail_sku_goods')->where(array('goods_id' => $goods_id, 'state' => 0))->select();
$skuAttr = array();
if (!empty($skuList)) {
foreach ($skuList as &$value) {
$tempId = explode(',', $value['sku_id_list']);
foreach ($tempId as &$v) {
$v = intval($v);
$value['name'][] = M('retail_sku_list')->where(array('id' => $v))->getField('name');
}
$value['tempId'] = $tempId;
$goods_num = D('SSaleMGoods')->getFindField(array('goods_id' => $goods_id, 'sku_id' => $value['id']), "goods_num");
$goods_num = $goods_num ? $goods_num : 0;
$value['goods_num'] = round($goods_num, 2);
if ($value['sku_num'] == round($value['sku_num'])) {
$value['sku_num'] = round($value['sku_num']);
}
$value['sku_purchase_num'] = "";
$purchase_info = D('SPurchaseGoods')->getFind(array('goods_id' => $goods_id, 'sku_id' => $value['id']), "id desc");
if (!empty($purchase_info)) {
$value['purchase_price'] = $purchase_info['purchase_price'];
} else {
$value['purchase_price'] = round($value['purchase_price'], 2);
}
}
//为了保证规格顺序
$skuAttr = array();
for ($i = 0; $i < count($skuList[0]['tempId']); $i++) {
$skuAttr[] = M('retail_sku_attr as s')
->join('ls_retail_sku_list as l on l.attr_id=s.id')
->where(array('s.state' => 0, 'l.id' => $skuList[0]['tempId'][$i]))
->group('l.attr_id')
->field('s.id,s.name')
->find();
}
}
$data['attr'] = $skuAttr;
$data['list'] = $skuList;
return $data;
}
/*
* 采购单信息
*/
public function index()
{
$arr = array(
'addPurchaseOrder' => '/index.php/Retail/SPurchaseOrder/addPurchaseOrder',
'exportOperation' => '/index.php/Retail/SPurchaseOrder/export',
'OrderInfo' => '/index.php/Retail/SPurchaseOrder/details',
'edit' => '/index.php/Retail/SPurchaseOrder/warehousing',
'Warehousing' => '/index.php/Retail/SPurchaseOrder/warehousingOperation'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$store_id = session("storeid");
$this->Info($user['merchantid'], $store_id);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//采购单金额统计
public function orderTotal()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['showPrice'] = self::$showPrice;
$data['identity'] = self::$identity;
$PurchaseOrderClass = new PurchaseOrder();
$result = $PurchaseOrderClass->orderTotal($data);
$this->ajaxReturn($result);
}
//采购单列表
public function purchaseOrderList()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['showPrice'] = self::$showPrice;
$data['identity'] = self::$identity;
$PurchaseOrderClass = new PurchaseOrder();
$result = $PurchaseOrderClass->orderList($data);
$this->ajaxReturn($result);
}
/*
* 新增采购单信息
*/
public function addPurchaseOrder()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/SPurchaseOrder/goodsList',
'onSubmit' => '/index.php/Retail/SPurchaseOrder/purchaseOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$store_id = session("storeid");
$this->Info($user['merchantid'], $store_id);
$this->goodsClass($user['merchantid']);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
$this->assign('set_batch_number', $set_batch_number);
$this->display();
}
//初始化数据
public function addPurchaseOrderBasics()
{
$inventorySet = new InventorySet();
$inventory_set = $inventorySet->getInfo([
'user_type' => 4,
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id
]);
$this->ajaxReturn([
'status' => 1,
'message' => "查询成功",
'data' => [
'inventory_set' => $inventory_set
]
]);
}
//串号验证
public function serialVerify()
{
$data = I('post.');
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['user_type'] = 4;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->singleGoodsVerify($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->purchaseSearchGoods($data);
$this->ajaxReturn($result);
}
/*
* 规格信息已作废
*/
public function skuInfo()
{
$id = I("post.goods_id");
$data = $this->getMGoodsSkuInfo($id);
$this->ajaxReturn($data);
}
/*
* 采购单详情
*/
public function details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SPurchaseOrder/detailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
$operator = I("get.operator");
$where['id'] = $id;
$info = D('SPurchaseOrder')->getFind($where);
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['goods_species'] = round($info['goods_species'], 3);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
$goodsNum = D('SPurchaseGoods')->getSum(array('purchase_order_id' => $info['id']), "surplus_num");
$goodsNum = $goodsNum ? $goodsNum : 0;
if ($goodsNum > 0) {
$info['warehouse_state'] = "未入库";
} else {
$info['warehouse_state'] = "已入库";
}
$supplier = D('SSupplier')->getFindField(array('id' => $info['supplier_id']), "supplier_name");
$warehouse = D('SPurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
$this->assign('id', $id);
$this->assign('info', $info);
$this->assign('supplier', $supplier);
$this->assign('warehouse', $warehouse);
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign("operator", $operator);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
$this->assign('set_batch_number', $set_batch_number);
$this->display();
}
//采购单详情串号信息
public function detailSerialList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['type'] = 1;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->purchaseDetailSerial($data);
$this->ajaxReturn($result);
}
public function detailsList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['showPrice'] = self::$showPrice;
$data['identity'] = self::$identity;
$PurchaseGoodsInfo = new PurchaseGoodsInfo();
$result = $PurchaseGoodsInfo->basisIdGetPurchaseGoodsList($data);
$this->ajaxReturn($result);
}
//已经入库的串号列表
public function WarehousingSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->purchaseWarehouseSerial($data);
$this->ajaxReturn($result);
}
//已经退货的串号列表
public function retreatSerial()
{
$data = I('post.');
$data['user_type'] = 4;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->purchaseRetreatSerial($data);
$this->ajaxReturn($result);
}
/*
* *************************************************操作******************************************************
*/
//采购提交
public function purchaseOperation()
{
$data = I("post.");
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['supplier_type'] = session('ls_userinfo')['supplier_type'];
$data['operator_id'] = session("jurisdiction_user")['id'];
$result = A('Api/Inventory')->storePurchaseOperation($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 warehousing()
{
$arr = array(
'onSubmit' => '/index.php/Retail/SPurchaseOrder/purchaseOrderEdit',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$merchant_id = $user['merchantid'];
$store_id = session("storeid");
$id = I("get.id");
$purchaseOrder = D('SPurchaseOrder')->getFind(array('id' => $id));
$purchaseOrder['add_time'] = date('Y-m-d H:i:s', $purchaseOrder['add_time']);
$purchaseOrder['remarks'] = str_replace("\n", "", $purchaseOrder['remarks']);
$this->Info($merchant_id, $store_id);
$this->assign('id', $id);
$this->assign('info', $purchaseOrder);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
$this->assign('set_batch_number', $set_batch_number);
$this->display();
}
//编辑操作
public function purchaseOrderEdit()
{
$data = I("post.");
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['supplier_type'] = session('ls_userinfo')['supplier_type'];
$result = A("Api/Inventory")->StorePurchaseEdit($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 warehousingOperation()
{
$data = [
'id' => I('post.id'),
'merchant_id' => $this->merchant_id,
'store_id' => $this->store_id,
'operator_id' => session("jurisdiction_user")['id'],
];
$result = A('Api/Inventory')->storePurchaseWarehouse($data);
if (C('IS_SET_REDIS')) {
$redis_key = 'retail_merchant_id_' . $data['merchant_id'] . '_store_id_' . $data['store_id'] . '_purchase_order_id_' . $data['id'];
$CacheClass = new CacheHandle();
$CacheClass->deleteRedis($redis_key);
}
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()
{
$user = session("ls_userinfo");
$store_id = session("storeid");
$content = I("get.");
$order_number = $content['order_number'];
$supplier_id = $content['supplier_id'];
$warehouse_id = $content['warehouse_id'];
$add_time = $content['add_time'];
$type = $content['type'];
if (!empty($type)) {
$where['type'] = $type;
}
if (!empty($order_number)) {
$where['order_number'] = array('like', $order_number . '%');
}
if (!empty($supplier_id)) {
$where['supplier_id'] = $supplier_id;
}
if (!empty($warehouse_id)) {
$where['warehouse_id'] = $warehouse_id;
}
if (!empty($add_time)) {
if (!is_array($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['merchantid'];
$where['store_id'] = $store_id;
$where['status'] = 1;
$info = D('SPurchaseOrder')->getSelect($where, $page = '', $limit = '', $field = "*", $order = "id desc");
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['repair_time'] = date('Y-m-d H:i:s', $val['repair_time']);
$val['supplier'] = D('SSupplier')->getFindField(array('id' => $val['supplier_id']), "supplier_name");
$val['warehouse'] = D('SPurchaseWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name");
$val['goods_species'] = $val['goods_species'] . "种";
if ($val['type'] == 1) {
$val['type_name'] = "常规采购单";
} else {
$val['type_name'] = "补采购单";
}
if (self::$showPrice == 2 && self::$identity == 2) {
$val['money_total'] = '***';
}
}
} else {
$info = array();
}
$fileds_name = "采购单导出";
$arr = array(
array('index', '序号'),
array('operator', '操作人'),
array('type_name', '类型'),
array('add_time', '采购时间'),
array('repair_time', '操作时间'),
array('order_number', '批次号'),
array('supplier', '供应商'),
array('warehouse', '仓库'),
array('goods_species', '合计(种)'),
array('money_total', '金额'),
array('remarks', '备注'),
);
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
getExcel($fileds_name, $arr, $info, $str);
}
//详情导出
public function detailsExport()
{
$id = I('get.id');
$where['id'] = $id;
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
$info = D('SPurchaseOrder')->getFind($where);
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['goods_species'] = strval(round($info['goods_species'], 3));
$goodsNum = D('SPurchaseGoods')->getSum(array('purchase_order_id' => $info['id']), "surplus_num");
$goodsNum = $goodsNum ? $goodsNum : 0;
if ($goodsNum > 0) {
$info['warehouse_state'] = "未入库";
} else {
$info['warehouse_state'] = "已入库";
}
$supplier = D('SSupplier')->getFindField(array('id' => $info['supplier_id']), "supplier_name");
$warehouse = D('SPurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
$map['purchase_order_id'] = $id;
$detailsList = D('SPurchaseGoods')->getSelect($map, $page = '', $limit = '', $fields = '', 'id asc');
if ($detailsList) {
if (self::$showPrice == 2 && self::$identity == 2) {
$info['money_total'] = '***';
}
foreach ($detailsList 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'] = strval(round($val['sku_num'], 3));
$val['purchase_num'] = strval(round($val['purchase_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['purchase_price'] = '***';
$val['subtotal'] = '***';
} else {
$val['purchase_price'] = strval(round($val['purchase_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
$val['retail_price'] = $val['retail_price'] ? strval(round($val['retail_price'], 2)) : '';
$val['online_price'] = $val['online_price'] ? strval(round($val['online_price'], 2)) : '';
$val['retreat_num'] = strval(round($val['retreat_num'], 3));
$val['warehousing_num'] = strval(round($val['warehousing_num'], 3));
$val['operated_num'] = ($val['retreat_num'] + $val['warehousing_num']);
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
}
$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('retail_price', '店内零售价'),
array('online_price', '商城零售价'),
array('purchase_price', '进货价'),
array('purchase_num', '数量'),
array('subtotal', '合计'),
);
if ($set_batch_number == 1) {
$arr[] = ['goods_batch_number', '批号'];
}
$arr[] = ['remarks', '备注'];
$str = array();
$str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
$str[1] = '批次号:' . $info['order_number'] . " 供应商:" . $supplier . " 入库仓库:" . $warehouse;
$str[2] = '创建时间:' . $info['add_time'] . " 合计:" . $info['goods_species'] . " 金额:" . strval($info['money_total']);
$str[3] = "状态:" . $info['warehouse_state'] . " 备注:" . $info['remarks'];
detailGetExcel($fileds_name, $arr, $detailsList, $str);
}
}
/**
* 打印
* type 1采购单 2采购退货单
*/
public function prints()
{
$store_id = session("storeid");
$data = I('get.');
if ($data['type'] == 9 && $data['identity'] == 1) {
$merchant_id = session("merchant_userinfo")['id'];
$print = D("InventoryPrint")->getFind(array('type' => 1, 'merchant_id' => $merchant_id));
} else {
$print = D("InventoryPrint")->getFind(array('type' => 2, 'store_id' => $store_id));
}
if (!$print) {
$print = array(
'goods_name_state' => 1,
'sku_name_state' => 1,
'goods_number_state' => 1,
'goods_code_state' => 1,
'company_state' => 1,
'sku_num_state' => 1,
'price_state' => 1,
'num_state' => 1,
'remarks_state' => 1
);
}
if (!empty($print['font_num'])) {
$font_state = true;
$len = $print['font_num'];
if ($len <= 6) {
$px = 70;
} else if ($len > 6 && $len <= 8) {
$px = 100;
} else if ($len > 8 && $len <= 10) {
$px = 130;
} else if ($len > 10 && $len <= 12) {
$px = 145;
} else if ($len > 12 && $len <= 14) {
$px = 180;
} else if ($len > 14 && $len <= 16) {
$px = 210;
} else if ($len > 16 && $len <= 18) {
$px = 235;
} else if ($len > 18 && $len <= 20) {
$px = 250;
} else {
$px = 280;
}
} else {
$font_state = false;
}
$this->assign('font_state', $font_state);
$this->assign('px', $px);
$this->assign('print', $print);
$store_name = D("RetailStore")->getFindField(array('id' => $store_id), "storetag");
switch ($data['type']) {
case 1:
$type_name = $store_name . '采购单';
$where['purchase_order_id'] = $data['id'];
$detailsList = D('SPurchaseGoods')->getSelect($where, $page = '', $limit = '', $field = '', 'id asc');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$val['sku_num'] = round($val['sku_num'], 3);
$val['purchase_num'] = round($val['purchase_num'], 3);
$val['purchase_price'] = round($val['purchase_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'];
}
}
}
break;
case 2:
$type_name = $store_name . '采购退货单';
$where['retreat_order_id'] = $data['id'];
$detailsList = D('SRetreatGoods')->getSelect($where, $page = '', $limit = '', $field = '', 'id asc');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$val['retreat_num'] = round($val['retreat_num'], 3);
$val['retreat_price'] = round($val['retreat_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['sku_num'] = round($val['sku_num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
$val['difference_money'] = round(($val['retreat_price'] - $val['purchase_price']) * $val['retreat_num'], 2);
}
}
break;
case 3:
$type_name = $store_name . '盘点单';
$where['inventory_order_id'] = $data['id'];
$detailsList = D('SInventoryGoods')->getSelect($where, $page = '', $limit = '');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$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'];
}
}
}
break;
case 4:
$type_name = $store_name . '报损单';
$where['loss_order_id'] = $data['id'];
$detailsList = D('SLossReportGoods')->getSelect($where, $page = '', $limit = '');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$val['loss_num'] = round($val['loss_num'], 3);
$val['loss_price'] = round($val['loss_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['sku_num'] = round($val['sku_num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
}
break;
case 5:
$cate = $data['cate'];
$id = $data['id'];
switch ($cate) {
case 4:
$type_name = $store_name . '商户调拨单';
break;
case 5:
$type_name = $data['supplier'] . "至" . $store_name . '调拨单';
break;
case 6:
$type_name = $store_name . '申请商户调拨单';
break;
}
if ($cate == 4 || $cate == 6) {
//商家调拨单
$where['warehouse_record_id'] = $id;
if ($cate == 4) {
$where['type'] = 1;
} else if ($cate == 6) {
$where['type'] = 3;
}
$detailsList = D('StockOutGoods')->getSelect($where);
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$val['sku_num'] = round($val['sku_num'], 3);
$val['warehouse_num'] = round($val['stock_num'], 3);
$val['warehouse_price'] = round($val['stock_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
}
} else if ($cate == 5) {
//门店调拨
$where['warehouse_record_id'] = $id;
$where['type'] = 3;
$detailsList = D('SStockOutGoods')->getSelect($where, $page = '', $limit = '');
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$val['warehouse_num'] = round($val['stock_num'], 3);
$val['warehouse_price'] = round($val['stock_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['sku_num'] = round($val['sku_num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
}
break;
case 6:
$id = $data['id'];
$cate = $data['cate'];
switch ($cate) {
case 0:
$type_name = $store_name . "其他入库单";
break;
case 1:
$type_name = $store_name . "采购入库单";
break;
case 2:
$type_name = $store_name . "补货入库单";
break;
case 3:
$type_name = $store_name . "盘盈入库单";
break;
case 4:
$type_name = $store_name . "商户调拨入库单";
break;
case 5:
$type_name = $data['store_name'] . "至" . $store_name . "调拨入库单";
break;
case 6:
$type_name = $store_name . "申请商户调拨入库单";
break;
}
$detailsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $id), $page = '', $limit = '', $fields = '', 'id asc');
if ($detailsList) {
foreach ($detailsList 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($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$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);
}
}
break;
case 7:
$cate = $data['cate'];
switch ($cate) {
case 0:
$type_name = $store_name . "其他出库单";
break;
case 1:
$type_name = $store_name . "退货至商户出库单";
break;
case 2:
$type_name = $store_name . "盘亏出库单";
break;
case 3:
$type_name = $store_name . "调拨出库" . "至" . $data['store_name'] . "单";
break;
case 9:
$type_name = $store_name . "退货至供货商" . $data['store_name'] . "出库单";
break;
}
$where['stock_out_id'] = $data['id'];
$detailsList = D('SStockOutGoods')->getSelect($where, $page = '', $limit = '', "*", "id asc");
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$val['stock_num'] = round($val['stock_num'], 3);
$val['stock_price'] = round($val['stock_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['sku_num'] = round($val['sku_num'], 3);
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
}
}
break;
case 8:
$id = $data['id'];
$cate = $data['cate'];
switch ($cate) {
case 1:
$type_name = "商户入库单";
break;
case 3:
$type_name = $data['goods_to_name'] . "门店入库单";
break;
}
if ($cate == 1) {
//商户入库
$detailsList = D('WarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
} else if ($cate == 3) {
//门店入库
$detailsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
}
if ($detailsList) {
foreach ($detailsList 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($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
$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);
}
}
break;
case 9:
switch ($data['identity']) {
case 1:
$type_name = $data['store_name'] . '申请商户调拨单';
break;
case 2:
$type_name = $store_name . "申请商户调拨单";
break;
}
$id = $data['id'];
$orderInfo = D('AllocationOrder')->getFind(array('id' => $id));
if (!empty($orderInfo['stock_order_id'])) {
$stockGoods = D('StockOutGoods')->getSelect(array('stock_out_id' => $orderInfo['stock_order_id']));
}
if (!empty($orderInfo['warehouse_order_id'])) {
$warehouseGoods = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $orderInfo['warehouse_order_id']));
}
$detailsList = D('AllocationGoods')->getSelect(array('allocation_id' => $id));
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
if (!empty($print['font_num'])) {
if (mb_strlen($val['goods_name']) > $print['font_num']) {
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
}
}
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
$val['apply_num'] = round($val['apply_num'], 3);
$val['sku_num'] = round($val['sku_num'], 3);
if (!empty($stockGoods)) {
foreach ($stockGoods as $skey => $sval) {
if ($val['attribute_state'] == 2 && $val['goods_id'] == $sval['goods_id'] && $val['sku_id'] == $sval['sku_id'] || $val['attribute_state'] == 1 && $val['goods_id'] == $sval['goods_id']) {
$val['stock_num'] = round($sval['stock_num'], 3);
$val['stock_price'] = round($sval['stock_price'], 2);
$val['stock_price_total'] = round($val['stock_num'] * $val['stock_price'], 2);
}
}
}
if (!empty($warehouseGoods)) {
foreach ($warehouseGoods as $wkey => $wval) {
if ($val['attribute_state'] == 2 && $val['goods_number'] == $wval['sku_goods_number'] || $val['attribute_state'] == 1 && $val['goods_number'] == $wval['goods_number']) {
$val['warehouse_num'] = round($wval['warehouse_num'], 3);
$val['warehouse_price'] = round($wval['warehouse_price'], 2);
$val['warehouse_price_total'] = round($val['warehouse_num'] * $val['warehouse_price'], 2);
}
}
}
}
break;
}
$this->assign('showPrice', $data['showPrice']);
$this->assign('identity', $data['identity']);
$this->assign('list', $detailsList);
$this->assign('type', $data['type']);
$this->assign('type_name', $type_name);
$this->assign('warehouse', $data['warehouse']);
$this->assign('order_number', $data['order_number']);
$this->assign('add_time', $data['add_time']);
$this->assign('goods_species', $data['goods_species']);
$this->assign('remarks', $data['remarks']);
switch ($data['type']) {
case 1:
case 2:
$this->assign('supplier', $data['supplier']);
$this->assign('money_total', $data['money_total']);
$this->assign('warehouse_state', $data['warehouse_state']);
break;
case 3:
$this->assign('quantity', $data['quantity']);
$this->assign('amount', $data['amount']);
break;
case 4:
$this->assign('money_total', $data['money_total']);
break;
case 5:
case 6:
case 7:
case 8:
$this->assign('store_name', $data['store_name']);
$this->assign('money_total', $data['money_total']);
break;
case 9:
$this->assign('store_goods_species', $data['store_goods_species']);
$this->assign('stock_time', $data['stock_time']);
$this->assign('storage_time', $data['storage_time']);
$this->assign('accept_goods_species', $data['accept_goods_species']);
$this->assign('accept_money_total', $data['accept_money_total']);
$this->assign('warehouse_state', $data['status_name']);
$this->assign('money_total', $data['money_total']);
break;
}
$this->display();
}
}