305 行
11 KiB
PHP
可执行文件
305 行
11 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\LossReport;
|
||
use Common\Business\SaleGoods;
|
||
use Common\Business\SerialNumberGoods;
|
||
use Think\Controller;
|
||
|
||
//[1.7.90]
|
||
class SLossReportController extends BaseController
|
||
{
|
||
/*
|
||
* ***********************************************报损参数与方法*********************************************************
|
||
* @param $order_number 订单号
|
||
* @param $add_time 时间
|
||
*@param $warehouse_id 仓库id
|
||
* function Info 查询报损仓库映射方法
|
||
*/
|
||
/*
|
||
* ***********************************************查询信息*****************************************************
|
||
*/
|
||
/*
|
||
* 查询仓库
|
||
*/
|
||
private function Info($merchant_id, $store_id)
|
||
{
|
||
$map['merchant_id'] = $merchant_id;
|
||
$map['store_id'] = $store_id;
|
||
$map['status'] = 1;
|
||
$fields = "id,name";
|
||
$warehouse = D('SSaleWarehouse')->getSelect($map, $page = '', $limit = '', $fields);
|
||
$this->assign('warehouse', json_encode($warehouse)); //销售仓库
|
||
}
|
||
|
||
/*
|
||
* 商品分类
|
||
*/
|
||
private function goodsClass($merchant_id)
|
||
{
|
||
$class_name = M('retail_goods_class')->where(array('merchantid' => $merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
||
$this->assign('goodsClass1', json_encode($class_name));
|
||
}
|
||
|
||
/*
|
||
* 报损信息
|
||
*/
|
||
public function index()
|
||
{
|
||
$arr = array(
|
||
'addLossOrder' => '/index.php/Retail/SLossReport/addLoss',
|
||
'exportOperation' => '/index.php/Retail/SLossReport/export',
|
||
'OrderInfo' => '/index.php/Retail/SLossReport/details'
|
||
);
|
||
$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 LossList()
|
||
{
|
||
$data = I('post.');
|
||
$data['operator_type'] = 1;
|
||
$data['user_type'] = 4;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['store_id'] = $this->store_id;
|
||
$LossReportClass = new LossReport();
|
||
$result = $LossReportClass->orderList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/*
|
||
* 新增报损单信息
|
||
*/
|
||
public function addLoss()
|
||
{
|
||
$arr = array(
|
||
'goodsChoice' => '/index.php/Retail/SLossReport/goodsList',
|
||
'onSubmit' => '/index.php/Retail/SLossReport/LossOperation'
|
||
);
|
||
$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);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//选择商品的串号信息
|
||
public function serialList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 4;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['store_id'] = $this->store_id;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->warehouseSerialList($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->lossSearchGoods($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/*
|
||
* 报损单详情
|
||
*/
|
||
public function details()
|
||
{
|
||
$arr = array(
|
||
'exportOperation' => '/index.php/Retail/SLossReport/detailsExport',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$id = I('get.id');
|
||
$operator = I('get.operator');
|
||
$where['id'] = $id;
|
||
$info = D('SLossReportOrder')->getFind($where);
|
||
$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");
|
||
$this->assign('id', $id);
|
||
$this->assign('operator', $operator);
|
||
$this->assign('info', $info);
|
||
$this->assign('warehouse', $warehouse);
|
||
$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'] = 1;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->recordSerialList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//订单详情
|
||
public function detailsList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 4;
|
||
$data['showPrice'] = self::$showPrice;
|
||
$data['identity'] = self::$identity;
|
||
$LossClass = new LossReport();
|
||
$result = $LossClass->orderGoodsList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
/*
|
||
* *************************************************操作******************************************************
|
||
*/
|
||
//报损操作
|
||
public function LossOperation()
|
||
{
|
||
$data = I('post.');
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['store_id'] = $this->store_id;
|
||
$data['operator_id'] = session("jurisdiction_user")['id'];
|
||
$result = A('Api/Inventory')->StoreReportSub($data);
|
||
if ($result['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);
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//导出
|
||
public function export()
|
||
{
|
||
$user = session("ls_userinfo");
|
||
$merchant_id = $user['merchantid'];
|
||
$store_id = session("storeid");
|
||
$content = I("get.");
|
||
$order_number = $content['order_number'];
|
||
$add_time = $content['add_time'];
|
||
if (!empty($order_number)) {
|
||
$where['order_number'] = array('like', $order_number . '%');
|
||
}
|
||
if (!empty($add_time)) {
|
||
$add_time = explode(',', $add_time);
|
||
$start_time = strtotime($add_time[0]);
|
||
$end_time = strtotime($add_time[1]);
|
||
$where['add_time'] = array('between', array($start_time, $end_time));
|
||
}
|
||
$where['merchant_id'] = $merchant_id;
|
||
$where['store_id'] = $store_id;
|
||
$where['status'] = 1;
|
||
$info = D('SLossReportOrder')->getSelect($where);
|
||
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']);
|
||
if (self::$showPrice == 2 && self::$identity == 2) {
|
||
$val['money_total'] = '***';
|
||
} else {
|
||
$val['money_total'] = round($val['money_total'], 2);
|
||
}
|
||
$val['warehouse_name'] = D('SSaleWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name");
|
||
}
|
||
} else {
|
||
$info = array();
|
||
}
|
||
$fileds_name = "报损单导出";
|
||
$arr = array(
|
||
array('index', '序号'),
|
||
array('operator', '操作人'),
|
||
array('add_time', '报损时间'),
|
||
array('order_number', '报损单号'),
|
||
array('warehouse_name', '报损仓库'),
|
||
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;
|
||
$info = D('SLossReportOrder')->getFind($where);
|
||
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
|
||
$warehouse = D('SSaleWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
|
||
$map['loss_order_id'] = $id;
|
||
$detailsList = D('SLossReportGoods')->getSelect($map);
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
$val['loss_num'] = round($val['loss_num'], 3);
|
||
if (self::$showPrice == 2 && self::$identity == 2) {
|
||
$val['loss_price'] = "***";
|
||
$val['subtotal'] = "***";
|
||
} else {
|
||
$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'];
|
||
}
|
||
}
|
||
}
|
||
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('loss_price', '成本价'),
|
||
array('loss_num', '数量'),
|
||
array('subtotal', '合计'),
|
||
array('remarks', '备注'),
|
||
);
|
||
$str = array();
|
||
$str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time());
|
||
$str[1] = '报损单号:' . $info['order_number'] . " 报损仓库:" . $warehouse . " 报损时间:" . $info['add_time'];
|
||
$str[2] = '合计:' . $info['goods_species'] . " 金额:" . $info['money_total'];
|
||
$str[3] = "备注:" . $info['remarks'];
|
||
detailGetExcel($fileds_name, $arr, $detailsList, $str);
|
||
}
|
||
} |