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

750 行
28 KiB
PHP
可执行文件

<?php
namespace Retail\Controller;
use Common\Business\PurchaseGoodsInfo;
use Common\Business\SaleGoods;
use Common\Business\SerialNumberGoods;
use Common\Model\PurchaseGoodsModel;
use Think\Controller;
//[1.7.90]
class SaleMGoodsController extends BaseController
{
/*
* *****************************************************供应商品明细*****************************************
*/
/*
* 商品分类
*/
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 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";
$warehouse = D('SaleWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
$this->assign('warehouse', json_encode($warehouse));
$this->assign('supplier', json_encode($supplier));
}
public function index()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SaleMGoods/export',
'replenishment' => '/index.php/Retail/SaleMGoods/replenishment',
'warehousing_record' => '/index.php/Retail/SaleMGoods/warehousing_record',
'deposit_record' => '/index.php/Retail/SaleMGoods/deposit_record',
'cost_price_record' => '/index.php/Retail/SaleMGoods/cost_price_record'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("merchant_userinfo");
$this->Info($user['id']);
$this->goodsClass($user['id']);
try {
$isTable = M()->query('SHOW TABLES LIKE "ls_retail_allocation"');
if ($isTable) {
$jiuban = M("retail_allocation")->where(array('merchantid' => $user['id']))->find();
}
} catch (Exception $e) {
}
if ($jiuban) {
$this->assign('jiuban', 1);
} else {
$this->assign('jiuban', 0);
}
$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['user_type'] = 3;
$data['merchant_id'] = $this->merchant_id;
$SaleClass = new SaleGoods();
$result = $SaleClass->warehouseGoods($data);
$this->ajaxReturn($result);
}
public function export()
{
$user = session("merchant_userinfo");
$merchant_id = $user['id'];
$content = I("get.");
$warehouse_id = $content['warehouse_id'];
$goods_number = $content['goods_number'];
$stock_status = $content['stock_status'];
$status = $content['status'];
$person1 = $content['person1'];
$person2 = $content['person2'];
$person3 = $content['person3'];
if (!empty($warehouse_id)) {
$where['warehouse_id'] = $warehouse_id;
}
if (!empty($goods_number)) {
$where['goods_number|sku_goods_number|goods_code|sku_code|goods_name|sku_name'] = array('like', $goods_number . "%");
}
if (!empty($stock_status)) {
switch ($stock_status) {
case 1:
$where['_string'] = "goods_num <= less_num";
break;
case 2:
$where['_string'] = "goods_num >= more_num";
break;
case 3:
$where['_string'] = "goods_num <= 0";
break;
}
}
$flag = 0;
if (!empty($person3)) {
$where['goods_class_id'] = $person3;
} else if (!empty($person2)) {
$class = M('retail_goods_class as c2')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
->where(array('c2.id' => $person2, 'c3.status' => 0))
->field('c3.id')->select();
$flag = 1;
} else if (!empty($person1)) {
$class = M('retail_goods_class as c1')
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
->where(array('c1.id' => $person1, 'c2.status' => 0))
->field('c2.id,c3.id as c3_id')->select();
$flag = 1;
}
if (!empty($class)) {
$arr = array();
foreach ($class as &$val) {
if (!in_array($val['id'], $arr)) {
$arr[] = $val['id'];
}
if (!empty($val['c3_id'])) {
if (!in_array($val['c3_id'], $arr)) {
$arr[] = $val['c3_id'];
}
}
}
$str = implode(',', $arr);
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
} else if ($flag == 1) {
$where['goods_class_id'] = $person2 ? $person2 : $person1;
}
$where['status'] = array('in', '0,1');
if ($status != '') {
$where['status'] = $status;
}
$where['merchant_id'] = $merchant_id;
$goodsList = D('SaleMGoods')->getSelect($where);
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
$val['index'] = $key + 1;
$val['more_num'] = round($val['more_num'], 3);
$val['less_num'] = round($val['less_num'], 3);
$val['goods_num'] = round($val['goods_num'], 3);
$val['cost_price'] = round($val['cost_price'], 2);
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
$val['sku_num'] = round($val['sku_num'], 3);
} else {
$val['sku_num'] = "";
}
$val['warehouse_name'] = D('SaleWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name");
$map = array();
$map['merchant_id'] = $merchant_id;
$map['goods_id'] = $val['goods_id'];
$map['surplus_num'] = array('gt', 0);
if ($val['attribute_state'] == 2) {
$map['sku_id'] = $val['sku_id'];
}
$field = "surplus_num,purchase_price";
$purchaseGoodsList = D('PurchaseGoods')->getSelect($map, $page = '', $limit = '', $field);
$actual_num = 0; //采购库总数量
$amount_total = 0; //采购库总金额
if ($purchaseGoodsList) {
foreach ($purchaseGoodsList as $ke => &$va) {
$actual_num += $va['surplus_num'];
$amount_total += ($va['surplus_num'] * $va['purchase_price']);
}
}
$val['actual_num'] = round($val['goods_num'] + $actual_num, 3);
$val['amount_total'] = round(($val['cost_price'] * $val['goods_num']) + $amount_total, 2);
if ($val['goods_num'] <= $val['less_num']) {
$val['warning_name'] = "缺货";
} else if ($val['goods_num'] >= $val['more_num']) {
$val['warning_name'] = "超量";
} else {
$val['warning_name'] = "正常";
}
switch ($val['status']) {
case 0:
$val['status_name'] = "上架";
break;
case 1:
$val['status_name'] = "下架";
break;
}
}
}
$fileds_name = "商品库存状况导出";
$arr = array(
array('index', '序号'),
array('goods_name', '名称'),
array('sku_name', '规格'),
array('goods_number', '货号'),
array('goods_code', '条码'),
array('company', '单位'),
array('sku_num', '规格基数'),
array('goods_num', '供应库存'),
array('actual_num', '实际库存'),
array('more_num', '库存上限'),
array('less_num', '库存下限'),
array('cost_price', '成本价'),
array('amount_total', '库存金额'),
array('warning_name', '库存状态'),
array('status_name', '上下架状态'),
);
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
getExcel($fileds_name, $arr, $goodsList, $str);
}
//入库导出
public function detailsExport()
{
$user = session("merchant_userinfo");
$goods_id = I("get.goods_id");
$attribute_state = I("get.attribute_state");
$sku_id = I("get.sku_id");
$order_number = I("get.order_number");
$add_time = I("get.add_time");
$where['goods_id'] = $goods_id;
$where['merchant_id'] = $user['id'];
if ($attribute_state == 2) {
$where['sku_id'] = $sku_id;
}
if (!empty($order_number)) {
$where['warehouse_order_number'] = $order_number;
}
if (!empty($add_time)) {
$add_time = explode(",", $add_time);
$start_time = strtotime($add_time[0] . "00:00:00");
$end_time = strtotime($add_time[1] . "23:59:59");
$where['add_time'] = array('between', array($start_time, $end_time));
}
$list = D('WarehousingGoods')->getSelect($where);
if ($list) {
foreach ($list 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);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
switch ($val['type']) {
case 0:
$val['type_name'] = "其他入库";
break;
case 1:
$val['type_name'] = "采购入库";
break;
case 2:
$val['type_name'] = "补货入库";
break;
case 3:
$val['type_name'] = "盘盈入库";
break;
case 4:
$val['type_name'] = "退货入库";
break;
case 5:
$val['type_name'] = "初始化入库";
break;
}
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
}
} else {
$list = array();
}
$fileds_name = "入库记录导出";
$arr = array(
array('index', '序号'),
array('warehouse_order_number', '入库单号'),
array('type_name', '入库类型'),
array('add_time', '入库时间'),
array('goods_name', '商品名称'),
array('sku_name', '规格'),
array('goods_number', '货号'),
array('goods_code', '条码'),
array('sku_num', '规格基数'),
array('company', '单位'),
array('build_date', '生产日期'),
array('quality_guarantee_period', '保质期'),
array('warehouse_num', '数量'),
array('warehouse_price', '入库价'),
array('subtotal', '小计'),
array('remarks', '备注'),
);
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
getExcel($fileds_name, $arr, $list, $str);
}
/*
* *****************************************************成本价**********************************
*/
public function cost_price_record()
{
$goods_id = I('get.goods_id');
$attribute_state = I('get.attribute_state');
$sku_id = I('get.sku_id');
$this->assign('goods_id', $goods_id);
$this->assign('attribute_state', $attribute_state);
$this->assign('sku_id', $sku_id);
$this->display();
}
//成本价
public function trend_info()
{
$user = session("merchant_userinfo");
$goods_id = I('post.goods_id');
$attribute_state = I('post.attribute_state');
$sku_id = I('post.sku_id');
$add_time = I("post.date");
if (!empty($add_time)) {
$start_time = strtotime($add_time[0] . "00:00:00");
$end_time = strtotime($add_time[1] . "23:59:59");
$where['add_time'] = array('between', array($start_time, $end_time));
} else {
$limit = 7;
}
$where['merchant_id'] = $user['id'];
$where['type'] = ['in', '1,3']; //入库
$where['goods_id'] = $goods_id;
if ($attribute_state == 2) {
$where['sku_id'] = $sku_id;
}
$field = 'purchase_price,cost_price,add_time';
$order = 'id desc';
$list = D('CostPriceRecord')->getSelect($where, $limit, $field, $order);
$where['type'] = 2; //出库
$retreatList = D('CostPriceRecord')->getSelect($where, $limit, $field, $order);
if ($list) {
$cost_price = array_column($list, 'cost_price');
$purchase_price = array_column($list, 'purchase_price');
$time = array_column($list, 'add_time');
foreach ($cost_price as &$val) {
$val = floatval($val);
}
foreach ($purchase_price as &$val) {
$val = floatval($val);
}
foreach ($time as &$val) {
$val = date('Y-m-d', $val);
}
}
if ($retreatList) {
$retreat_cost_price = array_column($retreatList, 'cost_price');
$retreat_price = array_column($retreatList, 'purchase_price');
$r_time = array_column($retreatList, 'add_time');
foreach ($retreat_cost_price as &$val) {
$val = floatval($val);
}
foreach ($retreat_price as &$val) {
$val = floatval($val);
}
foreach ($r_time as &$val) {
$val = date('Y-m-d', $val);
}
}
$cost_price = $cost_price ? array_reverse($cost_price) : array();
$purchase_price = $purchase_price ? array_reverse($purchase_price) : array();
$time = $time ? array_reverse($time) : array();
$retreat_cost_price = $retreat_cost_price ? array_reverse($retreat_cost_price) : array();
$retreat_price = $retreat_price ? array_reverse($retreat_price) : array();
$r_time = $r_time ? array_reverse($r_time) : array();
if (empty($list) && empty($retreatList)) {
$res['status'] = 0;
} else {
$res['status'] = 1;
$res['cost_price'] = $cost_price;
$res['purchase_price'] = $purchase_price;
$res['time'] = $time;
$res['retreat_cost_price'] = $retreat_cost_price;
$res['retreat_price'] = $retreat_price;
$res['r_time'] = $r_time;
}
$this->ajaxReturn($res);
}
/*
* ***************************************************记录***********************************************
*/
public function warehousing_record()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SaleMGoods/detailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$goods_id = I('get.goods_id');
$attribute_state = I('get.attribute_state');
$sku_id = I('get.sku_id');
$this->assign('goods_id', $goods_id);
$this->assign('attribute_state', $attribute_state);
$this->assign('sku_id', $sku_id);
$this->display();
}
//入库记录串号列表
public function warehouseSerialList()
{
$data = I('post.');
$data['user_type'] = 3;
$data['serial_type'] = 2;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//入库记录
public function WarehousingRecordList()
{
$user = session("merchant_userinfo");
$goods_id = I("post.goods_id");
$attribute_state = I("post.attribute_state");
$sku_id = I("post.sku_id");
$order_number = I("post.order_number");
$add_time = I("post.add_time");
$where['goods_id'] = $goods_id;
$where['merchant_id'] = $user['id'];
if ($attribute_state == 2) {
$where['sku_id'] = $sku_id;
}
if (!empty($order_number)) {
$where['warehouse_order_number'] = $order_number;
}
if (!empty($add_time)) {
$start_time = strtotime($add_time[0] . "00:00:00");
$end_time = strtotime($add_time[1] . "23:59:59");
$where['add_time'] = array('between', array($start_time, $end_time));
}
$page = I("post.page");
$limit = I("post.limit");
$list = D('WarehousingGoods')->getSelect($where, $page, $limit, $field = "", $order = '');
if ($list) {
$count = D('WarehousingGoods')->getCount($where);
foreach ($list 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);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
switch ($val['type']) {
case 0:
$val['type_name'] = "其他入库";
break;
case 1:
$val['type_name'] = "采购入库";
break;
case 2:
$val['type_name'] = "补货入库";
break;
case 3:
$val['type_name'] = "盘盈入库";
break;
case 4:
$val['type_name'] = "退货入库";
break;
case 5:
$val['type_name'] = "初始化入库";
break;
}
}
} else {
$list = array();
$count = 0;
}
$res['status'] = 1;
$res['msg'] = '';
$res['count'] = $count;
$res['data'] = $list;
$this->ajaxReturn($res);
}
//出库记录
public function deposit_record()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SaleMGoods/depositExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$goods_id = I('get.goods_id');
$attribute_state = I('get.attribute_state');
$sku_id = I('get.sku_id');
$this->assign('goods_id', $goods_id);
$this->assign('attribute_state', $attribute_state);
$this->assign('sku_id', $sku_id);
$this->display();
}
//出库记录串号列表
public function stockSerialList()
{
$data = I('post.');
$data['user_type'] = 3;
$data['serial_type'] = 3;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//出库记录
public function DepositRecordList()
{
$user = session("merchant_userinfo");
$goods_id = I("post.goods_id");
$attribute_state = I("post.attribute_state");
$sku_id = I("post.sku_id");
$order_number = I("post.order_number");
$add_time = I("post.add_time");
if (!empty($order_number)) {
$where['stock_order_number'] = $order_number;
}
if (!empty($add_time)) {
$start_time = strtotime($add_time[0] . "00:00:00");
$end_time = strtotime($add_time[1] . "23:59:59");
$where['add_time'] = array("between", array($start_time, $end_time));
}
$where['goods_id'] = $goods_id;
$where['merchant_id'] = $user['id'];
if ($attribute_state == 2) {
$where['sku_id'] = $sku_id;
}
$page = I("post.page");
$limit = I("post.limit");
$list = D('StockOutGoods')->getSelect($where, $page, $limit, $field = "", $order = '');
if ($list) {
$count = D('StockOutGoods')->getCount($where);
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['stock_price'] = round($val['stock_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
switch ($val['type']) {
case 0:
$val['type_name'] = "其他出库";
break;
case 1:
$val['type_name'] = "调拨出库";
break;
case 2:
$val['type_name'] = "盘亏出库";
break;
case 3:
$val['type_name'] = "申请调拨出库";
break;
case 4:
$val['type_name'] = "退货出库";
break;
}
}
} else {
$list = array();
$count = 0;
}
$res['status'] = 1;
$res['msg'] = '';
$res['count'] = $count;
$res['data'] = $list;
$this->ajaxReturn($res);
}
//出库导出
public function depositExport()
{
$user = session("merchant_userinfo");
$goods_id = I("get.goods_id");
$attribute_state = I("get.attribute_state");
$sku_id = I("get.sku_id");
$order_number = I("get.order_number");
$add_time = I("get.add_time");
if (!empty($order_number)) {
$where['stock_order_number'] = $order_number;
}
if (!empty($add_time)) {
$add_time = explode(",", $add_time);
$start_time = strtotime($add_time[0] . "00:00:00");
$end_time = strtotime($add_time[1] . "23:59:59");
$where['add_time'] = array('between', array($start_time, $end_time));
}
$where['goods_id'] = $goods_id;
$where['merchant_id'] = $user['id'];
if ($attribute_state == 2) {
$where['sku_id'] = $sku_id;
}
$list = D('StockOutGoods')->getSelect($where);
if ($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['stock_price'] = round($val['stock_price'], 2);
$val['subtotal'] = round($val['subtotal'], 2);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
switch ($val['type']) {
case 0:
$val['type_name'] = "其他出库";
break;
case 1:
$val['type_name'] = "调拨出库";
break;
case 2:
$val['type_name'] = "盘亏出库";
break;
case 3:
$val['type_name'] = "申请调拨出库";
break;
case 4:
$val['type_name'] = "退货出库";
break;
}
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
}
} else {
$list = array();
}
$fileds_name = "出库记录导出";
$arr = array(
array('index', '序号'),
array('stock_order_number', '出库单号'),
array('type_name', '出库类型'),
array('add_time', '出库时间'),
array('goods_name', '商品名称'),
array('sku_name', '规格'),
array('goods_number', '货号'),
array('goods_code', '条码'),
array('sku_num', '规格基数'),
array('company', '单位'),
array('stock_num', '数量'),
array('stock_price', '出库价'),
array('subtotal', '小计'),
array('remarks', '备注'),
);
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
getExcel($fileds_name, $arr, $list, $str);
}
/*
* ****************************************************补货**********************************************
*/
public function replenishment()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/SaleMGoods/purchaseList',
'onSubmit' => '/index.php/Retail/SaleMGoods/repairOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("merchant_userinfo");
$goods_id = I('get.goods_id');
$attribute_state = I('get.attribute_state');
$sku_id = I('get.sku_id');
$this->Info($user['id']);
$where['merchant_id'] = $user['id'];
$where['status'] = 1;
$purchase_warehouse = D('PurchaseWarehouse')->getSelect($where);
$this->assign('goods_id', $goods_id);
$this->assign('attribute_state', $attribute_state);
$this->assign('sku_id', $sku_id);
$this->assign('purchase_warehouse', json_encode($purchase_warehouse));
$this->display();
}
//补货可入库的串码
public function purchaseSerialList()
{
$data = I('post.');
$data['user_type'] = 3;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->returnableSerialList($data);
$this->ajaxReturn($result);
}
//补货商品列表
public function purchaseList()
{
$data = I('post.');
$data['user_type'] = 3;
$data['merchant_id'] = $this->merchant_id;
$PurchaseGoodsClass = new PurchaseGoodsInfo();
$result = $PurchaseGoodsClass->replenishGoodsList($data);
$this->ajaxReturn($result);
}
//补货操作
public function repairOperation()
{
$data = I('post.');
$data['merchant_id'] = $this->merchant_id;
$data['operator_id'] = session("jurisdiction_user")['id'];
$data['type'] = 2;
$data['stock'] = 1;
$res = A('Api/Inventory')->MerWarehousing($data);
$this->ajaxReturn($res);
}
}