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

1146 行
48 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Common\Business\AuthMerchant;
use Common\Business\Cashier;
use Common\Business\Plug;
use Common\Business\Role;
use Common\Model\JurisdictionUserModel;
use Common\Model\RetailCashierModel;
use Common\Model\RetailRecordModel;
use Common\Model\StoreConfigModel;
use PayApi\Controller\SellDataController;
use Retail\Model\CashBoxRecordModel;
use Think\Controller;
//[1.9.20]
/**
* 收银员管理
* Class CashierController
* @package Retail\Controller
*/
class CashierController extends BaseController
{
/**
* 收银员列表页
*/
public function index()
{
$this->display();
}
/**
* 获取收银员列表
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function lists()
{
$keyword = I("post.keyword");
$add_time = I('post.add_time');
if (!empty($keyword)) {
$map['name|mobile'] = array('like', "%" . $keyword . "%");
}
if (!empty($add_time)) {
$start_time = strtotime($add_time[0]);
$end_time = strtotime($add_time[1]);
$map['addtime'] = array('between', array($start_time, $end_time));
}
$map['merchantid'] = $this->merchant_id;
$map['storeid'] = $this->store_id;
$map['status'] = 1;
$info = M("retail_cashier")->where($map)->page(I("post.page"), I("post.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 ? "开启" : "关闭";
$info[$key]['goods_gifts_auth'] = $value['goods_gifts_auth'] == 1 ? "开启" : "关闭";
}
$res['code'] = 0;
$res['count'] = $count;
$res['data'] = $info;
$this->ajaxReturn($res);
}
/**
* 收银员信息导出
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function cashierInfoExport()
{
$keyword = I("get.keyword");
if (!empty($keyword)) {
if (is_numeric($keyword)) {
$map['mobile'] = $keyword;
} else {
$map['name'] = array('like', "%" . $keyword . "%");
}
}
$map['merchantid'] = $this->merchant_id;
$map['storeid'] = $this->store_id;
$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);
}
/**
* 新增收银员
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addCashier()
{
$store_id = $this->store_id;
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' => $store_id, 'jobnum' => $data['jobnum'], 'status' => 1))->find();
if (empty($jobnum)) {
$NowTime = time();
$data['password'] = createPassword($data['password'], $NowTime);
$data['storeid'] = $store_id;
$data['merchantid'] = $this->merchant_id;
$data['addtime'] = $NowTime;
$create = M("retail_cashier")->add($data);
if ($create) {
$Role = new Role();
$jurData = [
'login_name' => $data['mobile'],
'password' => $data['password'],
'name' => $data['name'],
'add_time' => $data['addtime'],
'user_type' => 6,
'system_user_id' => $create,
'pid' => $this->login_user['id'],
'jurisdiction_group_id' => $Role->createSystemGroup(['type' => 6]),
];
$JurisdictionUserModel = new JurisdictionUserModel();
$JurisdictionUserModel->addOrder($jurData);
//操作日志记录
$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'] = $store_id;
$map['merchantid'] = $this->merchant_id;
$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;
$w['storeid'] = $this->store_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);
}
}
/**
* 编辑收银员
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
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 shiftingdetail()
{
$id = I('get.id');
$this->assign('id', $id);
$arr = array(
'cashierExport' => '/index.php//Retail/Cashier/cashierExport',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/**
* 收银金额统计
* @param $where 搜索条件
* @return mixed
* $rmbpay 现金
* $wxpay 微信
* $alipay 支付宝
* $other_pay 其他
* $recharge_cash 现金充值
* $recharge_wx 微信充值
* $recharge_zfb 支付宝充值
* $mec_money 德育币支付金额
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
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;
$mec_money = 0;
$cash_box = 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'];
}
if (!empty($val['mec_money'])) {
$mec_money += $val['mec_money'];
}
}
}
$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])) {
$SellData = new SellDataController();
$payList = $SellData->getPayData_v1($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'];
$mec_money += $payList['MoralEducationCoin'];
}
$arr['isOpenCredit'] = false;
if (in_array('Credit', C('MODULE_ALLOW_LIST'))) {
$arr['isOpenCredit'] = true;
$creditArrearage = new \Credit\Model\CreditArrearageModel();
$creditRepayment = new \Credit\Model\CreditRepaymentModel();
//赊账
$ArrearageMap = [
'cashier_id' => $where['cashierid'],
'add_time' => $where['start_time'],
];
//未交班赊账数据
$workingCreditArrMap = [
'cashier_id' => $where['cashierid'],
'add_time' => ['between', [$record['start_time'], time()]],
];
$workingCreditArr = $creditArrearage->getSum($workingCreditArrMap, 'bill_money');
$creditArreaMoney = $creditArrearage->getSum($ArrearageMap, 'bill_money');
$arr['credit_arrea_money'] = round($workingCreditArr + $creditArreaMoney, 2);
//还款
$RepaymentMap = [
'operate_type' => 1, //操作人员类型为收银员
'operate_id' => $where['cashierid'],
'add_time' => $where['start_time'],
];
//未交班还款数据
$workingCreditRypayMap = [
'operate_type' => 1, //操作人员类型为收银员
'operate_id' => $where['cashierid'],
'add_time' => ['between', [$record['start_time'], time()]],
];
$workingCreditRepay = $creditRepayment->getSum($workingCreditRypayMap, 'money');
$creditRepayMoney = $creditRepayment->getSum($ArrearageMap, 'money');
$arr['credit_repay_money'] = round($workingCreditRepay + $creditRepayMoney, 2);
}
$arr['rmbpay'] = round($rmbpay, 2);
$arr['wxpay'] = round($wxpay, 2);
$arr['alipay'] = round($alipay, 2);
$arr['other_pay'] = round($other_pay, 2);
$arr['recharge_cash'] = round($recharge_cash, 2);
$arr['recharge_wx'] = round($recharge_wx, 2);
$arr['recharge_zfb'] = round($recharge_zfb, 2);
$arr['mec_money'] = round($mec_money, 2);
return $arr;
}
/**
* 交班记录列表
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function shiftingdetailinfo()
{
$StoreConfigModel = new StoreConfigModel();
$id = I('post.id');
$time = I('post.date01');
$page = I('post.page');
$limit = I('post.limit');
$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($page, $limit)->order('start_time desc')->select();
$index = 1;
//判断赊账插件是否存在
$Plug = new Plug();
$PlugData = $Plug->PlugPermissions([
'merchant_id' => $admin['merchantid'],
'identification_arr' => ['credit']
]);
if (!empty($PlugData['data']['plug']['credit'])) {
$is_credit = $StoreConfigModel->getFindField(['store_id' => $admin['storeid']], 'is_credit');
$rt['isOpenCredit'] = $is_credit == 1 ? true : false;
$creditArrearage = new \Credit\Model\CreditArrearageModel();
$creditRepayment = new \Credit\Model\CreditRepaymentModel();
//赊账
$ArrearageMap = [
'cashier_id' => $id,
];
//还款
$RepaymentMap = [
'operate_type' => 1, //操作人员类型为收银员
'operate_id' => $id,
];
} else {
$rt['isOpenCredit'] = false;
}
$SellData = new SellDataController();
foreach ($records as &$val) {
$val['index'] = $index;
$val['name'] = $admin['name'];
$val['start_time'] = date('Y-m-d H:i:s', $val['start_time']);
if ($val['end_time']) {
$val['end_time'] = date('Y-m-d H:i:s', $val['end_time']);
$jgtime = strtotime($val['end_time']) - strtotime($val['start_time']);
$val['jg_time'] = round($jgtime / 3600, 0) . '时' . round(($jgtime / 60) % 60, 0) . '分';
$val['other_pay_json'] = json_decode($val['other_pay_json'], true);
} else {
$now_time = time();
$payList = $SellData->getPayData_v1($val['start_time'], $now_time, $admin['storeid'], $id);
$val['end_time'] = '尚未交班';
$time = $now_time - strtotime($val['start_time']);
$val['jg_time'] = round($time / 3600, 0) . '时' . round(($time / 60) % 60, 0) . '分';
$val['wxpay'] = $payList['weChat_amount'];
$val['alipay'] = $payList['ali_amount'];
$val['rmbpay'] = $payList['cash_amount'];
$val['cash_box'] = floatval($val['cash_box']);
$val['recharge'] = round($payList['recharge_cash_amount'] + $payList['recharge_weChat_amount'] + $payList['recharge_ali_amount'], 2);
$val['recharge_cash'] = $payList['recharge_cash_amount'];
$val['recharge_wx'] = $payList['recharge_weChat_amount'];
$val['recharge_zfb'] = $payList['recharge_ali_amount'];
$val['other_pay'] = $payList['other_amount'];
$val['mec_money'] = $payList['MoralEducationCoin'];
$val['other_pay_json'] = $payList['other_amount_array'];
//赊账数据
if ($rt['isOpenCredit']) {
$ArrearageMap['add_time'] = ['gt', $val['start_time']];
$RepaymentMap['add_time'] = ['gt', $val['start_time']];
$val['credit_arrea_money'] = $creditArrearage->getSum($ArrearageMap, 'bill_money');
$val['credit_repay_money'] = $creditRepayment->getSum($ArrearageMap, 'money');
}
$val['cash_box'] = round($val['cash_box'] + $val['rmbpay'] + $val['recharge_cash'], 2);
$index++;
}
$json_array = '';
if ($val['other_pay_json']) {
foreach ($val['other_pay_json'] as $json) {
$json_array .= $json['name'] . ' : ¥' . $json['money'] . ' ';
}
} else {
$json_array = $val['other_pay'];
}
$val['other_pay'] = $json_array;
}
$rt['code'] = 0;
$rt['msg'] = '';
$rt['count'] = $count;
$rt['data'] = $records;
$this->ajaxReturn($rt);
}
/**
* 获取修改钱箱记录
* @param type 类型 1增加 2减少
* @param page 页码
* @param limit 页长
*/
public function getCashEditRecord()
{
$id = I('post.id');
if (!$id) {
$this->ajaxReturn(['status' => 0, 'msg' => '缺少必要参数']);
}
$type = I('post.type');
$page = I('post.page') ? I('post.page') : 1;
$limit = I('post.limit') ? I('post.limit') : 10;
$CashBoxRecordModel = new CashBoxRecordModel();
$field = [
'type',
'remark',
'add_time',
'operate_id',
'edit_money',
];
$map = ['record_id' => $id];
if ($type) {
$map['type'] = $type;
}
$list = $CashBoxRecordModel->getSelect($map, $field, 'id desc', $page . ',' . $limit);
foreach ($list as &$val) {
$val['add_time'] = date("Y-m-d H:i:s", $val['add_time']);
$val['type_name'] = $val['type'] == 1 ? '增加' : '减少';
}
$RetailRecordModel = new RetailRecordModel();
$record = $RetailRecordModel->getFind(['id' => $id]);
$startTime = date('Y-m-d H:i:s', $record['start_time']);
$endTime = $record['end_time'] ? date('Y-m-d H:i:s', $record['end_time']) : date('Y-m-d H:i:s');
$result = [
'status' => 1,
'msg' => empty($list) ? '暂无数据' : '获取成功',
'data' => [
'list' => $list ? $list : [],
'count' => $CashBoxRecordModel->getCount($map),
'time' => $startTime . '-' . $endTime,
],
];
$this->ajaxReturn($result);
}
/*
* 搜索收银员金额统计
*/
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()
{
$StoreConfigModel = new StoreConfigModel();
$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;
$Plug = new Plug();
$PlugData = $Plug->PlugPermissions([
'merchant_id' => $admin['merchantid'],
'identification_arr' => ['credit']
]);
if (!empty($PlugData['data']['plug']['credit'])) {
$is_credit = $StoreConfigModel->getFindField(['store_id' => $admin['storeid']], 'is_credit');
$rt['isOpenCredit'] = $is_credit == 1 ?: false;
$creditArrearage = new \Credit\Model\CreditArrearageModel();
$creditRepayment = new \Credit\Model\CreditRepaymentModel();
//赊账
$ArrearageMap = [
'cashier_id' => $id,
];
//还款
$RepaymentMap = [
'operate_type' => 1, //操作人员类型为收银员
'operate_id' => $id,
];
} else {
$rt['isOpenCredit'] = false;
}
foreach ($records as $k => $v) {
$records[$k]['index'] = $index;
$records[$k]['name'] = $admin['name'];
//赊账数据
if ($rt['isOpenCredit']) {
if ($records[$k]['end_time']) {
$ArrearageMap['add_time'] = ['between', [$records[$k]['start_time'], $records[$k]['end_time']]];
$RepaymentMap['add_time'] = ['between', [$records[$k]['start_time'], $records[$k]['end_time']]];
} else {
$ArrearageMap['add_time'] = ['gt', $records[$k]['start_time']];
$RepaymentMap['add_time'] = ['gt', $records[$k]['start_time']];
}
$records[$k]['credit_arrea_money'] = $creditArrearage->getSum($ArrearageMap, 'bill_money');
$records[$k]['credit_repay_money'] = $creditRepayment->getSum($ArrearageMap, 'money');
}
$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 = [
['index', '序号'],
['name', '姓名'],
['jobnum', '工号'],
['start_time', '开班时间'],
['end_time', '交班时间'],
['jg_time', '间隔时间'],
['wxpay', '微信金额(元)'],
['alipay', '支付宝金额(元)'],
['rmbpay', '现金(元)'],
['other_pay', '其他支付(元)'],
['recharge_cash', '现金充值支付(元)'],
['recharge_wx', '微信充值支付(元)'],
['recharge_zfb', '支付宝充值支付(元)'],
['recharge', '充值总金额(元)'],
];
if (in_array('Credit', C('MODULE_ALLOW_LIST'))) {
$arr = [
['index', '序号'],
['name', '姓名'],
['jobnum', '工号'],
['start_time', '开班时间'],
['end_time', '交班时间'],
['jg_time', '间隔时间'],
['wxpay', '微信金额(元)'],
['alipay', '支付宝金额(元)'],
['rmbpay', '现金(元)'],
['other_pay', '其他支付(元)'],
['recharge_cash', '现金充值支付(元)'],
['recharge_wx', '微信充值支付(元)'],
['recharge_zfb', '支付宝充值支付(元)'],
['recharge', '赊账金额'],
['recharge', '赊账还款金额'],
['recharge', '充值总金额(元)'],
];
}
$str = $field . '导出日期' . date('Y-m-d H:i:s', time());
getExcel($field, $arr, $records, $str);
}
/**
* 收银员 模板设置页面
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function model()
{
$type = I('get.type');
if (empty($type)) {
$this->error('访问错误');
}
$store_id = $this->store_id;
if ($type == 2) {
$id = I('get.id');
if (empty($id)) {
$this->error('访问错误');
}
$cashier = M('retail_cashier')->where(array('storeid' => $store_id, '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' => $store_id, 'status' => 1))->count();
$all1 = M('retail_cashier')->where(array('storeid' => $store_id, '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()
{
$store_id = $this->store_id;
$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' => $store_id, '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' => $store_id, '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);
}
/**
* 权限设置
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function permiset()
{
if (IS_POST) {
$id = I('post.id');
$field = array(
'refundcode',
'canrefund',
'canrecharge',
'rechargecode',
'modifymem',
'modifymemcode',
'modify_plus_mem',
'cash_model',
'print_time',
'salesdiction',
'preferential',
'customviprecharge',
'cashier_show_other_sell',
'cashier_add_goods',
'manual_discount',
'manual_min_discount',
'manual_max_amount',
'goods_gifts_auth',
'goods_gifts_num',
'credit_user_manage',
'credit_money_manage',
'push_state',
'openid',
'is_goods_manage',
'goods_manage_edit',
'goods_manage_del',
'goods_manage_operate',
'is_scales_author', //传秤权限
'edit_goods_price', //收银员修改商品价格权限
'use_no_code_goods', //使用无码商品的权限 1开启 2关闭
'del_out_line_data', //收银员删除离线数据的权限 1开启 2关闭
'other_store_goods', //收银员查看其他门店商品库存的权限 1开启 2关闭
'small_changes_state', //收银员抹零的权限 1开启 2关闭
);
$info = M("retail_cashier")->where(array('id' => $id))->field($field)->find();
if (!empty($info)) {
if ($info['goods_gifts_num']) {
$info['goods_gifts_num'] = intval($info['goods_gifts_num']);
}
$url = getServerUrl() . '/index.php/Retail/AuthMerchant/auth?merchant_id=' . $this->merchant_id . '&cashier_id=' . $id;
$Plug = new Plug();
$plug_auth = $Plug->PlugPermissions(array(
'merchant_id' => $this->merchant_id,
'identification_arr' => ['credit']
));
$this->ajaxReturn(array(
'status' => 1,
'msg' => '获取成功',
'data' => array(
'info' => $info,
'code_url' => $url,
'plug' => $plug_auth['data']['plug'],
'bind_wx_state' => empty($info['openid']) ? false : true,
),
));
} else {
$this->ajaxReturn(array(
'status' => 0,
'msg' => '收银员不存在',
));
}
} else {
$this->display();
}
}
/**
* 修改权限并提交
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function permisetsub()
{
if (IS_POST) {
$store_id = $this->store_id;
$info = I('post.');
if (empty($info['id'])) {
$res['status'] = 0;
$res['msg'] = '参数有误';
$this->ajaxReturn($res);
exit;
}
$canrecharge = $info['canrecharge'] == 2 ? 2 : 1;
$canrefund = $info['canrefund'] == 2 ? 2 : 1;
$modifymem = $info['modifymem'] == 2 ? 2 : 1;
$modify_plus_mem = $info['modify_plus_mem'] == 2 ? 2 : 1;
$salesdiction = $info['salesdiction'] == 1 ? 1 : 2;
$preferential = $info['preferential'] == 1 ? 1 : 0;
$cashier_show_other_sell = $info['cashier_show_other_sell'] == 1 ? 1 : 2;
$cashier_add_goods = $info['cashier_add_goods'] == 1 ? 1 : 2;
$data['push_state'] = $info['push_state'] == 1 ? 1 : 2;
$data['code_auth'] = $info['code_auth'] == 1 ? 1 : 0; // 授权码总权限 是否需要授权码(总):0=不需要,1=需要
// 单品打折
$data['manual_discount'] = $info['manual_discount'] == 1 ? 1 : 0; // 手动打折权限:0=未开启,1=开启
$data['manual_min_discount'] = (float)$info['manual_min_discount']; // 手动打折最低折扣
$data['manual_max_amount'] = (float)$info['manual_max_amount']; // 手动打折最多优惠金额
$data['goods_gifts_auth'] = $info['goods_gifts_auth'] == 1 ? 1 : 0; // 收银员赠品权限:0=关闭,1=开启
$data['goods_gifts_num'] = $info['goods_gifts_num'] ? $info['goods_gifts_num'] : null; // 收银员赠品最大数量
// 商品管理
$data['is_goods_manage'] = $info['is_goods_manage'] == 1 ? 1 : 2; // 收银端商品管理权限 1开启 2关闭
$data['goods_manage_edit'] = $info['goods_manage_edit'] ? $info['goods_manage_edit'] : 2; //编辑商品权限 1开启 2关闭
$data['goods_manage_del'] = $info['goods_manage_del'] ? $info['goods_manage_del'] : 2; //删除商品权限 1开启 2关闭
$data['goods_manage_operate'] = $info['goods_manage_operate'] ? $info['goods_manage_operate'] : 2; //批量修改商品权限 1开启 2关闭
$data['is_scales_author'] = $info['is_scales_author'] ? $info['is_scales_author'] : 1; //收银员传称权限 1开启 2关闭
$data['edit_goods_price'] = $info['edit_goods_price'] ? $info['edit_goods_price'] : 2; //收银员修改商品价格权限 1开启 2关闭
$data['use_no_code_goods'] = $info['use_no_code_goods'] == 1 ? 1 : 2; //使用无码商品的权限 1开启 2关闭
$data['del_out_line_data'] = $info['del_out_line_data'] == 1 ? 1 : 2; //收银员删除离线数据的权限 1开启 2关闭
$data['other_store_goods'] = $info['other_store_goods'] == 1 ? 1 : 2; //收银员查看其他门店商品库存的权限 1开启 2关闭
$data['small_changes_state'] = $info['small_changes_state'] == 1 ? 1 : 2; //收银员抹零权限 1开启 2关闭
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 ($data['manual_discount'] == 1 && empty($data['manual_min_discount'])) {
$res['status'] = 0;
$res['msg'] = '请输入最低折扣';
$this->ajaxReturn($res);
}
if (!empty($data['manual_min_discount'])) {
if (($data['manual_min_discount'] > 1 || $data['manual_min_discount'] <= 0 || !is_numeric($data['manual_min_discount']))) {
$res['status'] = 0;
$res['msg'] = '最低折扣值有误';
$this->ajaxReturn($res);
}
} else {
$data['manual_min_discount'] = null;
}
if (!empty($data['manual_max_amount'])) {
if ($data['manual_max_amount'] < 0 || !is_numeric($data['manual_max_amount'])) {
$res['status'] = 0;
$res['msg'] = '优惠金额错误';
$this->ajaxReturn($res);
}
} else {
$data['manual_max_amount'] = null;
}
if ($data['goods_gifts_auth'] == 1) {
// 整数判断
if (!is_numeric($data['goods_gifts_num']) || strpos($data['goods_gifts_num'], '.') !== false) {
$res['status'] = 0;
$res['msg'] = '请填写整数!';
$this->ajaxReturn($res);
}
if (($data['goods_gifts_num'] > 9999.99 || $data['goods_gifts_num'] <= 0 || !is_numeric($data['goods_gifts_num']))) {
$res['status'] = 0;
$res['msg'] = '赠送数量有误!';
$this->ajaxReturn($res);
}
}
if ($modifymem == 2 || $modify_plus_mem == 2) {
$jurisdiction = M('retail_store_jurisdiction')->field("store_operation_vip,store_edit_vip_info")->where(array('storeid' => $store_id))->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'] == 2 ? 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);
}
if ($canrefund == 2 && empty($data['refundcode']) || $canrefund == 2 && strlen($data['refundcode']) > 30) {
$res['status'] = 0;
$res['msg'] = '退款权限权限码有误';
$this->ajaxReturn($res);
}
if ($modifymem == 2 && empty($data['modifymemcode']) || $modifymem == 2 && strlen($data['modifymemcode']) > 30) {
$res['status'] = 0;
$res['msg'] = '编辑会员权限码有误';
$this->ajaxReturn($res);
}
if (empty($data['print_time']) || $data['print_time'] < 0 || !is_numeric($data['print_time'])) {
$res['status'] = 0;
$res['msg'] = '打印次数格式错误';
$this->ajaxReturn($res);
}
//赊账
$data['credit_user_manage'] = $info['credit_user_manage'] == 2 ? 2 : 1;
$data['credit_money_manage'] = $info['credit_money_manage'] == 2 ? 2 : 1;
$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);
}
/**
* 获取门店的收银员列表共选择
*/
public function getChooseCashierList()
{
$Cashier = new Cashier();
$store_id = I('post.store_id');
$this->ajaxReturn($Cashier->getChooseCashierList(['store_id' => $store_id ? $store_id : $this->store_id]));
}
}