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

857 行
36 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\GoodsClassify;
use Common\Business\RefuseWarehousing;
use Common\Business\SerialNumberGoods;
use Common\Model\AllocationOrderModel;
use Common\Model\StockGoodsSerialModel;
use Common\Model\StockOutGoodsModel;
use Think\Controller;
//[1.8.76]
class AllocationApplyController 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));
}
public function index()
{
$arr = array(
'exportOperation' => '/index.php/Retail/AllocationApply/export',
'addOrder' => '/index.php/Retail/AllocationApply/addOrder',
'apply' => '/index.php/Retail/AllocationApply/apply_details',
'warehousingOperation' => '/index.php/Retail/AllocationApply/warehousingInfo',
'refuse' => '/index.php/Retail/AllocationApply/refuse',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
/*
* 订单列表
*/
public function OrderList()
{
$merchant_id = session("ls_userinfo")['merchantid'];
$store_id = session("storeid");
$data = I("post.");
$add_time = $data['add_time'];
$status = $data['status'];
$order_number = $data['order_number'];
$page = $data['page'];
$limit = $data['limit'];
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));
}
if (!empty($order_number)) {
$where['order_number'] = $order_number;
}
if (!empty($status)) {
$where['status'] = $status;
}
$where['store_id'] = $store_id;
$where['merchant_id'] = $merchant_id;
$list = D('AllocationOrder')->getSelect($where, $page, $limit);
if ($list) {
$count = D('AllocationOrder')->getCount($where);
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
$val['operator'] = A('Api/Inventory')->OperatorName($val['s_operator_id']);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
if (!empty($val['stock_time'])) {
$val['stock_time'] = date('Y-m-d H:i:s', $val['stock_time']);
}
if (!empty($val['storage_time'])) {
$val['storage_time'] = date('Y-m-d H:i:s', $val['storage_time']);
} else if (!empty($val['refuse_time'])) {
$val['storage_time'] = date('Y-m-d H:i:s', $val['refuse_time']);
}
switch ($val['status']) {
case 1:
$val['status_name'] = "申请中";
break;
case 2:
if ($val['refuse_status'] == 2) {
$val['status_name'] = "已拒收";
} else {
$val['status_name'] = "已出库";
}
break;
case 3:
$val['status_name'] = "已入库";
break;
}
}
} else {
$count = 0;
}
$res['status'] = 1;
$res['count'] = $count;
$res['data'] = $list;
$this->ajaxReturn($res);
}
/*
* 新增调拨单
*/
public function addOrder()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/AllocationApply/goodsList',
'onSubmit' => '/index.php/Retail/AllocationApply/ApplyOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$merchant_id = session("ls_userinfo")['merchantid'];
$this->goodsClass($merchant_id);
$this->display();
}
/*
* 商户的商品
*/
public function goodsList()
{
$merchant_id = $this->merchant_id;
$content = I("post.");
$page = $content['page'];
$limit = $content['limit'];
$notInIds = $content['notInIds'];
$searchText = $content['searchText'];
$person1 = $content['person1'];
$person2 = $content['person2'];
$person3 = $content['person3'];
if (!empty($searchText)) {
$where['goods_number|sku_goods_number|goods_code|sku_code|goods_name|sku_name'] = array('like', "%" . $searchText . "%");
}
$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;
}
//调拨目标门店的行业id
if (empty($where['goods_class_id']) && !empty($content['industry_id'])) {
$GoodsClass = new GoodsClassify();
$classResult = $GoodsClass->basisIndustryGetClass([
'industry_id' => $content['industry_id'],
'merchant_id' => $merchant_id
]);
if (!empty($classResult['data'])) {
$where['goods_class_id'] = ['in', $classResult['data']];
}
}
if (!empty($notInIds)) {
$where['id'] = array('not in', $notInIds);
}
$where['status'] = 0;
$where['merchant_id'] = $merchant_id;
$goodsList = D('SaleMGoods')->getSelect($where, $page, $limit);
if ($goodsList) {
$count = D('SaleMGoods')->getCount($where);
foreach ($goodsList as $key => &$val) {
$val['index'] = $key + 1;
$val['goods_num'] = round($val['goods_num'], 3);
$val['sku_num'] = round($val['sku_num'], 3);
}
} else {
$goodsList = array();
$count = 0;
}
// var_dump($goodsList);
$res['status'] = 1;
$res['count'] = $count;
$res['data'] = $goodsList;
$this->ajaxReturn($res);
}
/*
* 提交申请
*/
public function ApplyOperation()
{
$reg2 = "/^[0-9]+(.[0-9]{1,3})?$/";
$reg3 = "/^\+?[1-9][0-9]*$/";
$data = I("post.");
$merchant_id = $this->merchant_id;
$store_id = $this->store_id;
$time = $_SERVER['REQUEST_TIME'];
$goodsList = $data['goodsList'];
$goodsList = json_decode(htmlspecialchars_decode($goodsList), true);
if (!$merchant_id || !$store_id || !$goodsList) {
$res['status'] = 0;
$res['msg'] = '缺少参数';
$this->ajaxReturn($res);
}
$remarks = $data['remarks'];
if (count($goodsList) > 500) {
$res['status'] = 0;
$res['msg'] = '单次操作上限为500种';
$this->ajaxReturn($res);
}
foreach ($goodsList as $key => &$val) {
if (!$val['apply_num']) {
$res['status'] = 0;
$res['msg'] = $val['goods_name'] . $val['sku_name'] . "请输入正确数量";
$this->ajaxReturn($res);
}
if ($val['attribute_state'] == 1 && $val['pricing_method'] == 2) {
if (!preg_match($reg2, $val['apply_num'])) {
$res['status'] = 0;
$res['msg'] = $val['goods_name'] . $val['sku_name'] . "请输入正确数量";
$this->ajaxReturn($res);
}
} else {
if (!preg_match($reg3, $val['apply_num'])) {
$res['status'] = 0;
$res['msg'] = $val['goods_name'] . $val['sku_name'] . "请输入正确数量";
$this->ajaxReturn($res);
}
}
}
$order = array();
$order['store_id'] = $store_id;
$order['merchant_id'] = $merchant_id;
$order['add_time'] = $time;
$order['status'] = 1;
$order['remarks'] = $remarks;
$OperatorInfo = A('Api/Inventory')->Operator(session("jurisdiction_user"));
if ($OperatorInfo) {
$order['s_operator_id'] = $OperatorInfo['id'];
}
$res = D('AllocationOrder')->addData($order);
if ($res['status'] == 0) {
$res['msg'] = "订单创建失败";
$this->ajaxReturn($res);
}
$orderId = $res['data'];
$orderNumber = 'SS' . orderNumber($orderId);
foreach ($goodsList as $key => &$val) {
$content = [];
$content['store_id'] = $store_id;
$content['merchant_id'] = $merchant_id;
$content['allocation_id'] = $orderId;
$content['order_number'] = $orderNumber;
$content['add_time'] = $time;
$content['goods_id'] = $val['goods_id'];
$content['goods_name'] = $val['goods_name'];
$content['goods_class_id'] = $val['goods_class_id'];
$content['goods_number'] = $val['goods_number'];
$content['goods_code'] = $val['goods_code'];
$content['company'] = $val['company'];
$content['attribute_state'] = $val['attribute_state'];
$content['pricing_method'] = $val['pricing_method'];
$content['apply_num'] = $val['apply_num'];
$content['remarks'] = $val['remarks'];
$content['serial_number_state'] = $val['serial_number_state'] ? $val['serial_number_state'] : 0;
if ($val['attribute_state'] == 2) {
$content['sku_id'] = $val['sku_id'];
$content['sku_name'] = $val['sku_name'];
$content['sku_id_list'] = $val['sku_id_list'];
$content['sku_goods_number'] = $val['sku_goods_number'];
$content['sku_code'] = $val['sku_code'];
$content['sku_num'] = $val['sku_num'];
}
$res = D('AllocationGoods')->addData($content);
if ($res['status'] == 0) {
$res['msg'] = '商品存入失败';
$this->ajaxReturn($res);
}
}
$text = array();
$text['store_goods_species'] = count($goodsList);
$text['order_number'] = $orderNumber;
$res = D('AllocationOrder')->updateData(array('id' => $orderId), $text);
if ($res['status'] == 0) {
$res['msg'] = '订单修改失败';
$this->ajaxReturn($res);
}
//操作日志记录
$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($res);
}
/*
* 申请调拨详情
*/
public function apply_details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/AllocationApply/applyDetailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I("get.id");
$operator = I("get.operator");
$this->assign('operator', $operator);
$store_name = I("get.store_name");
$info = D('AllocationOrder')->getFind(array('id' => $id));
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
if (!empty($info['stock_time'])) {
$info['stock_time'] = date('Y-m-d H:i:s', $info['stock_time']);
}
if (!empty($info['storage_time'])) {
$info['storage_time'] = date('Y-m-d H:i:s', $info['storage_time']);
}
switch ($info['status']) {
case 1:
$info['status_name'] = '申请中';
break;
case 2:
$info['status_name'] = '商户已出库';
break;
case 3:
$info['status_name'] = '已入库';
break;
}
$this->assign('id', $id);
$this->assign('store_name', $store_name);
$this->assign('info', $info);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->assign("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//申请调拨列表
public function detailsList()
{
$id = I("post.id");
$orderInfo = D('AllocationOrder')->getFind(array('id' => $id));
if (!empty($orderInfo['stock_order_id'])) {
$stockGoods = D('StockOutGoods')->getSelect(['stock_out_id' => $orderInfo['stock_order_id'], 'type' => ['in', '0,1,2,3,9']]);
}
if (!empty($orderInfo['warehouse_order_id'])) {
$warehouseGoods = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $orderInfo['warehouse_order_id']));
}
$list = D('AllocationGoods')->getSelect(array('allocation_id' => $id));
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
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);
$val['stock_id'] = $sval['id'];
}
}
}
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);
if (!empty($wval['build_date'])) {
$val['build_date'] = date('Y-m-d', $wval['build_date']);
}
$val['quality_guarantee_period'] = $wval['quality_guarantee_period'];
$val['warehouse_id'] = $wval['id'];
}
}
}
}
$res['status'] = 1;
$res['data'] = $list;
$this->ajaxReturn($res);
}
/*
* 入库信息
*/
public function warehousingInfo()
{
$global_store_jurisdiction = session('global_store_jurisdiction');
$arr = array(
'onSubmit' => '/index.php/Retail/AllocationApply/warehousingOperation',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I("get.id");
$stock_order_id = I("get.stock_order_id");
$info = D('StockOutOrder')->getFind(array('id' => $stock_order_id));
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['remarks'] = str_replace("\n", "", $info['remarks']);
$this->assign('info', $info);
$this->assign('id', $id);
$this->assign('stock_order_id', $stock_order_id);
$this->assign('allocation_state', $global_store_jurisdiction['allocation']);
$this->assign('showPrice', self::$showPrice);
$this->assign('identity', self::$identity);
$this->display();
}
/*
* 入库商品信息
*/
public function warehousingList()
{
$id = I("post.id");
$StockOutGoodsModel = new StockOutGoodsModel();
$StockSerialModel = new StockGoodsSerialModel();
$goodsList = $StockOutGoodsModel->getSelect(array('stock_out_id' => $id));
if (!empty($goodsList)) {
$where = [
'merchant_id' => $this->merchant_id,
'num' => ['gt', 0]
];
$fields = 'id,main_serial_number,auxiliary_serial_number_one,auxiliary_serial_number_two';
foreach ($goodsList as $key => &$val) {
$val['stock_num'] = round($val['stock_num'], 3);
$val['warehouse_num'] = $val['stock_num'];
$val['warehouse_price'] = $val['stock_price'];
$val['build_date'] = '';
$val['quality_guarantee_period'] = '';
if ($val['serial_number_state'] == 1) {
$where['outside_id'] = $val['id'];
$val['serial_list'] = $StockSerialModel->getSelect($where, '', '', $fields);
}
}
}
$res['status'] = 1;
$res['data'] = $goodsList;
$this->ajaxReturn($res);
}
/*
* 验证商品信息
*/
public function goodsVerify()
{
$merchant_id = session("ls_userinfo")['merchantid'];
$store_id = session("storeid");
$goodsList = I("post.goodsList");
$id = I("post.id");
$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 . "_allocation_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 300, $id);
}
$success = A('Api/Inventory')->goodsVerify($merchant_id, $store_id, $goodsList);
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
if ($success['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($success);
}
/*
* 同步商户的商品信息
*/
public function batchSync()
{
$merchant_id = session("ls_userinfo")['merchantid'];
$store_id = I('session.storeid');
$goodsIds = I("post.goodsIds");
$id = I("post.id");
$type = 4; //商户调拨
if (!$merchant_id || !$store_id || !$goodsIds) {
$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 . "_allocation_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 300, $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 warehousingOperation()
{
$merchant_id = session("ls_userinfo")['merchantid'];
$store_id = session("storeid");
$id = I("post.id");
$goodsList = json_decode(htmlspecialchars_decode(I("post.goodsList")), true);
$refuseList = json_decode(htmlspecialchars_decode(I("post.refuse_list")), true);
$remarks = I("post.remarks");
if (!$id || !$goodsList) {
$res['status'] = 0;
$res['msg'] = '参数错误';
$this->ajaxReturn($res);
}
$info = D('AllocationOrder')->getFind(array('id' => $id));
if (!$info) {
$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 . "_allocation_id_" . $id;
if ($ApiRedis::$redis->exists($key_name)) {
$res['status'] = 0;
$res['msg'] = "正在入库,请勿重复操作";
$this->ajaxReturn($res);
}
$ApiRedis::$redis->setex($key_name, 60, $id);
}
$warehouse_id = D('SSaleWarehouse')->getFindField(array('store_id' => $store_id, 'merchant_id' => $merchant_id, 'status' => 1), "id");
$parameter = array(
'merchant_id' => $merchant_id,
'store_id' => $store_id,
'id' => $info['warehouse_order_id'],
'type' => 6, //申请调拨入库,
'order_number' => $info['order_number'],
'goodsList' => $goodsList,
'warehouse_id' => $warehouse_id,
'remarks' => $remarks,
'operator_id' => session("jurisdiction_user")['id'],
'refuseList' => $refuseList,
);
$res = A('Api/Inventory')->allocationWarehousing($parameter);
if ($res['status'] == 1) {
$saveData = array(
'accept_goods_species' => $res['accept_goods_species'],
'accept_money_total' => $res['accept_money_total'],
'accept_total_cost_money' => $res['accept_total_cost_money'],
'status' => 3,
'storage_time' => time(),
);
if ($res['refuse_status'] == 2) {
//有拒收
$saveData['refuse_status'] = 2;
$saveData['refuse_total_cost_money'] = $res['refuse_total_cost_money'];
$saveData['refuse_total_stock_money'] = $res['refuse_total_stock_money'];
$saveData['refuse_goods_species'] = $res['refuse_goods_species'];
}
$res = D('AllocationOrder')->updateData(array('id' => $id), $saveData);
if ($res['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0后台系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '调拨单-入库';//操作行为描述
action_log($source, $type, $request_data, $desc);
}
} else {
$res['status'] = 0;
$res['msg'] = '操作失败';
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($res);
}
/*
* 订单导出
*/
public function export()
{
$merchant_id = session("ls_userinfo")['merchantid'];
$store_id = session("storeid");
$data = I("get.");
$add_time = $data['add_time'];
$status = $data['status'];
$order_number = $data['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));
}
if (!empty($order_number)) {
$where['order_number'] = $order_number;
}
if (!empty($status)) {
$where['status'] = $status;
}
$where['store_id'] = $store_id;
$where['merchant_id'] = $merchant_id;
$list = D('AllocationOrder')->getSelect($where);
if ($list) {
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
$val['operator'] = A('Api/Inventory')->OperatorName($val['s_operator_id']);
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
if (self::$showPrice == 2 && self::$identity == 2) {
$val['money_total'] = "***";
$val['accept_money_total'] = "***";
}
if (!empty($val['stock_time'])) {
$val['stock_time'] = date('Y-m-d H:i:s', $val['stock_time']);
}
if (!empty($val['storage_time'])) {
$val['storage_time'] = date('Y-m-d H:i:s', $val['storage_time']);
} else if (!empty($val['refuse_time'])) {
$val['storage_time'] = date('Y-m-d H:i:s', $val['refuse_time']);
}
switch ($val['status']) {
case 1:
$val['status_name'] = "申请中";
break;
case 2:
if ($val['refuse_status'] == 2) {
$val['status_name'] = "已拒收";
} else {
$val['status_name'] = "已出库";
}
break;
case 3:
$val['status_name'] = "已入库";
break;
}
}
}
$fileds_name = "调拨单导出";
$arr = array(
array('index', '序号'),
array('operator', '操作人'),
array('add_time', '申请时间'),
array('stock_time', '出库时间'),
array('storage_time', '已入库时间'),
array('order_number', '调拨单号'),
array('store_goods_species', '申请合计(种)'),
array('goods_species', '应收合计(种)'),
array('money_total', '应收金额'),
array('accept_goods_species', '实收合计(种)'),
array('accept_money_total', '实收金额'),
array('refuse_goods_species', '拒收合计(种)'),
array('refuse_total_stock_money', '拒收金额'),
array('remarks', '备注'),
array('status_name', '状态'),
);
$str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
getExcel($fileds_name, $arr, $list, $str);
}
/*导出
*
*/
public function applyDetailsExport()
{
$id = I("get.id");
$orderInfo = D('AllocationOrder')->getFind(array('id' => $id));
if (!empty($orderInfo['stock_time'])) {
$orderInfo['stock_time'] = date('Y-m-d H:i:s', $orderInfo['stock_time']);
}
if (!empty($orderInfo['storage_time'])) {
$orderInfo['storage_time'] = date('Y-m-d H:i:s', $orderInfo['storage_time']);
}
switch ($orderInfo['status']) {
case 1:
$orderInfo['status_name'] = '申请中';
break;
case 2:
$orderInfo['status_name'] = '商家已出库';
break;
case 3:
$orderInfo['status_name'] = '门店已入库';
break;
}
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']));
}
$list = D('AllocationGoods')->getSelect(array('allocation_id' => $id));
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
$val['apply_num'] = strval(round($val['apply_num'], 3));
$val['sku_num'] = strval(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'] = strval(round($sval['stock_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['stock_price'] = "***";
$val['stock_price_total'] = "***";
} else {
$val['stock_price'] = strval(round($sval['stock_price'], 2));
$val['stock_price_total'] = strval(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'] = strval(round($wval['warehouse_num'], 3));
if (self::$showPrice == 2 && self::$identity == 2) {
$val['warehouse_price'] = "***";
$val['warehouse_price_total'] = "***";
} else {
$val['warehouse_price'] = strval(round($wval['warehouse_price'], 2));
$val['warehouse_price_total'] = strval(round($val['warehouse_num'] * $val['warehouse_price'], 2));
}
if (!empty($wval['build_date'])) {
$val['build_date'] = date('Y-m-d', $wval['build_date']);
}
$val['quality_guarantee_period'] = $wval['quality_guarantee_period'];
}
}
}
}
if (self::$showPrice == 2 && self::$identity == 2) {
$orderInfo['money_total'] = "***";
$orderInfo['accept_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('apply_num', '申请数量'),
array('stock_num', '出库数量'),
array('stock_price', '出库金额'),
array('stock_price_total', '合计'),
array('warehouse_num', '入库数量'),
array('warehouse_price', '入库金额'),
array('warehouse_price_total', '合计'),
array('remarks', '备注'),
);
$str = array();
$str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
$str[1] = "调拨单号:" . $orderInfo['order_number'] . " 申请时间:" . date('Y-m-d H:i:s', $orderInfo['add_time']) . " 合计:" . $orderInfo['store_goods_species'];
$str[2] = "商家出库时间:" . $orderInfo['stock_time'] . " 合计:" . $orderInfo['goods_species'] . " 金额:" . strval($orderInfo['money_total']);
$str[3] = "门店入库时间:" . $orderInfo['storage_time'] . " 合计:" . $orderInfo['accept_goods_species'] . " 金额:" . strval($orderInfo['accept_money_total']) . " 状态:" . $orderInfo['status_name'];
detailGetExcel($fileds_name, $arr, $list, $str);
}
//拒收
public function refuse()
{
$data = I("post.");
$store_id = session("storeid");
$merchant_id = session("ls_userinfo")['merchantid'];
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' => 6, //申请调拨
'store_id' => session('storeid'), //门店id
'merchant_id' => session("ls_userinfo")['merchantid'] //商户id
]
);
if ($result['status'] == 1) {
$AllocationOrderModel = new AllocationOrderModel();
$update = array(
'refuse_goods_species' => $result['data']['refuse_goods_species'],
'refuse_total_cost_money' => $result['data']['refuse_total_cost_money'],
'refuse_total_stock_money' => $result['data']['refuse_total_stock_money'],
'refuse_status' => 2,
'refuse_time' => time()
);
$AllocationOrderModel->updateData(array('id' => $data['id']), $update);
}
if (C('IS_SET_REDIS')) {
$ApiRedis::$redis->delete($key_name);
}
$this->ajaxReturn($result);
}
}