809 行
34 KiB
PHP
可执行文件
809 行
34 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\CacheHandle;
|
||
use Common\Business\Goods;
|
||
use Common\Business\InventorySet;
|
||
use Common\Business\PinYin;
|
||
use Common\Business\PurchaseOrder;
|
||
use Common\Business\SaleGoods;
|
||
use Common\Business\SerialNumberGoods;
|
||
use Common\Model\PurchaseGoodsModel;
|
||
use Think\Controller;
|
||
use Common\Business\PurchaseGoodsInfo;
|
||
|
||
//[1.7.90]
|
||
|
||
/**
|
||
* Class PurchaseOrderController
|
||
* @package Retail\Controller
|
||
*/
|
||
class PurchaseOrderController extends BaseController
|
||
{
|
||
/*
|
||
* ***********************************************采购订单参数与方法*********************************************************
|
||
* @param $order_number 订单号
|
||
* @param $add_time 采购时间
|
||
* @param $supplier_id 供货商id
|
||
* @param $warehouse_id 仓库id
|
||
*
|
||
* function Info 查询供货商与采购仓库映射方法
|
||
*/
|
||
/*
|
||
* ***********************************************查询信息*****************************************************
|
||
*/
|
||
/*
|
||
* 查询供货商与仓库
|
||
* @param $merchant_id 商户id
|
||
*/
|
||
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('PurchaseWarehouse')->getSelect($map, $page = '', $limit = '', $fields, $order = 'default_state desc');
|
||
$this->assign('supplier', json_encode($supplier));
|
||
$this->assign('warehouse', json_encode($warehouse));
|
||
}
|
||
|
||
/*
|
||
* 商品分类
|
||
* @param $merchant_id 商户id
|
||
*/
|
||
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));
|
||
}
|
||
|
||
/*
|
||
* 规格信息2020-1-3已作废
|
||
* @param $goods_id 商品id
|
||
*/
|
||
private function getMGoodsSkuInfo($goods_id)
|
||
{
|
||
$skuList = M('retail_sku_mgoods')->where(array('mgoods_id' => $goods_id, 'state' => 0))->select();
|
||
$skuAttr = array();
|
||
if (!empty($skuList)) {
|
||
foreach ($skuList as &$value) {
|
||
$tempId = explode(',', $value['sku_id_list']);
|
||
foreach ($tempId as &$v) {
|
||
$v = intval($v);
|
||
$value['name'][] = M('retail_sku_list')->where(array('id' => $v))->getField('name');
|
||
}
|
||
$value['tempId'] = $tempId;
|
||
$goods_num = D('SaleMGoods')->getFindField(array('goods_id' => $goods_id, 'sku_id' => $value['id'], 'status' => array('neq', 2)), "goods_num");
|
||
$goods_num = $goods_num ? $goods_num : 0;
|
||
$value['goods_num'] = round($goods_num, 2);
|
||
if ($value['sku_num'] == round($value['sku_num'])) {
|
||
$value['sku_num'] = round($value['sku_num']);
|
||
}
|
||
$value['sku_purchase_num'] = "";
|
||
$purchase_info = D('PurchaseGoods')->getFind(array('goods_id' => $goods_id, 'sku_id' => $value['id']), "id desc");
|
||
if (!empty($purchase_info)) {
|
||
$value['purchase_price'] = $purchase_info['purchase_price'];
|
||
} else {
|
||
$value['purchase_price'] = round($value['purch_price'], 2);
|
||
}
|
||
}
|
||
//为了保证规格顺序
|
||
$skuAttr = array();
|
||
for ($i = 0; $i < count($skuList[0]['tempId']); $i++) {
|
||
$skuAttr[] = M('retail_sku_attr as s')
|
||
->join('ls_retail_sku_list as l on l.attr_id=s.id')
|
||
->where(array('s.state' => 0, 'l.id' => $skuList[0]['tempId'][$i]))
|
||
->group('l.attr_id')
|
||
->field('s.id,s.name')
|
||
->find();
|
||
}
|
||
}
|
||
$data['attr'] = $skuAttr;
|
||
$data['list'] = $skuList;
|
||
return $data;
|
||
}
|
||
|
||
/*
|
||
* 采购单信息
|
||
*/
|
||
public function index()
|
||
{
|
||
$arr = array(
|
||
'search' => '/index.php/Retail/PurchaseOrder/purchaseOrderList',
|
||
'addPurchaseOrder' => '/index.php/Retail/PurchaseOrder/addPurchaseOrder',
|
||
'exportOperation' => '/index.php/Retail/PurchaseOrder/export',
|
||
'OrderInfo' => '/index.php/Retail/PurchaseOrder/details',
|
||
'edit' => '/index.php/Retail/PurchaseOrder/warehousing',
|
||
'warehousing' => '/index.php/Retail/PurchaseOrder/warehousingOperation',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$user = session("merchant_userinfo");
|
||
$this->Info($user['id']);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//采购单金额统计
|
||
public function orderTotal()
|
||
{
|
||
$data = I('post.');
|
||
$data['operator_type'] = 1;
|
||
$data['user_type'] = 3;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$PurchaseOrderClass = new PurchaseOrder();
|
||
$result = $PurchaseOrderClass->orderTotal($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//采购单列表
|
||
public function purchaseOrderList()
|
||
{
|
||
$data = I('post.');
|
||
$data['operator_type'] = 1;
|
||
$data['user_type'] = 3;
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$PurchaseOrderClass = new PurchaseOrder();
|
||
$result = $PurchaseOrderClass->orderList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/*新增采购单信息
|
||
*
|
||
*/
|
||
public function addPurchaseOrder()
|
||
{
|
||
$arr = array(
|
||
'goodsChoice' => '/index.php/Retail/PurchaseOrder/goodsList',
|
||
'onSubmit' => '/index.php/Retail/PurchaseOrder/purchaseOperation',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$user = session("merchant_userinfo");
|
||
$this->Info($user['id']);
|
||
$this->goodsClass($user['id']);
|
||
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
|
||
$this->assign('set_batch_number', $set_batch_number);
|
||
$this->display();
|
||
}
|
||
|
||
//添加采购单的基础数据
|
||
public function addPurchaseOrderBasics()
|
||
{
|
||
//采购修改售价权限
|
||
$InventorySetClass = new InventorySet();
|
||
$info = $InventorySetClass->getInfo([
|
||
'merchant_id' => $this->merchant_id,
|
||
'user_type' => 3
|
||
]);
|
||
$this->ajaxReturn([
|
||
'status' => 1,
|
||
'message' => '查询成功',
|
||
'data' => [
|
||
'modify_price_state' => $info['modify_price_state']
|
||
]
|
||
]);
|
||
}
|
||
|
||
|
||
//串号验证
|
||
public function serialVerify()
|
||
{
|
||
$data = I('post.');
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['user_type'] = 3;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->singleGoodsVerify($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//采购选择商品
|
||
public function goodsList()
|
||
{
|
||
$content = I('post.');
|
||
$content['operator_type'] = 1;
|
||
$content['user_type'] = 3;
|
||
$content['merchant_id'] = $this->merchant_id;
|
||
$SaleClass = new SaleGoods();
|
||
$result = $SaleClass->purchaseSearchGoods($content);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//规格信息已作废
|
||
public function skuInfo()
|
||
{
|
||
$id = I("post.goods_id");
|
||
$data = $this->getMGoodsSkuInfo($id);
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
|
||
//采购单详情
|
||
public function details()
|
||
{
|
||
$arr = array(
|
||
'exportOperation' => '/index.php/Retail/PurchaseOrder/purchaseOrderList',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$id = I('get.id');
|
||
$operator = I('get.operator');
|
||
$this->assign('operator', $operator);
|
||
$where['id'] = $id;
|
||
$info = D('PurchaseOrder')->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']);
|
||
$goodsNum = D('PurchaseGoods')->getSum(array('purchase_order_id' => $info['id']), "surplus_num");
|
||
$goodsNum = $goodsNum ? $goodsNum : 0;
|
||
if ($goodsNum > 0) {
|
||
$info['warehouse_state'] = "未入库";
|
||
} else {
|
||
$info['warehouse_state'] = "已入库";
|
||
}
|
||
$supplier = M('retail_supplier')->where(array('id' => $info['supplier_id']))->getField("supplier_name");
|
||
$warehouse = D('PurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
|
||
$this->assign('id', $id);
|
||
$this->assign('info', $info);
|
||
$this->assign('supplier', $supplier);
|
||
$this->assign('warehouse', $warehouse);
|
||
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
|
||
$this->assign('set_batch_number', $set_batch_number);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
/**
|
||
* 打印
|
||
* type 1采购单 2采购退货单
|
||
*/
|
||
public function prints()
|
||
{
|
||
$merchant_id = session("merchant_userinfo")['id'];
|
||
$print = D("InventoryPrint")->getFind(array('type' => 1, 'merchant_id' => $merchant_id));
|
||
if (!$print) {
|
||
$print = array(
|
||
'goods_name_state' => 1,
|
||
'sku_name_state' => 1,
|
||
'goods_number_state' => 1,
|
||
'goods_code_state' => 1,
|
||
'company_state' => 1,
|
||
'sku_num_state' => 1,
|
||
'price_state' => 1,
|
||
'num_state' => 1,
|
||
'remarks_state' => 1
|
||
);
|
||
}
|
||
if (!empty($print['font_num'])) {
|
||
$font_state = true;
|
||
$len = $print['font_num'];
|
||
if ($len <= 6) {
|
||
$px = 70;
|
||
} else if ($len > 6 && $len <= 8) {
|
||
$px = 100;
|
||
} else if ($len > 8 && $len <= 10) {
|
||
$px = 130;
|
||
} else if ($len > 10 && $len <= 12) {
|
||
$px = 145;
|
||
} else if ($len > 12 && $len <= 14) {
|
||
$px = 180;
|
||
} else if ($len > 14 && $len <= 16) {
|
||
$px = 210;
|
||
} else if ($len > 16 && $len <= 18) {
|
||
$px = 235;
|
||
} else if ($len > 18 && $len <= 20) {
|
||
$px = 250;
|
||
} else {
|
||
$px = 280;
|
||
}
|
||
} else {
|
||
$font_state = false;
|
||
}
|
||
$this->assign('px', $px);
|
||
$this->assign('font_state', $font_state);
|
||
$this->assign('print', $print);
|
||
$data = I('get.');
|
||
switch ($data['type']) {
|
||
case 1:
|
||
$type_name = '商户采购单';
|
||
$where['purchase_order_id'] = $data['id'];
|
||
$detailsList = D('PurchaseGoods')->getSelect($where, $page = '', $limit = '', $field = '', 'id asc');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$val['sku_num'] = round($val['sku_num'], 3);
|
||
$val['purchase_num'] = round($val['purchase_num'], 3);
|
||
$val['purchase_price'] = round($val['purchase_price'], 2);
|
||
$val['subtotal'] = round($val['subtotal'], 2);
|
||
$val['totalInfo'] = $val['sku_num'] . "*" .
|
||
$val['warehousing_num'] = round($val['warehousing_num'], 2);
|
||
$val['retreat_num'] = round($val['retreat_num'], 2);
|
||
$val['operated_num'] = round($val['retreat_num'] + $val['warehousing_num'], 2);
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
$val['goods_code'] = $val['sku_code'];
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 2:
|
||
$type_name = '商户采购退货单';
|
||
$where['retreat_order_id'] = $data['id'];
|
||
$detailsList = D('RetreatGoods')->getSelect($where, $page = '', $limit = '', $field = '', 'id asc');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$val['retreat_num'] = round($val['retreat_num'], 3);
|
||
$val['retreat_price'] = round($val['retreat_price'], 2);
|
||
$val['subtotal'] = round($val['subtotal'], 2);
|
||
$val['sku_num'] = round($val['sku_num'], 3);
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
$val['goods_code'] = $val['sku_code'];
|
||
}
|
||
$val['purchase_price'] = round($val['purchase_price'], 2);
|
||
$val['difference_money'] = round(($val['retreat_price'] - $val['purchase_price']) * $val['retreat_num'], 2);
|
||
}
|
||
}
|
||
break;
|
||
case 3:
|
||
$type_name = '商户盘点单';
|
||
$where['inventory_order_id'] = $data['id'];
|
||
$detailsList = D('InventoryGoods')->getSelect($where, $page = '', $limit = '');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$val['inventory_num'] = round($val['inventory_num'], 3);
|
||
$val['cost_price'] = round($val['cost_price'], 2);
|
||
$val['subtotal'] = round($val['subtotal'], 2);
|
||
$val['sku_num'] = round($val['sku_num'], 3);
|
||
$val['goods_num'] = round($val['goods_num'], 3);
|
||
$val['num'] = round($val['num'], 3);
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_code'] = $val['sku_code'];
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 4:
|
||
$type_name = '商户报损单';
|
||
$where['loss_order_id'] = $data['id'];
|
||
$detailsList = D('LossReportGoods')->getSelect($where, $page = '', $limit = '');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$val['loss_num'] = round($val['loss_num'], 3);
|
||
$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'];
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 5:
|
||
$type_name = $data['stock_name'] . '单';
|
||
$id = $data['id'];
|
||
$detailsList = D('WarehousingGoods')->getSelect(array('warehouse_record_id' => $id), $page = '', $limit = '', $fields = '', 'id asc');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$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);
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
$val['goods_code'] = $val['sku_code'];
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 6:
|
||
$type_name = '门店退货单';
|
||
//门店退货详情
|
||
$where['warehouse_record_id'] = $data['id'];
|
||
$where['type'] = 1;
|
||
$detailsList = D('SStockOutGoods')->getSelect($where, $page = '', $limit = '');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$val['sku_num'] = round($val['sku_num'], 3);
|
||
$val['warehouse_num'] = round($val['stock_num'], 3);
|
||
$val['warehouse_price'] = round($val['stock_price'], 2);
|
||
$val['subtotal'] = round($val['subtotal'], 2);
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_code'] = $val['sku_code'];
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 7:
|
||
$type_name = $data['stock_name'] . '单';
|
||
$where['stock_out_id'] = $data['id'];
|
||
$detailsList = D('StockOutGoods')->getSelect($where, $page = '', $limit = '', $fields = '', 'id asc');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$val['stock_num'] = round($val['stock_num'], 3);
|
||
$val['stock_price'] = round($val['stock_price'], 2);
|
||
$val['subtotal'] = round($val['subtotal'], 2);
|
||
$val['sku_num'] = round($val['sku_num'], 3);
|
||
$val['cost_price'] = round($val['cost_price'], 3);
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_code'] = $val['sku_code'];
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 8:
|
||
$type_name = '门店入库单';
|
||
$id = $data['id'];
|
||
$detailsList = D('SWarehousingGoods')->getSelect(array('warehouse_record_id' => $id));
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_code'] = $val['sku_code'];
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
}
|
||
$val['index'] = $key + 1;
|
||
if (!empty($print['font_num'])) {
|
||
if (mb_strlen($val['goods_name']) > $print['font_num']) {
|
||
$val['goods_name'] = mb_substr($val['goods_name'], 0, $print['font_num'], 'utf-8');
|
||
}
|
||
}
|
||
$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);
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
$this->assign('list', $detailsList);
|
||
$this->assign('type', $data['type']);
|
||
$this->assign('type_name', $type_name);
|
||
$this->assign('warehouse', $data['warehouse']);
|
||
$this->assign('order_number', $data['order_number']);
|
||
$this->assign('add_time', $data['add_time']);
|
||
$this->assign('goods_species', $data['goods_species']);
|
||
$this->assign('remarks', $data['remarks']);
|
||
switch ($data['type']) {
|
||
case 1:
|
||
case 2:
|
||
$this->assign('supplier', $data['supplier']);
|
||
$this->assign('money_total', $data['money_total']);
|
||
$this->assign('warehouse_state', $data['warehouse_state']);
|
||
break;
|
||
case 3:
|
||
$this->assign('quantity', $data['quantity']);
|
||
$this->assign('amount', $data['amount']);
|
||
break;
|
||
case 4:
|
||
$this->assign('money_total', $data['money_total']);
|
||
break;
|
||
case 5:
|
||
case 6:
|
||
case 7:
|
||
case 8:
|
||
$this->assign('store_name', $data['store_name']);
|
||
$this->assign('money_total', $data['money_total']);
|
||
break;
|
||
}
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//采购单详情串号信息
|
||
public function detailSerialList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$data['type'] = 1;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->purchaseDetailSerial($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//采购单详情列表
|
||
public function detailsList()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$PurchaseGoodsInfo = new PurchaseGoodsInfo();
|
||
$result = $PurchaseGoodsInfo->basisIdGetPurchaseGoodsList($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//已经入库的串号列表
|
||
public function WarehousingSerial()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->purchaseWarehouseSerial($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//已经退货的串号列表
|
||
public function retreatSerial()
|
||
{
|
||
$data = I('post.');
|
||
$data['user_type'] = 3;
|
||
$SerialClass = new SerialNumberGoods();
|
||
$result = $SerialClass->purchaseRetreatSerial($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
* *************************************************操作******************************************************
|
||
*/
|
||
//采购提交
|
||
public function purchaseOperation()
|
||
{
|
||
$data = I('post.');
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['operator_id'] = session("jurisdiction_user")['id'];
|
||
$result = A('Api/Inventory')->merchantPurchaseOperation($data);
|
||
if ($result['status'] == 1) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '采购单-新增';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//编辑页面
|
||
public function warehousing()
|
||
{
|
||
$arr = array(
|
||
'onSubmit' => '/index.php/Retail/PurchaseOrder/purchaseOrderEdit',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$user = session("merchant_userinfo");
|
||
$merchant_id = $user['id'];
|
||
$id = I("get.id");
|
||
$purchaseOrder = D('PurchaseOrder')->getFind(array('id' => $id));
|
||
$purchaseOrder['add_time'] = date('Y-m-d H:i:s', $purchaseOrder['add_time']);
|
||
$purchaseOrder['remarks'] = str_replace("\n", "", $purchaseOrder['remarks']);
|
||
$this->Info($merchant_id);
|
||
$this->assign('id', $id);
|
||
$this->assign('info', $purchaseOrder);
|
||
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
|
||
$this->assign('set_batch_number', $set_batch_number);
|
||
$this->display();
|
||
}
|
||
|
||
|
||
//编辑操作
|
||
public function purchaseOrderEdit()
|
||
{
|
||
$data = I("post.");
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$result = A("Api/Inventory")->purchaseOrderEdit($data);
|
||
if ($result['status'] == 1) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '采购单-编辑';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//全部入库至供给仓
|
||
public function warehousingOperation()
|
||
{
|
||
$param = [
|
||
'id' => I('post.id'),
|
||
'merchant_id' => $this->merchant_id,
|
||
'operator_id' => session("jurisdiction_user")['id'],
|
||
];
|
||
$result = A('Api/Inventory')->MerPurchaseWarehouse($param);
|
||
if (C('IS_SET_REDIS')) {
|
||
$redis_key = 'retail_merchant_id_' . $param['merchant_id'] . '_purchase_order_id_' . $param['id'];
|
||
$CacheClass = new CacheHandle();
|
||
$CacheClass->deleteRedis($redis_key);
|
||
}
|
||
if ($result['status'] == 1) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0后台系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '采购单-入库至供给仓/入库单-新增';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
//采购单导出
|
||
public function export()
|
||
{
|
||
set_time_limit(0);
|
||
ini_set('memory_limit', '-1');
|
||
$user = session("merchant_userinfo");
|
||
$content = I("get.");
|
||
$order_number = $content['order_number'];
|
||
$supplier_id = $content['supplier_id'];
|
||
$warehouse_id = $content['warehouse_id'];
|
||
$add_time = $content['add_time'];
|
||
$type = $content['type'];
|
||
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)) {
|
||
$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($type)) {
|
||
$where['type'] = $type;
|
||
}
|
||
$where['merchant_id'] = $user['id'];
|
||
$where['status'] = 1;
|
||
$info = D('PurchaseOrder')->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['repair_time'] = date('Y-m-d H:i:s', $val['repair_time']);
|
||
$val['supplier'] = M('retail_supplier')->where(array('id' => $val['supplier_id']))->getField("supplier_name");
|
||
$val['warehouse'] = D('PurchaseWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name");
|
||
$val['goods_species'] = $val['goods_species'] . "种";
|
||
if ($val['type'] == 1) {
|
||
$val['type_name'] = "常规采购单";
|
||
} else {
|
||
$val['type_name'] = "补采购单";
|
||
}
|
||
}
|
||
}
|
||
$fileds_name = "采购单导出";
|
||
$arr = array(
|
||
array('index', '序号'),
|
||
array('operator', '操作人'),
|
||
array('type_name', '类型'),
|
||
array('add_time', '采购时间'),
|
||
array('repair_time', '操作时间'),
|
||
array('order_number', '批次号'),
|
||
array('supplier', '供应商'),
|
||
array('warehouse', '仓库'),
|
||
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;
|
||
|
||
$set_batch_number = D('RetailMerchantConfig')->getFindField(['merchant_id' => $this->merchant_id], 'set_batch_number');
|
||
$info = D('PurchaseOrder')->getFind($where);
|
||
$info['add_time'] = date('Y-m-d H:i:s', $info['add_time']);
|
||
$info['goods_species'] = strval(round($info['goods_species'], 3));
|
||
$supplier = M('retail_supplier')->where(array('id' => $info['supplier_id']))->getField("supplier_name");
|
||
$warehouse = D('PurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name");
|
||
$map['purchase_order_id'] = $id;
|
||
$detailsList = D('PurchaseGoods')->getSelect($map, $page = '', $limit = '', $field = '', 'id asc');
|
||
if ($detailsList) {
|
||
foreach ($detailsList as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
$val['sku_num'] = strval(round($val['sku_num'], 3));
|
||
$val['purchase_num'] = strval(round($val['purchase_num'], 3));
|
||
$val['purchase_price'] = strval(round($val['purchase_price'], 2));
|
||
$val['retail_price'] = $val['retail_price'] ? strval(round($val['retail_price'], 2)) : '';
|
||
$val['online_price'] = $val['online_price'] ? strval(round($val['online_price'], 2)) : '';
|
||
$val['subtotal'] = strval(round($val['subtotal'], 2));
|
||
$val['warehousing_num'] = strval(round($val['warehousing_num'], 2));
|
||
$val['retreat_num'] = strval(round($val['retreat_num'], 2));
|
||
$val['operated_num'] = strval(round($val['retreat_num'] + $val['warehousing_num'], 2));
|
||
if (!empty($val['build_date'])) {
|
||
$val['build_date'] = date('Y-m-d', $val['build_date']);
|
||
}
|
||
if ($val['attribute_state'] == 2) {
|
||
$val['goods_number'] = $val['sku_goods_number'];
|
||
$val['goods_code'] = $val['sku_code'];
|
||
}
|
||
}
|
||
}
|
||
$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('retail_price', '店内零售价'),
|
||
array('online_price', '商城零售价'),
|
||
array('purchase_num', '数量'),
|
||
array('purchase_price', '进货价'),
|
||
array('subtotal', '进货价合计'),
|
||
);
|
||
if ($set_batch_number == 1) {
|
||
$arr[] = ['goods_batch_number', '批号'];
|
||
}
|
||
$arr[] = ['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);
|
||
}
|
||
} |