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

1043 行
44 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\PurchaseGoodsInfo;
use Common\Business\SaleGoods;
use Common\Business\SerialNumberGoods;
use Common\Business\WarehousingRecord;
use Common\Model\SWarehousingRecordModel;
use Think\Controller;
use Common\Business\RefuseWarehousing;
//[1.7.90]
class SWarehousingRecordController 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['store_id'] = $store_id;
$map['status'] = 1;
$fields = "id,name";
$warehouse = D('SSaleWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
$purchase_warehouse = D('SPurchaseWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
$this->assign('supplier', json_encode($supplier)); //供货商
$this->assign('warehouse', json_encode($warehouse)); //销售仓库
$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(
'addWarehousing' => '/index.php/Retail/SWarehousingRecord/addWarehousing',
'exportOperation' => '/index.php/Retail/SWarehousingRecord/export',
'allocationDetails' => '/index.php/Retail/SWarehousingRecord/allocationDetails',
'allocation' => '/index.php/Retail/SWarehousingRecord/allocation',
'OrderInfo' => '/index.php/Retail/SWarehousingRecord/details',
'refuse' => '/index.php/Retail/SWarehousingRecord/refuseOperation',
'refuseInfo' => '/index.php/Retail/StockOutOrder/refuseInfo'
);
$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->assign('supplier_type', session('ls_userinfo')['supplier_type']);
$this->display();
}
//入库单列表
public function WarehousingRecordList()
{
$content = I("post.");
$content['operator_type'] = 1;
$content['merchant_id'] = $this->merchant_id;
$content['store_id'] = $this->store_id;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->storeWarehousingOrderList($content);
$this->ajaxReturn($result);
}
/*
* 新增入库单信息
*/
public function addWarehousing()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/SWarehousingRecord/otherList',
'onSubmit' => '/index.php/Retail/SWarehousingRecord/WarehouseOperation'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$store_id = session("storeid");
$supplier_type = D("RetailStore")->getFindField(array('id' => $store_id), "supplier_type");
$this->Info($user['merchantid'], $store_id);
$this->goodsClass($user['merchantid']);
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign('supplier_type', $supplier_type);
$order_number = I('get.order_number');
$supplier_id = I('get.supplier_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'] = 4;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->returnableSerialList($data);
$this->ajaxReturn($result);
}
//入库选择采购入库的商品列表
public function goodsList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$PurchaseClass = new PurchaseGoodsInfo();
$result = $PurchaseClass->warehousePurchaseGoodsList($data);
$this->ajaxReturn($result);
}
//其他入库串号验证
public function serialVerify()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->singleGoodsVerify($data);
$this->ajaxReturn($result);
}
//其他入库选择的商品列表
public function otherList()
{
$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->otherGoodsList($data);
$this->ajaxReturn($result);
}
/*
* 调拨入库
*/
public function allocation()
{
$global_store_jurisdiction = session('global_store_jurisdiction');
$arr = array(
'onSubmit' => '/index.php/Retail/SWarehousingRecord/allocationOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$user = session("ls_userinfo");
$merchant_id = $user['merchantid'];
$store_id = session("storeid");
$id = I("get.id");
$type = I("get.type");
$info = D('SWarehousingRecord')->getFind(array('id' => $id));
$info['add_time'] = date('Y-m-d H:i:s', $info['allocation_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
$warehouse = D('SSaleWarehouse')->getFind(array('merchant_id' => $merchant_id, 'store_id' => $store_id, 'status' => 1));
if ($info['type'] == 4) {
$supplier = '商户调拨';
} else if ($info['type'] == 5) {
$supplier = D('Store')->getStoreName(array('id' => $info['source_store_id']));
}
$this->assign('id', $id);
$this->assign('type', $type);
$this->assign('info', $info);
$this->assign('supplier', $supplier);
$this->assign('warehouse', $warehouse);
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign('allocation_state', $global_store_jurisdiction['allocation']);
$this->display();
}
//入库调拨的商品列表
public function allocationList()
{
$data = I("post.");
$data['show_type'] = 1;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getStoreAllocationGoodsList($data); //获取调拨商品列表
$this->ajaxReturn($result);
}
//调拨详情
public function allocationDetails()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SWarehousingRecord/allocationDetailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
$type = I('get.type');
$where['id'] = $id;
$info = D('SWarehousingRecord')->getFind($where);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
if ($type == 4 || $type == 6) {
//商户调拨入库
$info['add_time'] = date('Y-m-d H:i:s', $info['allocation_time']);
if ($type == 4) {
$warehouse_id = D('StockOutOrder')->getFindField(array('warehouse_record_id' => $id, 'type' => 1), "warehouse_id");
} else if ($type == 6) {
$warehouse_id = D('StockOutOrder')->getFindField(array('warehouse_record_id' => $id, 'type' => 3), "warehouse_id");
}
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $warehouse_id), "name");
$supplier = "商家调拨";
} else if ($type == 5) {
//门店调拨入库
$info['add_time'] = date('Y-m-d H:i:s', $info['allocation_time']);
$supplier = D('Store')->getStoreName(array('id' => $info['source_store_id']));
$warehouse_id = D('SStockOutOrder')->getFindField(array('warehouse_record_id' => $id, 'type' => 3), "warehouse_id");
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $warehouse_id), "name");
}
$this->assign('id', $id);
$this->assign('info', $info);
$this->assign('supplier', $supplier);
$this->assign('warehouse', $warehouse);
$this->assign('type', $type);
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//调拨串号列表
public function allocationSerial()
{
$data = I('post.');
if($data['type'] == 4 || $data['type'] == 6){
$data['user_type'] = 3;
}else{
$data['user_type'] = 4;
}
$data['serial_type'] = 3;
unset($data['type']);
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
/**
* 门店调拨详情
* [
* id 门店的入库单id
* type 0其他入库 1采购入库 2补货入库 3盘盈入库 4商户调拨入库 5其他门店调拨入库 6门店申请调拨入库
* ]
*/
public function allocationDetailsList()
{
$data = I("post.");
$data['show_type'] = 2;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getStoreAllocationGoodsList($data); //获取调拨商品列表
$this->ajaxReturn($result);
}
/*
* 调拨详情
*/
public function details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SWarehousingRecord/detailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I("get.id");
$type = I("get.type");
$operator = I("get.operator");
$this->assign('operator', $operator);
$info = D('SWarehousingRecord')->getFind(array('id' => $id));
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
switch ($info['type']) {
case 0:
$warehousing_type = "其他入库";
break;
case 1:
$warehousing_type = "采购入库";
break;
case 2:
$warehousing_type = "补货入库";
break;
case 3:
$warehousing_type = "盘盈入库";
break;
case 4:
$warehousing_type = "商户调拨入库";
break;
case 5:
$warehousing_type = "门店调拨入库";
$store_name = D('Store')->getStoreName(array('id' => $info['source_store_id']));
break;
case 6:
$warehousing_type = "申请调拨入库";
break;
}
if ($info['type'] == 0 || $info['type'] == 1 || $info['type'] == 2) {
$supplier = D('SSupplier')->getFindField(array('id' => $info['supplier_id']), "supplier_name");
}
$supplier = $supplier ? $supplier : "";
$store_name = $store_name ? $store_name : "";
$this->assign('id', $id);
$this->assign('type', $type);
$this->assign('warehousing_type', $warehousing_type);
$this->assign('info', $info);
$this->assign('warehouse', $warehouse);
$this->assign('supplier', $supplier);
$this->assign('store_name', $store_name);
$this->assign('showPrice', self::$showPrice);
$this->assign("identity", self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//入库详情串号列表
public function detailSerialList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['serial_type'] = 2;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->recordSerialList($data);
$this->ajaxReturn($result);
}
//入库详情的商品列表
public function detailsList()
{
$id = I("post.id"); //入库单id
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->getStoreWarehousingGoodsList(array('id' => $id)); //获取入库商品列表
$this->ajaxReturn($result);
}
/*
* *************************************************操作******************************************************
*/
/*门店入库供给仓
* @param $user 用户信息
* @param $merchant_id 商户id
* @param $operator_id 操作人id
* @param $supplier_id 供货商id
* @param $warehouse_id 入库仓库id
* @param $remarks 入库单备注
* @param $type 入库的商品来源 入库类型 0其他入库 1采购入库 2补货入库 3盘盈入库 4商户调拨入库 5其他门店调拨入库 6门店申请调拨入库
* @param $goodsList 入库商品
* @param $order_number 订单号
* @param $stock 采购库是否减少 1减少 其他不减少
*/
public function WarehouseOperation()
{
$data = I('post.');
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$data['operator_id'] = session("jurisdiction_user")['id'];
if ($data['type'] == 1) {
$data['stock'] = 1;
}
$result = A("Api/Inventory")->Warehousing($data);
if ($result['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台: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($result);
}
/*
* 确认调拨入库判断商品信息
*/
public function goodsVerify()
{
$store_id = $this->store_id;
$merchant_id = $this->merchant_id;
$id = I("post.id");
$goodsList = I('post.goodsList');
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_warehousing_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$success = A('Api/Inventory')->goodsVerify($merchant_id, $store_id, $goodsList);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($success);
}
/*将门店未有的商品信息同步到门店
* @param $type 4商户调拨过来 5其他门店调拨过来
*/
public function batchSync()
{
$merchant_id = session("ls_userinfo")['merchantid'];
$store_id = I('session.storeid');
$goodsIds = I("post.goodsIds");
$id = I("post.id");
$type = I("post.type");
if (!$store_id || !$goodsIds || !$type) {
$res['status'] = 0;
$res['msg'] = '登录超时,请重新登录';
$this->ajaxReturn($res);
}
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_warehousing_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$success = A('Api/Inventory')->batchSync([
'operate_id'=>session('jurisdiction_user')['id'],
'merchant_id'=>$merchant_id,
'store_id'=>$store_id,
'goodsIds'=>$goodsIds,
'type'=>$type
]);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($success);
}
//入库调拨过来的操作
public function allocationOperation()
{
$data = I('post.');
$merchant_id = $this->merchant_id;
$store_id = $this->store_id;
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_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']);
}
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'id' => $data['id'],
'type' => $data['type'],
'order_number' => $data['order_number'],
'goodsList' => json_decode(htmlspecialchars_decode($data['goodsList']), true),
'warehouse_id' => $data['warehouse_id'],
'remarks' => $data['remarks'],
'operator_id' => session("jurisdiction_user")['id'],
'refuseList' => json_decode(htmlspecialchars_decode($data['refuse_list']), true),
);
$success = A('Api/Inventory')->allocationWarehousing($parameter);
if ($success['status'] == 1) {
$res['status'] = 1;
$res['msg'] = '操作成功';
} else {
$res['status'] = 0;
$res['msg'] = '操作失败'.$success['msg'];
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($res);
}
/*此方法已作废 请调用Api下面的公共方法
* $id 入库单id
*$order_number 入库订单号
* $goodsList 入库商品
* $warehouse_id 入库仓库
* $textarea 备注
* 入库操作
*/
public function allocationWarehousing($merchant_id, $store_id, $id, $type, $order_number, $goodsList, $warehouse_id, $remarks, $refuseList)
{
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'id' => $id,
'type' => $type,
'order_number' => $order_number,
'goodsList' => $goodsList,
'warehouse_id' => $warehouse_id,
);
$param_state = $this->verify_param($parameter);
if ($param_state['status'] == 0) {
return $param_state;
} else {
$stime = time();
$money_total = 0;
//操作
foreach ($goodsList as $key => &$val) {
$store_where = array();
if ($val['attribute_state'] == 2) {
$store_where['sku_goods_number'] = $val['sku_goods_number'];
} else {
$store_where['goods_number'] = $val['goods_number'];
}
$store_where['status'] = array('in', '0,1');
$store_where['store_id'] = $store_id;
$store_where['merchant_id'] = $merchant_id;
$s_goods_info = D('SSaleMGoods')->getFind($store_where);
$data = array();
$data = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'warehouse_id' => $warehouse_id,
'warehouse_record_id' => $id,
'goods_class_id' => $s_goods_info['goods_class_id'],
'goods_id' => $s_goods_info['goods_id'],
'sku_id' => $s_goods_info['sku_id'],
'goods_name' => $val['goods_name'],
'sku_name' => $val['sku_name'],
'sku_id_list' => $val['sku_id_list'],
'goods_number' => $s_goods_info['goods_number'],
'sku_goods_number' => $s_goods_info['sku_goods_number'],
'goods_code' => $s_goods_info['goods_code'],
'sku_code' => $s_goods_info['sku_code'],
'company' => $val['company'],
'attribute_state' => $val['attribute_state'],
'pricing_method' => $val['pricing_method'],
'sku_num' => round($val['sku_num'], 3),
'warehouse_price' => round($val['warehouse_price'], 2),
'warehouse_num' => round($val['warehouse_num'], 3),
'surplus_num' => round($val['warehouse_num'], 3),
'subtotal' => round($val['warehouse_price'] * $val['warehouse_num'], 2),
'remarks' => $val['remarks'],
'warehouse_order_number' => $order_number,
'add_time' => $stime,
'build_date' => $val['build_date'] ? (strtotime($val['build_date']) ? strtotime($val['build_date']) : $val['build_date']) : '',
'quality_guarantee_period' => $val['quality_guarantee_period']
);
$data['type'] = $type;
$res = D('SWarehousingGoods')->addData($data); //入库记录
if ($res['status'] == 0) {
return $res;
}
$money_total += $data['subtotal'];
$map = array();
$map['merchant_id'] = $merchant_id;
$map['store_id'] = $store_id;
$map['warehouse_id'] = $warehouse_id;
$map['goods_id'] = $s_goods_info['goods_id'];
if ($val['attribute_state'] == 2) {
$map['sku_id'] = $s_goods_info['sku_id'];
}
$val['goods_id'] = $s_goods_info['goods_id'];
$val['goods_class_id'] = $s_goods_info['goods_class_id'];
$val['warehouse_num'] = round($val['warehouse_num'], 3);
$val['warehouse_price'] = round($val['warehouse_price'], 2);
$val['add_time'] = $stime;
A('Api/Inventory')->goodsStockOperation($map, $val); //数量与成本价操作
}
//门店入库单状态修改
$text = array();
$text['real_goods_species'] = count($goodsList);
$text['real_money_total'] = $money_total;
$text['add_time'] = $stime;
$text['remarks'] = $remarks;
$text['status'] = 1;
$text['operator_id'] = session("jurisdiction_user")['id'];
$success = D('SWarehousingRecord')->updateData(array('id' => $id), $text);
if (!$success) {
$res['status'] = 0;
$res['msg'] = '调拨单状态修改失败';
return $res;
}
if ($type == 4 || $type == 6) {
//商户调拨
$stock_out_id = D('SWarehousingRecord')->getFindField(array('id' => $id), "stock_out_id");
$real_data = array();
$real_data['real_goods_species'] = count($goodsList);
$real_data['real_money_total'] = $money_total;
$real_data['warehousing_status'] = 1;
$real_data['warehouse_time'] = $stime;
if ($type == 4) {
$success = D('StockOutOrder')->updateData(array('id' => $stock_out_id, 'type' => 1), $real_data);
} else if ($type == 6) {
$success = D('StockOutOrder')->updateData(array('id' => $stock_out_id, 'type' => 3), $real_data);
}
if ($success['status'] == 0) {
$res['status'] = 0;
$res['msg'] = '商户调拨单状态修改失败';
return $res;
}
} else if ($type == 5) {
//门店调拨
$real_data = array();
$real_data['real_goods_species'] = count($goodsList);
$real_data['real_money_total'] = $money_total;
$real_data['warehousing_status'] = 1;
$real_data['warehouse_time'] = $stime;
$success = D('SStockOutOrder')->updateData(array('warehouse_record_id' => $id, 'type' => 3), $real_data);
if ($success['status'] == 0) {
$res['status'] = 0;
$res['msg'] = '门店调拨单状态修改失败';
return $res;
}
}
$res['status'] = 1;
$res['accept_goods_species'] = count($goodsList);
$res['accept_money_total'] = $money_total;
return $res;
}
}
/**
* @param $param 验证门店入库参数(已作废请调用Api下面的公共方法)
*/
protected function verify_param($param)
{
if (!$param['id'] || !$param['goodsList'] || !$param['warehouse_id'] || !$param['order_number'] || !$param['merchant_id'] || !$param['store_id'] || !$param['type']) {
$res['status'] = 0;
$res['msg'] = '参数缺失';
return $res;
}
if (in_array($param['type'], array(4, 5, 6))) {
switch ($param['type']) {
case 4:
case 6:
//商户调拨
$res = D('SWarehousingRecord')->merchant_param_verify($param['id']);
break;
case 5:
//门店调拨
$res = D("SStockOutOrder")->store_param_verify($param['id']);
break;
}
} else {
$res['status'] = 1;
$res['msg'] = '验证成功';
}
return $res;
}
//商品库存增加成本价重置 (已作废请调用Api下面的公共方法)
public function goodsStockOperation($where, $data)
{
$info = D('SSaleMGoods')->getFind($where);
if ($info) {
D('SSaleMGoods')->updateSetInc(array('id' => $info['id']), "goods_num", $data['warehouse_num']);
if ($info['cost_price'] != $data['warehouse_price']) {//入库价与成本价不一样
$success = $this->costPrice($where);
if ($success['status'] == 1) {
$cost_price = $success['data'];
D('SSaleMGoods')->updateData($where, array('cost_price' => $cost_price));
if (!empty($where['sku_id'])) {
M('retail_sku_goods')->where(array('id' => $where['sku_id'], 'goods_id' => $where['goods_id']))->save(array('purchase_price' => $cost_price));
} else {
D('Goods')->updateOrder(array('id' => $where['goods_id']), array('purchase_price' => $cost_price));
}
} else {
$res['status'] = 0;
$res['msg'] = '成本价计算出错';
}
} else {
$cost_price = $data['warehouse_price'];
}
if ($cost_price) {
$cost_record = array();
$cost_record['merchant_id'] = $where['merchant_id'];
$cost_record['store_id'] = $where['store_id'];
$cost_record['cost_price'] = $cost_price;
$cost_record['goods_id'] = $where['goods_id'];
if ($data['attribute_state'] == 2) {
$cost_record['sku_id'] = $where['sku_id'];
}
$cost_record['purchase_price'] = $data['warehouse_price'];
$cost_record['goods_class_id'] = $data['goods_class_id'];
$cost_record['attribute_state'] = $data['attribute_state'];
$cost_record['pricing_method'] = $data['pricing_method'];
$cost_record['add_time'] = $data['add_time'];
$success = D('SCostPriceRecord')->addData($cost_record);
if ($success['status'] == 1) {
$res['status'] = 1;
$res['msg'] = '成功';
} else {
$res['status'] = 0;
$res['msg'] = '成本价记录失败';
}
}
} else {
$res['status'] = 0;
$res['msg'] = '未找到该商品';
}
return $res;
}
//成本价计算(已作废请调用Api下面的公共方法)
public function costPrice($where)
{
$where['surplus_num'] = array('gt', 0);
$fields = "surplus_num,warehouse_price";
$order = "add_time asc";
$list = D('SWarehousingGoods')->getSelect($where, $page = '', $limit = '', $fields, $order);
if ($list) {
$priceTotal = 0;
$numTotal = 0;
foreach ($list as $key => &$val) {
$priceTotal += $val['surplus_num'] * $val['warehouse_price'];
$numTotal += $val['surplus_num'];
}
$cost_price = round(($priceTotal / $numTotal), 2);
$res['status'] = 1;
$res['data'] = $cost_price;
} else {
$res['status'] = 0;
$res['msg'] = '未找到该商品';
}
return $res;
}
//拒收
public function refuseOperation()
{
$data = I("post.");
$store_id = $this->store_id;
$merchant_id = $this->merchant_id;
if (C('IS_SET_REDIS')) {
$ApiRedis = new \Addons\Api\RedisController();
$key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_warehousing_id_" . $data['warehousing_id'];
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $data['warehousing_id']);
}
$refuse = new RefuseWarehousing();
$result = $refuse->refuseMerchantAllocation(
[
'operator_id' => session("jurisdiction_user")['id'], //操作人id
'warehousing_id' => $data['warehousing_id'], //入库单id
'stock_out_id' => $data['stock_out_id'], //出库单id
'type' => $data['type'], //入库类型
'store_id' => session('storeid'), //门店id
'merchant_id' => session("ls_userinfo")['merchantid'], //商户id
]
);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($result);
}
//导出
public function export()
{
$content = I("get.");
$content['operator_type'] = 1; //web端
$content['merchant_id'] = $this->merchant_id;
$content['store_id'] = $this->store_id;
$warehousingRecord = new WarehousingRecord();
$result = $warehousingRecord->storeWarehousingOrderList($content);
$fileds_name = "入库单导出";
$arr = array(
array('index', '序号'),
array('operator', '操作人'),
array('allocation_time', '调拨时间'),
array('add_time', '操作时间'),
array('order_number', '入库单号'),
array('warehouse_name', '入库仓库'),
array('type_name', '入库类型'),
array('supplier_name', '供应商'),
array('goods_species', '应收商品种数'),
array('money_total', '应收金额'),
array('real_goods_species', '实收合计(种)'),
array('real_money_total', '实收金额'),
array('refuse_goods_species', '拒收商品种数'),
array('refuse_total_stock_money', '拒收收金额'),
array('remarks', '备注'),
array('examine_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");
$info = D('SWarehousingRecord')->getFind(array('id' => $id));
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
switch ($info['type']) {
case 0:
$warehousing_type = "其他入库";
break;
case 1:
$warehousing_type = "采购入库";
break;
case 2:
$warehousing_type = "补货入库";
break;
case 3:
$warehousing_type = "盘盈入库";
break;
case 4:
$warehousing_type = "商户调拨入库";
break;
case 5:
$warehousing_type = "门店调拨入库";
$store_name = D('Store')->getStoreName(array('id' => $info['source_store_id']));
break;
case 6:
$warehousing_type = "申请调拨入库";
break;
}
if ($info['type'] == 0 || $info['type'] == 1 || $info['type'] == 2) {
$supplier = D('SSupplier')->getFindField(array('id' => $info['supplier_id']), "supplier_name");
}
$supplier = $supplier ? $supplier : "";
$store_name = $store_name ? $store_name : "";
$goodsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $id), $page = '', $limit = '', $fields = '', 'id asc');
if ($goodsList) {
foreach ($goodsList as $key => &$val) {
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
if (!empty($val['build_date'])) {
$val['build_date'] = date('Y-m-d', $val['build_date']);
}
$val['index'] = $key + 1;
$val['sku_num'] = strval(round($val['sku_num'], 3));
$val['warehouse_num'] = strval(round($val['warehouse_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['warehouse_price'] = "***";
$val['subtotal'] = "***";
} else {
$val['warehouse_price'] = strval(round($val['warehouse_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
}
}
if (self::$showPrice == 2 && self::$identity == 2) {
$info['real_money_total'] = "***";
}
$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 == 0 || $type == 1 || $type == 2) {
$str[1] = '入库单号:' . $info['order_number'] . ' 供应商:' . $supplier . " 类型:" . $warehousing_type . " 入库仓库:" . $warehouse;
} else if ($type == 5) {
$str[1] = '入库单号:' . $info['order_number'] . " 门店:" . $store_name . " 类型:" . $warehousing_type . " 入库仓库:" . $warehouse;
} else {
$str[1] = '入库单号:' . $info['order_number'] . " 类型:" . $warehousing_type . " 入库仓库:" . $warehouse;
}
$str[2] = '创建时间:' . $info['add_time'] . " 合计:" . $info['real_goods_species'] . "种" . " 金额:" . strval($info['real_money_total']);
$str[3] = "备注:" . $info['remarks'];
detailGetExcel($fileds_name, $arr, $goodsList, $str);
}
//调拨详情导出
public function allocationDetailsExport()
{
$id = I('get.id');
$type = I('get.type');
$where['id'] = $id;
$SWarehousingRecord = new SWarehousingRecordModel();
$info = $SWarehousingRecord->getFind($where);
if ($type == 4 || $type == 6) {
//商户调拨入库
$info['add_time'] = date('Y-m-d H:i:s', $info['allocation_time']);
if ($type == 4) {
$warehouse_id = D('StockOutOrder')->getFindField(array('warehouse_record_id' => $id, 'type' => 1), "warehouse_id");
} else if ($type == 6) {
$warehouse_id = D('StockOutOrder')->getFindField(array('warehouse_record_id' => $id, 'type' => 3), "warehouse_id");
}
$warehouse = D('SaleWarehouse')->getFindField(array('id' => $warehouse_id), "name");
$supplier = "商家调拨";
} else if ($type == 5) {
//门店调拨入库
$info['add_time'] = date('Y-m-d H:i:s', $info['allocation_time']);
$supplier = D('Store')->getStoreName(array('id' => $info['source_store_id']));
$warehouse_id = D('SStockOutOrder')->getFindField(array('warehouse_record_id' => $id, 'type' => 3), "warehouse_id");
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $warehouse_id), "name");
}
if ($type == 4 || $type == 6) {
//商家调拨单
$where = array();
$where['warehouse_record_id'] = $id;
if ($type == 4) {
$where['type'] = 1;
} else if ($type == 6) {
$where['type'] = 3;
}
$detailsList = D('StockOutGoods')->getSelect($where);
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));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['warehouse_price'] = "***";
$val['subtotal'] = "***";
} else {
$val['warehouse_price'] = strval(round($val['stock_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
$val['build_date'] = $val['build_date'] ? date('Y-m-d', $val['build_date']) : '';
}
}
} else if ($type == 5) {
//门店调拨
$where = array();
$where['warehouse_record_id'] = $id;
$where['type'] = 3;
$detailsList = D('SStockOutGoods')->getSelect($where, $page = '', $limit = '');
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
$val['warehouse_num'] = strval(round($val['stock_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['warehouse_price'] = "***";
$val['subtotal'] = "***";
} else {
$val['warehouse_price'] = strval(round($val['stock_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
}
$val['sku_num'] = strval(round($val['sku_num'], 3));
if ($val['attribute_state'] == 2) {
$val['goods_code'] = $val['sku_code'];
$val['goods_number'] = $val['sku_goods_number'];
}
$val['build_date'] = $val['build_date'] ? date('Y-m-d', $val['build_date']) : '';
}
}
if (self::$showPrice == 2 && self::$identity == 2) {
$info['money_total'] = "***";
}
$fileds_name = "调拨详情导出";
$arr = array(
array('index', '序号'),
array('goods_name', '商品名称'),
array('sku_name', '规格'),
array('goods_number', '货号'),
array('goods_code', '条码'),
array('company', '单位'),
array('sku_num', '规格基数'),
array('build_date', '生产日期'),
array('quality_guarantee_period', '保质期'),
array('warehouse_price', '调拨价'),
array('warehouse_num', '数量'),
array('subtotal', '合计'),
array('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['remarks'];
detailGetExcel($fileds_name, $arr, $detailsList, $str);
}
}