文件
mashangyoujiu/Application/CashierApi/Controller/CashierController.class.php

978 行
40 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Think\Controller;
//[1.4.53]
/*
* 拒绝直接更新 2019-6-3版本
*/
class CashierController extends BaseController
{
// public function index()
// {
// $userinfo = session("ls_userinfo");
//
// $this->display();
// }
public function index()
{
$userinfo = session("ls_userinfo");
$store_id = I('session.storeid');
$jur = M('retail_store_jurisdiction')->where(array('storeid'=>$store_id))->field('data_export')->find(); //判断是否有导出权限
$arr = array(
'cashierInfoExport' => '/index.php/Retail/Cashier/cashierInfoExport',
'addCashier' => '/index.php/Retail/Cashier/addCashier',
'editadCashier' => '/index.php/Retail/Cashier/editadCashier',
'model' => '/index.php/Retail/Cashier/model',
'delCashier' => '/index.php/Retail/Cashier/delCashier',
'shiftingdetailinfo' => '/index.php/Retail/Cashier/shiftingdetailinfo',
'permiset' => '/index.php/Retail/Cashier/permiset',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->assign('data_export', $jur['data_export']);
$this->display();
}
public function lists()
{
$userinfo = session("ls_userinfo");
$storeid = session("storeid");
$keyword = I("post.keyword");
if (!empty($keyword)) {
if (is_numeric($keyword)) {
$map['mobile'] = $keyword;
} else {
$map['name'] = array('like', "%" . $keyword . "%");
}
}
$map['merchantid'] = $userinfo['merchantid'];
$map['storeid'] = $storeid;
$map['status'] = 1;
$info = M("retail_cashier")->where($map)->page(I("get.page"), I("get.limit"))->select();
$count = M("retail_cashier")->where($map)->count();
foreach ($info as $key => $value) {
$info[$key]['index'] = $key + 1;
$info[$key]['storetag'] = M("retail_store")->where(array('id' => $value['storeid']))->getField('storetag');
$info[$key]['addtime'] = date("Y-m-d H:i:s", $value['addtime']);
$info[$key]['canrefund'] = $value['canrefund'] == 2 ? "开启" : "关闭";
$info[$key]['canrecharge'] = $value['canrecharge'] == 2 ? "开启" : "关闭";
$info[$key]['modifymem'] = $value['modifymem'] == 2 ? "开启" : "关闭";
$info[$key]['customviprecharge'] = $value['customviprecharge'] == 2 ? "开启" : "关闭";
$info[$key]['salesdiction'] = $value['salesdiction'] == 1 ? "开启" : "关闭";
$info[$key]['preferential'] = $value['preferential'] == 1 ? "开启" : "关闭";
$info[$key]['sku_discount'] = $value['sku_discount'] == 1 ? "开启" : "关闭";
$info[$key]['code_auth'] = $value['code_auth'] == 1 ? "开启" : "关闭";
}
$res['code'] = 0;
$res['count'] = $count;
$res['data'] = $info;
$this->ajaxReturn($res);
}
//收银员信息导出
public function cashierInfoExport()
{
$userinfo = session("ls_userinfo");
$storeid = session("storeid");
$keyword = I("get.keyword");
if (!empty($keyword)) {
if (is_numeric($keyword)) {
$map['mobile'] = $keyword;
} else {
$map['name'] = array('like', "%" . $keyword . "%");
}
}
$map['merchantid'] = $userinfo['merchantid'];
$map['storeid'] = $storeid;
$map['status'] = 1;
$info = M("retail_cashier")->where($map)->select();
foreach ($info as $key => $value) {
$info[$key]['index'] = $key + 1;
$info[$key]['storetag'] = M("retail_store")->where(array('id' => $value['storeid']))->getField('storetag');
$info[$key]['addtime'] = date("Y-m-d H:i:s", $value['addtime']);
$info[$key]['canrefund'] = $value['canrefund'] == 2 ? "开启" : "关闭";
$info[$key]['canrecharge'] = $value['canrecharge'] == 2 ? "开启" : "关闭";
$info[$key]['modifymem'] = $value['modifymem'] == 2 ? "开启" : "关闭";
$info[$key]['customviprecharge'] = $value['customviprecharge'] == 2 ? "开启" : "关闭";
$info[$key]['salesdiction'] = $value['salesdiction'] == 1 ? "开启" : "关闭";
$info[$key]['preferential'] = $value['preferential'] == 1 ? "开启" : "关闭";
}
$field_name = '收银员信息';
$arr = array(
array('index', '序号'),
array('name', '姓名'),
array('jobnum', '工号'),
array('mobile', '手机号码'),
array('storetag', '门店'),
array('addtime', '加入时间'),
array('canrefund', '退款权限'),
array('canrecharge', '充值权限'),
array('modifymem', '编辑资料权限'),
array('customviprecharge', '赠送金额权限(自定义)'),
array('salesdiction', '销售明细权限'),
array('preferential', '结算打折'),
);
$str = $field_name . '导出日期' . date('Y-m-d H:i:s', time());
$this->getExcel($field_name, $arr, $info, $str);
}
public function addCashier()
{
$userinfo = session("ls_userinfo");
$storeid = session("storeid");
if (IS_POST) {
$data = I("post.");
//需要先判断手机号是否被使用过
$map = array(
'c.mobile' => $data['mobile'],
'c.status' => 1,
's.state' => 0,
);
$cashier = M('retail_cashier as c')
->join('ls_retail_store as s on s.id=c.storeid')
->where($map)
->find();
if (empty($cashier)) {
if (strlen($data['password']) > 16) {
$res['status'] = 0;
$res['msg'] = '密码不能大于16位';
$this->ajaxReturn($res);
exit;
}
//工号不可重复
$jobnum = M("retail_cashier")->where(array('storeid' => $storeid, 'jobnum' => $data['jobnum'], 'status' => 1))->find();
if (empty($jobnum)) {
$NowTime = time();
$CryptrModel = new \Addons\Api\Crypto ();
$data['password'] = $CryptrModel->encrypt($data['password'], date('YmdHis', $NowTime));
$data['storeid'] = $storeid;
$data['merchantid'] = $userinfo['merchantid'];
$data['addtime'] = $NowTime;
$create = M("retail_cashier")->add($data);
if ($create) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '收银员-添加';//操作行为描述
action_log($source,$type,$request_data,$desc);
$res['status'] = 1;
$res['msg'] = '添加成功';
} else {
$res['status'] = 0;
$res['msg'] = '添加失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '工号已存在,请更换工号';
}
} else {
$res['status'] = 0;
$res['msg'] = '该手机号已被使用,请更换手机号';
}
$this->ajaxReturn($res);
}
//门店名称
$map['id'] = $storeid;
$map['merchantid'] = $userinfo['merchantid'];
$storetag = M("retail_store")->where($map)->getField('storetag');
$this->assign('storetag', $storetag);
$this->display();
}
public function delCashier()
{
if (IS_POST) {
$id = I('post.id');
$w['id'] = $id;
$data['status'] = 2;
$ret = M('retail_cashier')->where($w)->save($data);
if ($ret) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '收银员-删除';//操作行为描述
action_log($source,$type,$request_data,$desc);
$rt['status'] = 1;
$rt['msg'] = '删除成功';
} else {
$rt['status'] = 2;
$rt['msg'] = '删除失败';
}
$this->ajaxReturn($rt);
}
}
public function editadCashier()
{
if (IS_POST) {
$data = I("post.");
if (empty($data['id'])) {
$res['status'] = 0;
$res['msg'] = '参数错误,请重试';
} else {
if (empty($data['password'])) {
//不修改密码
//手机号是否使用
$map['status'] = 1;
$map['mobile'] = $data['mobile'];
$map['id'] = array('neq', $data['id']);
$find = M("retail_cashier")->where($map)->find();
unset($map['mobile']);
$map['jobnum'] = $data['jobnum'];
$map['storeid'] = session("storeid");
$jobunm = M("retail_cashier")->where($map)->find();
if (empty($find)) {
if (empty($jobunm)) {
unset($data['password']);
$save = M("retail_cashier")->where(array('id' => $data['id']))->save($data);
if ($save) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '收银员-编辑-不修改密码';//操作行为描述
action_log($source,$type,$request_data,$desc);
$res['status'] = 1;
$res['msg'] = '修改成功';
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '该工号已被使用,请更换工号';
}
} else {
$res['status'] = 0;
$res['msg'] = '该手机号已被使用,请更换手机账号';
}
} else {
//修改密码
if (strlen($data['password']) > 16) {
$res['status'] = 0;
$res['msg'] = '密码不能大于16位';
$this->ajaxReturn($res);
exit;
}
$map['status'] = 1;
$map['mobile'] = $data['mobile'];
$map['id'] = array('neq', $data['id']);
$find = M("retail_cashier")->where($map)->find();
unset($map['mobile']);
$map['jobnum'] = $data['jobnum'];
$map['storeid'] = session("storeid");
$jobunm = M("retail_cashier")->where($map)->find();
if (empty($find)) {
if (empty($jobunm)) {
//查询出用户的创建时间
$ctime = M("retail_cashier")->where(array('id' => $data['id']))->getField("addtime");
$CryptrModel = new \Addons\Api\Crypto ();
$data['password'] = $CryptrModel->encrypt($data['password'], date('YmdHis', $ctime));
$save = M("retail_cashier")->where(array('id' => $data['id']))->save($data);
if ($save) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '收银员-编辑-修改密码';//操作行为描述
action_log($source,$type,$request_data,$desc);
$res['status'] = 1;
$res['msg'] = '修改成功';
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '该工号已被使用,请更换工号';
}
} else {
$res['status'] = 0;
$res['msg'] = '该手机号已被使用,请更换手机账号';
}
}
}
$this->ajaxReturn($res);
}
$id = I("get.id");
$info = M("retail_cashier")->where(array('id' => $id))->find();
$info['storetag'] = M("retail_store")->where(array('id' => $info['storeid']))->getField('storetag');
$this->assign("info", $info);
$this->display();
}
// 收银
public function cashier()
{
$userinfo = session("ls_userinfo");
if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') {
$where['merchantid'] = $userinfo['merchantid'];
$where['store_type'] = 0;
$one = M("store")->where($where)->find();
if ($one) {
$storeid = $one['id'];
}
} else {
$storeid = $userinfo['storeid'];
}
if (IS_POST) {
} else {
$this->assign('storeid', $storeid);
$this->assign('merchantid', $userinfo['merchantid']);
$this->display();
}
}
// 收银详情
public function cashierlist()
{
$userinfo = session("ls_userinfo");
if ($userinfo['storeid'] == null || $userinfo['storeid'] == '') {
$where['merchantid'] = $userinfo['merchantid'];
$where['store_type'] = 0;
$one = M("store")->where($where)->find();
if ($one) {
$storeid = $one['id'];
}
} else {
$storeid = $userinfo['storeid'];
}
if (IS_POST) {
} else {
$sstr = I('get.start');
$estr = I('get.end');
$aid = I('get.aid');
$start = strtotime($sstr);
$end = strtotime($estr);
if (!$sstr) {
$start = strtotime(date('Y-m-d', time()));
$end = time();
}
if ($aid && $aid != -1) {
$w['c.handleid'] = $aid;
}
$w['c.addtime'] = array('between', array($start, $end));
$w['c.storeid'] = $storeid;
$info = M('cashier_pay')->alias('c')
->join('ls_admin as a on c.handleid=a.id', 'LEFT')
->field('c.*,a.real_name')
->where($w)->order('c.addtime')->select();
$w['c.type'] = 1;
$type1 = M('cashier_pay')->alias('c')
->where($w)->order('c.addtime')->sum('money');
$w['c.type'] = 2;
$type2 = M('cashier_pay')->alias('c')
->where($w)->order('c.addtime')->sum('money');
$w['c.type'] = 3;
$type3 = M('cashier_pay')->alias('c')
->where($w)->order('c.addtime')->sum('money');
$w['c.type'] = 4;
$type4 = M('cashier_pay')->alias('c')
->where($w)->order('c.addtime')->sum('money');
$w['c.type'] = 5;
$type5 = M('cashier_pay')->alias('c')
->where($w)->order('c.addtime')->sum('money');
$type1 = $type1 ? $type1 : 0;
$type2 = $type2 ? $type2 : 0;
$type3 = $type3 ? $type3 : 0;
$type4 = $type4 ? $type4 : 0;
$type5 = $type5 ? $type5 : 0;
$this->assign('type1', $type1);
$this->assign('type2', $type2);
$this->assign('type3', $type3);
$this->assign('type4', $type4);
$this->assign('type5', $type5);
$this->assign('cashierlist', $info);
$cw1['merchantid'] = $userinfo['merchantid'];
$one = M('admin')->where($cw1)->find();
$cw['merchantid'] = $userinfo['merchantid'];
$cw['storeid'] = $storeid;
$cw['account_type'] = array('in', array(2, 3)); // 店长和收银员。。。
$cw['state'] = 0;
$clist = M('admin')->where($cw)->select();
$this->assign('clist', $clist);
$this->display();
}
}
// 交接班数据
public function shiftingdetail()
{
$id = I('get.id');
$where['cashierid'] = $id;
$cashierInfo = $this->cashierMoneyTotal($where);
$this->assign('id', $id);
$this->assign('cashierInfo', $cashierInfo);
$arr = array(
'cashierExport' => '/index.php//Retail/Cashier/cashierExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/*
* 收银金额统计
* @param $rmbpay 现金
* @param $wxpay 微信
* @param $alipay 支付宝
* @param $other_pay 其他
* @param $recharge_cash 现金充值
* @parma $recharge_wx 微信充值
* @param $recharge_zfb 支付宝充值
*/
public function cashierMoneyTotal($where)
{
$cashierInfo = M('retail_record')->where($where)->select();
$rmbpay = 0;
$wxpay = 0;
$alipay = 0;
$other_pay = 0;
$recharge_cash = 0;
$recharge_wx = 0;
$recharge_zfb = 0;
if ($cashierInfo) {
foreach ($cashierInfo as $key => &$val) {
if (!empty($val['rmbpay'])) {
$rmbpay += $val["rmbpay"];
}
if (!empty($val['wxpay'])) {
$wxpay += $val['wxpay'];
}
if (!empty($val['alipay'])) {
$alipay += $val['alipay'];
}
if (!empty($val['other_pay'])) {
$other_pay += $val['other_pay'];
}
if (!empty($val['recharge_cash'])) {
$recharge_cash += $val['recharge_cash'];
}
if (!empty($val['recharge_wx'])) {
$recharge_wx += $val['recharge_wx'];
}
if (!empty($val['cash_box'])) {
$cash_box += $val['cash_box'];
}
if (!empty($val['recharge_zfb'])) {
$recharge_zfb += $val['recharge_zfb'];
}
}
}
$store_id = session('storeid');
$cashier_id = $where['cashierid'];
$WorkRecordModel = D('WorkRecord');
$map = array(
$WorkRecordModel::STORE_ID => $store_id,
$WorkRecordModel::CASHIER_ID => $cashier_id
);
$record = $WorkRecordModel->getOrderFind($map, '*', $WorkRecordModel::START_TIME . ' desc');
if (!empty($record) && empty($record[$WorkRecordModel::END_TIME])) {
$payList = A('PayApi/SellData')->getPayData($record[$WorkRecordModel::START_TIME], time(), $store_id, $cashier_id);
$rmbpay += $payList['cash_amount'];
$wxpay += $payList['weChat_amount'];
$alipay += $payList['ali_amount'];
$other_pay += $payList['other_amount'];
$recharge_cash += $payList['recharge_cash_amount'];
$recharge_wx += $payList['recharge_weChat_amount'];
$recharge_zfb += $payList['recharge_ali_amount'];
}
$arr['rmbpay'] = $rmbpay;
$arr['wxpay'] = $wxpay;
$arr['alipay'] = $alipay;
$arr['other_pay'] = $other_pay;
$arr['recharge_cash'] = $recharge_cash;
$arr['recharge_wx'] = $recharge_wx;
$arr['recharge_zfb'] = $recharge_zfb;
return $arr;
}
public function shiftingdetailinfo()
{
$id = I('get.id');
$time = I('get.date01');
$admin = M('retail_cashier')->where(array('id' => $id))->find();
if (!empty($time)) {
$time = explode("至", $time);
$start_time = strtotime($time[0] . "00:00:00");
$end_time = strtotime($time[1] . "23:59:59");
$where['start_time'] = array('between', array($start_time, $end_time));
}
$where['cashierid'] = $id;
$count = M('retail_record')->where($where)->count();
$records = M('retail_record')->where($where)->page($_GET['page'], $_GET['limit'])->order('start_time desc')->select();
$index = 1;
foreach ($records as $k => $v) {
$records[$k]['index'] = $index;
$records[$k]['name'] = $admin['name'];
$records[$k]['start_time'] = date('Y-m-d H:i:s', $v['start_time']);
if ($v['end_time']) {
$records[$k]['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
$jgtime = $v['end_time'] - $v['start_time'];
$records[$k]['jg_time'] = round($jgtime / 3600, 0) . '时' . round(($jgtime / 60) % 60, 0) . '分';
} else {
$now_time = time();
$payList = A('PayApi/SellData')->getPayData($v['start_time'], $now_time, $admin['storeid'], $id);
$records[$k]['end_time'] = '尚未交班';
$time = $now_time - $records[$k]['start_time'];
$records[$k]['jg_time'] = round($time / 3600, 0) . '时' . round(($time / 60) % 60, 0) . '分';
$records[$k]['wxpay'] = $payList['weChat_amount'];
$records[$k]['alipay'] = $payList['ali_amount'];
$records[$k]['rmbpay'] = $payList['cash_amount'];
$records[$k]['cash_box'] = $this->rnf($v['cash_box']);
//rnf封装在controller.class里,下面是不用封装方法的写法
// $records[$k]['cash_box'] = rtrim(rtrim(number_format($v['cash_box'], 2), '0'), '.');
$records[$k]['recharge'] = round($payList['recharge_cash_amount'] + $payList['recharge_weChat_amount'] + $payList['recharge_ali_amount'], 2);
$records[$k]['recharge_cash'] = $payList['recharge_cash_amount'];
$records[$k]['recharge_wx'] = $payList['recharge_weChat_amount'];
$records[$k]['recharge_zfb'] = $payList['recharge_ali_amount'];
$records[$k]['other_pay'] = $payList['other_amount'];
}
$index++;
}
$rt['code'] = 0;
$rt['msg'] = '';
$rt['count'] = $count;
$rt['data'] = $records;
$this->ajaxReturn($rt);
}
/*
* 搜索收银员金额统计
*/
public function cashierSearch()
{
$date01 = I('post.date01');
if (!empty($date01)) {
$time = explode("至", $date01);
$start_time = strtotime($time[0] . "00:00:00");
$end_time = strtotime($time[1] . "23:59:59");
$where['start_time'] = array('between', array($start_time, $end_time));
}
$where['cashierid'] = I('post.id');
$cashierInfo = $this->cashierMoneyTotal($where);
$res['status'] = 1;
$res['cashierInfo'] = $cashierInfo;
$this->ajaxReturn($res);
}
/*
* 交班记录导出
*/
public function cashierExport()
{
$id = I('get.id');
$time = I('get.date01');
$admin = M('retail_cashier')->where(array('id' => $id))->find();
if (!empty($time)) {
$time = explode("至", $time);
$start_time = strtotime($time[0] . "00:00:00");
$end_time = strtotime($time[1] . "23:59:59");
$where['start_time'] = array('between', array($start_time, $end_time));
}
$where['cashierid'] = $id;
$records = M('retail_record')->where($where)->order('start_time desc')->select();
$index = 1;
foreach ($records as $k => $v) {
$records[$k]['index'] = $index;
$records[$k]['name'] = $admin['name'];
$records[$k]['start_time'] = date('Y-m-d H:i:s', $v['start_time']);
if ($v['end_time']) {
$records[$k]['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
$jgtime = $v['end_time'] - $v['start_time'];
$records[$k]['jg_time'] = round($jgtime / 3600, 0) . '时' . round(($jgtime / 60) % 60, 0) . '分';
} else {
$records[$k]['end_time'] = '尚未交班';
$records[$k]['jg_time'] = '--';
$records[$k]['wxpay'] = '--';
$records[$k]['alipay'] = '--';
$records[$k]['rmbpay'] = '--';
$records[$k]['recharge'] = '--';
$records[$k]['recharge_cash'] = '--';
$records[$k]['recharge_wx'] = '--';
$records[$k]['recharge_zfb'] = '--';
$records[$k]['other_pay'] = '--';
}
$index++;
}
$field = '收银员交班记录导出';
$arr = array(
array('index', '序号'),
array('name', '姓名'),
array('jobnum', '工号'),
array('start_time', '开班时间'),
array('end_time', '交班时间'),
array('jg_time', '间隔时间'),
array('wxpay', '微信金额(元)'),
array('alipay', '支付宝金额(元)'),
array('rmbpay', '现金(元)'),
array('other_pay', '其他支付(元)'),
array('recharge_cash', '现金充值支付(元)'),
array('recharge_wx', '微信充值支付(元)'),
array('recharge_zfb', '支付宝充值支付(元)'),
array('recharge', '充值总金额(元)'),
);
$str = $field . '导出日期' . date('Y-m-d H:i:s', time());
$this->getExcel($field, $arr, $records, $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 editadCashierrefund()
{
if (IS_POST) {
$id = I('post.id');
$canrefund = I('post.canrefund');
$refundcode = I('post.refundcode');
$refundcode = trim($refundcode);
$canrefund = $canrefund ? 2 : 1;
if ($canrefund == 1) {
$sdata['refundcode'] = $refundcode;
$sdata['canrefund'] = $canrefund;
} else {
if ($refundcode) {
$sdata['refundcode'] = $refundcode;
$sdata['canrefund'] = $canrefund;
} else {
$rt['status'] = 0;
$rt['msg'] = '设置失败,开启权限时授权码不得为空';
$this->ajaxReturn($rt);
}
}
$info = M("retail_cashier")->where(array('id' => $id))->save($sdata);
if ($info !== false) {
$rt['status'] = 1;
$rt['msg'] = '设置成功';
} else {
$rt['status'] = 0;
$rt['msg'] = '设置失败,请稍后再试';
}
$this->ajaxReturn($rt);
} else {
$id = I("get.id");
$info = M("retail_cashier")->where(array('id' => $id))->find();
$this->assign("info", $info);
$this->display();
}
}
public function editadCashierrecharge()
{
if (IS_POST) {
$id = I('post.id');
$canrefund = I('post.canrecharge');
$refundcode = I('post.rechargecode');
$refundcode = trim($refundcode);
$canrefund = $canrefund ? 2 : 1;
if ($canrefund == 1) {
$sdata['rechargecode'] = $refundcode;
$sdata['canrecharge'] = $canrefund;
} else {
if ($refundcode) {
$sdata['rechargecode'] = $refundcode;
$sdata['canrecharge'] = $canrefund;
} else {
$rt['status'] = 0;
$rt['msg'] = '设置失败,开启权限时授权码不得为空';
$this->ajaxReturn($rt);
}
}
$info = M("retail_cashier")->where(array('id' => $id))->save($sdata);
if ($info !== false) {
$rt['status'] = 1;
$rt['msg'] = '设置成功';
} else {
$rt['status'] = 0;
$rt['msg'] = '设置失败,请稍后再试';
}
$this->ajaxReturn($rt);
} else {
$id = I("get.id");
$info = M("retail_cashier")->where(array('id' => $id))->find();
$this->assign("info", $info);
$this->display();
}
}
public function model()
{
$type = I('get.type');
if (empty($type)) {
$this->error('访问错误');
}
$storeid = session('storeid');
if ($type == 2) {
$id = I('get.id');
if (empty($id)) {
$this->error('访问错误');
}
$cashier = M('retail_cashier')->where(array('storeid' => $storeid, 'id' => $id, 'status' => 1))->find();
if (empty($cashier)) {
$this->error('收银员不存在');
}
$this->assign('status', $cashier['cash_model']);
$this->assign('id', $id);
} else {
$all = M('retail_cashier')->where(array('storeid' => $storeid, 'status' => 1))->count();
$all1 = M('retail_cashier')->where(array('storeid' => $storeid, 'status' => 1, 'cash_model' => 1))->count();
if ($all && $all == $all1) {
$this->assign('status', 1);
} else if ($all && $all1 == 0) {
$this->assign('status', 2);
}
}
$this->assign('type', $type);
$this->display();
}
public function setModel()
{
$storeid = session('storeid');
$type = I('post.type');
$id = I('post.id');
$status = I('post.status');
if (empty($status) || empty($type)) {
$res['status'] = 0;
$res['msg'] = '缺少参数';
$this->ajaxReturn($res);
}
if ($type == 1) {
$update = M('retail_cashier')->where(array('storeid' => $storeid, 'status' => 1))->save(array('cash_model' => $status));
} else if ($type == 2) {
if (empty($id)) {
$res['status'] = 0;
$res['msg'] = '缺少参数';
$this->ajaxReturn($res);
}
$update = M('retail_cashier')->where(array('storeid' => $storeid, 'status' => 1, 'id' => $id))->save(array('cash_model' => $status));
} else {
$res['status'] = 0;
$res['msg'] = '参数有误';
$this->ajaxReturn($res);
}
if ($update) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '收银员-模板设置';//操作行为描述
action_log($source,$type,$request_data,$desc);
$res['status'] = 1;
$res['msg'] = '设置成功';
} else {
$res['status'] = 0;
$res['msg'] = '设置成功';
}
$this->ajaxReturn($res);
}
//权限设置
public function permiset()
{
$id = I("get.id");
$info = M("retail_cashier")->where(array('id' => $id))->find();
$this->assign("info", $info);
$this->display();
}
//权限提交
public function permisetsub()
{
if (IS_POST) {
$storeid = session('storeid');
$info = I('post.');
if (empty($info['id'])) {
$res['status'] = 0;
$res['msg'] = '参数有误';
$this->ajaxReturn($res);
exit;
}
$canrecharge = $info['canrecharge'] == 'on' ? 2 : 1;
$canrefund = $info['canrefund'] == 'on' ? 2 : 1;
$modifymem = $info['modifymem'] == 'on' ? 2 : 1;
$modify_plus_mem = $info['modify_plus_mem'] == 'on' ? 2 : 1;
$salesdiction = $info['salesdiction'] == 'on' ? 1 : 2;
$preferential = $info['preferential'] == 'on' ? 1 : 0;
$cashier_show_other_sell = $info['cashier_show_other_sell'] == 'on' ? 1 : 2;
$cashier_add_goods = $info['cashier_add_goods'] == 'on' ? 1 : 2;
$data['code_auth'] = $info['code_auth'] == 'on' ? 1 : 0; // 授权码总权限 是否需要授权码(总):0=不需要,1=需要
// 单品打折
$data['manual_discount'] = $info['manual_discount'] == 'on' ? 1 : 0; // 手动打折权限:0=未开启,1=开启
$data['manual_min_discount'] = $info['manual_min_discount']; // 手动打折最低折扣
$data['manual_max_amount'] = $info['manual_max_amount']; // 手动打折最多优惠金额
$data['manual_discount_code'] = $info['manual_discount_code']; // 手动打折授权码
if( !empty($data['code_auth']) ){
if ( empty($data['sku_discount_code']) || strlen($data['sku_discount_code']) > 30) {
$res['status'] = 0;
$res['msg'] = '单品打折授权码有误';
$this->ajaxReturn($res);
}
}
// if( !empty($data['manual_discount']) ){
if( empty($data['manual_min_discount']) || $data['manual_min_discount'] > 1 || $data['manual_min_discount'] <= 0 || !is_numeric($data['manual_min_discount']) ){
$res['status'] = 0;
$res['msg'] = '折扣数据错误1';
$this->ajaxReturn($res);
}
if( !empty($data['manual_max_amount']) ){
if( $data['manual_max_amount'] > 100 || $data['manual_max_amount'] < 0 || !is_numeric($data['manual_max_amount']) ){
$res['status'] = 0;
$res['msg'] = '优惠金额错误,金额取值0.01~99.99';
$this->ajaxReturn($res);
}
} else {
$data['manual_max_amount'] = null;
}
// }
if ($modifymem == 2 || $modify_plus_mem == 2) {
$jurisdiction = M('retail_store_jurisdiction')->field("store_operation_vip,store_edit_vip_info")->where(array('storeid' => $storeid))->find();
if (!empty($jurisdiction) && $jurisdiction['store_operation_vip'] == 2) {
$res['status'] = 0;
$res['msg'] = '门店暂无编辑会员资料权限';
$this->ajaxReturn($res);
exit;
}
if (!empty($jurisdiction) && $jurisdiction['store_edit_vip_info'] == 2) {
$res['status'] = 0;
$res['msg'] = '门店暂无编辑会员资料权限';
$this->ajaxReturn($res);
exit;
}
}
//充值
$data['canrecharge'] = $canrecharge;
$data['refundcode'] = $info['refundcode'];
//退款码
$data['canrefund'] = $canrefund;
$data['rechargecode'] = $info['rechargecode'];
//修改资料
$data['modifymem'] = $modifymem;
$data['modifymemcode'] = $info['modifymemcode'];
$data['customviprecharge'] = $info['customviprecharge'] == 'on' ? 2 : 1;
//打印销售明细
$data['salesdiction'] = $salesdiction;
//打印次数
$data['print_time'] = intval($info['print_time']);
if ($canrecharge == 2 && empty($data['rechargecode']) || $canrecharge == 2 && strlen($data['rechargecode']) > 30) {
$res['status'] = 0;
$res['msg'] = '充值权限权限码有误';
$this->ajaxReturn($res);
exit;
}
if ($canrefund == 2 && empty($data['refundcode']) || $canrefund == 2 && strlen($data['refundcode']) > 30) {
$res['status'] = 0;
$res['msg'] = '退款权限权限码有误';
$this->ajaxReturn($res);
exit;
}
if ($modifymem == 2 && empty($data['modifymemcode']) || $modifymem == 2 && strlen($data['modifymemcode']) > 30) {
$res['status'] = 0;
$res['msg'] = '编辑会员权限码有误';
$this->ajaxReturn($res);
exit;
}
if (empty($data['print_time']) || $data['print_time'] < 0 || !is_numeric($data['print_time'])) {
$res['status'] = 0;
$res['msg'] = '打印次数格式错误';
$this->ajaxReturn($res);
exit;
}
$data['preferential'] = $preferential;
$data['cashier_show_other_sell'] = $cashier_show_other_sell;
$data['cashier_add_goods'] = $cashier_add_goods;
$data['modify_plus_mem'] = $modify_plus_mem;
$save = M('retail_cashier')->where(array('id' => $info['id']))->save($data);
if ($save) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '收银员-设置';//操作行为描述
action_log($source,$type,$request_data,$desc);
$res['status'] = 1;
$res['msg'] = '设置成功';
} else {
$res['status'] = 1;
$res['msg'] = '暂无修改';
}
} else {
$res['status'] = 0;
$res['msg'] = '非法请求';
}
$this->ajaxReturn($res);
}
}