2303 行
96 KiB
PHP
可执行文件
2303 行
96 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Retail\Controller;
|
|
|
|
use Common\Business\DownFile;
|
|
use Common\Business\Export;
|
|
use Common\Business\GoodsClassify;
|
|
use Common\Business\PayCoupon;
|
|
use Common\Business\Sell;
|
|
use Common\Business\SerialNumberGoods;
|
|
use Common\Business\Supplier;
|
|
use Common\Model\PayOrderModel;
|
|
use Common\Model\RetailGuideModel;
|
|
use Common\Model\RetailPayOrderModel;
|
|
use Common\Model\RetailStoreModel;
|
|
use Common\Model\SSupplierModel;
|
|
use Common\Model\StoreModel;
|
|
use Common\Order\BillOrder;
|
|
use Common\Order\PayOrder;
|
|
use Think\Controller;
|
|
use Common\Business\Plug;
|
|
|
|
//[1.9.21]
|
|
class SaleController extends BaseController
|
|
{
|
|
public function recebles()
|
|
{
|
|
$this->display();
|
|
}
|
|
|
|
//销售汇总
|
|
public function saleDetails()
|
|
{
|
|
//查出门店名称
|
|
$class_name = M('retail_goods_class')->where(array('merchantid' => $this->merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select();
|
|
$this->assign('class_name', json_encode($class_name));
|
|
$arr = array(
|
|
'saledetailsexport' => '/index.php/Retail/Sale/saledetailsexport',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
// 商品销售明细
|
|
public function particulars()
|
|
{
|
|
//获取门店信息
|
|
$supplier_type = session('ls_userinfo')['supplier_type'];
|
|
$this->assign('supplier_type', $supplier_type);
|
|
$this->display();
|
|
}
|
|
|
|
//获取分类
|
|
public function getChildClass()
|
|
{
|
|
$user = session('ls_userinfo');
|
|
if (IS_POST && !empty($user)) {
|
|
$id = I('post.id');
|
|
$type = I('post.type');
|
|
if ($type == 1) {
|
|
$class = M('retail_goods_class')
|
|
->where(array('merchantid' => $this->merchant_id, 'type' => 1, 'status' => 0))
|
|
->field('id,class_name')
|
|
->select();
|
|
} else if ($type == 2) {
|
|
$class = M('retail_goods_class as c1')
|
|
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
|
|
->where(array('c1.id' => $id, 'c2.status' => 0))
|
|
->field('c2.id,c2.class_name')
|
|
->order('c2.code asc')
|
|
->select();
|
|
} else {
|
|
$class = M('retail_goods_class as c2')
|
|
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
|
|
->where(array('c2.id' => $id, 'c3.status' => 0))
|
|
->field('c3.id,c3.class_name')
|
|
->order('c3.code asc')
|
|
->select();
|
|
}
|
|
if (!empty($class)) {
|
|
$result['status'] = 1;
|
|
$result['data'] = $class;
|
|
$result['msg'] = '查询成功';
|
|
} else {
|
|
$result['status'] = 2;
|
|
$result['msg'] = '暂无分类';
|
|
}
|
|
} else {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '登录超时';
|
|
}
|
|
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
//滞销商品
|
|
public function deadStock()
|
|
{
|
|
//查出门店名称
|
|
$store_name = M('retail_store')->where(array('id' => $this->store_id))->find();
|
|
$this->assign('store_name', $store_name);
|
|
$arr = array(
|
|
'unsalableexport' => '/index.php/Retail/Sale/unsalableexport',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
public function deadStockinfo()
|
|
{
|
|
//出售的商品
|
|
$start = strtotime("-1 month");
|
|
$end = time();
|
|
$where['pay_type'] = array('neq', 0);
|
|
$where['store_id'] = $this->store_id;
|
|
$where['add_time'] = array('between', array($start, $end));
|
|
$dead_info = M('retail_sell')->where($where)->group('goods_id')->getField('goods_id', true);
|
|
$dead_info = $dead_info ? $dead_info : array(0);
|
|
//所有商品
|
|
//查询条件货号
|
|
$goodsnum = I('post.name02');
|
|
if (!empty($goodsnum)) {
|
|
$data['goods_number'] = $goodsnum;
|
|
}
|
|
//查询品名
|
|
$product = I('post.name03');
|
|
if (!empty($product)) {
|
|
$data['goods_name'] = array('like', array("%" . $product . "%"));
|
|
}
|
|
$data['store_id'] = $this->store_id;
|
|
$data['status'] = 0;
|
|
$data['id'] = array('not in', $dead_info);
|
|
$good_info = M('retail_goods')->where($data)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
|
|
$count = M('retail_goods')->where($data)->count();
|
|
if (!$good_info) {
|
|
$rt['code'] = 0;
|
|
$rt['msg'] = '';
|
|
$rt['data'] = $good_info;
|
|
$rt['count'] = $count;
|
|
$this->ajaxReturn($rt);
|
|
exit;
|
|
}
|
|
foreach ($good_info as $key => &$val) {
|
|
$val['key'] = $key + 1;
|
|
//销量
|
|
$volume = M('retail_sell')->where(array('goods_id' => $val['id'], 'pay_type' => array('neq', 0)))->sum('num');
|
|
$val['saleVol'] = $volume ? $volume : 0;
|
|
$val['goods_code'] = $val['goods_code'] ? $val['goods_code'] : '---';
|
|
$val['good_number'] = $val['goods_number'] ? $val['goods_number'] : '---';
|
|
}
|
|
$rt['code'] = 0;
|
|
$rt['msg'] = '';
|
|
$rt['data'] = $good_info;
|
|
$rt['count'] = $count;
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
|
|
//畅销商品
|
|
public function salable()
|
|
{
|
|
//查出门店名称
|
|
$store_name = M('retail_store')->where(array('id' => $this->store_id))->find();
|
|
$this->assign('store_name', $store_name);
|
|
$arr = array(
|
|
'Bestexport' => '/index.php/Retail/Sale/Bestexport',
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$GoodsClassify = new GoodsClassify();
|
|
$result = $GoodsClassify->getGoodsClassTopLevel($this->merchant_id);
|
|
$this->assign('goodsClass1', json_encode($result['data']['list']));
|
|
$this->display();
|
|
}
|
|
|
|
public function bestGoodsList()
|
|
{
|
|
ini_set('memory_limit', '64M');
|
|
$merchant_id = $this->merchant_id;
|
|
//搜索条件
|
|
$seek_data = I('post.seek_data') ? I('post.seek_data') : [];
|
|
$seek_data['start_time'] = $seek_data['start_time'] ? $seek_data['start_time'] : date('Y-m-d', strtotime("-1 month"));
|
|
$seek_data['end_time'] = $seek_data['end_time'] ? $seek_data['end_time'] : date('Y-m-d', time());
|
|
//向上向下排序 默认desc =1 asc =2 desc
|
|
$seek_data['sort_type'] = $seek_data['sort_type'] ? $seek_data['sort_type'] : 2;
|
|
$page = I('post.page') ? I('post.page') : 1;
|
|
$limit = I('post.limit') ? I('post.limit') : 10;
|
|
$result = $this->getPrivateInfoData($this->store_id, $merchant_id, $seek_data, $page, $limit);
|
|
if ($result['status'] == 0) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '暂无数据']);
|
|
}
|
|
//汇总
|
|
$res = $this->calculateSellSum_2($result['sell_list'], $result['total']);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
public function salableInfoExcel()
|
|
{
|
|
if (IS_POST) {
|
|
ini_set('memory_limit', '64M');
|
|
$merchant_id = $this->merchant_id;
|
|
//搜索条件
|
|
$seek_data = I('post.seek_data') ? I('post.seek_data') : array();
|
|
$seek_data['start_time'] = $seek_data['start_time'] ? $seek_data['start_time'] : date('Y-m-d', strtotime("-1 month"));
|
|
$seek_data['end_time'] = $seek_data['end_time'] ? $seek_data['end_time'] : date('Y-m-d', time());
|
|
//向上向下排序 默认desc =1 asc =2 desc
|
|
$seek_data['sort_type'] = $seek_data['sort_type'] ? $seek_data['sort_type'] : 2;
|
|
$page = I('post.page') ? I('post.page') : 1;
|
|
$limit = I('post.limit') ? I('post.limit') : 500;
|
|
$data = $this->getPrivateInfoData($this->store_id, $merchant_id, $seek_data, $page, $limit);
|
|
if ($data['status'] == 0) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '暂无商品可导出']);
|
|
}
|
|
//汇总
|
|
$res = $this->calculateSellSum_2($data['sell_list'], $data['total']);
|
|
|
|
if (empty($res['sell_sum'])) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '暂无商品可导出']);
|
|
}
|
|
$directory_name = I('post.directory_name');
|
|
//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入
|
|
import("Vendor.PHPExcel.PHPExcel");
|
|
import("Vendor.PHPExcel.Writer.Excel5");
|
|
import("Vendor.PHPExcel.IOFactory.php");
|
|
$filename = "畅销商品导出数据时间为" . date("Y_m_d_H_i_s", strtotime($seek_data['start_time'])) . "至" . date("Y_m_d_H_i_s", strtotime($seek_data['end_time'])) . " 畅销商品导出时间" . date("Y_m_d_H_i_s");
|
|
$headArr = array(
|
|
array('goods_name', '商品名称'),
|
|
array('goods_number', '商品货号'),
|
|
array('goods_code', '商品条码'),
|
|
array('class_name', '商品分类名'),
|
|
array('sell_num', '总销量'),
|
|
);
|
|
$str = $filename;
|
|
if (!$directory_name) {
|
|
$num = createKey();
|
|
$directory_name = "./Uploads/storeGoodsExcel/{$this->store_id}/{$num}";
|
|
}
|
|
$this->setExcel($filename, $headArr, $res['sell_sum'], $str, $directory_name);
|
|
$result = array(
|
|
'status' => 1,
|
|
'type' => 1,
|
|
'directory_name' => $directory_name,
|
|
'msg' => '请继续生成文件'
|
|
);
|
|
if (count($res['sell_sum']) < $limit) {
|
|
$result['type'] = 2;
|
|
$result['msg'] = '数据生成完毕';
|
|
}
|
|
$this->ajaxReturn($result);
|
|
} else if (IS_GET) {
|
|
$directory_name = I('get.directory_name');
|
|
$ExporttalController = new ExporttableController();
|
|
$res = $ExporttalController->fileZipAddToDel($directory_name, '畅销商品导出');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
//滞销商品导出
|
|
public function unsalableexport()
|
|
{
|
|
//出售的商品
|
|
$start = strtotime("-1 month");
|
|
$end = time();
|
|
$where['pay_type'] = array('neq', 0);
|
|
$where['store_id'] = $this->store_id;
|
|
// $where['status'] = 1;
|
|
// $where['is_refund'] = 1;
|
|
$where['add_time'] = array('between', array($start, $end));
|
|
$dead_info = M('retail_sell')->where($where)->group('goods_id')->getField('goods_id', true);
|
|
$dead_info = $dead_info ? $dead_info : array(0);
|
|
//所有商品
|
|
//查询条件货号
|
|
$goodsnum = I('get.name02');
|
|
if (!empty($goodsnum)) {
|
|
$data['goods_number'] = $goodsnum;
|
|
}
|
|
//查询品名
|
|
$product = I('get.name03');
|
|
if (!empty($product)) {
|
|
$data['goods_name'] = array('like', array("%" . $product . "%"));
|
|
}
|
|
$data['store_id'] = $this->store_id;
|
|
$data['status'] = 0;
|
|
$data['id'] = array('not in', $dead_info);
|
|
$good_info = M('retail_goods')->where($data)->order('id desc')->select();
|
|
$count = M('retail_goods')->where($data)->count();
|
|
if (!empty($good_info)) {
|
|
foreach ($good_info as $key => &$val) {
|
|
$val['key'] = $key + 1;
|
|
//销量
|
|
$volume = M('retail_sell')->where(array('goods_id' => $val['id'], 'pay_type' => array('neq', 0)))->sum('num');
|
|
$val['saleVol'] = $volume ? $volume : 0;
|
|
$val['goods_code'] = $val['goods_code'] ? $val['goods_code'] : '---';
|
|
$val['good_number'] = $val['goods_number'] ? $val['goods_number'] : '---';
|
|
}
|
|
} else {
|
|
$good_info = array();
|
|
}
|
|
$filename = "滞销商品";
|
|
$str = $filename . "导出时间:" . date('Y-m-d H:i:s', time());
|
|
$headArr = array(
|
|
array('key', '序号'),
|
|
array('goods_number', '货号'),
|
|
array('goods_code', '商品条码'),
|
|
array('goods_name', '品名'),
|
|
array('saleVol', '总销量'),
|
|
);
|
|
getExcel($filename, $headArr, $good_info, $str);
|
|
}
|
|
|
|
//畅销导出
|
|
public function Bestexport()
|
|
{
|
|
//按照出售商品销量排序
|
|
//查询条件货号
|
|
$number = I('get.name02');
|
|
if (!empty($number)) {
|
|
$where['g.goods_number'] = $number;
|
|
}
|
|
$product = I('get.name03');
|
|
//查询品名
|
|
if (!empty($product)) {
|
|
$where['s.goods_name'] = array('like', '%' . $product . '%');
|
|
}
|
|
$start = strtotime("-1 month");
|
|
$end = time();
|
|
$where['s.add_time'] = array('between', array($start, $end));
|
|
$where['s.store_id'] = $this->store_id;
|
|
$where['s.pay_type'] = array('neq', 0);
|
|
$count = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->where($where)
|
|
->group('goods_id')
|
|
->select();
|
|
$count = count($count);
|
|
$best_sell = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->where($where)
|
|
->group('goods_id')
|
|
->order('s.id desc')
|
|
->select();
|
|
if (!empty($best_sell)) {
|
|
foreach ($best_sell as $key => &$val) {
|
|
$val['goods_number'] = M('retail_goods')->where(array('id' => $val['goods_id']))->getField('goods_number');
|
|
$val['goods_number'] = $val['goods_number'] ? $val['goods_number'] : '---';
|
|
$val['key'] = $key + 1;
|
|
$val['goods_code'] = M('retail_goods')->where(array('id' => $val['goods_id']))->getField('goods_code');
|
|
$val['goods_code'] = $val['goods_code'] ? $val['goods_code'] : '---';
|
|
$val['good_name'] = M('retail_goods')->where(array('id' => $val['goods_id']))->getField('goods_name');
|
|
|
|
//30天销量
|
|
$where['goods_id'] = $val['goods_id'];
|
|
$val['ynum'] = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->where($where)
|
|
->sum('num');
|
|
|
|
//总销量
|
|
$data['s.store_id'] = $this->store_id;
|
|
$data['s.pay_type'] = array('neq', 0);
|
|
$data['goods_id'] = $val['goods_id'];
|
|
//查询条件货号
|
|
if (!empty($number)) {
|
|
$data['g.goods_number'] = $number;
|
|
}
|
|
//查询品名
|
|
if (!empty($product)) {
|
|
$data['s.goods_name'] = array('like', '%' . $product . '%');
|
|
}
|
|
$val['znum'] = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->where($data)
|
|
->sum('num');
|
|
}
|
|
} else {
|
|
$best_sell = array();
|
|
}
|
|
$filename = "畅销商品";
|
|
$str = $filename . "导出时间:" . date('Y-m-d H:i:s', time());
|
|
$headArr = array(
|
|
array('key', '序号'),
|
|
array('goods_number', '货号'),
|
|
array('goods_code', '商品条码'),
|
|
array('good_name', '品名'),
|
|
array('ynum', '近30天销量'),
|
|
array('znum', '总销量'),
|
|
);
|
|
getExcel($filename, $headArr, $best_sell, $str);
|
|
}
|
|
|
|
/* 获取销售数据 */
|
|
public function get_sell_list()
|
|
{
|
|
$global_store_jurisdiction = I('session.global_store_jurisdiction'); // 权限
|
|
$showpurch_price = $global_store_jurisdiction['showpurch_price'] ? $global_store_jurisdiction['showpurch_price'] : 2; // 查看进价权限
|
|
// 商品名称搜索
|
|
$keyword = I('get.keyword');
|
|
if (!empty($keyword)) {
|
|
$keyword = trim($keyword, ' ');
|
|
$map['g.goods_name'] = array('like', '%' . $keyword . '%');
|
|
}
|
|
// 供货商搜索
|
|
$supplier_id = I('get.supplier_id');
|
|
if (!empty($supplier_id)) {
|
|
$map['g.supplier_id'] = trim($supplier_id, '');
|
|
}
|
|
// 品牌搜索
|
|
$goods_brand_id = I('get.goods_brand_id');
|
|
if (!empty($goods_brand_id)) {
|
|
$map['g.goods_brand_id'] = trim($goods_brand_id, '');
|
|
}
|
|
// 时间搜索
|
|
$start_time = I('get.start_time');
|
|
$end_time = I('get.end_time');
|
|
if (!empty($start_time) && !empty($end_time)) {
|
|
$start_time = strtotime($start_time);
|
|
$end_time = strtotime($end_time . '23:59:59');
|
|
$map['s.addtime'] = array('between', array($start_time, $end_time));
|
|
}
|
|
if (!empty($start_time) && empty($end_time)) {
|
|
$start_time = strtotime($start_time);
|
|
$map['s.addtime'] = array('egt', $start_time);
|
|
}
|
|
if (empty($start_time) && !empty($end_time)) {
|
|
$end_time = strtotime(($end_time . '23:59:59'));
|
|
$map['s.addtime'] = array('elt', $end_time);
|
|
}
|
|
// 按照商品分类搜索
|
|
$person1 = I('get.person1');
|
|
$person2 = I('get.person2');
|
|
$person3 = I('get.person3');
|
|
$flag = 0;
|
|
if (!empty($person3)) {
|
|
$map['g.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['g.goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
|
} else if ($flag == 1) {
|
|
$map['g.goods_class_id'] = $person2 ? $person2 : $person1;
|
|
}
|
|
$map['s.paytype'] = array('neq', 0);
|
|
$map['s.merchantid'] = $this->merchant_id;
|
|
$map['s.storeid'] = $this->store_id;
|
|
$sell_list = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->field('s.id,s.price,s.num,s.allmoney,s.paytype,s.type,s.purch_price,s.yuan_price,s.discount,s.addtime,s.skuinfo,s.status,s.sku_json_info,g.goods_name,g.supplier_id,goods_brand_id,g.goods_class_id')
|
|
->page($_GET['page'], $_GET['limit'])
|
|
->where($map)
|
|
->order('id desc')
|
|
->select();
|
|
$count = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->where($map)
|
|
->count();
|
|
if ($sell_list) {
|
|
foreach ($sell_list as $key => &$val) {
|
|
$val['index'] = ++$key;
|
|
$val['num'] = intval($val['num']) == $val['num'] ? intval($val['num']) : $val['num'];
|
|
$val['addtime'] = date('Y-m-d', $val['addtime']);
|
|
if ($val['sku_json_info']) {
|
|
$sku = json_decode($val['sku_json_info'], true);
|
|
$val['yuan_price'] = $sku['retail_price'] ? $sku['retail_price'] : $sku['actprice'];
|
|
$val['sku_name'] = $sku['name'];
|
|
}
|
|
if ($val['skuinfo']) {
|
|
$sku = json_decode($val['skuinfo'], true);
|
|
$val['yuan_price'] = $sku[0]['retail_price'] ? $sku[0]['retail_price'] : $sku[0]['actprice'];
|
|
$val['sku_name'] = $sku[0]['sku'];
|
|
}
|
|
switch ($val['paytype']) {
|
|
case 1:
|
|
$val['pay_type'] = '现金支付';
|
|
break;
|
|
case 2:
|
|
$val['pay_type'] = '银行卡支付';
|
|
break;
|
|
case 3:
|
|
$val['pay_type'] = '微信支付';
|
|
break;
|
|
case 4:
|
|
$val['pay_type'] = '支付宝支付';
|
|
break;
|
|
case 5:
|
|
$val['pay_type'] = '余额支付';
|
|
break;
|
|
case 6:
|
|
$val['pay_type'] = '微信支付';
|
|
break;
|
|
case 7:
|
|
$val['pay_type'] = '其他支付';
|
|
break;
|
|
}
|
|
if ($showpurch_price == 1) {
|
|
$val['profit'] = round($val['allmoney'] - ($val['purch_price'] * $val['num']), 2);
|
|
$val['profit_margin'] = round(($val['profit'] * 100) / $val['allmoney'], 2) . '%';
|
|
} else {
|
|
$val['purch_price'] = '*';
|
|
$val['profit'] = '*';
|
|
$val['profit_margin'] = '*';
|
|
}
|
|
|
|
$val['discount'] = $val['discount'] == 1 ? '' : $val['discount']; // 折扣
|
|
$val['class'] = M('retail_goods_class')->where(array('id' => $val['goods_class_id'], 'merchantid' => $this->merchant_id, 'status' => 0))->getField('class_name');
|
|
$val['supplier'] = M('retail_supplier')->where(array('id' => $val['supplier_id'], 'merchantid' => $this->merchant_id, 'status' => 1))->getField('supplier_name');
|
|
$val['brand'] = M('retail_goods_brand')->where(array('id' => $val['goods_brand_id'], 'merchantid' => $this->merchant_id, 'state' => 0))->getField('name');
|
|
$val['sell_type'] = $val['type'] == 1 ? '商城' : '店内';
|
|
$val['sell_status'] = $val['status'] == 1 ? '购买' : '退款';
|
|
}
|
|
}
|
|
$res = $this->statistics_sell($map);
|
|
$res['code'] = 0;
|
|
$res['count'] = $count ? $count : 0;
|
|
$res['data'] = $sell_list;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 统计总金额 总成本 总利润 */
|
|
protected function statistics_sell($map)
|
|
{
|
|
$global_store_jurisdiction = I('session.global_store_jurisdiction'); // 权限
|
|
$showpurch_price = $global_store_jurisdiction['showpurch_price'] ? $global_store_jurisdiction['showpurch_price'] : 2; // 查看进价权限
|
|
$sell_data = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on g.id=s.goods_id')
|
|
->field('s.id,s.num,s.allmoney,s.type,s.purch_price,s.yuan_price,s.discount,s.addtime,s.skuinfo,s.status,s.sku_json_info')
|
|
->where($map)
|
|
->select();
|
|
if ($sell_data) {
|
|
$sell_count = 0;
|
|
$refund_count = 0;
|
|
$all_purch_price = 0; // 总进价
|
|
$all_sell_money = 0; // 总销售金额
|
|
foreach ($sell_data as &$value) {
|
|
if ($value['status'] == 1) {
|
|
$all_purch_price += $value['purch_price'] * $value['num'];
|
|
$all_sell_money += $value['allmoney'];
|
|
++$sell_count;
|
|
} else {
|
|
$all_purch_price -= $value['purch_price'] * $value['num'];
|
|
$all_sell_money -= $value['allmoney'];
|
|
++$refund_count;
|
|
}
|
|
}
|
|
$all_sell_money = $all_sell_money ? round($all_sell_money, 2) : 0;
|
|
if ($showpurch_price == 1) {
|
|
$all_purch_price = $all_purch_price ? round($all_purch_price, 2) : 0;
|
|
$all_profit = round($all_sell_money - $all_purch_price, 2);
|
|
$all_profit_margin = round(($all_profit * 100) / $all_sell_money, 2) . '%';
|
|
} else {
|
|
$all_purch_price = '*';
|
|
$all_profit = '*';
|
|
$all_profit_margin = '*';
|
|
}
|
|
}
|
|
$res['sell_count'] = $sell_count ? $sell_count : 0;
|
|
$res['refund_count'] = $refund_count ? $refund_count : 0;
|
|
$res['all_sell_money'] = $all_sell_money ? $all_sell_money : 0;
|
|
$res['all_purch_price'] = $all_purch_price ? $all_purch_price : 0;
|
|
$res['all_profit'] = $all_profit ? $all_profit : 0;
|
|
$res['all_profit_margin'] = $all_profit_margin ? $all_profit_margin : '0%';
|
|
return $res;
|
|
}
|
|
|
|
public function vip_user()
|
|
{
|
|
$this->display();
|
|
}
|
|
|
|
public function applyFor()
|
|
{
|
|
$order = I('post.order');
|
|
|
|
$res = M('retail_store_settlement')->where(['order_num' => $order])->save([
|
|
'status' => 2
|
|
]);
|
|
|
|
if (!empty($res)) {
|
|
$arr = [
|
|
'code' => 200,
|
|
'msg' => '申请成功,请等待店铺确认。'
|
|
];
|
|
} else {
|
|
$arr = [
|
|
'code' => 400,
|
|
'msg' => '申请失败,请重试。'
|
|
];
|
|
}
|
|
|
|
$this->ajaxReturn($arr);
|
|
}
|
|
|
|
public function applyFor1()
|
|
{
|
|
$storeId = I("post.storeId");
|
|
$timer = I("post.date");
|
|
|
|
$sid = $_SESSION['store_id'];
|
|
|
|
$time_where = "";
|
|
|
|
|
|
if(!empty($timer)){
|
|
|
|
$start_date = strtotime($timer[0]);
|
|
$end_date = strtotime($timer[1]);
|
|
|
|
if(!empty($start_date)){
|
|
|
|
$time_where .= " AND finish_time >= ".$start_date;
|
|
|
|
}
|
|
|
|
if(!empty($end_date)){
|
|
$time_where .= " AND finish_time <= ".$end_date;
|
|
}
|
|
|
|
}
|
|
|
|
$where = " store_id = $sid AND ( pay_store_id = $storeId OR pay_store_id1 = $storeId ) AND pay_state = 1 AND pay_type = 5 AND order_type = 1 AND (pay_store_state = 0 OR pay_store1_state = 0) ".$time_where;
|
|
|
|
|
|
$order_id_list = M("retail_bill_order")->field("id,all_money,pay_store_id,current_balance,current_balance1,pay_store_id1")->where($where)->select();
|
|
|
|
// 生成结算订单
|
|
$money = 0;
|
|
|
|
|
|
|
|
foreach ($order_id_list as $val){
|
|
|
|
if($storeId == $val['pay_store_id']){
|
|
|
|
if($val['current_balance'] >= 0 && $v['pay_store_state'] == 0){
|
|
|
|
$money = $money + $val['all_money'];
|
|
|
|
}else{
|
|
$money = $money + ($val['all_money'] + $val['current_balance']);
|
|
}
|
|
|
|
$r = M("retail_bill_order")->where("id = ".$val['id'])->save(array("pay_store_state" => 1));
|
|
|
|
}
|
|
|
|
if($storeId == $val['pay_store_id1']){
|
|
|
|
if($val['current_balance1'] >= 0 && $v['pay_store1_state'] == 0){
|
|
|
|
$money = $money + $val['all_money'];
|
|
|
|
}else{
|
|
|
|
$money = $money + ($val['all_money'] + $val['current_balance1']);
|
|
|
|
}
|
|
|
|
$r = M("retail_bill_order")->where("id = ".$val['id'])->save(array("pay_store1_state" => 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// var_dump($money);
|
|
// die();
|
|
|
|
$add_arr = array(
|
|
"order_id_list" => json_encode($order_id_list),
|
|
"money" => $money,
|
|
"date" => $timer,
|
|
"add_time" => date("Y-m-d H:i:s"),
|
|
"store_id" => $sid,
|
|
"pay_store_id" => $storeId,
|
|
"state" => 1
|
|
);
|
|
|
|
$r = M("store_cash_out_order")->add($add_arr);
|
|
|
|
$this->ajaxReturn(array("code" => 200,"data" => $r,"msg" => "操作成功"));
|
|
}
|
|
|
|
public function confirmMoney()
|
|
{
|
|
$order = I('post.order');
|
|
|
|
$res = M('retail_store_settlement')->where(['order_num' => $order])->save([
|
|
'status' => 1
|
|
]);
|
|
|
|
if (!empty($res)) {
|
|
$arr = [
|
|
'code' => 200,
|
|
'msg' => '确认结算成功'
|
|
];
|
|
} else {
|
|
$arr = [
|
|
'code' => 400,
|
|
'msg' => '确认结算失败'
|
|
];
|
|
}
|
|
|
|
$this->ajaxReturn($arr);
|
|
}
|
|
|
|
public function getVipUserList()
|
|
{
|
|
|
|
$timer = I('post.time/a');
|
|
$orderNum = I('post.order_no');
|
|
$storeId = $_SESSION['store_id'];
|
|
|
|
$type = 1;
|
|
|
|
$time_where = "";
|
|
|
|
if(!empty($timer)){
|
|
|
|
$start_date = strtotime($timer[0]);
|
|
$end_date = strtotime($timer[1]);
|
|
|
|
if(!empty($start_date)){
|
|
|
|
$time_where .= " AND finish_time >= ".$start_date;
|
|
|
|
}
|
|
|
|
if(!empty($end_date)){
|
|
$time_where .= " AND finish_time <= ".$end_date;
|
|
}
|
|
|
|
}
|
|
|
|
$store_list = M("retail_store")->where(" id != '$storeId' AND store_status = 0 ")->select();
|
|
|
|
$tem = array();
|
|
|
|
foreach ($store_list as $key => $val){
|
|
|
|
$sid = $val['id'];
|
|
|
|
// 在我店里充钱去别的店里消费
|
|
// $where = " store_id = $sid AND (pay_store_id = $storeId OR pay_store_id1 = $storeId )AND pay_state = 1 AND pay_type = 5 AND order_type = 1 AND pay_store_state = 0 ".$time_where;
|
|
|
|
// $r = M("retail_bill_order")->where($where)->select();
|
|
|
|
// $decMoney = 0;
|
|
|
|
// if(!empty($r)){
|
|
|
|
// foreach ($r as $v){
|
|
|
|
// $decMoney = $decMoney + $v['all_money'];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// 在别的店里充值 在我的店里消费
|
|
|
|
$where1 = " store_id = $storeId AND ( pay_store_id = $sid OR pay_store_id1 = $sid ) AND pay_state = 1 AND pay_type = 5 AND order_type = 1 AND ( pay_store_state = 0 OR pay_store1_state = 0 ) ".$time_where;
|
|
|
|
$r1 = M("retail_bill_order")->where($where1)->select();
|
|
|
|
$addMoney = 0;
|
|
|
|
if(!empty($r1)){
|
|
|
|
foreach ($r1 as $v){
|
|
if($sid == $v['pay_store_id'] && $v['pay_store_state'] == 0){
|
|
|
|
if($v['current_balance'] >= 0){
|
|
|
|
$addMoney = $addMoney + $v['all_money'];
|
|
|
|
}else{
|
|
$addMoney = $addMoney + ($v['all_money'] + $v['current_balance']);
|
|
}
|
|
|
|
}
|
|
|
|
if($sid == $v['pay_store_id1'] && $v['pay_store1_state'] == 0){
|
|
|
|
if($v['current_balance1'] >= 0){
|
|
|
|
$addMoney = $addMoney + $v['all_money'];
|
|
|
|
}else{
|
|
|
|
$addMoney = $addMoney + ($v['all_money'] + $v['current_balance1']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$val['dec_money'] = $decMoney;
|
|
|
|
$val['add_money'] = $addMoney;
|
|
|
|
array_push($tem,$val);
|
|
}
|
|
|
|
$result['code'] = 0;
|
|
$result['data'] = $tem;
|
|
$result['date'] = $timer;
|
|
$result['total'] = sizeof($tem);
|
|
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
// 获取结算列表
|
|
public function getCashOutList()
|
|
{
|
|
$timer = I('post.time/a');
|
|
$page = I("post.page");
|
|
$limit = I("post.limit");
|
|
$type = I("post.type");
|
|
|
|
$sid = $_SESSION['store_id'];
|
|
|
|
$pages = ($page - 1) * $limit;
|
|
|
|
if(!$type){
|
|
$where = " ( store_id = $sid OR pay_store_id = $sid ) ";
|
|
}else{
|
|
if($type == 1){
|
|
$where = " store_id = $sid ";
|
|
}else if($type == 2){
|
|
$where = " pay_store_id = $sid ";
|
|
}
|
|
}
|
|
|
|
$res = M("store_cash_out_order")->where($where)->limit($pages,$limit)->order("add_time desc")->select();
|
|
|
|
$count = M("store_cash_out_order")->where($where)->count();
|
|
|
|
$tem = array();
|
|
|
|
foreach ($res as $val){
|
|
$val['order_id_list'] = json_decode($val['order_id_list'],true);
|
|
|
|
$val['pay_store'] = M("retail_store")->field("id,storetag,address")->where("id = ".$val['pay_store_id'])->find();
|
|
|
|
$val['store'] = M("retail_store")->field("id,storetag,address")->where("id = ".$val['store_id'])->find();
|
|
|
|
$val['current_store'] = $sid;
|
|
|
|
array_push($tem,$val);
|
|
}
|
|
|
|
$result['data'] = $tem;
|
|
$result['total'] = $count;
|
|
$result['code'] = 0;
|
|
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
// 通过结算
|
|
public function successCashOut()
|
|
{
|
|
$id = I("post.id");
|
|
$state = I("post.state");
|
|
|
|
$res = M("store_cash_out_order")->where(" id = $id ")->save(array("state" => $state));
|
|
|
|
if($res > 0){
|
|
$r = M("store_cash_out_order")->where("id = $id")->find();
|
|
$order_list = json_decode($r['order_id_list'],true);
|
|
if(!empty($order_list)){
|
|
|
|
foreach ($order_list as $val){
|
|
$id = $val['id'];
|
|
|
|
M("retail_bill_order")->where(" id = $id ")->save(array("state" => $state));
|
|
}
|
|
}
|
|
}
|
|
$result['code'] = 200;
|
|
$result['data'] = $res;
|
|
$result['msg'] = $res > 0 ? "操作成功" : '操作失败';
|
|
|
|
$this->ajaxReturn($result);
|
|
|
|
}
|
|
|
|
public function getVipUserList1()
|
|
{
|
|
$timer = I('post.time/a');
|
|
$orderNum = I('post.order_no');
|
|
$storeId = $_SESSION['store_id'];
|
|
$where = "store_id = {$storeId}";
|
|
$totalMoneyWhere = "store_id = {$storeId} AND use_store_id = {$storeId}";
|
|
if (!empty($timer) && !empty($timer[0])) {
|
|
$where .= ' AND create_time >= ' . strtotime($timer[0]) . ' AND create_time <= ' . strtotime($timer[0]) . ' AND status = 3';
|
|
$totalMoneyWhere .= ' AND create_time >= ' . strtotime($timer[0]) . ' AND create_time <= ' . strtotime($timer[0]) . ' AND status = 3';
|
|
}
|
|
if (!empty($orderNum)) {
|
|
$where .= ' AND order_num = ' . $orderNum;
|
|
$totalMoneyWhere .= ' AND order_num = ' . $orderNum;
|
|
}
|
|
|
|
$list = M('retail_store_settlement')
|
|
->where($where)
|
|
->page((int)I('post.page'), (int)I('post.limit'))
|
|
->select();
|
|
$count = M('retail_store_settlement')->where($where)->count();
|
|
$totalMoney = M('retail_store_settlement')->where($totalMoneyWhere)->sum('money');
|
|
|
|
if (!empty($list)) {
|
|
foreach ($list as &$v) {
|
|
if ($storeId == $v['use_store_id']) {
|
|
// 申请门店
|
|
$oneWhere = "storeid = {$v['recharge_store_id']}";
|
|
$twoWhere = "id = {$v['recharge_store_id']}";
|
|
} else {
|
|
// 结算门店
|
|
$oneWhere = "storeid = {$v['use_store_id']}";
|
|
$twoWhere = "id = {$v['use_store_id']}";
|
|
$v['money'] = "-{$v['money']}";
|
|
}
|
|
|
|
// 店铺信息
|
|
$manage = M('retail_manager')->where($oneWhere)->find();
|
|
$v['name'] = '';
|
|
$v['mobile'] = '';
|
|
if (!empty($manage)) {
|
|
$v['name'] = $manage['name'];
|
|
$v['mobile'] = $manage['mobile'];
|
|
}
|
|
$v['title'] = M('retail_store')->where($twoWhere)->getField('storetag');
|
|
|
|
// 时间戳转换
|
|
$v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
|
|
if (!empty($v['settlement_time'])) {
|
|
$v['settlement_time'] = date('Y-m-d H:i:s', $v['settlement_time']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$res['code'] = 0;
|
|
$res['data'] = $list;
|
|
$res['count'] = $count;
|
|
$res['store_id'] = $storeId;
|
|
$res['totalMoney'] = !empty($totalMoney) ? $totalMoney : 0;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// public function getVipUserList()
|
|
// {
|
|
// $info = $_SESSION['jurisdiction_user'];
|
|
// $type = I('post.type', 1);
|
|
// $where = [];
|
|
//
|
|
// if ($type == 1) {
|
|
// // 申请结算
|
|
// $where['store_id'] = $info['id'];
|
|
// } else {
|
|
// // 确认结算
|
|
// $where['withhold_store_id'] = $info['id'];
|
|
// }
|
|
//
|
|
// $list = M('retail_store_settlement')
|
|
// ->where($where)
|
|
// ->page((int)I('post.page'), (int)I('post.limit'))
|
|
// ->select();
|
|
// $count = M('retail_store_settlement')->where($where)->count();
|
|
//
|
|
// if (!empty($list)) {
|
|
// foreach ($list as &$v) {
|
|
// // 店长信息
|
|
// $where = $type == 1 ? ['store_id' => $v['withhold_store_id']] : ['store_id' => $v['store_id']];
|
|
// $manage = M('retail_manager')->where($where)->find();
|
|
// $v['name'] = '';
|
|
// $v['mobile'] = '';
|
|
// if (!empty($manage)) {
|
|
// $v['name'] = $manage['name'];
|
|
// $v['mobile'] = $manage['mobile'];
|
|
// }
|
|
// // 名称
|
|
// $where = $type == 1 ? ['id' => $v['withhold_store_id']] : ['id' => $v['store_id']];
|
|
// $v['title'] = M('retail_store')->where($where)->getField('storetag');
|
|
// }
|
|
// }
|
|
//
|
|
// $res['code'] = 0;
|
|
// $res['data'] = $list;
|
|
// $res['count'] = $count;
|
|
// $this->ajaxReturn($res);
|
|
// }
|
|
|
|
/* 店内收款明细 */
|
|
public function get_store_sell_list()
|
|
{
|
|
$RetailGuideModel = new RetailGuideModel();
|
|
|
|
/* 时间查询 */
|
|
$user_type = I('post.user_type');
|
|
if (in_array($user_type, ['1', '2', '3'])) {
|
|
switch ($user_type) {
|
|
case '1':
|
|
//零售会员
|
|
$map['b.vid'] = ['gt', 0];
|
|
break;
|
|
case '2':
|
|
//散客
|
|
$map['b.vid'] = [['exp', 'IS NULL'], 0, 'OR'];
|
|
$map['b.third_vip_code'] = ['exp', 'IS NULL'];
|
|
break;
|
|
case '3':
|
|
//德育币会员
|
|
$map['b.third_vip_code'] = ['exp', 'IS NOT NULL'];
|
|
break;
|
|
}
|
|
}
|
|
/* 订单号搜索 */
|
|
if (I('post.order_no')) {
|
|
$map['b.order_no'] = I('post.order_no');
|
|
}
|
|
/* 会员号搜索 */
|
|
if (I('post.member_number')) {
|
|
$map['v.mobile_phone|v.card_key|v.cardnum'] = array('like', '%' . I('post.member_number') . '%');
|
|
}
|
|
/* 德育币会员搜索 */
|
|
if (I('post.mec_vip_key')) {
|
|
$map['b.third_vip_code|b.third_vip_name'] = strval(I('post.mec_vip_key'));
|
|
}
|
|
/* 德育币村镇ID搜索 */
|
|
if (I('post.mec_villages_id')) {
|
|
$StoreModel = new RetailStoreModel();
|
|
$storeIds = $StoreModel->getFindField(['third_code' => strval(I('post.mec_villages_id'))]);
|
|
$storeIds = $storeIds ? $storeIds : '0';
|
|
$map['b.store_id'] = array('in', $storeIds);
|
|
}
|
|
$time = I("post.time");
|
|
if ($time) {
|
|
$start_date = strtotime($time[0]);
|
|
$end_date = strtotime($time[1]);
|
|
$map['b.add_time'] = ['between', [$start_date, $end_date]];
|
|
}
|
|
/* 收银员搜索 */
|
|
if (I('post.cashier_id')) {
|
|
$map['b.cashier_id'] = I('post.cashier_id');
|
|
}
|
|
/* 支付方式搜索 */
|
|
$pay_type = I('post.pay_type');
|
|
if ($pay_type) {
|
|
$map['b. pay_type'] = $pay_type;
|
|
}
|
|
/* 订单类型 */
|
|
if (I('post.order_type')) {
|
|
$map['b.order_type'] = I('post.order_type');
|
|
}
|
|
// 其他支付
|
|
$other_type = I('post.other_type');
|
|
$p_string = 'ls_retail_pay_order as p on p.bill_id=b.id';
|
|
if ($pay_type == 7 && $other_type) {
|
|
$p_string .= ' AND p.other_pay_id=' . $other_type;
|
|
}
|
|
$map['b.pay_state'] = 1;
|
|
$map['b.type'] = 2;
|
|
$map['b.store_id'] = $this->store_id;
|
|
|
|
$sell_list = M('retail_bill_order as b')
|
|
->join($p_string, 'LEFT')
|
|
->join('ls_retail_bill_discount as d on d.bill_id=b.id', 'LEFT')
|
|
->join('ls_retail_cashier as c on c.id=b.cashier_id', 'LEFT')
|
|
->join('ls_retail_vip as v on v.id=b.vid', 'LEFT')
|
|
->field('b.*,v.name as vip_name,v.nickname,v.mobile_phone as vip_mobile,v.card_key,c.name as adminname,d.coupon_money,d.vip_dis_money,d.cashier_dis_money,d.discount,d.small_changes_money,d.vip_less_money,d.use_integral,d.cashier_dis_money,d.cashier_manual_money,d.pay_coupon_fee,d.coupon_type,b.third_vip_code,b.third_vip_name')
|
|
->where($map)
|
|
->group('b.id')
|
|
->order("b.add_time desc")
|
|
->page((int)I('post.page'), (int)I('post.limit'))
|
|
->select();
|
|
$count = M('retail_bill_order as b')
|
|
->join('ls_retail_cashier as c on c.id=b.cashier_id', 'LEFT')
|
|
->join('ls_retail_vip as v on v.id=b.vid', 'LEFT')
|
|
->join('ls_retail_bill_discount as d on d.bill_id=b.id', 'LEFT')
|
|
->where($map)->count();
|
|
$guideIdArr = [];
|
|
$guideList = [];
|
|
//优惠券名称
|
|
$coupon_name = [
|
|
'门店优惠券:',
|
|
'会员优惠券:',
|
|
'微信商家券:',
|
|
];
|
|
$BillOrder = new BillOrder();
|
|
|
|
$StoreModel = new RetailStoreModel();
|
|
$villageId = $StoreModel->getFindField(['id' => $this->store_id], 'third_code');
|
|
$Plug = new Plug();
|
|
$plug_result = $Plug->merPlugState([
|
|
'merchant_id' => $this->merchant_id,
|
|
'identification_arr' => ['moraleducationcoin']
|
|
]);
|
|
foreach ($sell_list as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['use_integral'] = round($val['use_integral']);
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$total_discount = round($val['coupon_money'] + $val['cashier_dis_money'] + $val['vip_dis_money'] + $val['small_changes_money'] + $val['vip_less_money'] + $val['cashier_manual_money'], 2); // 总减少金额
|
|
$val['type_name'] = $val['type'] == 1 ? '商城' : '店内';
|
|
$val['all_money'] = floatval($val['all_money']); // 消费金额
|
|
$val['discount'] = $val['discount'] >= 1 ? '无折扣' : floatval($val['discount']) . ' 折'; // 手动折扣
|
|
$val['coupon_money'] = $val['coupon_money'] > 0 ? $coupon_name[$val['coupon_type'] - 1] . floatval($val['coupon_money']) : ''; // 优惠券金额
|
|
$val['pay_coupon_fee'] = $val['pay_coupon_fee'] > 0 ? '微信代金券:' . floatval($val['pay_coupon_fee']) : '';
|
|
if (empty($val['coupon_money']) && empty($val['pay_coupon_fee'])) {
|
|
$val['reduction'] = 1;
|
|
} else {
|
|
$val['reduction'] = 2;
|
|
}
|
|
$val['cashier_dis_money'] = $val['cashier_dis_money'] && $val['cashier_dis_money'] > 0 ? floatval($val['cashier_dis_money']) . '(元)' : '无优惠'; // 手动折扣金额
|
|
$val['cashier_manual_money'] = $val['cashier_manual_money'] && $val['cashier_manual_money'] > 0 ? floatval($val['cashier_manual_money']) . '(元)' : '无优惠'; // 单品折扣金额
|
|
$vip_dis_money = $val['vip_dis_money'] ? $val['vip_dis_money'] : 0;
|
|
$vip_less_money = $val['vip_less_money'] ? $val['vip_less_money'] : 0;
|
|
$val['vip_dis_money'] = round($vip_dis_money + $vip_less_money, 2);
|
|
$val['small_changes_money'] = $val['small_changes_money'] && $val['small_changes_money'] > 0 ? floatval($val['small_changes_money']) . '(元)' : '未抹零'; // 手动折扣金额
|
|
$val['total_discount'] = $total_discount ? $total_discount . '(元)' : '无优惠';
|
|
if ($val['vid']) { // 会员信息
|
|
$val['vip_name'] = $val['vip_name'] ? $val['vip_name'] : ($val['nickname'] ? $val['nickname'] : '会员');
|
|
$val['vip_mobile'] = $val['vip_mobile'] ? $val['vip_mobile'] : '未设置';
|
|
$val['card_key'] = $val['card_keycard_key'] ? $val['card_key'] : '未绑定';
|
|
} else if ($plug_result['moraleducationcoin']) {
|
|
$val['vip_name'] = $val['third_vip_name'];
|
|
$val['villageId'] = $villageId;
|
|
$val['vip_mobile'] = '';
|
|
$val['card_key'] = '';
|
|
} else {
|
|
$val['vip_name'] = '散客';
|
|
$val['vip_mobile'] = '未设置';
|
|
$val['card_key'] = '未绑定';
|
|
}
|
|
|
|
$val['pay_name'] = $BillOrder->getPayType($val['pay_type'], $val['id']);
|
|
|
|
/* 订单类型 */
|
|
if ($val['order_type'] == 2) {
|
|
$val['status_name'] = '退款订单';
|
|
$val['all_money'] = 0 - $val['all_money'];
|
|
} else {
|
|
if ($val['refund_money'] > 0) {
|
|
$val['status_name'] = '有退款';
|
|
} else {
|
|
$val['status_name'] = '购买订单';
|
|
}
|
|
}
|
|
/* 导购员 */
|
|
if ($val['guide_id']) {
|
|
if (in_array($val['guide_id'], $guideIdArr)) {
|
|
$val['guide_name'] = $guideList[$val['guide_id']]['guidename'] ? $guideList[$val['guide_id']]['guidename'] : '自购';
|
|
} else {
|
|
$guideData = $RetailGuideModel->getFind(['id' => $val['guide_id']], 'id,guidename');
|
|
$val['guide_name'] = $guideData['guidename'] ? $guideData['guidename'] : '自购';
|
|
$guideIdArr[] = $guideData['id'];
|
|
$guideList[$val['guide_id']] = $guideData;
|
|
}
|
|
} else {
|
|
$val['guide_name'] = '自购';
|
|
}
|
|
}
|
|
|
|
$plugClass = new Plug();
|
|
//订单获取祝福码,判断该门店是否,有,并且开启
|
|
$storePlugStatusPost = [
|
|
'store_id' => $this->store_id,
|
|
'identification_arr' => ['blessing'],
|
|
];
|
|
$storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态
|
|
if ($storePlugStatus === true) {
|
|
//有权限
|
|
$jurisdictionBlessing = 1;
|
|
} else {
|
|
//无权限
|
|
$jurisdictionBlessing = 2;
|
|
}
|
|
|
|
$res['code'] = 0;
|
|
$res['data'] = $sell_list;
|
|
$res['count'] = $count;
|
|
$res['jurisdiction_blessing'] = $jurisdictionBlessing;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/*
|
|
* 店内明细统计
|
|
*/
|
|
public function getSellListTotal()
|
|
{
|
|
/* 时间查询 */
|
|
$data = I("post.");
|
|
$time = $data['time'];
|
|
if (!empty($time)) {
|
|
$start_date = strtotime($time[0]);
|
|
$end_date = strtotime($time[1]);
|
|
$map['b.add_time'] = ['between', [$start_date, $end_date]];
|
|
}
|
|
/* 时间查询 */
|
|
$user_type = I('post.user_type');
|
|
if (in_array($user_type, ['1', '2', '3'])) {
|
|
switch ($user_type) {
|
|
case '1':
|
|
//零售会员
|
|
$map['b.vid'] = ['gt', 0];
|
|
break;
|
|
case '2':
|
|
//散客
|
|
$map['b.vid'] = [['exp', 'IS NULL'], 0, 'OR'];
|
|
$map['b.third_vip_code'] = ['exp', 'IS NULL'];
|
|
break;
|
|
case '3':
|
|
//德育币会员
|
|
$map['b.third_vip_code'] = ['exp', 'IS NOT NULL'];
|
|
break;
|
|
}
|
|
}
|
|
/* 订单号搜索 */
|
|
if (I('post.order_no')) {
|
|
$map['b.order_no'] = I('post.order_no');
|
|
}
|
|
/* 会员号搜索 */
|
|
if (I('post.member_number')) {
|
|
$map['v.mobile_phone|v.card_key|v.cardnum'] = array('like', '%' . I('post.member_number') . '%');
|
|
}
|
|
/* 德育币会员搜索 */
|
|
if (I('post.mec_vip_key')) {
|
|
$map['b.third_vip_code|b.third_vip_name'] = strval(I('post.mec_vip_key'));
|
|
}
|
|
/* 德育币村镇ID搜索 */
|
|
if (I('post.mec_villages_id')) {
|
|
$StoreModel = new RetailStoreModel();
|
|
$storeIds = $StoreModel->getFindField(['third_code' => strval(I('post.mec_villages_id'))]);
|
|
$storeIds = $storeIds ? $storeIds : '0';
|
|
$map['b.store_id'] = array('in', $storeIds);
|
|
}
|
|
/* 收银员搜索 */
|
|
if ($data['cashier_id']) {
|
|
$map['b.cashier_id'] = $data['cashier_id'];
|
|
}
|
|
/* 支付方式搜索 */
|
|
if ($data['pay_type']) {
|
|
$map['b. pay_type'] = $data['pay_type'];
|
|
}
|
|
/* 订单类型 */
|
|
if ($data['order_type']) {
|
|
$map['b.order_type'] = $data['order_type'];
|
|
}
|
|
$map['b.pay_state'] = 1;
|
|
$map['b.type'] = 2;
|
|
$map['b.store_id'] = $this->store_id;
|
|
$sell_list = M('retail_bill_order as b')
|
|
->join('ls_retail_cashier as c on c.id=b.cashier_id', 'LEFT')
|
|
->join('ls_retail_vip as v on v.id=b.vid', 'LEFT')
|
|
->join('ls_retail_bill_discount as d on d.bill_id=b.id', 'LEFT')
|
|
->field('b.*,d.coupon_money,d.cashier_manual_money,d.vip_dis_money,d.cashier_dis_money,d.discount,d.small_changes_money,d.pay_coupon_fee')
|
|
->where($map)
|
|
->select();
|
|
$sell_count = 0; // 销售笔数
|
|
$sell_money = 0; //销售总金额
|
|
$refund_count = 0; //退款笔数
|
|
$refund_money = 0; //退款金额
|
|
$sell_dismoney = 0; //购买订单的会员折扣金额
|
|
$refund_dismoney = 0; //退款订单的会员折扣金额
|
|
$sell_cashierdiscountmoney = 0; //购买订单手动折扣金额
|
|
$refund_cashierdiscountmoney = 0; //退款订单手动折扣金额
|
|
$sell_exchange_money = 0; //购买订单优惠金额
|
|
$refund_exchange_money = 0; //退款订单优惠金额
|
|
$sell_small_changes_money = 0; //购买订单抹零金额
|
|
$refund_small_changes_money = 0; //退款订单抹零金额
|
|
$pay_coupon_money = 0; //微信代金券金额
|
|
$cashier_manual_money = 0; //单品折扣金额
|
|
foreach ($sell_list as $key => &$val) {
|
|
if ($val['order_type'] == 1) { //购买订单
|
|
$sell_count += 1;
|
|
$sell_money += $val['all_money'];
|
|
$sell_dismoney += $val['vip_dis_money'];
|
|
$sell_cashierdiscountmoney += $val['cashier_dis_money'];
|
|
$sell_exchange_money += $val['coupon_money'];
|
|
$sell_small_changes_money += $val['small_changes_money'];
|
|
$pay_coupon_money += $val['pay_coupon_fee'];
|
|
$cashier_manual_money += $val['cashier_manual_money'];
|
|
}
|
|
if ($val['order_type'] == 2) { //退款订单
|
|
$refund_count += 1;
|
|
$refund_money += $val['refund_money'];
|
|
$refund_dismoney += $val['vip_dis_money'];
|
|
$refund_cashierdiscountmoney += $val['cashier_dis_money'];
|
|
$refund_exchange_money += $val['coupon_money'];
|
|
$refund_small_changes_money += $val['small_changes_money'];
|
|
$pay_coupon_money -= $val['pay_coupon_fee'];
|
|
$cashier_manual_money -= $val['cashier_manual_money'];
|
|
}
|
|
}
|
|
$money = round($sell_money - $refund_money, 2);
|
|
$dismoney = round($sell_dismoney - $refund_dismoney, 2);
|
|
$cashierdiscountmoney = round($sell_cashierdiscountmoney - $refund_cashierdiscountmoney, 2);
|
|
$exchange_money = round($sell_exchange_money - $refund_exchange_money, 2);
|
|
$small_changes_money = round($sell_small_changes_money - $refund_small_changes_money, 2);
|
|
$res['sell_count'] = $sell_count ? $sell_count . '(笔)' : 0 . '(笔)';
|
|
$res['refund_count'] = $refund_count ? $refund_count . '(笔)' : 0 . '(笔)';
|
|
$res['exchange_money'] = $exchange_money ? $exchange_money . '(元)' : 0 . '(元)';
|
|
$res['dismoney'] = $dismoney ? $dismoney . '(元)' : 0 . '(元)';
|
|
$res['cashierdiscountmoney'] = $cashierdiscountmoney ? $cashierdiscountmoney . '(元)' : 0 . '(元)';
|
|
$res['small_changes_money'] = $small_changes_money ? $small_changes_money . '(元)' : 0 . '(元)';
|
|
$res['sell_money'] = $sell_money ? $sell_money . '(元)' : 0 . '(元)';
|
|
$res['refund_money'] = $refund_money ? $refund_money . '(元)' : 0 . '(元)';
|
|
$res['money'] = $money ? $money . '(元)' : 0 . '(元)';
|
|
$res['pay_coupon_money'] = round($pay_coupon_money, 2) . '(元)';
|
|
$res['cashier_manual_money'] = round($cashier_manual_money, 2) . '(元)';
|
|
$res['status'] = 1;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 店内收款明细导出 */
|
|
public function export()
|
|
{
|
|
/* 时间查询 */
|
|
$time = json_decode(htmlspecialchars_decode(I("get.time")), true);
|
|
if (!empty($time)) {
|
|
$start_date = strtotime($time[0]);
|
|
$end_date = strtotime($time[1]);
|
|
$map['b.add_time'] = array('between', array($start_date, $end_date));
|
|
} else {
|
|
//本月
|
|
$start_date = strtotime(date("Y-m-01 00:00:00", time()));
|
|
$end_date = time();
|
|
$map['b.add_time'] = array('between', array($start_date, $end_date));
|
|
}
|
|
/* 时间查询 */
|
|
$user_type = I('get.user_type');
|
|
if (in_array($user_type, ['1', '2', '3'])) {
|
|
switch ($user_type) {
|
|
case '1':
|
|
//零售会员
|
|
$map['b.vid'] = ['gt', 0];
|
|
break;
|
|
case '2':
|
|
//散客
|
|
$map['b.vid'] = [['exp', 'IS NULL'], 0, 'OR'];
|
|
$map['b.third_vip_code'] = ['exp', 'IS NULL'];
|
|
break;
|
|
case '3':
|
|
//德育币会员
|
|
$map['b.third_vip_code'] = ['exp', 'IS NOT NULL'];
|
|
break;
|
|
}
|
|
}
|
|
/* 订单号搜索 */
|
|
if (I('get.order_no')) {
|
|
$map['b.order_no'] = I('get.order_no');
|
|
}
|
|
/* 会员号搜索 */
|
|
if (I('get.member_number')) {
|
|
$map['v.mobile_phone|v.card_key|v.cardnum'] = array('like', '%' . I('get.member_number') . '%');
|
|
}
|
|
/* 德育币会员搜索 */
|
|
if (I('get.mec_vip_key')) {
|
|
$map['b.third_vip_code|b.third_vip_name'] = strval(I('get.mec_vip_key'));
|
|
}
|
|
/* 德育币村镇ID搜索 */
|
|
if (I('get.mec_villages_id')) {
|
|
$StoreModel = new RetailStoreModel();
|
|
$storeIds = $StoreModel->getFindField(['third_code' => strval(I('get.mec_villages_id'))]);
|
|
$storeIds = $storeIds ? $storeIds : '0';
|
|
$map['b.store_id'] = array('in', $storeIds);
|
|
}
|
|
/* 收银员搜索 */
|
|
$admin_id = I('get.cashier_id');
|
|
if ($admin_id) {
|
|
$map['b.cashier_id'] = $admin_id;
|
|
}
|
|
/* 支付方式搜索 */
|
|
$pay_type = I('get.pay_type');
|
|
if ($pay_type) {
|
|
$map['b. pay_type'] = $pay_type;
|
|
}
|
|
/* 订单类型 */
|
|
$order_type = I('get.order_type');
|
|
if ($order_type) {
|
|
$map['b.order_type'] = $order_type;
|
|
}
|
|
// 其他支付
|
|
$other_type = I('get.other_type');
|
|
$p_string = 'ls_retail_pay_order as p on p.bill_id=b.id';
|
|
if ($pay_type == 7 && $other_type) {
|
|
$p_string .= ' AND p.other_pay_id=' . $other_type;
|
|
}
|
|
$map['b.pay_state'] = 1;
|
|
$map['b.type'] = 2;
|
|
$map['b.store_id'] = $this->store_id;
|
|
$sell_list = M('retail_bill_order as b')
|
|
->join($p_string)
|
|
->join('ls_retail_bill_discount as d on d.bill_id=b.id', 'LEFT')
|
|
->join('ls_retail_cashier as c on c.id=b.cashier_id', 'LEFT')
|
|
->join('ls_retail_vip as v on v.id=b.vid', 'LEFT')
|
|
->field('b.*,v.name as vip_name,v.nickname,v.mobile_phone as vip_mobile,v.card_key,c.name as adminname,d.coupon_money,d.vip_dis_money,d.cashier_dis_money,d.discount,d.small_changes_money,d.vip_less_money,d.use_integral,d.pay_coupon_fee,d.coupon_type,b.third_vip_code,b.third_vip_name')
|
|
->where($map)
|
|
->group('b.id')
|
|
->order("b.id desc")
|
|
->select();
|
|
$coupon_name = [
|
|
'门店优惠券:',
|
|
'会员优惠券:',
|
|
'微信商家券:',
|
|
];
|
|
$BillOrder = new BillOrder();
|
|
$StoreModel = new StoreModel();
|
|
$villageId = $StoreModel->getFindField(['id' => $this->store_id], 'third_code');
|
|
$Plug = new Plug();
|
|
$plug_result = $Plug->merPlugState([
|
|
'merchant_id' => $this->merchant_id,
|
|
'identification_arr' => ['moraleducationcoin']
|
|
]);
|
|
foreach ($sell_list as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$total_discount = round($val['coupon_money'] + $val['cashier_dis_money'] + $val['vip_dis_money'] + $val['small_changes_money'] + $val['vip_less_money'] + $val['cashier_manual_money'], 2); // 总减少金额
|
|
$val['type_name'] = $val['type'] == 1 ? '商城' : '店内';
|
|
$val['all_money'] = floatval($val['all_money']); // 消费金额
|
|
$val['discount'] = $val['discount'] >= 1 ? '无折扣' : floatval($val['discount']) . ' 折'; // 手动折扣
|
|
$coupon_fee = '';
|
|
if ($val['coupon_money'] > 0) {
|
|
$coupon_fee .= $coupon_name[$val['coupon_type'] - 1] . floatval($val['coupon_money']);
|
|
}
|
|
if ($val['pay_coupon_fee'] > 0) {
|
|
$coupon_fee .= '微信代金券:' . floatval($val['pay_coupon_fee']);
|
|
}
|
|
$val['coupon_money'] = $coupon_fee;
|
|
$val['cashier_dis_money'] = $val['cashier_dis_money'] && $val['cashier_dis_money'] > 0 ? floatval($val['cashier_dis_money']) . '(元)' : '无优惠'; // 手动折扣金额
|
|
$vip_dis_money = $val['vip_dis_money'] ? $val['vip_dis_money'] : 0;
|
|
$vip_less_money = $val['vip_less_money'] ? $val['vip_less_money'] : 0;
|
|
$val['vip_dis_money'] = round($vip_dis_money + $vip_less_money, 2);
|
|
$val['small_changes_money'] = $val['small_changes_money'] && $val['small_changes_money'] > 0 ? floatval($val['small_changes_money']) . '(元)' : '未抹零'; // 手动折扣金额
|
|
$val['total_discount'] = $total_discount ? $total_discount . '(元)' : '无优惠';
|
|
if ($val['vid']) { // 会员信息
|
|
$val['vip_name'] = $val['vip_name'] ? $val['vip_name'] : ($val['nickname'] ? $val['nickname'] : '会员');
|
|
$val['vip_mobile'] = $val['vip_mobile'] ? $val['vip_mobile'] : '未设置';
|
|
$val['card_key'] = $val['card_keycard_key'] ? $val['card_key'] : '未绑定';
|
|
} else if ($plug_result['moraleducationcoin']) {
|
|
$val['vip_name'] = $val['third_vip_name'];
|
|
$val['villageId'] = $villageId;
|
|
$val['vip_mobile'] = '';
|
|
$val['card_key'] = '';
|
|
} else {
|
|
$val['vip_name'] = '散客';
|
|
$val['vip_mobile'] = '未设置';
|
|
$val['card_key'] = '未绑定';
|
|
}
|
|
$val['pay_name'] = $BillOrder->getPayType($val['pay_type'], $val['id']);
|
|
|
|
/* 订单类型 */
|
|
if ($val['order_type'] == 2) {
|
|
$val['status_name'] = '退款订单';
|
|
$val['all_money'] = -$val['all_money'];
|
|
} else {
|
|
if ($val['refund_money'] > 0) {
|
|
$val['status_name'] = '有退款';
|
|
} else {
|
|
$val['status_name'] = '购买订单';
|
|
}
|
|
}
|
|
/* 导购员 */
|
|
if ($val['guide_id']) {
|
|
$guide_name = M('retail_guide')->where(array('id' => $val['guide_id']))->getField('guidename');
|
|
$val['guide_name'] = $guide_name ? $guide_name : '自购';
|
|
} else {
|
|
$val['guide_name'] = '自购';
|
|
}
|
|
$out_trade_no = D("RetailPayOrder")->getFindField(array('bill_id' => $val['id'], 'order_state' => array('in', 'SUCCESS,REFUND')), "out_trade_no", true);
|
|
if (!empty($out_trade_no)) {
|
|
$val['out_trade_no'] = implode(',', $out_trade_no);
|
|
} else {
|
|
$val['out_trade_no'] = '';
|
|
}
|
|
}
|
|
$name = '店内收款明细';
|
|
$headArr = array(
|
|
array('index', '序号'),
|
|
array('order_no', '订单号'),
|
|
array('out_trade_no', '内部订单号'),
|
|
array('vip_name', '消费对象'),
|
|
array('vip_mobile', '会员手机号'),
|
|
array('card_key', '实体卡号'),
|
|
array('all_money', '支付金额'),
|
|
array('use_integral', '使用积分'),
|
|
array('pay_name', '支付类型'),
|
|
array('add_time', '消费时间'),
|
|
array('adminname', '收银员'),
|
|
array('guide_name', '导购员'),
|
|
array('coupon_money', '优惠券减免'),
|
|
array('discount', '手动折扣'),
|
|
array('cashier_dis_money', '手动折扣优惠'),
|
|
array('vip_dis_money', '会员价及会员折扣优惠'),
|
|
array('small_changes_money', '抹零'),
|
|
array('total_discount', '总优惠'),
|
|
array('status_name', '订单类型'),
|
|
array('business_remark', '订单备注'),
|
|
);
|
|
if ($plug_result['moraleducationcoin']) {
|
|
$headArr[] = ['third_vip_code', '德育币会员ID'];
|
|
$headArr[] = ['villageId', '村镇ID'];
|
|
}
|
|
$str = $name . '导出时间' . date('Y-m-d H:i:s', time());
|
|
getExcel($name, $headArr, $sell_list, $str);
|
|
}
|
|
|
|
/**
|
|
* 打印
|
|
*/
|
|
public function storeIdGet()
|
|
{
|
|
$bill_id = I('post.bill_id');
|
|
if (!$bill_id) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时,请刷新重试';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$res = A('PayApi/Printer')->linePrinting_v1($this->store_id, $bill_id, true);
|
|
if ($res['status'] == 0) {
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
/**销售明细、汇总
|
|
* 获取商品分类
|
|
* @return [array] $res
|
|
*/
|
|
public function getClassList()
|
|
{
|
|
/* 商品分类 */
|
|
$class_data = M('retail_goods_class')->field('id,class_name')->where(array('pid' => 0, 'status' => 0, 'merchantid' => $this->merchant_id))->order('id asc')->select();
|
|
if (!$class_data) {
|
|
$res = array('status' => 0, 'msg' => '暂无分类');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
foreach ($class_data as &$val) {
|
|
$children1 = M('retail_goods_class')->field('id,class_name')->where(array('pid' => $val['id'], 'status' => 0, 'merchantid' => $this->merchant_id))->order('id asc')->select();
|
|
if ($children1) {
|
|
foreach ($children1 as &$value) {
|
|
$children2 = M('retail_goods_class')->field('id,class_name')->where(array('pid' => $value['id'], 'status' => 0, 'merchantid' => $this->merchant_id))->order('id asc')->select();
|
|
$value['children'] = $children2;
|
|
}
|
|
}
|
|
$val['children'] = $children1;
|
|
}
|
|
$res = array('status' => 1, 'class_data' => $class_data);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 获取销售数据
|
|
* @param [array] $seek_data 搜索条件
|
|
* @return [array] $res
|
|
*/
|
|
public function getSellList()
|
|
{
|
|
// 搜索条件
|
|
$seek_data = I('post.seek_data') ? I('post.seek_data') : array();
|
|
$res = $this->getPublicSellData($this->store_id, $this->merchant_id, $seek_data, 1);
|
|
foreach ($res['sell_list'] as &$val) {
|
|
if ($val['sell_type'] != 1) {
|
|
$val['subtotal'] = '-' . $val['subtotal'];
|
|
}
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 销售明细导出
|
|
* @param [array] $seek_data 搜索条件
|
|
*/
|
|
public function sellListExport()
|
|
{
|
|
ini_set('memory_limit', '-1');
|
|
$storeid = I('session.storeid');
|
|
if (!$storeid) {
|
|
$res = array('status' => 0, 'msg' => '登录超时,请重新登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$supplier_type = session('ls_userinfo')['supplier_type'];
|
|
$merchantid = session("ls_userinfo")['merchantid'];
|
|
// 搜索条件
|
|
$seek_data = I('get.seek_data') ? json_decode(htmlspecialchars_decode(I('get.seek_data')), true) : array();
|
|
$res = $this->getPublicSellData($storeid, $merchantid, $seek_data, '');
|
|
if ($res['status'] == 1) {
|
|
$sell_list = $res['sell_list'];
|
|
foreach ($sell_list as &$val) {
|
|
if ($val['sell_type'] != 1) {
|
|
$val['subtotal'] = '-' . $val['subtotal'];
|
|
}
|
|
}
|
|
} else {
|
|
$sell_list = array();
|
|
}
|
|
$file_name = '商品销售明细';
|
|
$headArr = array(
|
|
array('index', '序号'),
|
|
array('type_name', '类型'),
|
|
array('order_no', '订单号'),
|
|
array('goods_name', '商品名称'),
|
|
array('class_name', '商品分类'),
|
|
array('goods_number', '货号'),
|
|
array('goods_code', '条码'),
|
|
array('company', '单位'),
|
|
array('purchase_price', '进价'),
|
|
array('original_price', '原单价'),
|
|
array('num', '数量'),
|
|
array('cashier_dis_money', '收银员打折金额'),
|
|
array('coupon_money', '优惠券优惠金额'),
|
|
array('integral_dis_money', '积分抵扣金额'),
|
|
array('small_changes_money', '抹零优惠金额'),
|
|
array('subtotal', '实售总价'),
|
|
array('sell_mold', '订单类型'),
|
|
array('refund_num', '退货'),
|
|
array('add_time', '交易时间'),
|
|
);
|
|
if ($supplier_type == 2) {
|
|
$headArr[17] = array('supplier_name', '供货商');
|
|
}
|
|
$str = $file_name . '导出时间' . date('Y-m-d H:i:s', time());
|
|
getExcel($file_name, $headArr, $sell_list, $str);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取数据
|
|
* @param [array] $seek_data 搜索条件
|
|
* @return [array] $res
|
|
*/
|
|
public function getSellSum()
|
|
{
|
|
ini_set('memory_limit', '-1');
|
|
// 搜索条件
|
|
$seek_data = I('post.seek_data') ? I('post.seek_data') : array();
|
|
$seek_data['start_time'] = $seek_data['seek_date'][0] ? $seek_data['seek_date'][0] : date('Y-m-01', strtotime(date("Y-m-d")));
|
|
$seek_data['end_time'] = $seek_data['seek_date'][1] ? $seek_data['seek_date'][1] : date('Y-m-d', time());
|
|
|
|
$result = $this->getPublicSellData($this->store_id, $this->merchant_id, $seek_data, 2);
|
|
if ($result['status'] == 0) {
|
|
$res = array('status' => 0, 'msg' => '暂无数据');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 汇总
|
|
$res = $this->calculateSellSum($result['sell_list']);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
|
|
//销售汇总2021-3-10getSellSummary
|
|
public function getSellSummary()
|
|
{
|
|
ini_set('memory_limit', '-1');
|
|
$data = I('post.');
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$data['store_id'] = $this->store_id;
|
|
$SellClass = new Sell();
|
|
$result = $SellClass->sellSummary($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
//汇总串号列表
|
|
public function summaryList()
|
|
{
|
|
$data = I('post.');
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$data['store_id'] = $this->store_id;
|
|
$SerialClass = new SerialNumberGoods();
|
|
$result = $SerialClass->serialSummaryList($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取商品销售汇总合计
|
|
*/
|
|
public function getStoreSellTotal()
|
|
{
|
|
// 搜索条件
|
|
$seek_data = I('post.');
|
|
$result = $this->getPublicSellData_2($seek_data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/**
|
|
* 销售汇总导出
|
|
* @param [array] $seek_data 搜索条件
|
|
*/
|
|
public function sellSumExport()
|
|
{
|
|
// 搜索条件
|
|
ini_set('memory_limit', '-1');
|
|
$data = I('get.');
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$data['store_id'] = $this->store_id;
|
|
$SellClass = new Sell();
|
|
$result = $SellClass->sellSummary($data);
|
|
$sell_sum = $result['data']['list'];
|
|
$file_name = '商品销售汇总';
|
|
$headArr = array(
|
|
array('index', '序号'),
|
|
array('goods_name', '商品名称'),
|
|
array('goods_name', '规格名称'),
|
|
array('class_name', '商品分类'),
|
|
array('goods_number', '货号'),
|
|
array('goods_code', '条码'),
|
|
array('company', '单位'),
|
|
array('sell_num', '售出数量'),
|
|
// array('sell_number', '实际数量'),//接口未统计这个字段
|
|
array('subtotal', '售出总额'),
|
|
array('purchase_price', '成本合计'),
|
|
array('profit', '利润合计'),
|
|
);
|
|
$str = $file_name . '导出时间' . date('Y-m-d H:i:s', time());
|
|
getExcel($file_name, $headArr, $sell_sum, $str);
|
|
}
|
|
|
|
/**
|
|
* 获取数据(销售公用)
|
|
* @param [int] $store_id 门店id
|
|
* @param [int] $merchant_id 商户id
|
|
* @param [array] $seek_data 搜索数据
|
|
* @param $type
|
|
* @return [array] $res
|
|
*
|
|
*/
|
|
protected function getPublicSellData($store_id, $merchant_id, $seek_data, $type)
|
|
{
|
|
/* 查看进价权限 */
|
|
$show_purch_price = I('session.global_store_jurisdiction')['showpurch_price'];
|
|
$inventory = I('session.identity');
|
|
$supplier_type = session("ls_userinfo")['supplier_type'];
|
|
// 时间搜索
|
|
if ($seek_data['start_time'] && $seek_data['end_time']) {
|
|
$start_time = strtotime($seek_data['start_time']);
|
|
$end_time = strtotime($seek_data['end_time']); //销售汇总没有时间
|
|
$map['s.add_time'] = array('between', array($start_time, $end_time));
|
|
} else if ($seek_data['start_time'] && !$seek_data['end_time']) {
|
|
$start_time = strtotime($seek_data['start_time']);
|
|
$map['s.add_time'] = array('gt', $start_time);
|
|
} else if (!$seek_data['start_time'] && $seek_data['end_time']) {
|
|
$end_time = strtotime($seek_data['end_time']);
|
|
$map['s.add_time'] = array('lt', $end_time);
|
|
}
|
|
if (!empty($seek_data['keyword'])) {
|
|
$keyword = trim($seek_data['keyword']);
|
|
if (!empty($seek_data['keyword_type'])) {
|
|
//商品销售明细
|
|
switch ($seek_data['keyword_type']) {
|
|
case 1:
|
|
//货号
|
|
$map['g.goods_number'] = ['like', '%' . $keyword . '%'];
|
|
break;
|
|
case 2:
|
|
//条码
|
|
$map['g.goods_code'] = ['like', '%' . $keyword . '%'];
|
|
break;
|
|
case 3:
|
|
//名称
|
|
$map['g.goods_name'] = ['like', '%' . $keyword . '%'];
|
|
break;
|
|
}
|
|
} else {
|
|
//其他地方调用货号、条码 商品名称
|
|
if (trim($seek_data['keyword'])) {
|
|
$map['g.goods_number|g.goods_code'] = ['like', '%' . $keyword . '%'];
|
|
}
|
|
}
|
|
}
|
|
// 分类
|
|
$GoodsClass = new GoodsClassify();
|
|
$map = $GoodsClass->getGoodsClassId($seek_data, $map, 'g.goods_class_id');
|
|
|
|
$map['s.pay_state'] = 1;
|
|
$map['s.merchant_id'] = $merchant_id;
|
|
$map['s.store_id'] = $store_id;
|
|
$field = array(
|
|
'b.order_no',
|
|
's.pay_type',
|
|
's.pay_state',
|
|
's.bill_id',
|
|
's.goods_id',
|
|
's.price',
|
|
's.num',
|
|
's.all_money',
|
|
's.use_integral',
|
|
's.add_time',
|
|
's.pay_type',
|
|
's.type',
|
|
's.purchase_price',
|
|
's.sell_type',
|
|
's.original_price',
|
|
's.refund_num',
|
|
's.goods_type',
|
|
's.sell_number',
|
|
's.cashier_dis_money',
|
|
's.coupon_money',
|
|
's.integral_dis_money',
|
|
's.small_changes_money',
|
|
's.company',
|
|
's.supplier_json',
|
|
's.id',
|
|
's.sku_json_info',
|
|
's.serial_number_state',
|
|
'g.goods_name',
|
|
'g.goods_number',
|
|
'g.goods_code',
|
|
'g.goods_class_id',
|
|
'g.company as goods_company',
|
|
'c.class_name',
|
|
);
|
|
if ($type == 1) { // 分页
|
|
$sell_list = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')
|
|
->join('ls_retail_goods_class as c on c.id=g.goods_class_id', 'LEFT')
|
|
->join('ls_retail_bill_order as b on b.id=s.bill_id', 'LEFT')
|
|
->field($field)
|
|
->where($map)
|
|
->page((int)I('post.page'), (int)I('post.limit'))
|
|
->order('add_time desc')
|
|
->select();
|
|
} else { // 无需分页
|
|
$sell_list = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')
|
|
->join('ls_retail_goods_class as c on c.id=g.goods_class_id', 'LEFT')
|
|
->join('ls_retail_bill_order as b on b.id=s.bill_id', 'LEFT')
|
|
->field($field)
|
|
->where($map)
|
|
->order('add_time desc')
|
|
->select();
|
|
}
|
|
if (!$sell_list) {
|
|
$res = array('status' => 0, 'msg' => '暂无销售数据');
|
|
return $res;
|
|
}
|
|
$total = M('retail_sell as s')->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')->where($map)->count();
|
|
$SupplierClass = new Supplier();
|
|
$supplier_list = $SupplierClass->getList([
|
|
'user_type' => 4,
|
|
'merchant_id' => $this->merchant_id,
|
|
'store_id' => $this->store_id,
|
|
'fields' => 'id,supplier_name'
|
|
]);
|
|
$supplier_list = array_column($supplier_list, null, 'id');
|
|
foreach ($sell_list as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['goods_name'] = $val['goods_name'] ? $val['goods_name'] : '无码商品';
|
|
if (!empty($val['sku_json_info'])) {
|
|
$val['sku_name'] = json_decode($val['sku_json_info'], true)['name'];
|
|
} else {
|
|
$val['sku_name'] = '';
|
|
}
|
|
$val['goods_number'] = $val['goods_number'] ? $val['goods_number'] : '无';
|
|
$val['goods_code'] = $val['goods_code'] ? $val['goods_code'] : '无';
|
|
$val['type_name'] = $val['type'] == 1 ? '商城' : '店内';
|
|
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
|
$val['class_name'] = $val['class_name'] ? $val['class_name'] : '无';
|
|
// 订单类型
|
|
if ($val['sell_type'] == 1) {
|
|
$val['sell_mold'] = '销售订单';
|
|
} else if ($val['sell_type'] == 2) {
|
|
$val['sell_mold'] = '退款订单';
|
|
} else {
|
|
$val['sell_mold'] = '未知订单';
|
|
}
|
|
$val['purch_price'] = strval($val[' purchase_price']);
|
|
$val['yuan_price'] = strval($val['original_price']);
|
|
$val['price'] = strval($val['price']);
|
|
$val['num'] = strval($val['num']);
|
|
$val['cashier_dis_money'] = strval($val['cashier_dis_money']);
|
|
$val['coupon_money'] = strval($val['coupon_money']);
|
|
$val['integral_dis_money'] = strval($val['integral_dis_money']);
|
|
$val['small_changes_money'] = strval($val['small_changes_money']);
|
|
$val['subtotal'] = strval($val['all_money']);
|
|
$val['refund_num'] = $val['refund_num'] && $val['refund_num'] != 0 ? floatval($val['refund_num']) : '无';
|
|
/* 判断权限 */
|
|
if ($inventory == 2 && $show_purch_price == 2) {
|
|
$val['purchase_price'] = '***';
|
|
}
|
|
$val['supplier_name'] = '';
|
|
if ($supplier_type == 2 && !empty($val['supplier_json']) && !empty($supplier_list)) {
|
|
$purchase_id_str = json_decode($val['supplier_json'], true);
|
|
$supplier = array_column($purchase_id_str, "supplier_id");
|
|
array_unique($supplier);
|
|
if (!empty($supplier)) {
|
|
foreach ($supplier as $k => $v) {
|
|
$val['supplier_name'] .= $supplier_list[$v]['supplier_name'] . ',';
|
|
}
|
|
$val['supplier_name'] = trim($val['supplier_name']);
|
|
}
|
|
}
|
|
}
|
|
$res = array('status' => 1, 'sell_list' => $sell_list, 'total' => (int)$total);
|
|
return $res;
|
|
}
|
|
|
|
|
|
//串号列表
|
|
public function sellSerialList()
|
|
{
|
|
$data = I('post.');
|
|
$SerialClass = new SerialNumberGoods();
|
|
$result = $SerialClass->sellSerialList($data);
|
|
$result['sell_sum'] = $result['data'];
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取销售汇总统计数据合计
|
|
* @param [array] $seek_data 搜索数据
|
|
* @return [array] $res
|
|
*
|
|
*/
|
|
protected function getPublicSellData_2($seek_data)
|
|
{
|
|
// 时间搜索
|
|
if (!empty($seek_data['time']) && $seek_data['time'] != 'null') {
|
|
if (!is_array($seek_data['time'])) {
|
|
$time = explode(',', $seek_data['time']);
|
|
} else {
|
|
$time = $seek_data['time'];
|
|
}
|
|
$start_time = strtotime($time[0]);
|
|
$end_time = strtotime($time[1]);
|
|
} else {
|
|
$start_time = strtotime(date('Y-m-01 00:00:00'));
|
|
$end_time = time();
|
|
}
|
|
$map['s.add_time'] = ['between', [$start_time, $end_time]];
|
|
if (!empty($seek_data['keyword'])) {
|
|
$keyword = trim($seek_data['keyword']);
|
|
if (!empty($seek_data['keyword_type'])) {
|
|
//商品销售明细
|
|
switch ($seek_data['keyword_type']) {
|
|
case 1:
|
|
//货号
|
|
$map['g.goods_number'] = ['like', '%' . $keyword . '%'];
|
|
break;
|
|
case 2:
|
|
//条码
|
|
$map['g.goods_code'] = ['like', '%' . $keyword . '%'];
|
|
break;
|
|
case 3:
|
|
//名称
|
|
$map['g.goods_name'] = ['like', '%' . $keyword . '%'];
|
|
break;
|
|
}
|
|
} else {
|
|
//其他地方调用货号、条码 商品名称
|
|
if (trim($seek_data['keyword'])) {
|
|
$map['g.goods_number|g.goods_code'] = ['like', '%' . $keyword . '%'];
|
|
}
|
|
}
|
|
}
|
|
// 分类
|
|
|
|
$class_id = getGoodsClass($seek_data['person1'], $seek_data['person2'], $seek_data['person3']);
|
|
if ($class_id) {
|
|
$map['g.goods_class_id'] = $class_id;
|
|
}
|
|
|
|
$map['s.pay_state'] = 1;
|
|
$map['s.merchant_id'] = $this->merchant_id;
|
|
$map['s.store_id'] = $this->store_id;
|
|
|
|
$field = array(
|
|
's.sell_type',
|
|
's.num',
|
|
's.all_money',
|
|
);
|
|
$sell_list = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')
|
|
->join('ls_retail_goods_class as c on c.id=g.goods_class_id', 'LEFT')
|
|
->join('ls_retail_bill_order as b on b.id=s.bill_id', 'LEFT')
|
|
->field($field)
|
|
->where($map)
|
|
->order('s.add_time desc')
|
|
->select();
|
|
if (empty($sell_list)) {
|
|
$res = ['moneyTotal' => 0, 'numTotal' => 0];
|
|
} else {
|
|
$moneyTotal = 0; // 合计金额
|
|
$numTotal = 0; // 合计数量
|
|
|
|
foreach ($sell_list as $value) {
|
|
if ($value['sell_type'] == 1) {
|
|
$moneyTotal += $value['all_money'];
|
|
$numTotal += $value['num'];
|
|
} else {
|
|
$numTotal -= $value['num'];
|
|
$moneyTotal -= $value['all_money'];
|
|
}
|
|
}
|
|
$res = ['numTotal' => round($numTotal, 2), 'moneyTotal' => round($moneyTotal, 2)];
|
|
}
|
|
return callBack(statusCode()['success'], '获取成功', $res);
|
|
}
|
|
|
|
/**
|
|
* 获取数据(畅销商品私用)
|
|
* @param [int] $store_id 门店id
|
|
* @param [int] $merchant_id 商户id
|
|
* @param [array] $seek_data 搜索数据
|
|
* @param [int] $page 页数
|
|
* @param [int] $limit 条数
|
|
* @return [array] $res
|
|
*
|
|
*/
|
|
private function getPrivateInfoData($store_id, $merchant_id, $seek_data, $page = 0, $limit = 0)
|
|
{
|
|
// 时间搜索
|
|
if ($seek_data['start_time'] && $seek_data['end_time']) {
|
|
$start_time = strtotime($seek_data['start_time'] . "00:00:00");
|
|
$end_time = strtotime($seek_data['end_time'] . "23:59:59"); //销售汇总没有时间
|
|
$start_time = $start_time ? $start_time : strtotime($seek_data['start_time']);
|
|
$end_time = $end_time ? $end_time : strtotime($seek_data['end_time']); //销售明细有时间
|
|
|
|
$map['s.add_time'] = array('between', array($start_time, $end_time));
|
|
} else if ($seek_data['start_time'] && !$seek_data['end_time']) {
|
|
$start_time = strtotime($seek_data['start_time']);
|
|
$map['s.add_time'] = array('gt', $start_time);
|
|
} else if (!$seek_data['start_time'] && $seek_data['end_time']) {
|
|
$end_time = strtotime($seek_data['end_time']);
|
|
$map['s.add_time'] = array('lt', $end_time);
|
|
}
|
|
// 货号、商品名称、条码
|
|
if (trim($seek_data['keyword'])) {
|
|
$map['g.goods_number|g.goods_name|g.goods_code'] = ['like', '%' . trim($seek_data['keyword']) . '%'];
|
|
}
|
|
$map['s.pay_type'] = array('neq', 0);
|
|
$map['s.pay_state'] = 1;
|
|
$map['s.merchant_id'] = $merchant_id;
|
|
$map['s.store_id'] = $store_id;
|
|
$GoodsClassify = new GoodsClassify();
|
|
$map = $GoodsClassify->getGoodsClassId($seek_data, $map, 's.goods_class_id');
|
|
|
|
$field = array(
|
|
's.pay_state',
|
|
's.bill_id',
|
|
's.goods_id',
|
|
's.add_time',
|
|
's.pay_type',
|
|
's.sell_type',
|
|
'sum(CASE WHEN s.sell_type = 1 THEN s.num ELSE 0 END) - sum(CASE WHEN s.sell_type = 2 THEN s.num ELSE 0 END) as num',
|
|
's.supplier_json',
|
|
'g.goods_name',
|
|
'g.goods_number',
|
|
'g.goods_code',
|
|
'g.goods_class_id',
|
|
'g.company as goods_company',
|
|
'c.class_name',
|
|
);
|
|
if ($seek_data['sort_type'] == 1) {
|
|
$order = 'num asc';
|
|
} else {
|
|
$order = 'num desc';
|
|
}
|
|
$sell_list = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')
|
|
->join('ls_retail_goods_class as c on c.id=g.goods_class_id', 'LEFT')
|
|
->group('goods_id')
|
|
->field($field)
|
|
->where($map)
|
|
->page((int)$page, (int)$limit)
|
|
->order($order)
|
|
->select();
|
|
if (!$sell_list) {
|
|
$res = array('status' => 0, 'msg' => '暂无畅销数据');
|
|
return $res;
|
|
}
|
|
$total = M('retail_sell as s')
|
|
->join('ls_retail_goods as g on s.goods_id=g.id', 'LEFT')
|
|
->where($map)
|
|
->count('distinct(goods_id)');
|
|
foreach ($sell_list as &$val) {
|
|
$val['goods_name'] = $val['goods_name'] ? $val['goods_name'] : '无码商品';
|
|
$val['goods_number'] = $val['goods_number'] ? $val['goods_number'] : '无';
|
|
$val['goods_code'] = $val['goods_code'] ? $val['goods_code'] : '无';
|
|
$val['class_name'] = $val['class_name'] ? $val['class_name'] : '无';
|
|
}
|
|
$res = array('status' => 1, 'sell_list' => $sell_list, 'total' => (int)$total);
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 计算汇总
|
|
* @param [array] $sell_list 销售数据
|
|
* @return [array] $res
|
|
*/
|
|
protected function calculateSellSum($sell_list)
|
|
{
|
|
$sell_sum = array();
|
|
$index = 1;
|
|
foreach ($sell_list as &$val) {
|
|
if (!$sell_sum[$val['goods_id']]) {
|
|
$sell_num = 0;
|
|
$sell_number = 0;
|
|
$subtotal = 0;
|
|
if ($val['sell_type'] == 1) {
|
|
$sell_num += $val['num'];
|
|
$sell_number += $val['sell_number'];
|
|
$subtotal += floatval($val['all_money']);
|
|
} else {
|
|
$sell_num -= $val['num'];
|
|
$sell_number -= $val['sell_number'];
|
|
$subtotal -= floatval($val['all_money']);
|
|
}
|
|
$arr = array(
|
|
'index' => $index++,
|
|
'goods_name' => $val['goods_name'],
|
|
'goods_number' => $val['goods_number'],
|
|
'goods_code' => $val['goods_code'],
|
|
'class_name' => $val['class_name'],
|
|
'sell_num' => $sell_num,
|
|
'sell_number' => $sell_number,
|
|
'subtotal' => $subtotal,
|
|
'company' => $val['goods_company']
|
|
);
|
|
$sell_sum[$val['goods_id']] = $arr;
|
|
unset($arr);
|
|
} else {
|
|
if ($val['sell_type'] == 1) { // 销售订单
|
|
$sell_sum[$val['goods_id']]['sell_num'] += $val['num'];
|
|
$sell_sum[$val['goods_id']]['sell_number'] += $val['sell_number'];
|
|
$sell_sum[$val['goods_id']]['subtotal'] += floatval($val['all_money']);
|
|
} else { // 退款订单
|
|
$sell_sum[$val['goods_id']]['sell_num'] -= $val['num'];
|
|
$sell_sum[$val['goods_id']]['sell_number'] -= $val['sell_number'];
|
|
$sell_sum[$val['goods_id']]['subtotal'] -= floatval($val['all_money']);
|
|
}
|
|
}
|
|
}
|
|
$res = array('status' => 1, 'sell_sum' => array_values($sell_sum), 'total' => (int)count($sell_sum));
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 计算汇总
|
|
* @param [array] $sell_list 销售数据
|
|
* @param [int] $total 总计
|
|
* @return [array] $res
|
|
*/
|
|
protected function calculateSellSum_2($sell_list, $total)
|
|
{
|
|
$sell_sum = array();
|
|
foreach ($sell_list as $key => &$val) {
|
|
if (!$sell_sum[$val['goods_id']]) {
|
|
$arr = array(
|
|
'goods_name' => $val['goods_name'],
|
|
'goods_number' => $val['goods_number'],
|
|
'goods_code' => $val['goods_code'],
|
|
'class_name' => $val['class_name'],
|
|
'sell_num' => (float)$val['num'],
|
|
'index' => $key + 1,
|
|
);
|
|
$sell_sum[$val['goods_id']] = $arr;
|
|
unset($arr);
|
|
} else {
|
|
if ($val['sell_type'] == 1) { // 销售订单
|
|
$sell_sum[$val['goods_id']]['sell_num'] += $val['num'];
|
|
} else { // 退款订单
|
|
$sell_sum[$val['goods_id']]['sell_num'] -= $val['num'];
|
|
}
|
|
}
|
|
}
|
|
$res = array('status' => 1, 'sell_sum' => array_values($sell_sum), 'total' => (int)$total);
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取其他支付类型
|
|
*/
|
|
public function getOtherPayType()
|
|
{
|
|
// 获取商户id
|
|
$merchant_id = M('retail_store')->where(['id' => $this->store_id])->getField('merchantid');
|
|
if (!$merchant_id) {
|
|
$res = array('status' => 0, 'msg' => '商户查询失败');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 查询其他支付
|
|
// 查询其他支付方式
|
|
$OtherPay = D('RetailOtherPay');
|
|
$other_map = array(
|
|
$OtherPay::MERCHANT_ID => $merchant_id,
|
|
$OtherPay::STATUS => 1,
|
|
$OtherPay::STATE => 1
|
|
);
|
|
$other_field = array(
|
|
$OtherPay::ID, $OtherPay::NAME
|
|
);
|
|
$other_pay = $OtherPay->getSelect($other_map, $other_field, $OtherPay::PAY_ORDER . ' asc');
|
|
$other_pay = !empty($other_pay) ? $other_pay : array();
|
|
$res = array(
|
|
'status' => 1,
|
|
'other_pay' => $other_pay
|
|
);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 写入表格 把表格保存在服务器
|
|
* @param $expTitle
|
|
* @param $expCellName
|
|
* @param $expTableData
|
|
* @param string $common
|
|
* @param string $directory_name
|
|
* @throws \PHPExcel_Exception
|
|
* @throws \PHPExcel_Reader_Exception
|
|
* @throws \PHPExcel_Writer_Exception
|
|
*/
|
|
private function setExcel($expTitle, $expCellName, $expTableData, $common = "", $directory_name = "./Public")
|
|
{
|
|
$fileName = $expTitle; //or $xlsTitle 文件名称可根据自己情况设定
|
|
$cellNum = count($expCellName);
|
|
$dataNum = count($expTableData);
|
|
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);
|
|
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);
|
|
}
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
|
|
|
$this->createDir($directory_name); //生成文件目录
|
|
$path = "{$directory_name}/{$fileName}.xls";
|
|
$objWriter->save($path);
|
|
}
|
|
|
|
/**
|
|
* 生成文件目录
|
|
* @param $directory_name 目录地址
|
|
*/
|
|
private function createDir($directory_name)
|
|
{
|
|
if (!is_dir($directory_name)) {
|
|
$temp = ltrim($directory_name, './');
|
|
$arr = explode('/', $temp);
|
|
$str = './';
|
|
foreach ($arr as $key => $sv) {
|
|
if (!is_dir("{$str}/{$sv}")) {
|
|
mkdir("{$str}/{$sv}", 0777);
|
|
}
|
|
$str = "{$str}/{$sv}";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取订单的支付流水表的数据列表
|
|
*/
|
|
public function getOrderPayDetails()
|
|
{
|
|
$PayOrder = new PayOrder();
|
|
$this->ajaxReturn($PayOrder->getBillPayList([
|
|
'merchant_id' => $this->merchant_id,
|
|
'store_id' => $this->store_id,
|
|
'order_no' => I('post.order_no'),
|
|
]));
|
|
}
|
|
}
|