894 行
40 KiB
PHP
可执行文件
894 行
40 KiB
PHP
可执行文件
<?php
|
|
namespace Retail\Controller;
|
|
use Think\Controller;
|
|
|
|
//[1.6.48]
|
|
/*旧版门店盘点控制器*/
|
|
|
|
class CheckController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$user = session('ls_userinfo');
|
|
$class1 = M('retail_goods_class')->where(array('merchantid' => $user['merchantid'], 'status' => 0, 'type' => 1))->order('code asc')->select();
|
|
$this->assign('class1',json_encode($class1));
|
|
$arr = array(
|
|
'doInventory' => '/index.php/Retail/Check/doInventory',
|
|
'see_more' => '/index.php/Retail/Check/see_more',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
public function checkgoodslist()
|
|
{
|
|
$storeid = session('storeid');
|
|
$ispd = I('ispd');
|
|
if ($ispd == 1) {
|
|
$w['check_num'] = array('neq', '');
|
|
} else if ($ispd == 2) {
|
|
$w['check_num'] = array('eq', '');
|
|
}
|
|
$w['storeid'] = $storeid;
|
|
$w['status'] = array('in', array(0, 1));// 不包括已删除商品
|
|
$p = I('page');
|
|
$l = I('limit');
|
|
$goodslist = M('retail_goods')->where($w)->order('`status` asc')->page($p, $l)->select();
|
|
$count = M('retail_goods')->where($w)->count();
|
|
foreach ($goodslist as $k => &$v) {
|
|
if (!empty($v['production_date'])) {
|
|
$v['production_date'] = date('Y-m-d', $v['production_date']);
|
|
} else {
|
|
$v['production_date'] = '--';
|
|
}
|
|
$v['index'] = $k + 1 + ($p - 1) * $l;
|
|
$v['goods_code'] = $v['goods_code'] ? $v['goods_code'] : '--';
|
|
$v['goods_number'] = $v['goods_number'] ? $v['goods_number'] : '--';
|
|
}
|
|
$rt['code'] = 0;
|
|
$rt['msg'] = '';
|
|
$rt['data'] = $goodslist;
|
|
$rt['count'] = $count;
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
// 保存盘点数据
|
|
public function savepdnum()
|
|
{
|
|
if (IS_POST) {
|
|
$id = I('post.id');
|
|
$num = I('post.num');
|
|
$storeid = session('storeid');
|
|
$goods = M('retail_goods')->where(array('store_id' => $storeid, 'id' => $id, 'status' => array('in', '0,1')))->find();
|
|
if (empty($goods)) {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '登录超时';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
$ret = M('retail_goods')->where(array('id' => $id, 'store_id' => $storeid))->save(array('check_num' => $num));
|
|
if ($ret !== false) {
|
|
$add['goods_id'] = $id;
|
|
$add['merchant_id'] = session('ls_userinfo')['merchantid'];
|
|
$add['store_id'] = session('storeid');
|
|
$add['add_time'] = time();
|
|
$add['goods_num'] = $goods['goods_num'];
|
|
$add['check_num'] = $num;
|
|
$add['cashier_id'] = 0;
|
|
$add['status'] = 0;
|
|
$add['state'] = 0;
|
|
M('retail_goods_pd_logs')->add($add);//添加盘点记录
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '保存成功';
|
|
} else {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '保存失败';
|
|
}
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
}
|
|
|
|
public function doInventory(){
|
|
$user = session('ls_userinfo');
|
|
if (IS_POST) {
|
|
$storeid = session('storeid');
|
|
$w['store_id'] = $storeid;
|
|
$w['status'] = array('in', array(0, 1));// 不包括已删除商品
|
|
$w['check_num'] = array('neq', '');
|
|
$goodslist = M('retail_goods')->where($w)->order('id asc')->select();
|
|
if(empty($goodslist)){
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '暂无已盘数据,请先盘点商品再确认盘点';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
$time = time();
|
|
$detail_ids = '';
|
|
$yknum = 0;
|
|
$ykmoney = 0;
|
|
$pd_goods_ids = '';
|
|
foreach ($goodslist as $k => $v) {
|
|
// 添加此次盘点详情
|
|
$data['goods_id'] = $v['id'];
|
|
$data['goods_name'] = $v['goods_name'];
|
|
$data['good_number'] = $v['goods_number'];
|
|
$data['purchase_price'] = $v['purchase_price'];
|
|
$data['retail_price'] = $v['retail_price'];
|
|
$data['add_time'] = $time;
|
|
$data['goods_num'] = $v['goods_num'];
|
|
$data['store_id'] = $v['store_id'];
|
|
$data['goods_code'] = $v['goods_code'];
|
|
$data['pd_num'] = $v['check_num'];
|
|
$res = M('retail_goods_pd')->add($data);
|
|
$pd_goods_ids .= $v['id'] . ',';
|
|
$detail_ids .= $res . ',';
|
|
// 重置商品库存
|
|
$sd['goods_num'] = $v['check_num'];
|
|
$sd['check_num'] = '';
|
|
if ($v['check_num'] > $v['goods_num']) {
|
|
$num = $v['check_num'] - $v['goods_num'];
|
|
$yknum = $yknum + $num;
|
|
$ykmoney = $ykmoney + $yknum * $v['purchase_price'];
|
|
$merchantid = $user['merchantid'];
|
|
$remark = '盘点增加';
|
|
// 增加商品盘点修改库存明细
|
|
A('Index')->quantityLogs(1, $v['id'], $storeid, $merchantid, $num, $remark);
|
|
} else if ($v['check_num'] == $v['goods_num']) {
|
|
// 未修改库存--不用添加修改库存明细
|
|
} else {
|
|
$num = $v['goods_num'] - $v['check_num'];
|
|
$yknum = $yknum + $num;
|
|
$ykmoney = $ykmoney + $yknum * $v['purchase_price'];
|
|
$merchantid = $user['merchantid'];
|
|
$remark = '盘点减少';
|
|
// 增加商品盘点修改库存明细
|
|
A('Index')->quantityLogs(2, $v['id'], $storeid, $merchantid, $num, $remark);
|
|
}
|
|
$res2 = M('retail_goods')->where(array('id' => $v['id']))->save($sd);
|
|
}
|
|
$detail_ids = trim($detail_ids, ',');
|
|
$pd_goods_ids = trim($pd_goods_ids, ',');
|
|
$Ad['pl_num'] = $yknum;
|
|
$Ad['pl_jiner'] = $ykmoney;
|
|
$Ad['adminid'] = $user['id'];
|
|
$Ad['account_type'] = $user['account_type'];
|
|
$Ad['detail_ids'] = $detail_ids;
|
|
$Ad['addtime'] = $time;
|
|
$Ad['storeid'] = $storeid;
|
|
$Ad['merchantid'] = $user['merchantid'];
|
|
$ret2 = M('retail_goods_pd_order')->add($Ad);
|
|
if ($ret2) {
|
|
$update = M('retail_goods_pd_logs')
|
|
->where(array('goods_id' => array('in', $pd_goods_ids), 'status' => 0, 'state' => 0, 'pd_order_id' => 0))
|
|
->save(array('status' => 1, 'pd_order_id' => $ret2));
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '盘点数据审核成功';
|
|
$this->ajaxReturn($rt);
|
|
} else {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '盘点数据审核失败';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
}
|
|
}
|
|
// 审核盘点数据
|
|
protected function doaudit()
|
|
{
|
|
$user = session('ls_userinfo');
|
|
$storeid = session('storeid');
|
|
$merchantid = M('retail_store')->where(array('id'=>$storeid))->getField("merchantid");
|
|
$stime = time();
|
|
$w['storeid'] = $storeid;
|
|
$w['status'] = array('in', array(0, 1));// 不包括已删除商品
|
|
$w['check_num'] = array('eq', '');
|
|
$notaudit = M('retail_goods')->where($w)->order('status asc')->find();
|
|
if ($notaudit) {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '您尚有商品未完成盘点,请确认';
|
|
$this->ajaxReturn($rt);
|
|
exit;
|
|
}
|
|
$w['check_num'] = array('neq','');
|
|
$goods_id_arr = M('retail_goods')->where($w)->getField("id",true);
|
|
$s['storeid'] = $storeid;
|
|
$s['state'] = 0;
|
|
$s['check_num'] =array('eq', '');
|
|
$s['goods_id'] =array('in', $goods_id_arr);
|
|
$notaudit_sku = M('retail_sku_goods')->where($s)->find();
|
|
if($notaudit_sku){
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '您尚有商品未完成盘点,请确认';
|
|
$this->ajaxReturn($rt);
|
|
exit;
|
|
}
|
|
unset($w['check_num']);
|
|
$goodslist = M('retail_goods')->where($w)->order('id asc')->select();
|
|
$detail_ids = '';
|
|
$yknum = 0;
|
|
$ykmoney = 0;
|
|
$pd_goods_ids = '';
|
|
$pd_goods_ids_sku = '';
|
|
$log_arr = '';
|
|
foreach ($goodslist as $k => $v) {
|
|
// 添加此次盘点详情
|
|
$data = array();
|
|
$data['merchantid'] = $merchantid;
|
|
$data['goods_id'] = $v['id'];
|
|
$data['goods_name'] = $v['goods_name'];
|
|
$data['goods_number'] = $v['goods_number'];
|
|
$data['addtime'] = $stime;
|
|
$data['storeid'] = $v['storeid'];
|
|
$data['goods_code'] = $v['goods_code'];
|
|
$data['attribute'] = $v['attribute'];
|
|
$data['can_exchange_weigh'] = $v['can_exchange_weigh'];
|
|
if($v['attribute_state'] == 2){
|
|
$sku_info = M('retail_sku_goods')->where(array('goods_id'=>$v['id'],'storeid'=>$storeid,'state'=>0))->select();
|
|
if($sku_info){
|
|
foreach ($sku_info as $skuk=>&$skuv){
|
|
$pd_goods_ids_sku .= $skuv['id'].',';
|
|
$data['sku_id'] = $skuv['id'];
|
|
$data['sku_code'] = $skuv['sku_code'];
|
|
$data['pd_num'] = $skuv['pd_num'];
|
|
$data['goods_num'] = $skuv['goods_num'];
|
|
$data['purch_price'] = $skuv['purch_price'];
|
|
$data['retail_price'] = $skuv['retail_price'];
|
|
$res = M('retail_goods_pd')->add($data);
|
|
$detail_ids .= $res.',';
|
|
if ($skuv['pd_num'] > $skuv['goods_num']) { //增加
|
|
$num = $skuv['pd_num'] - $skuv['goods_num'];
|
|
$yknum += $num;
|
|
$ykmoney += round($num * $skuv['purch_price'],2);
|
|
$remark = '盘点增加';
|
|
// 增加商品盘点修改库存明细
|
|
$log_add = A('Index')->quantityLogs(1, $v['id'], $storeid, $merchantid, $num, $remark,$skuv['id']);
|
|
$log_arr .= $log_add.',';
|
|
$allocat = array();
|
|
$allocat['merchantid'] = $merchantid;
|
|
$allocat['storeid'] = $storeid;
|
|
$allocat['store_goods_id'] = $v['id'];
|
|
$allocat['goods_name'] = $v['goods_name'];
|
|
$allocat['good_number'] = $v['goods_number'];
|
|
$allocat['goods_code'] = $v['goods_code'];
|
|
$allocat['sku_code'] = $skuv['sku_code'];
|
|
$allocat['goods_class_id'] = $v['goods_class_id'];
|
|
$allocat['goods_num'] = $num * $skuv['sku_num'];
|
|
$allocat['shipment_num'] = $num;
|
|
$allocat['operation_goods_num'] = $num;
|
|
$allocat['sku_num'] = $skuv['sku_num'];
|
|
$allocat['addtime'] = $stime;
|
|
$allocat['store_goods_sku_id'] = $skuv['id'];
|
|
$allocat['sku_id_list'] = $skuv['sku_id_list'];
|
|
$allocat['goods_info'] = json_encode($v);
|
|
$allocat['goods_sku_info'] = json_encode($skuv);
|
|
$allocat['purch_price'] = $skuv['purchase_price'];
|
|
$allocat['attribute'] = $v['attribute_state'];
|
|
$allocat['isweigh'] = $v['pricing_method'];
|
|
$allocat['type'] = 3;
|
|
M('retail_allocat_sku_goods')->add($allocat);
|
|
}else if($skuv['pd_num'] < $skuv['goods_num']) { //减少
|
|
$num = $skuv['goods_num'] - $skuv['pd_num'];
|
|
$yknum += $num;
|
|
$ykmoney += round($num * $skuv['purch_price'],2);
|
|
$remark = '盘点减少';
|
|
// 增加商品盘点修改库存明细
|
|
$log_add = A('Index')->quantityLogs(2, $v['id'], $storeid, $merchantid, $num, $remark,$skuv['id']);
|
|
$log_arr .= $log_add.',';
|
|
$this->Inventory($merchantid,$storeid,$v['id'],$skuv['id'],$num);
|
|
}
|
|
$skus = array();
|
|
$skus['goods_num'] = $skuv['pd_num'];
|
|
$skus['pd_num'] = '';
|
|
M('retail_sku_goods')->where(array('id'=>$skuv['id']))->save($skus);
|
|
}
|
|
}
|
|
}else if($v['attribute_state'] == 1){
|
|
$data['purch_price'] = $v['purchase_price'];
|
|
$data['retail_price'] = $v['retail_price'];
|
|
$data['check_num'] = $v['check_num'];
|
|
$data['goods_num'] = $v['goods_num'];
|
|
$res = M('retail_goods_pd')->add($data);
|
|
$detail_ids .= $res . ',';
|
|
if ($v['check_num'] > $v['goods_num']) { //增加
|
|
$num = $v['check_num'] - $v['goods_num'];
|
|
$yknum += $num;
|
|
$ykmoney += round(($num * $v['purch_price']),2);
|
|
$merchantid = $user['merchantid'];
|
|
$remark = '盘点增加';
|
|
// 增加商品盘点修改库存明细
|
|
$log_add = A('Index')->quantityLogs(1, $v['id'], $storeid, $merchantid, $num, $remark);
|
|
$log_arr .= $log_add.',';
|
|
$allocat = array();
|
|
$allocat['merchantid'] = $merchantid;
|
|
$allocat['storeid'] = $storeid;
|
|
$allocat['store_goods_id'] = $v['id'];
|
|
$allocat['goods_name'] = $v['goods_name'];
|
|
$allocat['good_number'] = $v['goods_number'];
|
|
$allocat['goods_code'] = $v['goods_code'];
|
|
$allocat['goods_class_id'] = $v['goods_class_id'];
|
|
$allocat['goods_num'] = $num;
|
|
$allocat['shipment_num'] = $num;
|
|
$allocat['operation_goods_num'] = $num;
|
|
$allocat['addtime'] = $stime;
|
|
$allocat['goods_info'] = json_encode($v);
|
|
$allocat['purch_price'] = $v['purchase_price'];
|
|
$allocat['attribute'] = $v['attribute_state'];
|
|
$allocat['isweigh'] = $v['pricing_method'];
|
|
$allocat['type'] = 3;
|
|
M('retail_allocat_sku_goods')->add($allocat);
|
|
}else if($v['check_num'] < $v['goods_num']) { //减少
|
|
$num = $v['goods_num'] - $v['check_num'];
|
|
$yknum += $num;
|
|
$ykmoney += round($num * $v['purchase_price'],2);
|
|
$merchantid = $user['merchantid'];
|
|
$remark = '盘点减少';
|
|
// 增加商品盘点修改库存明细
|
|
$log_add = A('Index')->quantityLogs(2, $v['id'], $storeid, $merchantid, $num, $remark);
|
|
$log_arr .= $log_add.',';
|
|
$this->Inventory($merchantid,$storeid,$v['id'],$sku_id='',$num);
|
|
}
|
|
}
|
|
// 重置商品库存
|
|
$sd = array();
|
|
$sd['goods_num'] = $v['check_num'];
|
|
$sd['check_num'] = '';
|
|
$res2 = M('retail_goods')->where(array('id' => $v['id']))->save($sd);
|
|
$pd_goods_ids .= $v['id'] . ',';
|
|
}
|
|
$detail_ids = trim($detail_ids, ',');
|
|
$Ad['pl_num'] = $yknum;
|
|
$Ad['pl_jiner'] = $ykmoney;
|
|
$Ad['adminid'] = $user['id'];
|
|
$Ad['account_type'] = $user['account_type'];
|
|
$Ad['detail_ids'] = $detail_ids;
|
|
$Ad['addtime'] = $stime;
|
|
$Ad['storeid'] = $storeid;
|
|
$Ad['merchantid'] = $merchantid;
|
|
$ret2 = M('retail_goods_pd_order')->add($Ad);
|
|
if ($ret2) {
|
|
$order_id = createOrderTradeNo($ret2);//订单号
|
|
$order_id = 'P'.$order_id;
|
|
M('retail_goods_pd_order')->where(array('id'=>$ret2))->save(array('order_id'=>$order_id));
|
|
$pd_goods_ids = trim($pd_goods_ids, ',');
|
|
$update = M('retail_goods_pd_logs')
|
|
->where(array('goods_id' => array('in', $pd_goods_ids), 'status' => 0, 'state' => 0, 'pd_order_id' => 0))
|
|
->save(array('status' => 1, 'pd_order_id' => $ret2));
|
|
$goods_pd = array();
|
|
$goods_pd['merchantid'] = $merchantid;
|
|
$goods_pd['storeid'] = $storeid;
|
|
$goods_pd['id'] = array('in',$detail_ids);
|
|
$goods_pd['pd_order_id'] = array('eq',0);
|
|
M('retail_goods_pd')->where($goods_pd)->save(array('pd_order_id'=>$ret2));
|
|
$log_arr = trim($log_arr,',');
|
|
M('retail_quantity_logs')->where(array('id'=>array('in',$log_arr)))->save(array('ordernum'=>$order_id));
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '盘点数据审核成功';
|
|
$this->ajaxReturn($rt);
|
|
} else {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '盘点数据审核失败';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
}
|
|
//盘点减少库存
|
|
public function Inventory($merchantid,$storeid,$goods_id,$sku_id,$num)
|
|
{
|
|
$where['merchantid'] = $merchantid;
|
|
$where['storeid'] = $storeid;
|
|
$where['store_goods_id'] = $goods_id;
|
|
$where['operation_goods_num'] = array('gt',0);
|
|
if(!empty($sku_id)){
|
|
$where['store_goods_sku_id'] = $sku_id;
|
|
}
|
|
$allocat_info = M('retail_allocat_sku_goods')->where($where)->order('id asc')->find();
|
|
if($allocat_info){
|
|
if($num > $allocat_info['operation_goods_num']){
|
|
$num = ($num - $allocat_info['operation_goods_num'])*1;
|
|
M('retail_allocat_sku_goods')->where(array('id'=>$allocat_info['id']))->save(array('operation_goods_num'=>0));
|
|
return $this->Inventory($merchantid,$storeid,$goods_id,$sku_id,$num);
|
|
}else{
|
|
M('retail_allocat_sku_goods')->where(array('id'=>$allocat_info['id']))->setDec('operation_goods_num',$num);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
// 盘点单据
|
|
public function order()
|
|
{
|
|
$arr = array(
|
|
'orderdetail' => '/index.php/Retail/Check/orderdetail',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
//
|
|
public function ordermsg()
|
|
{
|
|
$global_store_jurisdiction = I('session.global_store_jurisdiction'); // 权限
|
|
$showpurch_price = $global_store_jurisdiction['showpurch_price'] ? $global_store_jurisdiction['showpurch_price'] : 2; // 查看进价权限
|
|
$storeid = session('storeid');
|
|
$merchantid = M('retail_store')->where(array('id'=>$storeid))->getField("merchantid");
|
|
$page = I('get.page');
|
|
$limit = I('get.limit');
|
|
$date = I('get.date');
|
|
$order_id = I('get.order_id');
|
|
if (!empty($date)) {
|
|
$time = explode('至', $date);
|
|
$start_time = strtotime(date('Y-m-d 0:0:0', strtotime($time[0])));
|
|
$end_time = strtotime(date('Y-m-d 23:59:59', strtotime($time[1])));
|
|
$where['addtime'] = array('between', array($start_time, $end_time));
|
|
}
|
|
if(!empty($order_id)){
|
|
$where['order_id'] = $order_id;
|
|
}
|
|
$where['merchantid'] = $merchantid;
|
|
$where['storeid'] = $storeid;
|
|
$count = M('retail_goods_pd_order')->where($where)->count();
|
|
$list = M('retail_goods_pd_order')
|
|
->where($where)
|
|
->page($page, $limit)
|
|
->order('id desc')
|
|
->select();
|
|
foreach ($list as $k => &$v) {
|
|
$v['addtime'] = date('Y-m-d', $v['addtime']);
|
|
if ($v['account_type'] == 1) {
|
|
$v['adminid'] = M('retail_merchant')->where(array('id' => $v['adminid']))->getField('name');
|
|
} elseif ($v['account_type'] == 2) {
|
|
$v['adminid'] = M('retail_manager')->where(array('id' => $v['adminid']))->getField('name');
|
|
}
|
|
if($showpurch_price == 2){
|
|
$v['pl_jiner'] = '*';
|
|
}
|
|
$v['adminid'] = $v['adminid'] ? $v['adminid'] : '未知用户';
|
|
$v['index'] = $k + 1;
|
|
}
|
|
$rt['code'] = 0;
|
|
$rt['msg'] = '';
|
|
$rt['count'] = $count;
|
|
$rt['data'] = $list;
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
|
|
// 盘点详情
|
|
public function orderdetail()
|
|
{
|
|
$id = I('get.id');
|
|
$this->assign('id', $id);
|
|
$arr = array(
|
|
'exporttablecheck' => '/index.php/Retail/Exporttable/exporttablecheck',
|
|
'see_more' => '/index.php/Retail/Check/see_more',
|
|
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
// 盘点详情数据
|
|
public function orderdetaillist()
|
|
{
|
|
$id = I('get.id');
|
|
$storeid = session('storeid');
|
|
$p = I('page');
|
|
$l = I('limit');
|
|
$where['storeid'] = $storeid;
|
|
$where['id'] = $id;
|
|
$id_list = M('retail_goods_pd_order')->where($where)->getField('detail_ids');
|
|
$count = M('retail_goods_pd')->where(array('id'=>array('in',$id_list)))->count();
|
|
$orderlist = M('retail_goods_pd')
|
|
->where(array('id'=>array('in',$id_list)))
|
|
->page($p, $l)
|
|
->select();
|
|
foreach ($orderlist as $k => &$v) {
|
|
$v['index'] = $k + 1;
|
|
if($v['attribute'] == 2){
|
|
$v['goods_code'] = $v['sku_code'] ? $v['sku_code'] : '--';
|
|
$sku_list = M('retail_sku_goods')->where(array('id'=>$v['sku_id']))->getField("sku_id_list");
|
|
$sku_list = explode(',',$sku_list);
|
|
$sku_name = '';
|
|
foreach ($sku_list as $skuk=>&$skuv){
|
|
$sku_name .= ','.M('retail_sku_list')->where(array('id'=>$skuv))->getField("name");
|
|
}
|
|
$v['goods_name'] = $v['goods_name'].$sku_name;
|
|
}else if($v['attribute'] == 1){
|
|
$v['goods_code'] = $v['goods_code'] ? $v['goods_code'] : '--';
|
|
$v['sku_id'] = '';
|
|
}
|
|
$v['good_number'] = $v['good_number'] ? $v['good_number'] : '--';
|
|
$v['change_num'] = round($v['check_num'] - $v['goods_num'], 3);
|
|
$v['all_money'] = round(($v['check_num'] - $v['goods_num']) * $v['purch_price'], 2);
|
|
}
|
|
$rt['code'] = 0;
|
|
$rt['msg'] = '';
|
|
$rt['data'] = $orderlist;
|
|
$rt['count'] = $count;
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
$global_store_jurisdiction = I('session.global_store_jurisdiction'); // 权限
|
|
$showpurch_price = $global_store_jurisdiction['showpurch_price'] ? $global_store_jurisdiction['showpurch_price'] : 2; // 查看进价权限
|
|
$storeid = session('storeid');
|
|
$merchantid = M('retail_store')->where(array('id'=>$storeid))->getField("merchantid");
|
|
$date = I('get.date');
|
|
$order_id = I('get.order_id');
|
|
if (!empty($date)) {
|
|
$time = explode('至', $date);
|
|
$start_time = strtotime(date('Y-m-d 0:0:0', strtotime($time[0])));
|
|
$end_time = strtotime(date('Y-m-d 23:59:59', strtotime($time[1])));
|
|
$where['addtime'] = array('between', array($start_time, $end_time));
|
|
}
|
|
if(!empty($order_id)){
|
|
$where['order_id'] = $order_id;
|
|
}
|
|
$where['merchantid'] = $merchantid;
|
|
$where['storeid'] = $storeid;
|
|
$list = M('retail_goods_pd_order')
|
|
->where($where)
|
|
->order('id desc')
|
|
->select();
|
|
foreach ($list as $k => &$v) {
|
|
$v['addtime'] = date('Y-m-d', $v['addtime']);
|
|
if ($v['account_type'] == 1) {
|
|
$v['adminid'] = M('retail_merchant')->where(array('id' => $v['adminid']))->getField('name');
|
|
} elseif ($v['account_type'] == 2) {
|
|
$v['adminid'] = M('retail_manager')->where(array('id' => $v['adminid']))->getField('name');
|
|
}
|
|
if($showpurch_price == 2){
|
|
$v['pl_jiner'] = '*';
|
|
}
|
|
$v['adminid'] = $v['adminid'] ? $v['adminid'] : '未知用户';
|
|
$v['index'] = $k + 1;
|
|
}
|
|
import("Vendor.PHPExcel.PHPExcel");
|
|
import("Vendor.PHPExcel.Writer.Excel5");
|
|
import("Vendor.PHPExcel.IOFactory.php");
|
|
$filename = "商品盘点(" . ($date ? $date : '所有') . ")明细";
|
|
$headArr = array(
|
|
array('index', '序号'),
|
|
array('order_id', '订单号'),
|
|
array('pl_num', '盈亏数量'),
|
|
array('pl_jiner', '盈亏金额(元)'),
|
|
array('adminid', '盘点审核人姓名'),
|
|
array('addtime', '盘点时间'),
|
|
);
|
|
$str = $filename . ',导出日期:' . date('Y-m-d H:i:s');
|
|
$this->getExcel($filename, $headArr, $list, $str);
|
|
}
|
|
|
|
private function getExcel($expTitle, $expCellName, $expTableData, $str = "")
|
|
{
|
|
|
|
$xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
|
|
$fileName = $expTitle . date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
|
|
$cellNum = count($expCellName);
|
|
$dataNum = count($expTableData);
|
|
$common = $str;
|
|
vendor("PHPExcel.PHPExcel");
|
|
ob_clean();
|
|
$objPHPExcel = new \PHPExcel();
|
|
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
|
|
|
|
$objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格
|
|
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $common);
|
|
// $objPHPExcel->setActiveSheetIndex(1)->setCellValue('A1', $str);
|
|
for ($i = 0; $i < $cellNum; $i++) {
|
|
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]);
|
|
}
|
|
|
|
for ($i = 0; $i < $dataNum; $i++) {
|
|
for ($j = 0; $j < $cellNum; $j++) {
|
|
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 3), ' ' . $expTableData[$i][$expCellName[$j][0]]);
|
|
|
|
}
|
|
}
|
|
foreach ($cellName as $value) {
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension($value)->setWidth(20);
|
|
|
|
}
|
|
header('pragma:public');
|
|
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
|
|
header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
|
$objWriter->save('php://output');
|
|
exit();
|
|
}
|
|
|
|
public function see_more()
|
|
{
|
|
$id = I('get.id');
|
|
$pd_order_id = I('get.pd_order_id') ? I('get.pd_order_id') : 0;
|
|
$status = $pd_order_id ? 1 : 0;
|
|
$logs = M('retail_goods_pd_logs as l')
|
|
->join('ls_retail_cashier as c on c.id=l.cashier_id', 'LEFT')
|
|
->where(array('l.goods_id' => $id, 'l.pd_order_id' => $pd_order_id, 'l.status' => $status, 'l.state' => 0))
|
|
->field('l.*,c.name as username')
|
|
->order('l.addtime desc')
|
|
->select();
|
|
foreach ($logs as &$val) {
|
|
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
|
|
if (!$val['username']) {
|
|
$val['username'] = '店长';
|
|
}
|
|
$val['goods_num'] = round($val['goods_num'], 3);
|
|
$val['check_num'] = round($val['check_num'], 3);
|
|
}
|
|
$this->assign('logs', $logs);
|
|
$this->display();
|
|
}
|
|
|
|
//单个保存盘点数据
|
|
public function savePDNum_v1()
|
|
{
|
|
if (IS_POST) {
|
|
$id = I('post.id');
|
|
$num = I('post.num');
|
|
$storeid = session('storeid');
|
|
if (empty($id) || empty($storeid) || !isset($num)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$goods = M('retail_goods')->where(array('store_id' => $storeid, 'id' => $id, 'status' => array('in', '0,1')))->find();
|
|
if (empty($goods)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '商品查询失败';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$ret = M('retail_goods')->where(array('id' => $id, 'store_id' => $storeid))->save(array('check_num' => $num));
|
|
if ($ret !== false) {
|
|
$add['goods_id'] = $id;
|
|
$add['merchantid'] = session('ls_userinfo')['merchantid'];
|
|
$add['storeid'] = session('storeid');
|
|
$add['addtime'] = time();
|
|
$add['goods_num'] = $goods['goods_num'];
|
|
$add['check_num'] = $num;
|
|
$add['cashier_id'] = 0;
|
|
$add['status'] = 0;
|
|
$add['state'] = 0;
|
|
M('retail_goods_pd_logs')->add($add);//添加盘点记录
|
|
$res['status'] = 1;
|
|
$res['msg'] = '保存成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '保存失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
public function savePDNumsku_v1()
|
|
{
|
|
if (IS_POST) {
|
|
$id = I('post.id');
|
|
$num = I('post.num');
|
|
$storeid = session('storeid');
|
|
$merchantid = M('retail_store')->where(array('id'=>$storeid))->getField("merchantid");
|
|
if (empty($id) || empty($storeid) || !isset($num)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$goods = M('retail_sku_goods')->where(array('id'=>$id))->find();
|
|
if (empty($goods)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$ret = M('retail_sku_goods')->where(array('id'=>$id))->save(array('pd_num' => $num));
|
|
if ($ret) {
|
|
$sku_info = M('retail_sku_goods')->where(array('goods_id'=>$goods['goods_id'],'state'=>0))->select();
|
|
$sku_pd_num = 0;
|
|
foreach ($sku_info as $key=>&$val){
|
|
$sku_pd_num += ($val['pd_num']*$val['sku_num']*1);
|
|
}
|
|
M('retail_goods')->where(array('id'=>$goods['goods_id']))->save(array('check_num'=>$sku_pd_num));
|
|
$add['goods_id'] = $goods['goods_id'];
|
|
$add['sku_id'] = $id;
|
|
$add['merchantid'] = $merchantid;
|
|
$add['storeid'] = $storeid;
|
|
$add['addtime'] = time();
|
|
$add['goods_num'] = $goods['goods_num'];
|
|
$add['pd_num'] = $num;
|
|
$add['cashier_id'] = 0;
|
|
$add['status'] = 0;
|
|
$add['state'] = 0;
|
|
M('retail_goods_pd_logs')->add($add);//添加盘点记录
|
|
$res['status'] = 1;
|
|
$res['msg'] = '保存成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '保存失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
// 批量保存盘点数据
|
|
public function saveAllPDNum()
|
|
{
|
|
$data = I('post.data');
|
|
$storeid = session('storeid');
|
|
if (empty($storeid)) {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '登录超时';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
$merchantid = M('retail_store')->where(array('id'=>$storeid))->getField("merchantid");
|
|
foreach ($data as &$val) {
|
|
$goods = M('retail_goods')->where(array('store_id' => $storeid, 'id' => $val['id'], 'status' => array('in', '0,1')))->find();
|
|
$ret = M('retail_goods')->where(array('id' => $val['id'], 'store_id' => $storeid))->save(array('check_num' => $val['check_num']));
|
|
if ($ret !== false) {
|
|
$add['goods_id'] = $val['id'];
|
|
$add['merchantid'] = $merchantid;
|
|
$add['storeid'] = session('storeid');
|
|
$add['addtime'] = time();
|
|
$add['goods_num'] = $goods['goods_num'];
|
|
$add['pd_num'] = $val['check_num'];
|
|
$add['cashier_id'] = 0;
|
|
$add['status'] = 0;
|
|
$add['state'] = 0;
|
|
M('retail_goods_pd_logs')->add($add);//添加盘点记录
|
|
}
|
|
}
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '保存成功';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
public function skusaveAllPDNum()
|
|
{
|
|
$data = I('post.data');
|
|
$storeid = session('storeid');
|
|
$goods_id = I('post.goods_id');
|
|
if (empty($storeid) || empty($goods_id)) {
|
|
$rt['status'] = 2;
|
|
$rt['msg'] = '登录超时';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
$merchantid = M('retail_store')->where(array('id'=>$storeid))->getField("merchantid");
|
|
$goods_num = 0;
|
|
foreach ($data as $val) {
|
|
$goods_num += ($val['check_num']*$val['sku_num']);
|
|
$goods = M('retail_sku_goods')->where(array('id'=>$val['id']))->find();
|
|
$ret = M('retail_sku_goods')->where(array('id'=>$val['id']))->save(array('pd_num' => $val['pd_num']));
|
|
if ($ret) {
|
|
$add['goods_id'] = $goods_id;
|
|
$add['sku_id'] = $val['id'];
|
|
$add['merchantid'] = $merchantid;
|
|
$add['storeid'] = $storeid;
|
|
$add['addtime'] = time();
|
|
$add['goods_num'] = $goods['goods_num'];
|
|
$add['pd_num'] = $val['check_num'];
|
|
$add['cashier_id'] = 0;
|
|
$add['status'] = 0;
|
|
$add['state'] = 0;
|
|
M('retail_goods_pd_logs')->add($add);//添加盘点记录
|
|
}
|
|
}
|
|
M('retail_goods')->where(array('id'=>$goods_id))->save(array('check_num'=>$goods_num));
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '保存成功';
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
public function getWaitingPDGoods()
|
|
{
|
|
$store_id = session('storeid');
|
|
$type = I('post.type');
|
|
$keyword = I('post.keyword');
|
|
if (empty($store_id) || empty($type)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
} else {
|
|
//按照商品类别搜索
|
|
$person1 = I('post.goodsClass1');
|
|
$person2 = I('post.goodsClass2');
|
|
$person3 = I('post.goodsClass3');
|
|
$flag = 0;
|
|
if (!empty($person3)) {
|
|
$map['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);
|
|
$map['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
|
} else if ($flag == 1) {
|
|
$map['goods_class_id'] = $person2 ? $person2 : $person1;
|
|
}
|
|
if ($type == 3) {
|
|
$map['check_num'] = array('eq', '');
|
|
} else if ($type == 2) {
|
|
$map['check_num'] = array('neq', '');
|
|
}
|
|
$map['store_id'] = $store_id;
|
|
$map['status'] = array('in', array(0, 1));// 不包括已删除商品
|
|
if ($keyword) {
|
|
$map['goods_name|goods_number|goods_code'] = array('like', $keyword . '%');
|
|
}
|
|
$p = I('page');
|
|
$l = I('limit');
|
|
$count = M('retail_goods')->where($map)->count();
|
|
// echo M()->_sql();
|
|
if ($count < $l) {
|
|
$p = 1;
|
|
}
|
|
$goodsList = M('retail_goods')->where($map)->order('status asc')->page($p, $l)->select();
|
|
$tempList = array();
|
|
foreach ($goodsList as $k => &$value) {
|
|
if (!empty($value['production_date'])) {
|
|
$temp['production_date'] = date('Y-m-d', $value['production_date']);
|
|
} else {
|
|
$temp['production_date'] = '--';
|
|
}
|
|
$temp['id'] = $value['id'];
|
|
$temp['index'] = $k + 1 + ($p - 1) * $l;
|
|
$temp['goods_code'] = $value['goods_code'] ? $value['goods_code'] : '--';
|
|
$temp['goods_number'] = $value['goods_number'] ? $value['goods_number'] : '--';
|
|
$temp['end_num'] = round($value['check_num'] - $value['goods_num'], 3);
|
|
if(is_numeric($value['check_num'])){
|
|
$temp['end_price'] = round(($value['check_num'] - $value['goods_num']) * $value['purchase_price'], 3);
|
|
}else{
|
|
$temp['end_price'] = '';
|
|
}
|
|
$temp['old_check_num'] = $value['check_num'];
|
|
$temp['check_num'] = $value['check_num'];
|
|
$temp['goods_num'] = round($value['goods_num'], 3);
|
|
$temp['purch_price'] = round($value['purchase_price'], 2);
|
|
$temp['retail_price'] = round($value['retail_price'], 2);
|
|
$temp['goods_name'] = $value['goods_name'];
|
|
$temp['can_exchange_weigh'] = $value['pricing_method'];
|
|
$tempList[] = $temp;
|
|
}
|
|
$res['page'] = round($p);
|
|
$res['status'] = 1;
|
|
$res['msg'] = '查询成功';
|
|
$res['data'] = $tempList;
|
|
$res['count'] = round($count);
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
//规格
|
|
public function skuList()
|
|
{
|
|
$goods_id = I('post.goods_id');
|
|
$store_id = session("storeid");
|
|
$sku_info = M('retail_sku_goods')->where(array('goods_id'=>$goods_id,'state'=>0,'store_id'=>$store_id))->select();
|
|
foreach ($sku_info as $key=>&$val){
|
|
$val['index'] = $key + 1;
|
|
$val['end_num'] = $val['pd_num'] ? round($val['pd_num'] - $val['goods_num'], 3) : '';
|
|
$val['end_price'] = $val['pd_num'] ? round(($val['pd_num'] - $val['goods_num']) * $val['purch_price'], 3) : '';
|
|
$val['old_pd_num'] = $val['pd_num'];
|
|
$sku_list = explode(',',$val['sku_id_list']);
|
|
$sku_name = '';
|
|
foreach ($sku_list as $klist=>&$vlist){
|
|
$sku_name .= M('retail_sku_list')->where(array('id'=>$vlist))->getField("name").',';
|
|
}
|
|
$val['goods_name'] = $sku_name;
|
|
}
|
|
$res['status'] = 1;
|
|
$res['data'] = $sku_info;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
} |