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

361 行
14 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\PurchaseGoodsInfo;
use Common\Business\RetreatOrder;
use Common\Business\SerialNumberGoods;
use Think\Controller;
//[1.7.90]
/**
* Class SRetreatOrderController
* @package Retail\Controller
*/
class SRetreatOrderController 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('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));
}
//采购退货单信息
public function index()
{
$arr = array(
'addRetreatOrder' => '/index.php/Retail/SRetreatOrder/addRetreatOrder',
'exportOperation' => '/index.php/Retail/SRetreatOrder/export',
'OrderInfo' => '/index.php/Retail/SRetreatOrder/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 OrderTotal()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$RetreatOrderClass = new RetreatOrder();
$result = $RetreatOrderClass->orderTotal($data);
$this->ajaxReturn($result);
}
public function retreatOrderList()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 4;
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$RetreatOrderClass = new RetreatOrder();
$result = $RetreatOrderClass->orderList($data);
$this->ajaxReturn($result);
}
//新增采购退货退货退货退货单信息
public function addRetreatOrder()
{
$arr = array(
'goodsChoice' => '/index.php/Retail/SRetreatOrder/goodsList',
'onSubmit' => '/index.php/Retail/SRetreatOrder/retreatOperation'
);
$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;
$SerialClass = new SerialNumberGoods();
$result = $SerialClass->returnableSerialList($data);
$this->ajaxReturn($result);
}
/**
* 采购退货的可退商品列表
* [
* notInIds 已选中的采购商品
* searchText 名称货号条码
* supplier_id 供货商id
* warehouse_id 仓库id
* ]
*/
public function goodsList()
{
$data = I("post.");
$data['user_type'] = 4; //门店
$data['merchant_id'] = $this->merchant_id;
$data['store_id'] = $this->store_id;
$PurchaseGoodsClass = new PurchaseGoodsInfo();
$result = $PurchaseGoodsClass->returnablePurchaseGoodsList($data);
$this->ajaxReturn($result);
}
//采购退货详情
public function details()
{
$arr = array(
'exportOperation' => '/index.php/Retail/SRetreatOrder/detailsExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
$operator = I('get.operator');
$this->assign('operator', $operator);
$where['id'] = $id;
$info = D('SPurchaseRetreatOrder')->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']);
$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("global_store_jurisdiction", self::$global_store_jurisdiction);
$this->display();
}
//详情串号列表
public function detailSerialList()
{
$data = I('post.');
$data['user_type'] = 4;
$data['type'] = 2;
$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;
$RetreatOrderClass = new RetreatOrder();
$result = $RetreatOrderClass->detailsList($data);
$this->ajaxReturn($result);
}
/*
* *************************************************操作******************************************************
*/
//采购退货的商品
public function retreatOperation()
{
$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")->StoreRetreatAction($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 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'];
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)) {
$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('SPurchaseRetreatOrder')->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['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 (self::$showPrice == 2 && self::$identity == 2) {
$val['money_total'] = '***';
$val['total_cost_price'] = '***';
$val['difference_money'] = '***';
} else {
$val['money_total'] = strval(round($val['money_total'], 2));
$val['total_cost_price'] = strval(round($val['total_cost_price'], 2));
$val['difference_money'] = strval(round($val['money_total'] - $val['total_cost_price'], 2));
}
}
}
$fileds_name = "采购退货单导出";
$arr = array(
array('index', '序号'),
array('operator', '操作人'),
array('add_time', '退货时间'),
array('order_number', '退货单号'),
array('supplier', '供应商'),
array('warehouse', '仓库'),
array('goods_species', '合计(种)'),
array('total_cost_price', '原采购金额'),
array('money_total', '退货金额'),
array('difference_money', '盈亏金额'),
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('SPurchaseRetreatOrder')->getFind($where);
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
$info['goods_species'] = round($info['goods_species'], 3);
$supplier = D('SSupplier')->getFindField(array('id' => $info['supplier_id']), "supplier_name");
$warehouse = D('SPurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
$map['retreat_order_id'] = $id;
$detailsList = D('SRetreatGoods')->getSelect($map, $page = '', $limit = '', $field = '', 'id asc');
if ($detailsList) {
foreach ($detailsList as $key => &$val) {
$val['index'] = $key + 1;
$val['retreat_num'] = strval(round($val['retreat_num'], 3));
if (!empty($val['build_date'])) {
$val['build_date'] = date('Y-m-d', $val['build_date']);
}
if (self::$showPrice == 2 && self::$identity == 2) {
$val['retreat_price'] = '***';
$val['subtotal'] = '***';
$val['difference_money'] = "***";
$val['purchase_price'] = "***";
} else {
$val['purchase_price'] = strval(round($val['purchase_price'], 2));
$val['retreat_price'] = strval(round($val['retreat_price'], 2));
$val['subtotal'] = strval(round($val['subtotal'], 2));
$val['difference_money'] = strval(round(($val['retreat_price'] - $val['purchase_price']) * $val['retreat_num'], 2));
}
$val['sku_num'] = strval(round($val['sku_num'], 3));
if ($val['attribute_state'] == 2) {
$val['goods_number'] = $val['sku_goods_number'];
$val['goods_code'] = $val['sku_code'];
}
}
}
if (self::$showPrice == 2 && self::$identity == 2) {
$info['money_total'] = '***';
}
$fileds_name = "采购退货单详情导出";
$arr = array(
array('index', '序号'),
array('purchase_order_number', '批次号'),
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('purchase_price', '原采购价'),
array('retreat_price', '退货价'),
array('retreat_num', '数量'),
array('subtotal', '合计'),
array('difference_money', '盈亏金额'),
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);
}
}