提交 686074ef authored 作者: wangkr's avatar wangkr

Merge branch 'test' into release

Conflicts: .gitignore application/admin/view/staff/role.html config/admin.php public/page/fonts/element-icons.535877f5.woff public/page/fonts/element-icons.732389de.ttf public/page/fonts/iconfont.0208023e.0208023e.eot public/page/fonts/iconfont.d8583a84.d8583a84.ttf public/page/fonts/iconfont.e9caaa06.e9caaa06.woff public/page/img/bpmn.deea5c90.svg public/page/img/icon-ext.ba81b24c.ba81b24c.png public/page/img/icon.551539f8.551539f8.png public/page/img/iconfont.5d06b488.5d06b488.svg public/page/img/loading-0.a72011cc.a72011cc.gif 修改: application/admin/controller/Base.php 删除: application/admin/controller/Excel(1).php 修改: application/admin/controller/SingleSign.php 修改: application/admin/model/PermissionModel.php 新文件: application/admin/validate/FkAddValidate.php 修改: application/admin/view/basestation/base_region.html 修改: application/admin/view/permission/index.html 修改: application/admin/view/staff/role.html 修改: application/admin/view/staff/role1.html 修改: application/api/common.php 新文件: application/api/controller/v2/common/Payment.php 新文件: application/api/controller/v2/common/Project.php 修改: application/em/common.php 修改: application/em/controller/Account.php 修改: application/em/controller/Em.php 修改: application/em/controller/Invoice.php 修改: application/em/controller/Payment.php 新文件: application/em/controller/Receipt.php 修改: application/em/controller/Region.php 修改: application/em/controller/Useage.php 删除: application/em/controller/Useage.php.bak 新文件: application/em/controller/WriteOff.php 修改: application/em/model/Em.php 新文件: application/em/model/EmAccountAmount.php 修改: application/em/model/EmCheckBill.php 修改: application/em/model/EmInvoice.php 修改: application/em/model/EmPayment.php 新文件: application/em/model/EmPaymentAccount.php 新文件: application/em/model/EmPaymentFk.php 新文件: application/em/model/EmPaymentMonthly.php 删除: application/em/model/Invoice.php 修改: application/em/model/Staff.php 新文件: application/em/validate/AddFkInfoDetailsValidate.php 新文件: application/em/validate/AddFkInfoValidate.php 修改: application/em/validate/UseageGeneralInfoValidate.php 修改: application/em/view/em/index.html 删除: application/em/view/invoice/Invoice.php 修改: application/em/view/invoice/detail.html 修改: application/em/view/invoice/index.html 删除: application/em/view/invoice/index_back.html 修改: application/em/view/invoice/merge_list.html 修改: application/em/view/payment/create.html 删除: application/em/view/payment/create2.html 删除: application/em/view/payment/create3.html 修改: application/em/view/payment/detail.html 修改: application/em/view/payment/index.html 新文件: application/em/view/payment/pay_oa.html 修改: application/em/view/region/region_list.html 新文件: application/em/view/region/region_list1.html 修改: application/em/view/useage/default.html 修改: application/em/view/useage/detail.html 修改: application/em/view/useage/detail_special.html 修改: application/em/view/useage/update.html 新文件: config/admin.php 新文件: config/oafk.php 新文件: public/page/css/app.96f2bf7e.css 新文件: public/page/favicon.ico 新文件: public/page/fonts/bpmn.499c9aa3.eot 新文件: public/page/fonts/bpmn.9b84e8c8.ttf 新文件: public/page/fonts/bpmn.b5d0cc49.woff 新文件: public/page/fonts/bpmn.f3d4b5d1.woff2 新文件: public/page/fonts/element-icons.535877f5.woff 新文件: public/page/fonts/element-icons.732389de.ttf 新文件: public/page/fonts/iconfont.0208023e.0208023e.eot 新文件: public/page/fonts/iconfont.d8583a84.d8583a84.ttf 新文件: public/page/fonts/iconfont.e9caaa06.e9caaa06.woff 新文件: public/page/img/bpmn.deea5c90.svg 新文件: public/page/img/icon-ext.ba81b24c.ba81b24c.png 新文件: public/page/img/icon.551539f8.551539f8.png 新文件: public/page/img/iconfont.5d06b488.5d06b488.svg 新文件: public/page/img/loading-0.a72011cc.a72011cc.gif 新文件: public/page/index.html 新文件: public/page/js/app.7eaa479e.js 新文件: public/page/js/app.7eaa479e.js.LICENSE 新文件: public/page/js/app.81004bd3.js 新文件: public/page/js/app.81004bd3.js.LICENSE 新文件: public/page1/css/app.7ad51aae.css 新文件: public/page1/css/app.f5cc36b7.css 新文件: public/page1/css/chunk-vendors.b27c2f9a.css 新文件: public/page1/favicon.ico 新文件: public/page1/fonts/bpmn.499c9aa3.eot 新文件: public/page1/fonts/bpmn.9b84e8c8.ttf 新文件: public/page1/fonts/bpmn.b5d0cc49.woff 新文件: public/page1/fonts/bpmn.f3d4b5d1.woff2 新文件: public/page1/fonts/element-icons.535877f5.woff 新文件: public/page1/fonts/element-icons.732389de.ttf 新文件: public/page1/fonts/iconfont.0208023e.0208023e.eot 新文件: public/page1/fonts/iconfont.d8583a84.d8583a84.ttf 新文件: public/page1/fonts/iconfont.e9caaa06.e9caaa06.woff 新文件: public/page1/img/bpmn.deea5c90.svg 新文件: public/page1/img/icon-ext.ba81b24c.ba81b24c.png 新文件: public/page1/img/icon.551539f8.551539f8.png 新文件: public/page1/img/iconfont.5d06b488.5d06b488.svg 新文件: public/page1/img/loading-0.a72011cc.a72011cc.gif 新文件: public/page1/index.html 新文件: public/page1/js/app.aa6907c3.js 新文件: public/page1/js/app.aa6907c3.js.LICENSE 新文件: public/page1/js/app.bc5c248b.js 新文件: public/page1/js/chunk-vendors.a06d51ef.js 修改: public/static/admin/css/style.css 修改: public/static/xadmin/lib/layui/lay/modules/tree.js 修改: route/admin.php 修改: route/api.php
......@@ -14,10 +14,16 @@
/config/database.php
/config/cache.php
/config/session.php
<<<<<<< HEAD
/config/admin.php
=======
/config/cookie.php
/config/jz.php
>>>>>>> test
/public/dist
/public/dist2
/public/static/uploads
/public/static/xadmin
/application/admin/view/staff/role.html
/config/jz.php
/config/cookie.php
......@@ -5,6 +5,7 @@ use app\admin\model\StaffRoleModel;
use think\Controller;
use think\facade\Cookie;
use think\facade\Request;
use think\facade\Session;
/**
* 控制器基类
......@@ -16,13 +17,18 @@ use think\facade\Request;
class Base extends Controller
{
protected $uid ;
protected $user = [];
//登录检测
protected function initialize(){
$this->user = Session::get('user');
$this->uid = $this->user['user_id'];
$this->check();
}
private function check(){
$single = new SingleSign();
try {
$user = $single->getUserInfo();
Cookie::set('user',$user['ukey']);
......
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2019-6-23
* Time: 23:53
*/
namespace app\admin\controller;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use app\admin\model\StaffModel;
use app\admin\model\ElectricMeter;
use app\admin\model\BaseStationModel;
use think\facade\Session;
use think\Controller;
use think\Db;
class Excel extends Controller
{
/**
* 使用PHPEXECL导入
*
* @param string $file 文件地址
* @param int $sheet 工作表sheet(传0则获取第一个sheet)
* @param int $columnCnt 列数(传0则自动获取最大列)
* @param array $options 操作选项
* array mergeCells 合并单元格数组
* array formula 公式数组
* array format 单元格格式数组
*
* @return array
* @throws Exception
*/
public function importExecl(string $file = '', int $sheet = 0, int $columnCnt = 0, &$options = [])
{
ini_set ('memory_limit', '1000M');
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));//判断导入表格后缀格式
// 有Xls和Xlsx格式两种
if ($extension == 'xlsx') {
$objReader =IOFactory::createReader('Xlsx');
$objPHPExcel = $objReader->load($file);
} elseif($extension == 'xls'){
$objReader =IOFactory::createReader('Xls');
$objPHPExcel = $objReader->load($file);
}else{
$this->error('必须为excel表格,且必须为xls或者xlsx格式!');
}
//$filename可以是上传的表格,或者是指定的表格
$sheet = $objPHPExcel->getSheet(0); //excel中的第一张sheet
$highestRow = $sheet->getHighestRow(); // 取得总行数
// $highestColumn = $sheet->getHighestColumn(); // 取得总列数
if($objPHPExcel->getActiveSheet()->getCell("A1")->getValue()!=='基站编号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("B1")->getValue()!=='基站名称'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("C1")->getValue()!=='项目编号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("D1")->getValue()!=='电表类型'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("E1")->getValue()!=='电表识别号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("F1")->getValue()!=='缴费号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("G1")->getValue()!=='倍率'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("H1")->getValue()!=='电表初始度数'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("I1")->getValue()!=='电表备注'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("J1")->getValue()!=='电表初始充值金额'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("K1")->getValue()!=='抄表单单价'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("L1")->getValue()!=='首次查表日期'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("M1")->getValue()!=='是否协议价'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("N1")->getValue()!=='协议价'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("O1")->getValue()!=='协议名称'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("P1")->getValue()!=='协议编号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("Q1")->getValue()!=='开始时间'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("R1")->getValue()!=='结束时间'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("S1")->getValue()!=='签订日期'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("T1")->getValue()!=='协议备注'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("U1")->getValue()!=='缴费周期'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("V1")->getValue()!=='业务员'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("W1")->getValue()!=='电表地址'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("X1")->getValue()!=='甲方联系人'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("Y1")->getValue()!=='甲方联系方式'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("Z1")->getValue()!=='机房位置'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AA1")->getValue()!=='物业位置'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AB1")->getValue()!=='收款单位'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AC1")->getValue()!=='出租单位名称'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AD1")->getValue()!=='机房备注'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AE1")->getValue()!=='合同编号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AF1")->getValue()!=='确认合同日期'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AG1")->getValue()!=='合同有效时间'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("AH1")->getValue()!=='机房二维码'){
return ['code' =>5,'message' => '模板错误'];
}
$usersExits = [];
//循环读取excel表格,整合成数组。如果是不指定key的二维,就用$data[i][j]表示。
$create_time=time();
$electric_meter['create_time']=$create_time;
$contract['create_time'] = $create_time;
$agreement['create_time'] = $create_time;
$engine_room['create_time'] = $create_time;
$electric_meter['update_time']=$create_time;
$contract['update_time'] = $create_time;
$agreement['update_time'] = $create_time;
$engine_room['update_time'] = $create_time;
for ($j = 2; $j <= $highestRow; $j++) {
//站号
$station_sp_code=$objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();
//站名
$station_name=$objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();
//项目编号
$proj_number=$objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();
//通过站号 、站名、项目编号确认电表的station_id
$electric_meter['station_id']=(new ElectricMeter)->getStationID($proj_number);
//电表类型 electric_meter
$emt_id=$objPHPExcel->getActiveSheet()->getCell("D".$j)->getValue();
$electric_meter['emt_id']=(new ElectricMeter)->getEmtId($emt_id);
//电表识别号 electric_meter
$number=$objPHPExcel->getActiveSheet()->getCell("E".$j)->getValue();
$electric_meter['number']=isset($number)?$number:'';
//缴费号 electric_meter
$pay_number=$objPHPExcel->getActiveSheet()->getCell("F".$j)->getValue();
$electric_meter['pay_number']=isset($pay_number)?$pay_number:'';
//倍率 electric_meter
$multiple=$objPHPExcel->getActiveSheet()->getCell("G".$j)->getValue();
$electric_meter['multiple']=isset($multiple)?$multiple:'';
//电表初始度数 electric_meter
$init_degree=$objPHPExcel->getActiveSheet()->getCell("H".$j)->getValue();
$electric_meter['init_degree']=isset($init_degree)?$init_degree:'';
//电表备注 electric_meter
$text=$objPHPExcel->getActiveSheet()->getCell("I".$j)->getValue();
$electric_meter['remark']=isset($text)?$text:'';
//电表初始充值金额 init_amount
$init_amount=$objPHPExcel->getActiveSheet()->getCell("J".$j)->getValue();
$electric_meter['init_amount']=isset($init_amount)?$init_amount:0;
//抄表单单价 electric_meter
$unit_price=$objPHPExcel->getActiveSheet()->getCell("K".$j)->getValue();
$electric_meter['unit_price']=isset($unit_price)?$unit_price:'';
//首次查表日期 转换为时间戳first_cp_date electric_meter
// $first_cp_date= $objPHPExcel->getActiveSheet()->getCell("L".$j)->getValue();
$first_cp_date= Date::excelToTimestamp($objPHPExcel->getActiveSheet()->getCell("L".$j)->getValue());
$electric_meter['first_cp_date']=isset($first_cp_date)?$first_cp_date:'';
//是否协议价 electric_meter
$is_protocol=$objPHPExcel->getActiveSheet()->getCell("M".$j)->getValue();
if($is_protocol=='是'){
$electric_meter['is_protocol']=1;
}else{
$electric_meter['is_protocol']=0;
}
//协议价 electric_meter
$protocol_price=$objPHPExcel->getActiveSheet()->getCell("N".$j)->getValue();
$electric_meter['protocol_price']=isset($protocol_price)?$protocol_price:'';
//协议名称
$contract_name=$objPHPExcel->getActiveSheet()->getCell("O".$j)->getValue();
$agreement['name']=isset($contract_name)?$contract_name:'';
//协议编号
$contract_number=$objPHPExcel->getActiveSheet()->getCell("P".$j)->getValue();
$agreement['number']=isset($contract_number)?$contract_number:'';
//开始时间
$contract_start_date= $objPHPExcel->getActiveSheet()->getCell("Q".$j)->getValue();
if($contract_start_date){
$agreement['start_time']=Date::excelToTimestamp($contract_start_date);
}else{
$agreement['start_time']=0;
}
//结束时间
$contract_end_date= $objPHPExcel->getActiveSheet()->getCell("R".$j)->getValue();
if($contract_end_date){
$agreement['end_time']=Date::excelToTimestamp($contract_end_date);
}else{
$agreement['end_time']=0;
}
//签订日期
$contract_sign_date= $objPHPExcel->getActiveSheet()->getCell("S".$j)->getValue();
if($contract_sign_date){
$agreement['sign_time']=Date::excelToTimestamp($contract_sign_date);
}else{
$agreement['sign_time']=0;
}
//协议备注
$contract_remark=$objPHPExcel->getActiveSheet()->getCell("T".$j)->getValue();
$agreement['remark']=isset($contract_remark)?$contract_remark:'';
// 缴费周期 electric_meter
$pay_cycle=$objPHPExcel->getActiveSheet()->getCell("U".$j)->getValue();
$electric_meter['pay_cycle']=isset($pay_cycle)?$pay_cycle:'';
//业务员 electric_meter
$staff_id=$objPHPExcel->getActiveSheet()->getCell("V".$j)->getValue();
$electric_meter['staff_id']=(new ElectricMeter)->getStaffId($staff_id);
//电表地址 electric_meter
$address=$objPHPExcel->getActiveSheet()->getCell("W".$j)->getValue();
$electric_meter['address']=isset($address)?$address:'';
//合同附件id
$electric_meter['photo_id']=1;
//甲方联系人 engine_room
$contact=$objPHPExcel->getActiveSheet()->getCell("X".$j)->getValue();
$engine_room['contact']=isset($contact)?$contact:'';
//甲方联系方式 engine_room
$tel=$objPHPExcel->getActiveSheet()->getCell("Y".$j)->getValue();
$engine_room['tel']=isset($tel)?$tel:'';
$engine_room['station_id']=$electric_meter['station_id'];
//机房位置 engine_room
$position=$objPHPExcel->getActiveSheet()->getCell("Z".$j)->getValue();
$engine_room['position']=isset($position)?$position:'';
//物业位置 engine_room
$property_position=$objPHPExcel->getActiveSheet()->getCell("AA".$j)->getValue();
$engine_room['property_position']=isset($property_position)?$property_position:'';
// 实际收款单位 engine_room
$receive=$objPHPExcel->getActiveSheet()->getCell("AB".$j)->getValue();
$engine_room['receive']=isset($receive)?$receive:'';
//出租单位名称 engine_room
$rent=$objPHPExcel->getActiveSheet()->getCell("AC".$j)->getValue();
$engine_room['rent']=isset($rent)?$rent:'';
//机房名称
$engine_room['name']=isset($rent)?$rent:'';
//机房备注 engine_room
$remark=$objPHPExcel->getActiveSheet()->getCell("AD".$j)->getValue();
$engine_room['remark']=isset($remark)?$remark:'';
//合同编号 contract
$number=$objPHPExcel->getActiveSheet()->getCell("AE".$j)->getValue();
$contract['number']=isset($number)?$number:'contract-add-000000';
//确认合同日期 contract
//业务员id
$agreement['u_id'] = $electric_meter['staff_id'];
$agreement['type']=2;
$agreement['file_id']=1;
$agreement['d_id'] = (new ElectricMeter)->getDepartId($electric_meter['staff_id']);
$agreement['file_id'] = 0;
$time = $contract_end_date - $contract_start_date;
$agreement['period'] = ceil($time/(3600*24*30));
$sign_date= $objPHPExcel->getActiveSheet()->getCell("AF".$j)->getValue();
if($sign_date){
$contract['start_time']=Date::excelToTimestamp($sign_date);
$contract['end_time']=Date::excelToTimestamp($sign_date);
$contract['sign_time']=Date::excelToTimestamp($sign_date);
}else{
$contract['start_time']=0;
$contract['end_time']=0;
$contract['sign_time']=0;
}
//合同有效时间 contract
$period=$objPHPExcel->getActiveSheet()->getCell("AG".$j)->getValue();
$contract['period']=isset($period)?$period:'';
$qrcode=$objPHPExcel->getActiveSheet()->getCell("AH".$j)->getValue();
$electric_meter['qrcode']=isset($qrcode)?$qrcode:'';
$contract['name'] = '新增电表合同';
$contract['u_id'] = $electric_meter['staff_id'];
$contract['d_id'] = (new ElectricMeter)->getDepartId($electric_meter['staff_id']);;
$contract['type'] = 1;
$contract['file_id'] = 0;
$contract['remark'] = '';
$electricMeterAll[] = $electric_meter;
$contractAll[] = $contract;
$agreementAll[] = $agreement;
$engineRoomAll[] = $engine_room;
}
Db::name('contract')->insertAll($contractAll);
Db::name('engine_room')->insertAll($engineRoomAll);
Db::name('contract')->insertAll($agreementAll);
$contractID = Db::name('contract')->field('id')->where("create_time='$create_time'")->select();
$engineRoomID = Db::name('engine_room')->field('id')->where("create_time='$create_time'")->order('id asc')->select();
$agreementID = Db::name('contract')->field('id')->where("create_time='$create_time' and type=2")->select();
$electricMeterAllList = array();
foreach ($electricMeterAll as $key => $val){
$electricMeterAllList[]= array_merge($val,array('er_id'=>$engineRoomID[$key]['id']));
}
foreach ($electricMeterAllList as $key => $value) {
$electricMeterAllListb[] = array_merge($value,array('contract_id'=>$contractID[$key]['id']));
}
foreach ($electricMeterAllListb as $key => $value) {
$electricMeterAllListc[] = array_merge($value,array('protocol_id'=>$agreementID[$key]['id']));
}
$sucelectric= Db::name('electric_meter')->insertAll($electricMeterAllListc);
$data['total']=$highestRow-1;
$data['suc']=$sucelectric;
$data['er']=$highestRow-1-$sucelectric;
return ['code' =>200,'message' => '导入成功' ,'data' => $data];
}
//基站信息导入
public function baseExecl(string $file = '', int $sheet = 0, int $columnCnt = 0, &$options = [])
{
ini_set ('memory_limit', '1000M');
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));//判断导入表格后缀格式
// 有Xls和Xlsx格式两种
if ($extension == 'xlsx') {
$objReader =IOFactory::createReader('Xlsx');
$objPHPExcel = $objReader->load($file);
} elseif($extension == 'xls'){
$objReader =IOFactory::createReader('Xls');
$objPHPExcel = $objReader->load($file);
}else{
$this->error('必须为excel表格,且必须为xls或者xlsx格式!');
}
//$filename可以是上传的表格,或者是指定的表格
$sheet = $objPHPExcel->getSheet(0); //excel中的第一张sheet
$highestRow = $sheet->getHighestRow(); // 取得总行数
// $highestColumn = $sheet->getHighestColumn(); // 取得总列数
if($objPHPExcel->getActiveSheet()->getCell("A1")->getValue()!=='基站名称'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("B1")->getValue()!=='基站编号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("C1")->getValue()!=='项目编号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("D1")->getValue()!=='需求号'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("E1")->getValue()!=='运营商'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("F1")->getValue()!=='业务线'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("G1")->getValue()!=='区域'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("H1")->getValue()!=='基站状态'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("I1")->getValue()!=='经度'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("J1")->getValue()!=='纬度'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("K1")->getValue()!=='项目地址'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("L1")->getValue()!=='墙面天线数'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("M1")->getValue()!=='杆数'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("N1")->getValue()!=='箱体数'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("O1")->getValue()!=='光缆公里数'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("P1")->getValue()!=='RRU数量'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("Q1")->getValue()!=='RRU方位角'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("R1")->getValue()!=='施工队类型'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("S1")->getValue()!=='施工联系方式'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("T1")->getValue()!=='部门'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("U1")->getValue()!=='经理'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("V1")->getValue()!=='业务员'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("W1")->getValue()!=='需求来源'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("X1")->getValue()!=='公司上游客户'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("Y1")->getValue()!=='频段'){
return ['code' =>5,'message' => '模板错误'];
}
if($objPHPExcel->getActiveSheet()->getCell("Z1")->getValue()!=='创建时间'){
return ['code' =>5,'message' => '模板错误'];
}
$usersExits = [];
//循环读取excel表格,整合成数组。如果是不指定key的二维,就用$data[i][j]表示。
$create_time=time();
$station['update_time']=$create_time;
$detai['update_time'] = $create_time;
$vendor['update_time'] = $create_time;
for ($j = 2; $j <= $highestRow; $j++) {
//基站名称
$station_name=$objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();
$station['station_name']=isset($station_name)?$station_name:'';
//基站编号
$station_sp_code=$objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();
$station['station_sp_code']=isset($station_sp_code)?$station_sp_code:'';
// 项目编号
$proj_number=$objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();
if(empty($proj_number)){
return ['code' =>7,'message' => '项目编号不能为空'];
}
$ojnumber =(new BaseStationModel)->getproId($proj_number);
if($ojnumber){
return ['code' =>8,'message' => '该项目编号:'.$proj_number.'已存在,不能重复添加'];
}
$station['proj_number']=$proj_number;
//需求号
$sp_req_code=$objPHPExcel->getActiveSheet()->getCell("D".$j)->getValue();
$station['sp_req_code']=isset($sp_req_code)?$sp_req_code:'';
//运营商
$original_sp_id=$objPHPExcel->getActiveSheet()->getCell("E".$j)->getValue();
if($original_sp_id){
$station['original_sp_id']=(new BaseStationModel)->getoriginalById($original_sp_id);
}else{
$station['original_sp_id']=0;
}
//业务线
$business_line_id=$objPHPExcel->getActiveSheet()->getCell("F".$j)->getValue();
if($business_line_id){
$station['business_line_id']=(new BaseStationModel)->getbussById($business_line_id);
}else{
$station['business_line_id']=0;
}
//区域
$area_id=$objPHPExcel->getActiveSheet()->getCell("G".$j)->getValue();
if($area_id){
$station['area_id']=(new BaseStationModel)->getregionById($area_id);
}else{
$station['area_id']=0;
}
//基站状态
$base_station_state=$objPHPExcel->getActiveSheet()->getCell("H".$j)->getValue();
if($base_station_state){
$station['base_station_state']=(new BaseStationModel)->getstatusById($base_station_state);
}else{
$station['base_station_state']=0;
}
//经度
$longitude=$objPHPExcel->getActiveSheet()->getCell("I".$j)->getValue();
$detai['longitude']=isset($longitude)?$longitude:'';
//纬度
$latitude=$objPHPExcel->getActiveSheet()->getCell("J".$j)->getValue();
$detai['latitude']=isset($latitude)?$latitude:'';
// 项目地址
$location= $objPHPExcel->getActiveSheet()->getCell("K".$j)->getValue();
$station['location']=isset($location)?$location:'';
// 墙面天线数
$antenna_number=$objPHPExcel->getActiveSheet()->getCell("L".$j)->getValue();
$detai['antenna_number']=isset($antenna_number)?$antenna_number:'0';
// 杆数
$rod_number=$objPHPExcel->getActiveSheet()->getCell("M".$j)->getValue();
$detai['rod_number']=isset($rod_number)?$rod_number:'0';
// 箱体数
$box_number=$objPHPExcel->getActiveSheet()->getCell("N".$j)->getValue();
$detai['box_number']=isset($box_number)?$box_number:'0';
// 光缆公里数
$optical_cable=$objPHPExcel->getActiveSheet()->getCell("O".$j)->getValue();
$detai['optical_cable']=isset($optical_cable)?$optical_cable:'0';
// RRU数量
$rru_number= $objPHPExcel->getActiveSheet()->getCell("P".$j)->getValue();
$detai['rru_number']=isset($rru_number)?$rru_number:'0';
// RRU方位角
$rru_zimuth= $objPHPExcel->getActiveSheet()->getCell("Q".$j)->getValue();
$detai['rru_zimuth']=isset($rru_zimuth)?$rru_zimuth:'0';
// 施工队类型
$type= $objPHPExcel->getActiveSheet()->getCell("R".$j)->getValue();
if($type=='自建'){
$vendor['type']=1;
}elseif($type=='外围'){
$vendor['type']=2;
}elseif($type=='挂靠'){
$vendor['type']=3;
}else{
$vendor['type']=0;
}
// 施工联系方式
$construction_number=$objPHPExcel->getActiveSheet()->getCell("S".$j)->getValue();
$vendor['construction_number']=isset($construction_number)?$construction_number:'';
// 部门
$department_id=$objPHPExcel->getActiveSheet()->getCell("T".$j)->getValue();
if($department_id){
$station['department_id']=(new BaseStationModel)->getdepartById($department_id);
}else{
$station['department_id']=0;
}
// 经理
$three_level_manager=$objPHPExcel->getActiveSheet()->getCell("U".$j)->getValue();
$vendor['three_level_manager']=isset($three_level_manager)?$three_level_manager:'';
// 业务员
$salesman=$objPHPExcel->getActiveSheet()->getCell("V".$j)->getValue();
$vendor['salesman']=isset($salesman)?$salesman:'';
// 需求来源
$sources_id=$objPHPExcel->getActiveSheet()->getCell("W".$j)->getValue();
if($sources_id){
$station['sources_id']=(new BaseStationModel)->getsourceId($sources_id);
}else{
$station['sources_id']=0;
}
// 公司上游客户
$customers_id=$objPHPExcel->getActiveSheet()->getCell("X".$j)->getValue();
if($customers_id){
$station['customers_id']=(new BaseStationModel)->getcustomersId($customers_id);
}else{
$station['customers_id']=0;
}
// 频段
$frequencyband_id=$objPHPExcel->getActiveSheet()->getCell("Y".$j)->getValue();
if($frequencyband_id){
$detai['frequencyband_id']=(new BaseStationModel)->getfrequencybandId($frequencyband_id);
}else{
$detai['frequencyband_id']=0;
}
$add_date= strtotime($objPHPExcel->getActiveSheet()->getCell("Z".$j)->getValue());
if($add_date){
$station['create_time']=$add_date;
$detai['create_time'] = $add_date;
$vendor['create_time'] = $add_date;
}else{
$station['create_time']=$create_time;
$detai['create_time'] = $create_time;
$vendor['create_time'] = $create_time;
}
$stationAll[] = $station;
$detaiAll[] = $detai;
$vendorAll[] = $vendor;
}
$sucelectric= Db::name('station_info')->insertAll($stationAll);
$station_info = Db::name('station_info')->field('station_id,original_sp_id')->where("update_time='$create_time'")->select();
$detaiList = array();
foreach ($detaiAll as $key => $val){
$value = array_merge($val,array('stationid'=>$station_info[$key]['station_id']));
$detaiList[] = $value;
}
Db::name('station_info_detai')->insertAll($detaiList);
$vendinfoList = array();
foreach ($vendorAll as $k => $vo){
$value = array_merge($vo,array('vendor_id'=>$station_info[$k]['station_id']));
$vendinfoList[] = $value;
}
Db::name('vendor_info')->insertAll($vendinfoList);
$data['total']=$highestRow-1;
$data['suc']=$sucelectric;
$data['er']=$highestRow-1-$sucelectric;
return ['code' =>200,'message' => '导入成功' ,'data' => $data];
}
/**
* Excel导出,TODO 可继续优化
*
* @param array $datas 导出数据,格式['A1', => 'XXXX公司报表', 'B1' => '序号']
* @param string $fileName 导出文件名称
* @param array $options 操作选项,例如:
* bool print 设置打印格式
* string freezePane 锁定行数,例如表头为第一行,则锁定表头输入A2
* array setARGB 设置背景色,例如['A1',, 'C1']
* array setWidth 设置宽度,例如['A' => 30, 'C' => 20]
* bool setBorder 设置单元格边框
* array mergeCells 设置合并单元格,例如['A1:J1' => 'A1:J1']
* array formula 设置公式,例如['F2' => '=IF(D2>0,E42/D2,0)']
* array format 设置格式,整列设置,例如['A' => 'General']
* array alignCenter 设置居中样式,例如['A1',, 'A2']
* array bold 设置加粗样式,例如['A1',, 'A2']
* string savePath 保存路径,设置后则文件保存到服务器,不通过浏览器下载
*/
public function exportExcel(array $datas, string $fileName = '', array $options = []): bool
{
try {
if (empty($datas)) {
return false;
}
set_time_limit(0);
/** @var Spreadsheet $objSpreadsheet */
$objSpreadsheet = app(Spreadsheet::class);
/* 设置默认文字居左,上下居中 */
$styleArray = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_LEFT,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
$objSpreadsheet->getDefaultStyle()->applyFromArray($styleArray);
/* 设置Excel Sheet */
$activeSheet = $objSpreadsheet->setActiveSheetIndex(0);
/* 打印设置 */
if (isset($options['print']) && $options['print']) {
/* 设置打印为A4效果 */
$activeSheet->getPageSetup()->setPaperSize(PageSetup:: PAPERSIZE_A4);
/* 设置打印时边距 */
$pValue = 1 / 2.54;
$activeSheet->getPageMargins()->setTop($pValue / 2);
$activeSheet->getPageMargins()->setBottom($pValue * 2);
$activeSheet->getPageMargins()->setLeft($pValue / 2);
$activeSheet->getPageMargins()->setRight($pValue / 2);
}
/* 行数据处理 */
foreach ($datas as $sKey => $sItem) {
/* 默认文本格式 */
$pDataType = DataType::TYPE_STRING;
/* 设置单元格格式 */
if (isset($options['format']) && !empty($options['format'])) {
$colRow = Coordinate::coordinateFromString($sKey);
/* 存在该列格式并且有特殊格式 */
if (isset($options['format'][$colRow[0]]) &&
NumberFormat::FORMAT_GENERAL != $options['format'][$colRow[0]]) {
$activeSheet->getStyle($sKey)->getNumberFormat()
->setFormatCode($options['format'][$colRow[0]]);
if (false !== strpos($options['format'][$colRow[0]], '0.00') &&
is_numeric(str_replace(['¥', ','], '', $sItem))) {
/* 数字格式转换为数字单元格 */
$pDataType = DataType::TYPE_NUMERIC;
$sItem = str_replace(['¥', ','], '', $sItem);
}
} elseif (is_int($sItem)) {
$pDataType = DataType::TYPE_NUMERIC;
}
}
$activeSheet->setCellValueExplicit($sKey, $sItem, $pDataType);
/* 存在:形式的合并行列,列入A1:B2,则对应合并 */
if (false !== strstr($sKey, ":")) {
$options['mergeCells'][$sKey] = $sKey;
}
}
unset($datas);
/* 设置锁定行 */
if (isset($options['freezePane']) && !empty($options['freezePane'])) {
$activeSheet->freezePane($options['freezePane']);
unset($options['freezePane']);
}
/* 设置宽度 */
if (isset($options['setWidth']) && !empty($options['setWidth'])) {
foreach ($options['setWidth'] as $swKey => $swItem) {
$activeSheet->getColumnDimension($swKey)->setWidth($swItem);
}
unset($options['setWidth']);
}
/* 设置背景色 */
if (isset($options['setARGB']) && !empty($options['setARGB'])) {
foreach ($options['setARGB'] as $sItem) {
$activeSheet->getStyle($sItem)
->getFill()->setFillType(Fill::FILL_SOLID)
->getStartColor()->setARGB(Color::COLOR_YELLOW);
}
unset($options['setARGB']);
}
/* 设置公式 */
if (isset($options['formula']) && !empty($options['formula'])) {
foreach ($options['formula'] as $fKey => $fItem) {
$activeSheet->setCellValue($fKey, $fItem);
}
unset($options['formula']);
}
/* 合并行列处理 */
if (isset($options['mergeCells']) && !empty($options['mergeCells'])) {
$activeSheet->setMergeCells($options['mergeCells']);
unset($options['mergeCells']);
}
/* 设置居中 */
if (isset($options['alignCenter']) && !empty($options['alignCenter'])) {
$styleArray = [
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
];
foreach ($options['alignCenter'] as $acItem) {
$activeSheet->getStyle($acItem)->applyFromArray($styleArray);
}
unset($options['alignCenter']);
}
/* 设置加粗 */
if (isset($options['bold']) && !empty($options['bold'])) {
foreach ($options['bold'] as $bItem) {
$activeSheet->getStyle($bItem)->getFont()->setBold(true);
}
unset($options['bold']);
}
/* 设置单元格边框,整个表格设置即可,必须在数据填充后才可以获取到最大行列 */
if (isset($options['setBorder']) && $options['setBorder']) {
$border = [
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN, // 设置border样式
'color' => ['argb' => 'FF000000'], // 设置border颜色
],
],
];
$setBorder = 'A1:' . $activeSheet->getHighestColumn() . $activeSheet->getHighestRow();
$activeSheet->getStyle($setBorder)->applyFromArray($border);
unset($options['setBorder']);
}
$fileName = !empty($fileName) ? $fileName : (date('YmdHis') . '.xlsx');
if (!isset($options['savePath'])) {
/* 直接导出Excel,无需保存到本地,输出07Excel文件 */
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header(
"Content-Disposition:attachment;filename=" . iconv(
"utf-8", "GB2312//TRANSLIT", $fileName
)
);
header('Cache-Control: max-age=0');//禁止缓存
$savePath = 'php://output';
} else {
$savePath = $options['savePath'];
}
ob_clean();
ob_start();
$objWriter = IOFactory::createWriter($objSpreadsheet, 'Xlsx');
$objWriter->save($savePath);
/* 释放内存 */
$objSpreadsheet->disconnectWorksheets();
unset($objSpreadsheet);
ob_end_flush();
return true;
} catch (Exception $e) {
return false;
}
}
public function export($data,$name){
ini_set ('memory_limit', '1000M');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// $sheet->setCellValue('A1','station_name 基站名称');
// $sheet->setCellValue('B1','station_sp_code 基站编号');
// $sheet->setCellValue('C1','proj_number 项目编号');
// $sheet->setCellValue('D1','number 编号');
// $sheet->setCellValue('E1','emt_id 类型');
// $sheet->setCellValue('F1','pay_number 缴费号');
// $sheet->setCellValue('G1','multiple 倍率');
// $sheet->setCellValue('H1','pay_cycle 交费周期');
// $sheet->setCellValue('I1','unit_price 电表单价');
// $sheet->setCellValue('J1','protocol_price 协议单价');
// $sheet->setCellValue('K1','address 电表地址 地址');
// $sheet->setCellValue('L1','remark 备注');
// $sheet->setCellValue('M1','create_time 创建时');
// $sheet->setCellValue('N1','init_degree 初始度数');
// $sheet->setCellValue('O1','first_cp_date 第一次抄表日期');
// $sheet->setCellValue('P1','is_protocol 是否是协议价');
// $sheet->setCellValue('Q1','staff_name 员工姓名');
// $sheet->setCellValue('R1','er_name 机房名称');
// $sheet->setCellValue('S1','er_position 机房位置');
// $sheet->setCellValue('T1','qrcode 二维码');
// $sheet->setCellValue('U1','er_contact 联系人');
// $sheet->setCellValue('V1','er_tel 联系电话');
// $sheet->setCellValue('W1','property_position 物业位置');
// $sheet->setCellValue('X1','receive 实际收款单位');
// $sheet->setCellValue('Y1','rent 出租单位');
// $sheet->setCellValue('Z1','er_remark 机房备注');
// $sheet->setCellValue('AA1','contract_number 合同编号');
// $sheet->setCellValue('AB1','contract_sign_time 合同开始时间');
// $sheet->setCellValue('AC1','period 合同周期');
// $sheet->setCellValue('AD1','protocol_name 协议名称');
// $sheet->setCellValue('AE1','protocol_number 协议编号');
// $sheet->setCellValue('AF1','protocol_sign_date 协议签订时间');
// $sheet->setCellValue('AG1','protocol_start_date 协议开始时间');
// $sheet->setCellValue('AH1','protocol_end_date 协议结束时间');
// $sheet->setCellValue('AI1','protocol_remark 协议备注');
// $sheet->setCellValue('AJ1','init_amount 初始电表额度');
// $sheet->setCellValue('AK1','qrcode 二维码');
$sheet->setCellValue('A1','基站名称');
$sheet->setCellValue('B1','基站编号');
$sheet->setCellValue('C1','项目编号');
$sheet->setCellValue('D1','表号');
$sheet->setCellValue('E1','二维码');
$sheet->setCellValue('F1','类型');
$sheet->setCellValue('G1','缴费号');
$sheet->setCellValue('H1','倍率');
$sheet->setCellValue('I1','交费周期');
$sheet->setCellValue('J1','电表单价');
$sheet->setCellValue('K1','协议单价');
$sheet->setCellValue('L1','电表地址');
$sheet->setCellValue('M1','备注');
$sheet->setCellValue('N1','创建时');
$sheet->setCellValue('O1','初始度数');
$sheet->setCellValue('P1','第一次抄表日期');
$sheet->setCellValue('Q1','是否是协议价');
$sheet->setCellValue('R1','员工姓名');
$sheet->setCellValue('S1','机房名称');
$sheet->setCellValue('T1','机房位置');
$sheet->setCellValue('U1','二维码');
$sheet->setCellValue('V1','联系人');
$sheet->setCellValue('W1','联系电话');
$sheet->setCellValue('X1','物业位置');
$sheet->setCellValue('Y1','实际收款单位');
$sheet->setCellValue('Z1','出租单位');
$sheet->setCellValue('AA1','机房备注');
$sheet->setCellValue('AB1','合同编号');
$sheet->setCellValue('AC1','合同开始时间');
$sheet->setCellValue('AD1','合同周期');
$sheet->setCellValue('AE1','协议名称');
$sheet->setCellValue('AF1','协议编号');
$sheet->setCellValue('AG1','协议签订时间');
$sheet->setCellValue('AH1','协议开始时间');
$sheet->setCellValue('AI1','协议结束时间');
$sheet->setCellValue('AJ1','协议备注');
$sheet->setCellValue('AK1','初始电表额度');
$sheet->setCellValue('AL1','二维码');
for ($i = 0; $i < count($data); $i++) {
$sheet->setCellValue('A'.($i+2),$data[$i]['station_name']);
$sheet->setCellValue('B'.($i+2),$data[$i]['station_sp_code']);
$sheet->setCellValue('C'.($i+2),$data[$i]['proj_number']);
$sheet->setCellValue('D'.($i+2),$data[$i]['number']);
$sheet->setCellValue('E'.($i+2),$data[$i]['qrcode']);
$sheet->setCellValue('F'.($i+2),$data[$i]['emt_name']);
$sheet->setCellValue('G'.($i+2),$data[$i]['pay_number']);
$sheet->setCellValue('H'.($i+2),$data[$i]['multiple']);
$sheet->setCellValue('I'.($i+2),$data[$i]['pay_cycle']);
$sheet->setCellValue('J'.($i+2),$data[$i]['unit_price']);
$sheet->setCellValue('K'.($i+2),$data[$i]['protocol_price']);
$sheet->setCellValue('L'.($i+2),$data[$i]['address']);
$sheet->setCellValue('M'.($i+2),$data[$i]['remark']);
$sheet->setCellValue('N'.($i+2),$data[$i]['create_time']);
$sheet->setCellValue('O'.($i+2),$data[$i]['init_degree']);
$sheet->setCellValue('P'.($i+2),$data[$i]['first_cp_date']);
$sheet->setCellValue('Q'.($i+2),$data[$i]['isprotocol']);
$sheet->setCellValue('R'.($i+2),$data[$i]['staff_name']);
$sheet->setCellValue('S'.($i+2),$data[$i]['er_name']);
$sheet->setCellValue('T'.($i+2),$data[$i]['er_position']);
$sheet->setCellValue('U'.($i+2),$data[$i]['qrcode']);
$sheet->setCellValue('V'.($i+2),$data[$i]['er_contact']);
$sheet->setCellValue('W'.($i+2),$data[$i]['er_tel']);
$sheet->setCellValue('X'.($i+2),$data[$i]['property_position']);
$sheet->setCellValue('Y'.($i+2),$data[$i]['receive']);
$sheet->setCellValue('Z'.($i+2),$data[$i]['rent']);
$sheet->setCellValue('AA'.($i+2),$data[$i]['er_remark']);
$sheet->setCellValue('AB'.($i+2),$data[$i]['contract_number']);
$sheet->setCellValue('AC'.($i+2),$data[$i]['contract_sign_time']);
$sheet->setCellValue('AD'.($i+2),$data[$i]['period'].'月');
$sheet->setCellValue('AE'.($i+2),$data[$i]['protocol_name']);
$sheet->setCellValue('AF'.($i+2),$data[$i]['protocol_number']);
$sheet->setCellValue('AG'.($i+2),$data[$i]['protocol_sign_date']);
$sheet->setCellValue('AH'.($i+2),$data[$i]['protocol_start_date']);
$sheet->setCellValue('AI'.($i+2),$data[$i]['protocol_end_date']);
$sheet->setCellValue('AJ'.($i+2),$data[$i]['protocol_remark']);
$sheet->setCellValue('AK'.($i+2),$data[$i]['init_amount']);
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$name.'.xlsx"');
header('Cache-Control: max-age=0');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
ob_end_clean();
$writer->save('php://output');
exit;
}
public function baseexport($data,$name){
ini_set ('memory_limit', '1000M');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1','基站名称 station_name');
$sheet->setCellValue('B1','基站编号 station_sp_code');
$sheet->setCellValue('C1','运营商 operator_name');
$sheet->setCellValue('D1','需求号 sp_req_code');
$sheet->setCellValue('E1','基站状态 cate_name');
$sheet->setCellValue('F1','需求来源 sources_name');
$sheet->setCellValue('G1','上游客户 customers_name');
$sheet->setCellValue('H1','项目编号 proj_number');
$sheet->setCellValue('I1','经度 longitude');
$sheet->setCellValue('J1','纬度 latitude');
$sheet->setCellValue('K1','业务线 business_name');
$sheet->setCellValue('L1','区域 region_name');
$sheet->setCellValue('M1','项目地址 location');
$sheet->setCellValue('N1','墙面天线数 antenna_number');
$sheet->setCellValue('O1','杆数 rod_number');
$sheet->setCellValue('P1','箱体数 box_number');
$sheet->setCellValue('Q1','RRU数量 rru_number');
$sheet->setCellValue('R1','RRU方位角 rru_zimuth');
$sheet->setCellValue('S1','光缆公里数 optical_cable');
$sheet->setCellValue('T1','施工队类型 type');
$sheet->setCellValue('U1','施工联系方式 construction_number');
$sheet->setCellValue('V1','部门 name');
$sheet->setCellValue('W1','经理 three_level_manager');
$sheet->setCellValue('X1','业务员 salesman');
for ($i = 0; $i < count($data); $i++) {
$sheet->setCellValue('A'.($i+2),$data[$i]['station_name']);
$sheet->setCellValue('B'.($i+2),$data[$i]['station_sp_code']);
$sheet->setCellValue('C'.($i+2),$data[$i]['operator_name']);
$sheet->setCellValue('D'.($i+2),$data[$i]['sp_req_code']);
$sheet->setCellValue('E'.($i+2),$data[$i]['cate_name']);
$sheet->setCellValue('F'.($i+2),$data[$i]['sources_name']);
$sheet->setCellValue('G'.($i+2),$data[$i]['customers_name']);
$sheet->setCellValue('H'.($i+2),$data[$i]['proj_number']);
$sheet->setCellValue('I'.($i+2),$data[$i]['longitude']);
$sheet->setCellValue('J'.($i+2),$data[$i]['latitude']);
$sheet->setCellValue('K'.($i+2),$data[$i]['business_name']);
$sheet->setCellValue('L'.($i+2),$data[$i]['region_name']);
$sheet->setCellValue('M'.($i+2),$data[$i]['location']);
$sheet->setCellValue('N'.($i+2),$data[$i]['antenna_number']);
$sheet->setCellValue('O'.($i+2),$data[$i]['rod_number']);
$sheet->setCellValue('P'.($i+2),$data[$i]['box_number']);
$sheet->setCellValue('Q'.($i+2),$data[$i]['rru_number']);
$sheet->setCellValue('R'.($i+2),$data[$i]['rru_zimuth']);
$sheet->setCellValue('S'.($i+2),$data[$i]['optical_cable']);
$sheet->setCellValue('T'.($i+2),$data[$i]['type']);
$sheet->setCellValue('U'.($i+2),$data[$i]['construction_number']);
$sheet->setCellValue('V'.($i+2),$data[$i]['name']);
$sheet->setCellValue('W'.($i+2),$data[$i]['three_level_manager']);
$sheet->setCellValue('X'.($i+2),$data[$i]['salesman']);
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$name.'.xlsx"');
header('Cache-Control: max-age=0');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
ob_end_clean();
$writer->save('php://output');
exit;
}
public function meterexport($data,$name){
ini_set ('memory_limit', '5000M');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1','支票号');
$sheet->setCellValue('B1','缴费员');
$sheet->setCellValue('C1','更新日期');
$sheet->setCellValue('D1','项目编号');
$sheet->setCellValue('E1','缴费号');
$sheet->setCellValue('F1','电表数');
$sheet->setCellValue('G1','缴费次数');
$sheet->setCellValue('H1','和移动结算情况');
$sheet->setCellValue('I1','基站类型');
$sheet->setCellValue('J1','是否协议价');
$sheet->setCellValue('K1','区域');
$sheet->setCellValue('L1','网络标识');
$sheet->setCellValue('M1','站号');
$sheet->setCellValue('N1','站名');
$sheet->setCellValue('O1','机房二维码');
$sheet->setCellValue('P1','缴费周期');
$sheet->setCellValue('Q1','预交费日期');
$sheet->setCellValue('R1','上期表数');
$sheet->setCellValue('S1','本期表数');
$sheet->setCellValue('T1','实际报移动用电量');
$sheet->setCellValue('U1','上期查表日期');
$sheet->setCellValue('V1','本期查表日期');
$sheet->setCellValue('W1','倍率');
$sheet->setCellValue('X1','抄表单单价');
$sheet->setCellValue('Y1','财务单价');
$sheet->setCellValue('Z1','实际从财务支出金额');
$sheet->setCellValue('AA1','用电量(1.05元/度)');
$sheet->setCellValue('AB1','用电量(1.09元/度)');
$sheet->setCellValue('AC1','用电量(1.123元/度)');
$sheet->setCellValue('AD1','用电量(协议价)');
$sheet->setCellValue('AE1','协议价');
$sheet->setCellValue('AF1','移动结算金额');
$sheet->setCellValue('AG1','回款次数');
$sheet->setCellValue('AH1','毛利');
$sheet->setCellValue('AI1','电表类型');
$sheet->setCellValue('AJ1','电表识别号');
$sheet->setCellValue('AK1','电表问题');
$sheet->setCellValue('AL1','基站问题');
$sheet->setCellValue('AM1','地址');
$sheet->setCellValue('AN1','所属移动分公司');
$sheet->setCellValue('AO1','出租单位名称');
$sheet->setCellValue('AP1','甲方联系人');
$sheet->setCellValue('AQ1','实际收款单位');
$sheet->setCellValue('AR1','联系方式');
$sheet->setCellValue('AS1','机房位置');
$sheet->setCellValue('AT1','物业位置');
$sheet->setCellValue('AU1','备注');
$sheet->setCellValue('AV1','申请确认合同额');
$sheet->setCellValue('AW1','结算日期');
$sheet->setCellValue('AX1','确认合同时间');
$sheet->setCellValue('AY1','确认收入时间');
$sheet->setCellValue('AZ1','是否有发票');
$sheet->setCellValue('BA1','合同编号');
$sheet->setCellValue('BB1','发票类型');
$sheet->setCellValue('BC1','税点');
for ($i = 0; $i < count($data); $i++) {
$sheet->setCellValue('A'.($i+2),$data[$i]['cheque_number']);
$sheet->setCellValue('B'.($i+2),$data[$i]['payment_clerk']);
$sheet->setCellValue('C'.($i+2),$data[$i]['update_time']);
$sheet->setCellValue('D'.($i+2),$data[$i]['proj_number']);
$sheet->setCellValue('E'.($i+2),$data[$i]['payment_number']);
$sheet->setCellValue('F'.($i+2),$data[$i]['meters_number']);
$sheet->setCellValue('G'.($i+2),$data[$i]['payments_umber']);
$sheet->setCellValue('H'.($i+2),$data[$i]['settlement']);
$sheet->setCellValue('I'.($i+2),$data[$i]['base_type']);
$sheet->setCellValue('J'.($i+2),$data[$i]['is_protocol']);
$sheet->setCellValue('K'.($i+2),$data[$i]['region']);
$sheet->setCellValue('L'.($i+2),$data[$i]['network_identity']);
$sheet->setCellValue('M'.($i+2),$data[$i]['station_number']);
$sheet->setCellValue('N'.($i+2),$data[$i]['station_name']);
$sheet->setCellValue('O'.($i+2),$data[$i]['qrcode']);
$sheet->setCellValue('P'.($i+2),$data[$i]['payment_cycle']);
$sheet->setCellValue('Q'.($i+2),$data[$i]['advance_pay_time']);
$sheet->setCellValue('R'.($i+2),$data[$i]['last_number']);
$sheet->setCellValue('S'.($i+2),$data[$i]['current_number']);
$sheet->setCellValue('T'.($i+2),$data[$i]['report_electric']);
$sheet->setCellValue('U'.($i+2),$data[$i]['last_date']);
$sheet->setCellValue('V'.($i+2),$data[$i]['current_date']);
$sheet->setCellValue('W'.($i+2),$data[$i]['multiple']);
$sheet->setCellValue('X'.($i+2),$data[$i]['unit_price']);
$sheet->setCellValue('Y'.($i+2),$data[$i]['finance_unit']);
$sheet->setCellValue('Z'.($i+2),$data[$i]['finance_pay']);
$sheet->setCellValue('AA'.($i+2),$data[$i]['electricone']);
$sheet->setCellValue('AB'.($i+2),$data[$i]['electrictwo']);
$sheet->setCellValue('AC'.($i+2),$data[$i]['electricthree']);
$sheet->setCellValue('AD'.($i+2),$data[$i]['electricity_consumption']);
$sheet->setCellValue('AE'.($i+2),$data[$i]['agreed_price']);
$sheet->setCellValue('AF'.($i+2),$data[$i]['settlement_amount']);
$sheet->setCellValue('AG'.($i+2),$data[$i]['back_number']);
$sheet->setCellValue('AH'.($i+2),$data[$i]['gross_profit']);
$sheet->setCellValue('AI'.($i+2),$data[$i]['meter_type']);
$sheet->setCellValue('AJ'.($i+2),$data[$i]['meter_number']);
$sheet->setCellValue('AK'.($i+2),$data[$i]['meter_problem']);
$sheet->setCellValue('AL'.($i+2),$data[$i]['base_problem']);
$sheet->setCellValue('AM'.($i+2),$data[$i]['address']);
$sheet->setCellValue('AN'.($i+2),$data[$i]['subordinate']);
$sheet->setCellValue('AO'.($i+2),$data[$i]['rental_name']);
$sheet->setCellValue('AP'.($i+2),$data[$i]['contacts']);
$sheet->setCellValue('AQ'.($i+2),$data[$i]['receiving_unit']);
$sheet->setCellValue('AR'.($i+2),$data[$i]['contact_information']);
$sheet->setCellValue('AS'.($i+2),$data[$i]['room_location']);
$sheet->setCellValue('AT'.($i+2),$data[$i]['property_location']);
$sheet->setCellValue('AU'.($i+2),$data[$i]['remarks']);
$sheet->setCellValue('AV'.($i+2),$data[$i]['apply_contract_amount']);
$sheet->setCellValue('AW'.($i+2),$data[$i]['settlement_date']);
$sheet->setCellValue('AX'.($i+2),$data[$i]['confirmation_time']);
$sheet->setCellValue('AY'.($i+2),$data[$i]['income_time']);
$sheet->setCellValue('AZ'.($i+2),$data[$i]['is_invoice']);
$sheet->setCellValue('BA'.($i+2),$data[$i]['contract_number']);
$sheet->setCellValue('BB'.($i+2),$data[$i]['invoice_type']);
$sheet->setCellValue('BC'.($i+2),$data[$i]['tax_point']);
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$name.'.xls"');
header('Cache-Control: max-age=0');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
ob_end_clean();
$writer->save('php://output');
exit;
}
//基站流转数据信息导入
public function basestation_importExecl(string $file = '', int $sheet = 0, int $columnCnt = 0, &$options = []){
ini_set ('memory_limit', '1000M');
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));//判断导入表格后缀格式
// 有Xls和Xlsx格式两种
if ($extension == 'xlsx') {
$objReader =IOFactory::createReader('Xlsx');
$objPHPExcel = $objReader->load($file);
} elseif($extension == 'xls'){
$objReader =IOFactory::createReader('Xls');
$objPHPExcel = $objReader->load($file);
}else{
$this->error('必须为excel表格,且必须为xls或者xlsx格式!');
}
//$filename可以是上传的表格,或者是指定的表格
$sheet = $objPHPExcel->getSheet(0); //excel中的第一张sheet
$highestRow = $sheet->getHighestRow(); // 取得总行数
// $highestColumn = $sheet->getHighestColumn(); // 取得总列数
$error=0;
for ($j = 2; $j <= $highestRow; $j++) {
$data['jzProjectId']=$objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();
$data['jzRequire']=$objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();
$data['jzCode']=$objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();
$data['jzName']=$objPHPExcel->getActiveSheet()->getCell("D".$j)->getValue();
$data['projectCode']=$objPHPExcel->getActiveSheet()->getCell("E".$j)->getValue();
$data['jzType']=$objPHPExcel->getActiveSheet()->getCell("F".$j)->getValue();
$data['jzYys']=$objPHPExcel->getActiveSheet()->getCell("G".$j)->getValue();
$data['jzUpCustom']=$objPHPExcel->getActiveSheet()->getCell("H".$j)->getValue();
$data['businessLine']=$objPHPExcel->getActiveSheet()->getCell("I".$j)->getValue();
$data['jzQy']=$objPHPExcel->getActiveSheet()->getCell("J".$j)->getValue();
$data['projectAddress']=$objPHPExcel->getActiveSheet()->getCell("K".$j)->getValue();
$data['jzLongitude']=$objPHPExcel->getActiveSheet()->getCell("L".$j)->getValue();
$data['jzLatitude']=$objPHPExcel->getActiveSheet()->getCell("M".$j)->getValue();
$data['jzState']=$objPHPExcel->getActiveSheet()->getCell("N".$j)->getValue();
$data['jzCurDept']=$objPHPExcel->getActiveSheet()->getCell("O".$j)->getValue();
$data['jzProjectOwner']=$objPHPExcel->getActiveSheet()->getCell("P".$j)->getValue();
$data['jzCurUser']=$objPHPExcel->getActiveSheet()->getCell("Q".$j)->getValue();
$data['jzCreateDateStr']=$objPHPExcel->getActiveSheet()->getCell("R".$j)->getValue();
$data['jzEwm']=$objPHPExcel->getActiveSheet()->getCell("S".$j)->getValue();
$url='http://39.155.253.70:8081/jzmessage/KingDeeaddMessage';
$accessToken=$this->check_login();
$jzdata=self::jz($data,$url,$accessToken);
dump($jzdata);
$jzdata= json_decode($jzdata,true);
if($jzdata['code']!==200){
$error++;
}
}
// $datacount['total']=$highestRow-1;
// $datacount['suc']=$highestRow-1-$error;
// $datacount['er']=$error;
// return ['code' =>200,'message' => '导入成功' ,'data' => $datacount];
}
public function check_login(){
$data['password']=371;
$data['username']=371;
$data['userType']=1;
$url="http://39.155.253.70:8081/auth/login";
$token=self::jz($data,$url,'');
$token=json_decode($token,true);
if( $token['code']==200){
return $token['data'];
}
}
static function jz($jzdata,$url,$accessToken){
if($accessToken){
$headers[] = "Authorization: Bearer ". $accessToken;
}else{
$headers=[];
}
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER,0);
//设置请求头
curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
//设置post数据
curl_setopt($curl, CURLOPT_POSTFIELDS, $jzdata);
//执行命令
$data = curl_exec($curl);
//关闭URL请求
curl_close($curl);
//显示获得的数据
return $data;
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ namespace app\admin\controller;
use app\admin\model\StaffModel;
use think\Exception;
use think\facade\Cookie;
use think\facade\Session;
class SingleSign {
public $instence = null;
......@@ -19,6 +20,8 @@ class SingleSign {
if($res) $this->instence = $redis;
else throw new Exception("redis connect faild");
}
$sid = Cookie::get('PHPSESSID');
if(!empty($sid)) Cookie::set('PHPSESSID',$sid,['expire'=>time()+3600]);
}
//获取session
......@@ -37,15 +40,14 @@ class SingleSign {
$isAdmin = substr($str,$pos,1);
$user['is_admin'] = $isAdmin;
if($user['is_admin'] == true) {
$user['username'] = 'gonnadmin';
} else {
preg_match('/adminuser\|s\:(\d+)\:/',$str,$match);
if($match){
$pos = stripos($str,'adminuser|s:') + strlen('adminuser|s:');
$pos += strlen($match[1]) + 2;
$user['username'] = substr($str,$pos,$match[1]+0);
}
if($user['is_admin'] == true && $user['username'] == 'admin') {
$user['username'] = 'gonnadmin';
}
$pos = stripos($str,'ukey|s:10:') + 11;
......@@ -81,6 +83,8 @@ class SingleSign {
public function clear($prex = 'PHPREDIS_SESSION:'){
$sid = Cookie::get('PHPSESSID');
$sid = $prex.$sid;
Cookie::delete($sid);
if($this->instence->set($sid,'')) return true;
return false;
}
......
......@@ -11,7 +11,7 @@ class PermissionModel extends BaseModel
protected $deleteTime = 'delete_time';
protected $table = 'permission';
private $fields = 'id,title,pid,model_name,controller_name,method_name,params,is_nav,sort,status,update_time';
private $fields = '*';
private $ids = [];
private function getPermissionTree($fields = '',$isNav = false)
......
<?php
namespace app\admin\validate;
use think\Validate;
class FkAddValidate extends Validate
{
protected $rule = [
'title' => 'require',
'payee' => 'require',
'payOrg' => 'require',
'date' => 'require|date',
'fkinfo' => 'require'
];
protected $message = [
'title.require' => '标题必填',
'payee.require' => '收款方必填',
'payOrg.require' => '付款组织必填',
'date.require' => '日期必填',
'date.date' => '日期格式错误'
];
}
\ No newline at end of file
......@@ -20,9 +20,7 @@
<option value="1" {if $search_type eq 1 } selected {/if}>站名</option>
<option value="2" {if $search_type eq 2 } selected {/if}>站号</option>
<option value="3" {if $search_type eq 3 } selected {/if}>项目编号</option>
<option value="4" {if $search_type eq 4 } selected {/if}>机房二维码</option>
</select>
</div>
<div class="layui-input-inline layui-show-xs-block">
......@@ -44,11 +42,9 @@
{if $region.level == 0}
<option disabled='disabled' class='layui-disabled' >{$region.region_name}</option>
{else /}
<option value="{$region.id}" {if $area_id eq $region.id } selected {/if} >&nbsp;&nbsp;&nbsp;&nbsp;{$region.region_name}</option>
<option value="{$region.id}" {if $area_id eq $region.id } selected {/if} >{$region.region_name}</option>
{/if}
{/volist}
</select>
</div>
......
......@@ -18,7 +18,7 @@
<tr>
<th>菜单编号</th>
<th>名称</th>
<th>规则</th>
<th>路由</th>
<th>导航</th>
<th>排序</th>
<th>状态</th>
......@@ -29,7 +29,7 @@
<tr>
<td>{$item.id}</td>
<td>{$item.name}</td>
<td>{$item.model_name}/{$item.controller_name}/{$item.method_name}/{$item.params}</td>
<td>{$item.nav_url ?: '-'}</td>
<td>{if $item.is_nav == 1}是{else /}否{/if}</td>
<td>{$item.sort}</td>
<td class="td-status">
......@@ -97,7 +97,6 @@
var a='<span class="layui-btn layui-btn-normal layui-btn-mini">正常</span>'
$('#setstatus'+id).html(a);
return false;
}
},
error : function (XMLHttpRequest, textStatus, errorThrow ) {
......
......@@ -60,7 +60,12 @@
<script src="dist/js/md5.js"></script>
<script src="dist/js/sha1.js"></script>
<script src="dist/js/util.js"></script>
<<<<<<< HEAD
<!--<script src="dist/js/getUserToken.js"></script>-->
=======
<script src="dist/js/getUserToken.js"></script>
>>>>>>> test
<script>
layui.use(['laydate','form','upload'], function(){
upload = layui.upload;
......
File mode changed from 100755 to 100644
<?php
use app\admin\model\PermissionModel;
use app\admin\model\StaffRoleModel;
use think\db;
use think\facade\Session;
function check_data(){
$user = session('user');
//查找数据权限规则表
$map=[];
$permission=db::name('permission_data')->field('permission_ids')->where(['s_id'=>$user['user_id']])->find();
$arr= json_decode($permission['permission_ids'],true);
if($arr['department_id']){
$department_ids=strpos($arr['department_id'],',');
if($department_ids===false){
$map[]=['department_id','=', $arr['department_id']];
}else{
$map[]=['department_id','in',$arr['department_id']];
}
}
if($arr['region_id']){
$area_ids=strpos($arr['region_id'],',');
if($area_ids===false){
$map[]=['area_id','=', $arr['region_id']];
}else{
$map[]=['area_id','in',$arr['region_id']];
}
}
if($arr['business_id']){
$business_ids=strpos($arr['business_id'],',');
if($business_ids===false){
$map[]=['business_line_id','=', $arr['business_id']];
}else{
$map[]=['business_line_id','in',$arr['business_id']];
}
}
//如果数据规则表不存在数据信息 ,默认返回此用户的部门id
if(!$map){
$staff = db::name('staff')->field('d_id')->where(['id'=>$user['user_id']])->find();
if($staff && $staff['d_id']!==0){
$map[]=['department_id','=',$staff['d_id']];
}
}
return $map;
}
function loginlog($name,$id,$desc,$status){
$login['staff_id']=$id;
$login['name']=$name;
$login['description']=$desc;
$login['ip']=\think\facade\Request::ip();
$login['status']=$status;
$login['create_time']=time();
db::name('loginlog')->insert($login);
}
function activity_log($name,$desc,$type){
$login['name']=$name;
$login['description']=$desc;
$login['type']=$type;
$login['create_time']=time();
db::name('activity_log')->insert($login);
}
function curlGet($url=''){
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
$tmpInfo = curl_exec($curl); //返回api的json对象
//关闭URL请求
curl_close($curl);
return $tmpInfo; //返回json对象
}
function httpPOST($url , $post_data = array()){
$headers = array('Content-Type: application/x-www-form-urlencoded');
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);//捕抓异常
}
curl_close($curl); // 关闭CURL会话
return $result;
}
function decrypt ($pass) {
return md5($pass.config('admin.passwd_salt'));
}
//生成10位的随机密码
function createPass(){
return substr(md5(config('admin.passwd_salt').time()),0,10);
}
/**
* 基站状态递归实现无限极分类
* @param $array 分类数据
* @param $pid 父ID
* @param $level 分类级别
* @return $list 分好类的数组 直接遍历即可 $level可以用来遍历缩进
*/
function getTreeStatus($array, $pid =0, $level = 0){
//声明静态数组,避免递归调用时,多次声明导致数组覆盖
static $list = [];
foreach ($array as $key => $value){
//第一次遍历,找到父节点为根节点的节点 也就是pid=0的节点
if ($value['pid'] == $pid){
//父节点为根节点的节点,级别为0,也就是第一级
$value['level'] = $level;
//把数组放到list中
$list[] = $value;
//把这个节点从数组中移除,减少后续递归消耗
unset($array[$key]);
//开始递归,查找父ID为该节点ID的节点,级别则为原级别+1
getTreeStatus($array, $value['cate_id'], $level+1);
}
}
return $list;
}
/**
* 递归实现无限极分类
* @param $array 分类数据
* @param $pid 父ID
* @param $level 分类级别
* @return $list 分好类的数组 直接遍历即可 $level可以用来遍历缩进
*/
function getTree($array, $pid =0, $level = 0){
//声明静态数组,避免递归调用时,多次声明导致数组覆盖
static $list = [];
......@@ -17,3 +157,205 @@ function getTree($array, $pid =0, $level = 0){
}
return $list;
}
function getNodesTree($array,$pid=0){
$list = [];
foreach ($array as $k => $v) {
if ($v['pid'] == $pid) {
$v['children'] = getNodesTree($array, $v['id']);
$list[] = $v;
}
}
return $list;
}
function getNodeIds($data,$pid=0){
static $nodes = [];
if(empty($nodes)){
$nodes[] = $pid;
}
foreach ($data as $k=>$v){
if ($v['pid'] == $pid){
$nodes [] = $v['id'];
getNodesTree($data,$v['id']);
unset($data[$k]);
}
}
return $nodes;
}
function jsonSuc($message,$data=''){
if(!empty($data)){
return json([
'status' => 1,
'message' => $message,
'data' => $data
]);
} else {
return json([
'status' => 1,
'message' => $message
]);
}
}
function jsonErr($err){
return json([
'status' => 0,
'message' => $err
]);
}
function dd($mix)
{
echo "<pre/>";
var_dump($mix);
die;
}
function zero($num){
if(!is_numeric($num)) return '';
$len = strlen($num);
$str = str_repeat('0',5-$len).$num;
return $str;
}
//解析账单状态
function parseStatus($stauts,$type=0,$return=0){
$msg = [];
$arr = [];
for ($i=0;$i<strlen($stauts);$i++){
$arr[$i] = $stauts[$i];
}
switch ($arr[0]){
case 0:
$msg[] = '未缴费';
break;
case 1:
$msg[] = '部分缴费';
break;
case 2:
$msg[] = '已缴费';
break;
}
if($type == 1 && $return == 0) return $msg[0];
if($type == 1 && $return == 1) return $arr[0];
switch ($arr[1]){
case 0:
$msg[] = '未结算';
break;
case 1:
$msg[] = '部分结算';
break;
case 2:
$msg[] = '已结算';
break;
}
if($type == 1 && $return == 0) return $msg[1];
if($type == 1 && $return == 1) return $arr[1];
switch ($arr[2]){
case 0:
$msg[] = '未确收';
break;
case 1:
$msg[] = '确收中';
break;
case 2:
$msg[] = '已确收';
break;
}
if($type == 2 && $return == 0) return $msg[2];
if($type == 2 && $return == 1) return $arr[2];
return implode(' ',$msg);
}
/**
* 设置账单状态
* @param $statusCode
* @param $index
* @param $value
*/
function setInvoiceStatus($statusCode,$value,$index=0){
return substr_replace($statusCode,$value,$index,1);
}
/**
* 读取账单状态
* @param $statusCode
* @param $index
* @param $value
*/
function getInvoiceStatus($statusCode,$index=0){
return substr($statusCode,$index,1);
}
function getInvoicesStatusName($statusCode,$index=0){
$status = getInvoiceStatus($statusCode,$index);
if($index == 0){
switch ($status){
case 0:
return '未缴费';
break;
case 1:
return '部分缴费';
break;
case 2:
return '已缴清';
break;
}
}
elseif ($index == 1){
switch ($status){
case 0:
return '未结算';
break;
case 1:
return '部分结算';
break;
case 2:
return '已结算';
break;
}
} else {
switch ($status){
case 0:
return '未确收';
break;
case 1:
return '确收中';
break;
case 2:
return '已确收';
break;
}
}
}
//检测元素与按钮权限
function check_ele_permission($path){
$user = Session::get('user');
//获取当前用户的所有权限id
$permissions = StaffRoleModel::getStaffRolesById($user['user_id']);
$permissions = explode(',',$permissions);
//查询$path所对应id
$permission = PermissionModel::field('id,nav_url')->get(['nav_url'=>$path]);
if(isset($permission->id)){
if(!in_array($permission->id,$permissions) || $permission == null){
return false;
}
return true;
}
return false;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2020-6-21
* Time: 18:52
*/
namespace app\api\controller\v2\common;
use app\em\controller\Account;
use app\em\controller\WriteOff;
use app\em\model\EmInvoice;
use app\em\model\EmPayment;
use app\em\model\EmPaymentFk;
use app\em\model\EmPaymentInvoice;
use think\facade\Log;
class Payment
{
public function index()
{
$data = request()->get();
$res = $this->checkKey($data['key']);
if ($res !== true) return json([
'code' => 201,
'message' => $res,
'data' => ''
]);
if ($data['action'] == 1) {
Log::record(date('Y-m-d H:i:s').' OA单号:'.$data['numb'].' 接口操作:单据状态更新');
return $this->update($data['numb'],$data['status'],$data['mes']);
} else {
return $this->dropNumb($data['numb'],$data['status']);
}
}
//更新payment状态
private function update($numb,$status,$mes='')
{
$paymentFk = (new EmPaymentFk())->get(['oafk_numb' => $numb]);
$payment = (new EmPayment())->get(['payment_id' => $paymentFk->payment_id]);
//更新账户余额
if($payment->account_id != ''){
(new Account())->computerAmountFromPay($payment->account_id,$payment->amount);
}
$res = (new WriteOff())->writeOffFromPayment($payment->payment_id);
$payment->status = $status;
$payment->pay_date = time();
$payment->save();
Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb . $res);
return json([
'code' => 201,
'message' => $res,
'data' => ''
]);
}
//作废单据
private function dropNumb($numb,$status)
{
$paymentFk = (new EmPaymentFk())->get(['oafk_numb' => $numb,'status'=>1]);
$payment = (new EmPayment())->get(['payment_id' => $paymentFk->payment_id]);
$paymentFk->status = 0;
$paymentFk->save();
$payment->status = 9;
$payment->save();
//删除payment_invoice表
$delNum = (new EmPaymentInvoice())->where('payment_id', '=', $payment->payment_id)->delete();
Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb. '缴费单已作废');
return json(
[
'code' => 201,
'message' => json_encode($payment->toArray()),
'data' => ''
]);
}
private function checkKey($key)
{
if (empty($key)) {
return '秘钥不能为空';
}
$baseKey = substr(md5(config('oafk.oa_key') . date('Y-m-d')), 0, 12);
if ($key != $baseKey) {
return '秘钥错误';
}
return true;
}
public function setInvoiceStatus($statusCode, $value, $index = 0)
{
return substr_replace($statusCode, $value, $index, 1);
}
public function test(){
$data = request()->get();
if ($data['action'] == 1) {
Log::record(date('Y-m-d H:i:s').' OA单号:'.$data['numb'].' 接口操作:单据状态更新');
return $this->update($data['numb'],$data['status'],$data['mes']);
} else {
return $this->dropNumb($data['numb'],$data['status']);
}
}
public function commonCheckKey($key){
return $this->checkKey($key);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2020-6-21
* Time: 18:52
*/
namespace app\api\controller\v2\common;
use think\Controller;
use think\Db;
class Project extends Controller
{
public $jzdb;
public function initialize()
{
$this->jzdb = Db::connect([
'type' => config('jz.jztype'),
'hostname' => config('jz.jzhostname'),
'database' => config('jz.jzdatabase'),
'username' => config('jz.jzusername'),
'password' => config('jz.jzpassword'),
'hostport' => config('jz.jzhostport'),
'charset' => config('jz.jzcharset'),
]);
}
public function project_list()
{
$data = request()->get() ?: [];
if(!array_key_exists('key',$data)){
json([
'code' => 201,
'message' => 'request params not found!',
'data' => ''
]);
} else {
$res = (new Payment())->commonCheckKey($data['key']);
}
if ($res !== true) return json([
'code' => 201,
'message' => $res,
'data' => ''
]);
$project_code = $data['project_code'];
if (empty($project_code)) {
return json([
'code' => 202,
'message' => 'Not valid parameter',
]);
}
$map[] = ['project_code', '=', $project_code];
$datalist = $this->jzdb->table('jz_message')->field('project_code,jz_cur_dept')->where($map)->select();
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $datalist,
]);
}
}
\ No newline at end of file
......@@ -107,12 +107,6 @@ function createPass(){
return substr(md5(config('admin.passwd_salt').time()),0,10);
}
//生成10位的随机密码
//将密码返回给控制器
//控制器通过MD加密之后存储到数据库
/**
* 基站状态递归实现无限极分类
* @param $array 分类数据
......
<?php
namespace app\em\controller;
use app\admin\controller\Base;
use app\em\model\EmAccount;
use app\em\model\EmAccountAmount;
use think\Controller;
/**
* 电表账户
* Class Acount
* @package app\em\controller
*/
class Account extends Base
class Account extends Controller
{
//账户初始化
private function init($em_id){
......@@ -93,4 +94,34 @@ class Account extends Base
}
return $account->save();
}
public function computerAmountFromInv($em_id,$balance,$invoice_id = ''){
//更新账户余额
$account = (new EmAccount())->get(['em_id'=>$em_id]);
$account->amount -= $balance;
if($res = $account->save()){
$this->recordAmount($invoice_id,'抄表单',$balance);
}
return $res;
}
public function computerAmountFromPay($account_id,$balance){
//更新账户余额
$account = (new EmAccount())->get(['account_id'=>$account_id]);
$account->amount += $balance;
if($res = $account->save()){
$this->recordAmount($account_id,'缴费单',$balance);
}
return $res;
}
protected function recordAmount($numb,$type,$amount){
$record = new EmAccountAmount();
$record->numb = $numb;
$record->amount = $amount;
$record->type = $type;
return $record->save();
}
}
\ No newline at end of file
......@@ -40,40 +40,28 @@ class Em extends Base
if($search_text){
switch ($search_type) {
case '1':
$this->assign('search_text',$search_text);
$map[]=['s.station_name','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '2':
$this->assign('search_text',$search_text);
$map[]=['s.station_sp_code','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '3':
$this->assign('search_text',$search_text);
$map[]=['s.proj_number','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '4':
$this->assign('search_text',$search_text);
$map[]=['em.em_numb','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '5':
$this->assign('search_text',$search_text);
$map[]=['em.qrcode','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '6':
$this->assign('search_text',$search_text);
$map[]=['d.rent','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
}
}else{
$this->assign('search_type','');
$this->assign('search_text','');
}
$this->assign('search_type',$search_type ?: '');
$this->assign('search_text',$search_text ?: '');
$operator = Request::param('operator');
if($operator){
$map[] = ['s.original_sp_id','=',$operator];
......@@ -88,8 +76,8 @@ class Em extends Base
}else{
$this->assign('area_id','');
}
$page =Request::param('page')?Request::param('page'):1;
$limit = Request::param('limit')?Request::param('limit'):10;
$page =Request::param('page')?:1;
$limit = Request::param('limit')?:10;
$emModel = new EmList();
$list = $emModel->getEmList($map,$page,$limit);
......@@ -98,7 +86,6 @@ class Em extends Base
return ['code'=>0,'msg'=>'','count'=>$emCount,'data'=>$list];
}
$region=new ElectricMeter();
$operator=new OperatorModel();
$operators = OperatorModel::field('operator_id,operator_name')->where('operator_state','=',1)->select()->toArray();
$this->assign('regions',getTree($region->regions()));
$this->assign('operators',$operators);
......
......@@ -5,6 +5,7 @@
*/
namespace app\em\controller;
use app\admin\controller\Base;
use app\em\model\EmAccount;
use app\em\model\EmInvoice;
use app\em\model\EmInvoiceUseage;
use app\em\model\EmPayment;
......@@ -14,6 +15,7 @@ use app\em\model\EmSettle;
use app\em\model\EmSettleInvoice;
use app\em\model\EmSettleInvoiceBalance;
use app\em\model\UseageDetail;
use think\facade\Log;
use think\facade\Request;
use think\facade\Session;
......@@ -109,7 +111,6 @@ class Invoice extends Base
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$InvoiceCount,'data'=>$data];
}
return $this->fetch();
}
......@@ -158,7 +159,7 @@ class Invoice extends Base
$inv->type = 4;
$inv->rate = $uData['rate'];
$inv->repo_numb = round(($uData['current_sum_numb'] - $uData['last_sum_numb']) * $uData['rate'],3);
$inv->payment_amount = $inv->payment_balance = $inv->repo_numb * $uData['pay_price'];
$inv->payment_amount = $inv->payment_balance = $uData['amount'];
//结算信息
$inv->settle_amount = $inv->settle_balance = $inv->repo_numb * $uData['settle_price'];
$inv->status = '000';
......@@ -166,6 +167,8 @@ class Invoice extends Base
//获取账户ID
$inv->account_id = (new Account())->getAccountId($uData['em_id']);
$inv->em_id = $uData['em_id'];
$inv->uid = $this->uid;
//保存 并且更新抄表单与账单关联表
if($inv->save()){
......@@ -178,8 +181,9 @@ class Invoice extends Base
//更新电表账户
$useage = \app\em\model\Useage::get(['useage_id' => $uData['useage_id']]);
$account = new Account();
$account->updateAmount($useage->em_id,$inv->payment_amount,0);
if($uData['em_type_id'] == 2 || $uData['em_type_id'] == 4){
(new Account())->computerAmountFromInv($useage->em_id,$inv->payment_amount,$inv->invoice_id);
}
return $inv;
}
......@@ -210,7 +214,7 @@ class Invoice extends Base
$inv->repo_numb = ($curr_numb - $last_numb) * $uData['rate'];
//缴费信息
$inv->payment_amount = $inv->payment_balance = $amount * $uData['rate'];
$inv->payment_amount = $inv->payment_balance = $uData['amount'];
//结算信息
$inv->settle_amount = $inv->settle_balance = $repo_numb * $uData['rate'] *$uData['settle_price'];
$inv->status = '000';
......@@ -218,6 +222,7 @@ class Invoice extends Base
$inv->account_id = (new Account())->getAccountId($uData['em_id']);
$inv->em_id = $uData['em_id'];
//更新抄表单的status
$useage = \app\em\model\Useage::get(['useage_id'=>$uData['useage_id']]);
$useage->status = 2;
......@@ -233,6 +238,7 @@ class Invoice extends Base
$eiu->save();
}
(new Account())->computerAmountFromInv($useage->em_id,$inv->payment_amount,$inv->invoice_id);
return $inv;
}
......@@ -279,192 +285,6 @@ class Invoice extends Base
return $this->fetch('merge_list');
}
/**
* 账单触发销账,invoice_id 1:n payment_id
* @param $account_id
* @param $invoice_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return mixed
*/
public function writeOffFromInvoice($invoice_id,$account_id){
//获取账单对象
$invoice = EmInvoice::field('id,invoice_id,payment_amount,payment_balance')
->where('invoice_id','=',$invoice_id)->find();
//查询关系表中与当前invoice_id相关联的payment_id
$model = new EmPaymentInvoice;
$payments = $model->alias('epi')->field('epi.payment_id')
->leftJoin(['em_payment'=>'ep'],'epi.payment_id = ep.payment_id')
->leftJoin(['em_payment_invoice_balance'=>'epib'],'epib.invoice_id=epi.invoice_id')
->where('epib.balance','>',0)
->where('epi.invoice_id','=',$invoice_id)->select();
//如果没有找到记录 证明并没有形成对应关系
if($payments->isEmpty()) {
//查询是否有未缴费的缴费单存在
$payments = EmPayment::field('payment_id')->where('account_id','=',$account_id)
->where('balance','neq',0)
->order('payment_id asc')
->select();
if($payments->isEmpty()) {
return '没有销账的缴费单!';
}
}
$paymentIds = [];
foreach ($payments as $payment){
$paymentIds[] = $payment->payment_id;
}
$invsIds = [
'invoice_id' => $invoice->invoice_id
];
//开始销账
return $this->writeOff($paymentIds,$invsIds);
}
//从缴费单消账单
public function writeOffFromPayment($account_id,$payment_id){
//获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find();
//获取关联的账单对象
$invs = (new EmInvoice())->alias('ei')->field('ei.invoice_id')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.invoice_id = ei.invoice_id')
->where('epi.payment_id','=',$payment_id)
->where('ei.payment_balance','neq',0)
->order('ei.invoice_id asc')
->select();
$invsArr = [];
//更新缴费单状态
if($invs->isEmpty()){
$payment->status = 4;
$payment->save();
return '审核成功';
} else {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
//查询可消的额度
$payments_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('payment_balance');
//如果可以完全销账 则继续销账
if($payment->balance > $payments_balance){
$invs = (new EmInvoice())->field('invoice_id')
->where('account_id','=',$account_id)
->where('payment_balance','neq',0)
->order('invoice_id asc')
->select();
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
}
$paymentIds[] = $payment->payment_id;
//处理账户金额
return $this->writeOff($paymentIds,$invsArr);
}
/**
* @param $account_id
* @param $invoiceIds
* @param $paymentIds
* @return mixed
*/
private function writeOff($paymentIds,$invoiceIds){
//获取可销账缴费单
$payments = EmPayment::where('payment_id','in',$paymentIds)->select();
//获取可销账账单
$invs = EmInvoice::where('invoice_id','in',$invoiceIds)->select();
$result = 0;
foreach ($payments as $key => $payment){
if($payment->balance == 0)
continue;
foreach ($invs as $index => $inv) {
$balanceMode = new EmPaymentInvoiceBalance();
$balanceMode->payment_id = $payment->payment_id;
if ($inv->payment_balance == 0)
continue;
$balanceMode->invoice_id = $inv->invoice_id;
//如果该缴费单可以完全消除当前账单额度
if ($payment->balance >= $inv->payment_balance) {
//单笔销账多少
$balanceMode->balance = $inv->payment_balance;
//缴费额度变化
if(($payment->balance - $inv->payment_balance) == 0){
$payment->status = 4;
} else {
$payment->status = 4; //缴费部分销账
}
$payment->balance = $payment->balance - $inv->payment_balance;
//账单额度变化
$inv->payment_balance = 0;
//更新账户status 首字母 = 2
$inv->status = setInvoiceStatus($inv->status, 2);
} else {
//单笔销账多少
$balanceMode->balance = $payment->balance;
//账单额度变化
$inv->status = setInvoiceStatus($inv->status, 1);
$inv->payment_balance = $inv->payment_balance - $payment->balance;
//缴费额度变化
$payment->balance = 0;
$payment->status = 4; //缴费已经完全销账
}
$model = new EmPaymentInvoice();
if(!$model->where(['payment_id'=>$payment->payment_id,'invoice_id'=>$inv->invoice_id])->find()){
$model->payment_id = $payment->payment_id;
$model->invoice_id = $inv->invoice_id;
$model->save();
}
$result++;
//更新账单状态
$inv->save();
//todo::history; 保存历史记录
$invData = $inv->toArray();
$invData['id'] = null;
$invData['create_time'] = strtotime($invData['create_time']);
$invData['update_time'] = strtotime($invData['update_time']);
//EmInvoiceHistory::create($invData);
//unset($invs[$index]); //从结果集中去掉无效的数据
//更新状态
$payment->save();
//todo::history;保存历史记录
$payData = $payment->toArray();
$payData['id'] = null;
$payData['create_time'] = strtotime($payData['create_time']);
$payData['update_time'] = strtotime($payData['update_time']);
$payData['pay_date'] = strtotime($payData['pay_date']);
//EmPaymentHistory::create($payData);
unset($payments[$key]);
$balanceMode->isUpdate(false)->save();
}
}
$msg = $result == 0 ? '已审核,没有可销账的账单.' : '已审核,成功销账 '.$result.' 笔账单.';
return $msg;
}
public function writeOffFromSettle($account_id,$settle_id){
//获取缴费单对象
$settle = EmSettle::where('settle_id','=',$settle_id)->find();
......
......@@ -5,92 +5,106 @@
*/
namespace app\em\controller;
use app\admin\controller\Base;
use app\admin\model\DepartmentModel;
use app\admin\model\ElectricMeter;
use app\em\model\EmAccount;
use app\em\model\EmCert;
use app\em\model\EmCheckBill;
use app\em\model\EmInvoice;
use app\em\model\EmInvoiceHistory;
use app\em\model\EmPayment;
use app\em\model\EmPaymentFk;
use app\em\model\EmPaymentInvoice;
use app\em\model\EmPaymentInvoiceBalance;
use app\em\model\EmPaymentReceipt;
use app\em\model\Staff;
use app\em\model\Station;
use app\em\validate\AddFkInfoDetailsValidate;
use app\em\validate\AddFkInfoValidate;
use app\em\validate\AddPaymentValidate;
use function Sodium\library_version_major;
use think\Db;
use think\Exception;
use think\facade\Request;
use think\facade\Session;
class Payment extends Base
{
const PAYMENT_INIT_CODE = 0 ; //状态码
const PAYMENT_PARTIAL_CODE = 1; //状态码
const PAYMENT_FULL_CODE = 2; //状态码
const PAYMENT_STATUS_INDEX = 0; //索引位置
const PAYMENT_STATUS = [
0 => '待审核',
1 => '未提交',
2 => '审核中',
3 => '已付款',
4 => '已付款 缺发票',
5 => '已付款 发票已上传',
7 => '被驳回',
8 => '已确收',
9 => '审核失败',
];
const PAYMENT_STAUS_STYLE = [
0 => 'layui-color-black',
1 => 'layui-color-black',
2 => 'layui-color-black',
3 => 'layui-color-green',
4 => 'layui-color-green',
5 => 'layui-color-green',
7 => 'layui-color-gray',
8 => 'layui-color-blue',
9 => 'layui-color-cyan',
];
const PAYMENT_TYPE = [
0 => '未知',
1 => "读表",
2 => "充值",
3 => "读表",
4 => "充值"
];
const PAYMENT_STATUS_CHECK_NODE = 5;
//缴费单列表
public function index(){
$map=[];
//权限检测
$user = Session::get('user');
if(!$user['is_admin']){
$permissionData=check_data();
if($permissionData){
$map[]=$permissionData;
}
}
$search_text = Request::get('search_text');
$search_type = Request::get('search_type');
$payment_status = Request::get('payment_status');
$map=[];
//权限检测
if(!$this->user['is_admin']) $map[]= check_data();
if($search_text){
switch ($search_type) {
case '1':
$this->assign('search_text',$search_text);
if(strstr($search_text,',')){
$searchArr = explode(',',$search_text);
$map[]=['pay.payment_id','in',$searchArr];
} else {
$map[]=['pay.payment_id','like',"%$search_text%"];
$map[]=['pay.payment_id','=',"$search_text"];
}
$this->assign('search_type',$search_type);
break;
case '2':
$this->assign('search_text',$search_text);
$map[]=['epi.invoice_id','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '3':
$this->assign('search_text',$search_text);
$map[]=['em.em_numb','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '4':
$this->assign('search_text',$search_text);
$map[]=['station.station_name','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
}
}else{
$this->assign('search_type','');
$this->assign('search_text','');
}
$this->assign('search_type',$search_type ?: '');
$this->assign('search_text',$search_text ?: '');
//缴费状态
if($payment_status !== ''){
$map[]=['pay.status','=',"$payment_status"];
$this->assign('payment_status',$payment_status);
}else{
$this->assign('payment_status','');
}
if($payment_status !== '') $map[]=['pay.status','=',"$payment_status"];
$this->assign('payment_status',$payment_status ?: '');
//区域
$area_id = Request::get('area_id');
if($area_id){
$map[] = ['station.area_id','=',$area_id];
$this->assign('area_id',$area_id);
}else{
$this->assign('area_id','');
}
if($area_id) $map[] = ['station.area_id','=',$area_id];
$this->assign('area_id',$area_id ?: '');
//创建时间查询条件
$dateStart = strtotime(Request::get('date_start'));
$dateEnd = strtotime(Request::get('date_end'));
......@@ -114,48 +128,65 @@ class Payment extends Base
$page =Request::param('page')?Request::param('page'):1;
$limit = Request::param('limit')?Request::param('limit'):10;
$region=new ElectricMeter();
$data = (new EmPayment())->getPaymentList($map,$page,$limit);
$emPaymentModel = new EmPayment();
$data = $emPaymentModel->getPaymentList($map,$page,$limit);
$PaymentCount = (new EmPayment())->getPaymentCount($map);
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$PaymentCount,'data'=>$data];
}
$this->assign('regions',getTree($region->regions()));
return $this->fetch();
}
//批量生成缴费单
public function createAll(){
$ids = Request::param('ids');
//todo:优先锁定ids的状态,不能再次生成缴费单
//首先查询这些账单是否具备生成条件
$eiModel = new EmInvoice();
$invs = $eiModel->where('payment_balance','neq',0)
->where(['invoice_id'=>$ids])->order('invoice_id asc')->select();
$invs = $eiModel->alias('a')
->field('a.*,b.em_type_id')
->join(['em'=>'b'],'a.em_id = b.id')
->where('a.payment_balance','neq',0)
->where(['a.invoice_id'=>$ids])->order('a.invoice_id asc')->select();
if($invs->isEmpty()) {
$invIds = implode(',',$ids);
return json(['status'=>0,'message'=>'账单号: '.$invIds.' 不能重复生成缴费单!']);
return json(['status'=>0,'message'=>'账单号: '.$invIds.' 已缴清,不能重复生成缴费单!']);
}
$rInvs = [];
foreach ($invs as $inv){
if($inv->em_type_id == 2 || $inv->em_type_id ==4){
$rInvs[] = $inv['invoice_id'];
}
}
if(!empty($rInvs)){
$rInvsStr = implode(',',$rInvs);
return json(['status'=>0,'message'=>'账单号: '.$rInvsStr.'未充值卡表账单,不能进行合并缴费']);
}
//过滤不可以生成缴费单的账单ID
$idsArr = [];
$amount = 0;
foreach ($invs as $inv){
//未生成缴费或已挂起
if($inv->payment_amount >= $inv->payment_balance){
$amount += $inv->payment_balance;
//是否已挂起
$paymentField = EmPaymentInvoice::field('payment_id')
$epiModel = EmPaymentInvoice::field('payment_id')
->where('invoice_id','=',$inv->invoice_id)
->order('create_time desc')->find();
if($paymentField){
if($epiModel){
//找到关联的缴费单
$payment = EmPayment::where('payment_id','=',$paymentField->payment_id)->find();
$payment = EmPayment::where('payment_id','=',$epiModel->payment_id)->find();
if(!$payment) return json(['status'=>0,'message'=>'单据:'.$epiModel->payment_id.'出现异常,单据与账单关系存在,但缴费单不存在!']);
//如果缴费单并未缴费
if($payment->amount == 0){
$message = '账单号: '.$inv->invoice_id.' 已经挂起,无法生成缴费单';
if($payment->amount > 0){
$message = '账单号: '.$inv->invoice_id.' 已经与缴费单:'.$payment->payment_id.'挂起,无法生成缴费单';
return json(['status'=>0,'message'=>$message]);
} else {
$idsArr[] = $inv->invoice_id;
......@@ -163,7 +194,7 @@ class Payment extends Base
} else {
$idsArr[] = $inv->invoice_id;
}
}
}
$ids = $idsArr;
......@@ -183,15 +214,15 @@ class Payment extends Base
throw new Exception('保存账单与缴费关联数据失败');
};
$account = (new EmAccount())->getIdByInvoiceID($paymentInvoiceArr[0]['invoice_id']);
//3.将账单数据汇总写入缴费表
$pData = [];
$pData['amount'] = 0;
$pData['payment_id'] = $paymentId;
$pData['status'] = 0;
$pData['account_id'] = $account->account_id;
$pData['balance'] = $pData['amount'];
$pData['status'] = 1;
$pData['account_id'] = '\\'; //占位符,表示空的无效的
$pData['em_id'] = '\\'; //占位符,表示空的无效的
$pData['payment_type'] = 1;
$pData['balance'] = $pData['amount'] = round($amount,2);
if((new EmPayment())->save($pData)){
return json(['status'=>1,'message'=>'已创建缴费单']);
......@@ -209,70 +240,17 @@ class Payment extends Base
$payment = new EmPayment();
$payment->payment_id = $this->getPaymentId();
//当前用户
$user = Session::get('user');
$this->assign('uid',$user['user_id']);
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin']));
$account = (new EmAccount())->get(['em_id'=>$em_id]);
$this->assign('account',$account);
$this->assign('uid',$this->uid);
$this->assign('staffs',(new Staff())->getStaffs($this->user['is_admin']));
$this->assign('em_id',$em_id);
$this->assign('payment',$payment);
return $this->fetch();
}
//更新缴费数据 即保存缴费 记录一次缴费
// public function update(){
// $data = Request::post();
//
// //更新缴费信息
// $payment = EmPayment::get(['payment_id'=>$data['payment_id']]);
// $payment->amount = $data['paid_totle']; //记录凭证金额
// $payment->staff_id = $data['staff_id'];
// //等待审核1,2已审核 1阶段暂忽略
// //$payment->status = 1;
// $payment->status = 2;
// $payment->save();
//
// //更新账单状态
// //1.查询所有账单
// $invArr = [];
// foreach ($data['paid'] as $key => $item) {
// $invArr['invoice_id'] = $key;
// $invArr['paid_amount'] = $item['paid_amount'];
// }
// /*
// * 循环查询账单 并计算balance的数值 更新balance,并将当前的状态,同步到历史数据一份进行销账的追踪
// * 通过与balance的计算结果比较 如果balance=0,则账单状态更新为已缴费 如果不为0则更新为部分缴费
// * 账单与缴费凭证关系的建立 通过缴费单与凭证的关联关系获取,显示在账单详情中
// */
// foreach ($invArr as $item){
// $inv = EmInvoice::get(['invoice_id'=>$item['invoice_id']]);
//
// $balance = $inv->payment_balance - $inv['paid_amount'];
//
// //计算状态
// if($balance == 0){
// $inv->status = setInvoiceStatus($inv->status,self::PAYMENT_FULL_CODE,self::PAYMENT_STATUS_INDEX);
// } else {
// $inv->status = setInvoiceStatus($inv->status,self::PAYMENT_PARTIAL_CODE,self::PAYMENT_STATUS_INDEX);
// }
//
// $inv->payment_balance = $balance;
//
// //更新账单信息
// $inv->save();
// //保存销账明细,复制当前对象数据 到history表
//
// $invHistory = new EmInvoiceHistory();
//
// if(!$invHistory->save($inv->toarray())){
// throw new Exception('保存销账明细错误!');
// } else {
// return json(['status'=>1,'message'=>'缴费成功!']);
// }
// }
//
// }
//缴费单详情
public function detail(){
$payment_id = Request::param('payment_id');
......@@ -280,36 +258,40 @@ class Payment extends Base
//查询缴费单基本信息
$payment = $epModel->where('payment_id','=',$payment_id)->find();
switch ($payment->status){
case 0:
$payment->statusTitle = '未缴费';
break;
case 1:
$payment->statusTitle = '已缴费';
break;
case 2:
$payment->statusTitle = '已上传发票';
break;
case 3:
$payment->statusTitle = '凭证完整';
break;
case 4:
$payment->statusTitle = '已审核';
break;
if($payment->status > 1 && $payment->status != 7){
$fkModel = EmPaymentFk::get(['payment_id'=>$payment->payment_id]);
$fkModel->link = config('oafk.base_url').config('oafk.link') . $fkModel->oafk_id;
} else if ($payment->status == 7) {
$fkModel = EmCheckBill::get(['mode_id'=>$payment->payment_id]);
$fkModel->oafk_numb = '';
$fkModel->link = '';
} else {
$fkModel = new EmPaymentFk();
$fkModel->oafk_numb = '';
$fkModel->link = '';
}
$payment->statusStyle = self::PAYMENT_STAUS_STYLE[$payment->status];
$this->assign('fk',$fkModel);
$payment->statusTitle = self::PAYMENT_STATUS[$payment->status];
$payment->checkNode = self::PAYMENT_STATUS_CHECK_NODE;
$this->assign('payment',$payment);
//查询账单信息
$invs = $epModel->getinvsInfo($payment->payment_id);
$amount = 0;
foreach ($invs as $inv){
if($inv->payment_balance == 0){
$inv->paid_amount = $inv->payment_amount;
} else {
$inv->paid_amount = $inv->payment_amount - $inv->payment_balance;
}
$amount += $inv->payment_balance;
}
$payment->amount = $payment->amount ?: round($amount,2);
$this->assign('invs',$invs);
//实缴金额
......@@ -324,16 +306,25 @@ class Payment extends Base
$this->assign('payment_sum_amount',$amount);
//查询凭证信息
$receipts = (new EmPaymentReceipt)->getPaymentReceiptByPaymentId($payment_id);
if(!$receipts) $receipts = [];
foreach ($receipts as &$receipt){
$receipt->file_src = trim($receipt->file_src,'.');
}
$this->assign('receipts',$receipts);
//员工列表
$user = Session::get('user');
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin']));
$account = (new EmAccount())->get(['account_id'=>$payment->account_id]);
if($account){
$em = (new \app\em\model\Em())->field('em_type_id')->get(['id'=>$account->em_id]);
if($em->em_type_id == 2 || $em->em_type_id == 4){
$this->assign('em',$em);
$this->assign('account',$account);
}
} else {
$this->assign('em',[]);
$this->assign('account',[]);
}
return $this->fetch();
}
......@@ -357,53 +348,60 @@ class Payment extends Base
/**
* 保存缴费单
* 1.保存缴费人信息
* 2.保存费状态
* 2.保存费状态
*/
public function store(){
$data = Request::post();
//如果是预付费缴费 充值卡
if(isset($data['em_id'])){
$em = (new \app\em\model\Em())->get($data['em_id']);
$validate = new AddPaymentValidate();
if(!$validate->scene('s2')->check($data))
return json(['status'=>0,'message'=>$validate->getError()]);
$paymentModel = new EmPayment;
$paymentModel->payment_type = 4;
$paymentModel->payment_type = $em->em_type_id;
$paymentModel->em_id = $data['em_id'];
//更新账户
$account = (new Account());
$account = new Account();
$accountId = $account->getAccountId($data['em_id']);
$paymentModel->payment_id = $this->getPaymentId();
$paymentModel->account_id = $accountId;
$paymentModel->balance = $data['amount'];
$paymentModel->save($data);
//如果是后付费
} else {
$certs = EmCert::where('payment_id','=',$data['payment_id'])->select();
$paymentModel->staff_id = $data['staff_id'];
$paymentModel->cid = $this->uid;
$paymentModel->payment_type = $em->em_type_id;
// $paymentModel->is_check = $em->em_type_id == 2 || $em->em_type_id == 4 ? 0 : 1;
$paymentModel->status = 0;
$receipts = EmPaymentReceipt::where('payment_id','=',$data['payment_id'])->select();
if($paymentModel->save($data))
return json(['status'=>1,'message'=>'保存缴费信成功']);
else
return json(['status'=>0,'message'=>'保存缴费信息失败']);
}
$paymentModel = EmPayment::where('payment_id','=',$data['payment_id'])->find();
/**
* 预交费审核
*/
public function checkPayment(){
$payment_id = Request::param('payment_id');
$payment = EmPayment::get(['payment_id'=>$payment_id]);
if($payment->status !== 0) return json(['status'=>0,'message'=>'单据已经审核过,不能再次审核']);
//更新实缴金额
$amount = 0 ;
foreach ($certs as $cert){
$amount += $cert->amount;
}
$paymentModel->amount = $paymentModel->balance = $amount;
//判断是否已经上传缴费凭证信息
if(!$certs->isEmpty() && !$receipts->isEmpty()){
$paymentModel->status = 3; //代表已经缴费
} else if(!$certs->isEmpty()){
$paymentModel->status = 1;
} else if(!$receipts->isEmpty()){
$paymentModel->status = 2;
}
$paymentModel->staff_id = $data['staff_id'];
$paymentModel->save();
//如果是驳回则记录驳回状态
$checkType = Request::param('checkType');
(new EmCheckBill)->check(Request::param('refuseInfo'),$this->uid,Request::controller(),$payment_id,$checkType);
if($checkType == 2) {
$payment->status = 7; //7代表被驳回
$payment->save();
return json(['status'=>1,'message'=>'单据已经驳回']);
}
return json(['status'=>1,'message'=>'保存缴费信成功']);
$payment->status = 1;
// $payment->is_check = 1;
$payment->save();
return json(['status'=>1,'message'=>'已审核']);
}
//审核通过开始销账
......@@ -443,4 +441,193 @@ class Payment extends Base
$this->assign('data',$eibs);
return $this->fetch();
}
//下推缴费单
public function payoa(){
$payment_id = Request::param('payment_id');
$payment = EmPayment::get(['payment_id'=>$payment_id]);
//获取当前登录人信息
$staff = new Staff();
if($this->user['is_admin'] == 1){
$staff = $staff->get(['name' => $this->user['name']]);
} else {
$staff = $staff->get($this->uid);
}
$invs = null ;
if($payment->payment_type == 2 || $payment->payment_type == 4){
$invs[0]['invoice_id'] = '/';
$invs[0]['charge_type'] = "维护电费";
$invs[0]['payment_amount'] = $payment->amount;
$invs[0]['proj_number'] = $this->getCbzxIdByEmId($payment->em_id);
} else {
$invs = (new EmPayment())->getinvsInfo($payment_id);
foreach ($invs as $inv){
if($inv->payment_balance == 0){
$inv->paid_amount = $inv->payment_amount;
} else {
$inv->paid_amount = $inv->payment_amount - $inv->payment_balance;
}
}
}
$this->assign('invs',$invs);
$this->assign('payment_id',$payment_id);
$this->assign('payee',$this->getGys($staff->email));
$this->assign('org',$this->getFkInfo(2));
$this->assign('payway',$this->getFkInfo(1));
return $this->fetch('pay_oa');
}
//下推付款单
public function docnumb(){
$staff = Staff::get($this->uid);
$dept = DepartmentModel::get($staff->d_id);
$post = Request::post();
$payment = EmPayment::get(['payment_id'=>$post['payment_id']]);
if($this->checkFkStatus($post['payment_id'])) return json(['status'=>0,'message'=>'该缴费单已经创建付款单无法再次创建.']);
if($this->user['is_admin']) $staffName = 'admin';
else $staffName = substr($staff->email,0,strpos($staff->email,'@'));
$details = [];
if($payment->payment_type == 2 || $payment->payment_type == 4){
$details[0]['charge_type'] = "维护电费";
$details[0]['amount'] = $payment->amount;
$details[0]['cbzxid'] = $this->getCbzxIdByEmId($payment->em_id);
} else {
$invs = (new EmPayment())->getinvsInfo($payment->payment_id);
foreach ($invs as $k => $inv){
$details[$k]['charge_type'] = "维护电费";
if($inv->payment_balance == 0){
$details[$k]['amount'] = 0;
} else if($inv->payment_amount == $inv->payment_balance){
$details[$k]['amount'] = $inv->payment_amount;
} else {
$details[$k]['amount'] = $inv->payment_amount - $inv->payment_balance;
}
$details[$k]['cbzxid'] = $this->getDetailsFields($inv->account_id);
}
}
$data = [
'title'=>$post['title'] . ' 缴费单据:'.$post['payment_id'],
'uname'=>$staffName,
'payway'=>$post['payway'],
'dept'=>$dept->name,
'payee'=>$post['payee'],
'org'=>$post['org'],
'info'=>$post['info'],
'cause'=>$post['cause'],
'date'=>$post['date'],
'details'=> $details
];
//验证单据头
$fkValidate = new AddFkInfoValidate();
if(!$fkValidate->check($data)){
return json(['status'=>0,'message'=>$fkValidate->getError()]);
}
//验证单据体
$fkDetailsValidate = new AddFkInfoDetailsValidate();
foreach ($data['details'] as $a=>$b){
if(!$fkDetailsValidate->check($b)){
return json(['status'=>0,'message'=>$fkDetailsValidate->getError()]);
}
}
//创建付款单据
$receipt = $this->createFkNumb($data);
//创建结果
$result = false;
if(!empty($receipt['data'])){
$payment->status = 2;
$fkModel = new EmPaymentFk();
$fkModel->payment_id = $payment->payment_id;
$fkModel->oafk_id = $receipt['data']['id'];
$fkModel->oafk_numb = $receipt['data']['numb'];
$fkModel->status = 1;
Db::startTrans();
try{
$payment->save();
$fkModel->save();
Db::commit();
$result = true;
} catch (\Exception $e){
$result = false;
Db::rollback();
}
}
if($result) return json(['status'=>1,'message'=>'创建单据成功']);
else return json(['status'=>0,'message'=>'创建单据失败']);
}
public function apiKey(){
return md5(config('oafk.oa_key'));
}
public function getGys($email)
{
$url = config('oafk.base_url').config('oafk.gys') . $this->apiKey();
$url .= '&email='.$email;
$res = curlGet($url);
$res = json_decode($res,true);
foreach ($res['data'] as $k => $v){
if(!empty($v['bank_info'])){
foreach ($v['bank_info'] as $a => $b){
$temp[$a] = '银行名称: '.$b['open_bank_name']. '账号: '.$b['bank_code'];
}
$res['data'][$k]['bankInfo'] = json_encode($temp);
}
}
return $res['data'];
}
//获取付款所需信息
public function getFkInfo($type){
$url = config('oafk.base_url').config('oafk.type') . $this->apiKey();
$data = ['type'=>$type];
$res = httpPOST($url, $data);
$res = json_decode($res,true);
return $res['data'];
}
//创建付款编号
public function createFkNumb($data){
$url = config('oafk.base_url').config('oafk.fk') . $this->apiKey();
$res = httpPOST($url, ['data'=>json_encode($data)]);
// $start = strpos($res,'{');
// $end = strpos($res,'}');
// $str = substr($res,$start,$end);
$res = json_decode($res,true);
return $res;
}
public function checkFkStatus($payment_id){
$res = (new EmPaymentFk())->get(['payment_id'=>$payment_id,'status'=>1]);
return $res ? true : false;
}
public function getDetailsFields($account_id,$contract=false){
$account = EmAccount::get(['account_id'=>$account_id]);
$em = \app\em\model\Em::get($account->em_id);
if($contract === true){
if(!$em) return json(['status'=>0,'message'=>'没有找到所属电表']);
return $em->contract_numb ?: '';
}
$station = Station::get(['station_id'=>$em->station_id]);
if(!$station) return json(['status'=>0,'message'=>'没有找到所属基站']);
return $station->proj_number ?: '';
}
public function getCbzxIdByEmId($em_id){
$em = \app\em\model\Em::get($em_id);
$station = \app\station\model\Station::get(['station_id'=>$em->station_id]);
return $station->proj_number;
}
}
\ No newline at end of file
<?php
namespace app\em\controller;
use app\admin\controller\Base;
use app\em\model\EmInvoice;
use app\em\model\EmPaymentReceipt;
use app\em\model\EmReceiptType;
use app\em\validate\AddReceiptValidate;
use think\facade\Request;
/**
* 缴费发票
* Class Receipt
* @package app\em\controller
*/
class Receipt extends Base
{
//显示缴费凭证表单
public function create(){
$payment_id = Request::param('payment_id');
//将缴费应缴金额传递给模板
$balance = (new EmInvoice())->alias('ei')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.invoice_id=ei.invoice_id')
->where('epi.payment_id','=',$payment_id)
->where('ei.payment_balance','>',0)
->sum('ei.payment_balance');
$this->assign('balance',$balance?:0);
$this->assign('payment_id',$payment_id);
$types = EmReceiptType::select();
$this->assign('types',$types);
return $this->fetch();
}
public function store(){
$data = Request::post();
$validata = new AddReceiptValidate();
if(!$validata->check($data)){
return json(['status'=>0,'message'=>$validata->getError()]);
}
//获取certId
$data['receipt_id'] = $this->createReceiptId();
//保存凭证
$receiptModel = new EmPaymentReceipt();
if($receiptModel->save($data)){
//更新缴费单状态
return json(['status'=>1,'message'=>'上传发票成功']);
} else {
return json(['status'=>0,'message'=>'添加发票失败']);
}
}
//查看列表
public function receipts(){
$payment_id = Request::param('payment_id');
$list = EmPaymentReceipt::with('file,types')->where('payment_id','=',$payment_id)->order('receipt_id asc')->select();
foreach ($list as &$item){
if(!empty($item->file->src)){
$item->file->src = ltrim($item->file->src,'.');
}
}
$this->assign('data',$list);
return $this->fetch('list');
}
//创建凭证id
private function createReceiptId(){
$epr = EmPaymentReceipt::field('id')->order('id desc,create_time desc')->find();
if(!$epr) $id = 1;
else $id = $epr->id + 1;
return "RT".date('Ymd').zero($id);
}
}
\ No newline at end of file
......@@ -6,12 +6,8 @@
namespace app\em\controller;
use app\admin\controller\Base;
use app\admin\model\DepartmentModel;
use app\admin\model\ElectricMeter;
use app\admin\model\ElectricMeterType;
use app\admin\model\OperatorModel;
use app\admin\model\StaffModel;
use app\admin\model\BaseStationModel;
use think\db;
use think\Exception;
use think\facade\Request;
......
......@@ -9,7 +9,6 @@ use app\em\model\Staff;
use app\em\model\Station;
use app\em\model\UseageDetail;
use app\em\validate\UseageGeneralInfoValidate;
use think\Db;
use think\facade\Request;
use think\facade\Session;
......@@ -94,14 +93,14 @@ class Useage extends Base
}
//生成抄表单
public function create($detail=false){
public function create(){
$em_id = Request::param('id');
if(!(new Em())->checkEmComplete($em_id)){
$this->error('电表信息不完整,需要补充基础信息','/em');
}
$em = (new \app\em\model\Em)->getEmUseageInfoById($em_id,$detail);
$em = (new \app\em\model\Em)->getEmUseageInfoById($em_id,false);
//基站信息
$station_info = Station::getBaseInfoById($em->station_id);
......@@ -115,7 +114,7 @@ class Useage extends Base
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin'],'','useage'));
$this->assign('em',$em);
$this->assign('detail',$detail);
$this->assign('detail',false);
return $this->fetch('default');
}
......@@ -152,7 +151,12 @@ class Useage extends Base
//数据验证
$validate = new UseageGeneralInfoValidate();
//根据计量模式 验证去表单数据
if(!$validate->scene('s1')->check($data)){
$sence = 's1';
if($data['pricing_type'] == 2){
$sence = 's2';
}
if(!$validate->scene($sence)->check($data)){
return json(['status'=>0,'message'=>$validate->getError()]);
}
//获取电表基本信息
......@@ -161,15 +165,15 @@ class Useage extends Base
if(empty($useage_id)) {
$uModel = new \app\em\model\Useage();
$uModel->useage_id = $this->getUId();
$user = Session::get('user');
$uModel->uid = $user['user_id'];
$uModel->uid = $this->uid;
$uModel->last_sum_numb = $data['last_numb'];
$uModel->last_date = $data['last_date'];
$uModel->em_id = $data['em_id'];
$uModel->amount = isset($data['amount']) ? $data['amount'] : 0;
//峰谷类型
$uModel->type = $data['pricing_type'];
}
else {
} else {
$this->checkEnd($useage_id);
$action = '修改';
$uModel = (new \app\em\model\Useage())->get(['useage_id' => $useage_id]);
......@@ -226,9 +230,8 @@ class Useage extends Base
$useage->save();
//触发销账逻辑
$result = (new Invoice())->writeOffFromInvoice($inv->invoice_id,$inv->account_id);
$result = (new WriteOff())->writeOffFromInvoice($inv->invoice_id);
return json(['status'=>1,'message'=>"已审核,并生成账单,$result"]);
//return json(['status'=>1,'message'=>"已审核,并生成账单"]);
}
//获取单号
......@@ -310,16 +313,9 @@ class Useage extends Base
return true;
}
//审核
public function verify($usage_id,$status=2){
$user = Session::get('user');
$cModel = new EmCheckBill();
$cModel->info = Request::param('refuseInfo');
$cModel->uid = $user['user_id'];
$cModel->mode = 'useage';
$cModel->mode_id = $usage_id;
$cModel->status = $status;
$cModel->save();
(new EmCheckBill)->check(Request::param('refuseInfo'),$user['user_id'],Request::controller(),$usage_id,$status);
}
}
\ No newline at end of file
<?php
/**
* v2 抄表模块
*/
namespace app\em\controller;
use app\admin\controller\Base;
use app\em\model\Staff;
use app\em\model\Station;
use app\em\model\UseageDetail;
use app\em\validate\UseageGeneralInfoValidate;
use think\facade\Request;
use think\facade\Session;
class Useage extends Base
{
//获取抄表单列表
public function index(){
$map=[];
//权限检测
$user = Session::get('user');
if(!$user['is_admin']){
$permissionData=check_data();
if($permissionData){
$map[]=$permissionData;
}
}
$this->assign('admin',$user['is_admin']);
$search_text = Request::get('search_text');
$search_type = Request::get('search_type');
if($search_text){
switch ($search_type) {
case '1':
$this->assign('search_text',$search_text);
$map[]=['ue.useage_id','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '2':
$this->assign('search_text',$search_text);
$map[]=['station.station_name','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '3':
$this->assign('search_text',$search_text);
$map[]=['em.em_numb','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
}
}else{
$this->assign('search_type','');
$this->assign('search_text','');
}
//抄表时间查询条件
$dateStart = strtotime(Request::get('date_start'));
$dateEnd = strtotime(Request::get('date_end'));
//区间查询
if( !empty($dateStart) && !empty($dateEnd) ){
$map[] = ['ue.current_date','between',[$dateStart,$dateEnd]];
$this->assign('date_start',Request::get('date_start'));
$this->assign('date_end',Request::get('date_end'));
} elseif (!empty($dateStart) && empty($dateEnd)){
$map[] = ['ue.current_date','>',$dateStart];
$this->assign('date_start',Request::get('date_start'));
$this->assign('date_end','');
} elseif (empty($dateStart) && !empty($dateEnd)){
$map[] = ['ue.current_date','<',$dateEnd];
$this->assign('date_end',Request::get('date_end'));
$this->assign('date_start','');
}else{
$this->assign('date_start','');
$this->assign('date_end','');
}
$page =Request::param('page')?Request::param('page'):1;
$limit = Request::param('limit')?Request::param('limit'):10;
$data = (new \app\em\model\Useage)->getCopyList($map,$page,$limit);
$copyCount = (new \app\em\model\Useage)->getCopyListCount($map);
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$copyCount,'data'=>$data];
}
return $this->fetch();
}
//生成抄表单
public function create($detail=false){
$em_id = Request::param('id');
if(!(new Em())->checkEmComplete($em_id)){
$this->error('电表信息不完整,需要补充基础信息','/em');
}
$em = (new \app\em\model\Em)->getEmUseageInfoById($em_id,$detail);
//基站信息
$station_info = Station::getBaseInfoById($em->station_id);
$this->assign('station',$station_info);
//当前用户
$user = Session::get('user');
$this->assign('uid',$user['user_id']);
//员工列表
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin'],'','useage'));
$this->assign('em',$em);
if($em->rule->pricing_type == 1){
$template = 'default';
} else {
$template = 'special';
}
$this->assign('detail',$detail);
return $this->fetch($template);
}
//保存抄表单
public function store(){
//获取表单数据
$data = Request::post();
//数据验证
$validate = new UseageGeneralInfoValidate();
//根据计量模式 验证去表单数据
if(!$validate->scene('s'.$data['pricing_type'])->check($data)){
return json(['status'=>0,'message'=>$validate->getError()]);
}
//获取电表基本信息
$em = (new \app\em\model\Em)->getEmInfoById(['id'=>$data['em_id']],'rule');
//保存抄表单
$uModel = new \app\em\model\Useage();
//如果是普通计量模式
if($data['pricing_type'] != 1){
$data['current_sum_numb'] = $data['current_numb'];
$data['last_sum_numb'] = $data['last_numb'];
}
//生成抄表单ID
$data['useage_id'] = $this->getUId();
$uModel->save($data);
//抄表详情更新
$udModel = new UseageDetail(); //抄表详情模型
//如果是普通计量模式
if($data['pricing_type'] == 1){
//添加抄表详情记录
$data['type'] = 5; //保存详情类型 5->default
$udModel->save($data);
//更新主表
$data['type'] = $data['pricing_type']; //保存峰谷信息
$data['last_sum_numb'] = $data['last_numb'];
$data['current_sum_numb'] = $data['current_numb'];
$uModel->save($data);
} else {
$typeArr = [];
$data['last_sum_numb'] = 0;
$data['current_sum_numb'] = 0;
for ($i=0;$i<4;$i++){
$temp = $data;
$last_key = 'uType'.($i+1).'_last_numb';
$curr_key = 'uType'.($i+1).'_current_numb';
$price_key = 'uType'.($i+1).'_price';
//组装峰谷信息
$temp['type'] = $i+1;
$temp['last_numb'] = $data[$last_key];
$temp['current_numb'] = $data[$curr_key];
$temp['price'] = $data[$price_key];
//抄表汇总记录
$data['last_sum_numb'] += $temp['last_numb'];
$data['current_sum_numb'] += $temp['current_numb'];
$typeArr[] = $temp;
}
$udModel->saveAll($typeArr);
//更新主表
$data['type'] = $data['pricing_type']; //保存峰谷信息
$uModel->save($data);
}
return json(['status'=>1,'message'=>'添加抄表记录成功']);
}
/**
* 审核抄表单并生成账单
*/
public function check(){
$useage_id = Request::param('useage_id');
$useage = \app\em\model\Useage::get(['useage_id' => $useage_id]);
if($useage->status == 2) return json(['status'=>0,'message'=>'该抄表单已经生成了账单']);
$inv = (new Invoice())->createInvoice($useage_id);
$useage->status = 2;
$useage->save();
//触发销账逻辑
$result = (new Invoice())->writeOffFromInvoice($inv->invoice_id,$inv->account_id);
return json(['status'=>1,'message'=>"已审核,并生成账单,$result"]);
//return json(['status'=>1,'message'=>"已审核,并生成账单"]);
}
//获取单号
private function getUId(){
$uModel = \app\em\model\Useage::field('id')->order('id desc,create_time desc')->find();
if(!$uModel) $id = 1;
else $id = $uModel->id + 1;
return "CB".date('Ymd').zero($id);
}
/**
* 通过useage_id获取抄表单详情
* 通过useage_id找到电表类型
* 通过电表类型判断是否是峰谷表
* 如果是峰谷表就显示峰谷的详情
* 如果不是峰谷表就显示单条记录
*/
public function detail(){
$uid = Request::param('useage_id');
$useage = (new \app\em\model\Useage)->alias('u')
->field('u.*,em.rate')
->field('emr.pricing_type')
->leftJoin(['em'],'em.id=u.em_id')
->leftJoin(['em_rule'=>'emr'],'emr.em_id=em.id')
->where('u.useage_id','=',$uid)
->find();
$em = (new \app\em\model\Em())->getBaseInfo($useage->em_id);
$user = Session::get('user');
if($useage){
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin'],$useage->staff_id));
} else {
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin']));
}
$useage->repo_numb = round(round($useage->current_sum_numb - $useage->last_sum_numb,2) * $useage->rate,2);
$this->assign('em',$em);
$this->assign('useage',$useage);
//判断是否是峰谷表
if($useage->pricing_type == 2){
//获取峰谷表详情
$useage_detail = (new UseageDetail())->where('useage_id','=',$uid)->select()->toArray();
foreach ($useage_detail as &$ud){
switch ($ud['type']){
case 1:
$ud['typeName'] = '尖峰段';
break;
case 2:
$ud['typeName'] = '峰段';
break;
case 3:
$ud['typeName'] = '谷段';
break;
case 4:
$ud['typeName'] = '平段';
break;
default:
$ud['typeName'] = '普通';
break;
}
}
$this->assign('useage_detail',$useage_detail);
return $this->fetch('detail_special');
} else {
return $this->fetch('detail');
}
}
public function del(){
$uid = Request::param('uid');
$useage = (new \app\em\model\Useage())->get(['useage_id'=>$uid]);
$useage_details = (new UseageDetail())->select(['useage_id'=>$uid]);
if(!$useage){
return json(['status'=>0,'message'=>"删除异常,未找到单据编号,请联系管理员"]);
}
if($useage->delete()){
if(!$useage_details->isEmpty()){
foreach ($useage_details as $k => $v){
unset($useage_details[$k]);
}
}
return json(['status'=>1,'message'=>"删除单据成功"]);
} {
return json(['status'=>0,'message'=>"删除异常,单据删除失败,请联系管理员"]);
}
}
}
\ No newline at end of file
<?php
namespace app\em\controller;
use app\em\model\EmInvoice;
use app\em\model\EmPayment;
use app\em\model\EmPaymentInvoice;
use app\em\model\EmPaymentInvoiceBalance;
use think\Controller;
use think\facade\Log;
class WriteOff extends Controller
{
public function writeOffFromPayment($payment_id){
Log::info('触发销账:{$payment_id}');
//获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find();
$invModel = new EmInvoice();
//获取关联的账单对象
$invs = $invModel->alias('a')->field('a.invoice_id')
->join(['em_payment_invoice'=>'b'],'b.invoice_id = a.invoice_id')
->where('b.payment_id','=',$payment_id)
->where('a.payment_balance','neq',0)
->order('a.invoice_id asc')
->select();
$invsArr = [];
$payments_balance = 0;
//如果存在账单关联对象
if(!$invs->isEmpty()){
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
//查询可消的额度
$payments_balance = $invModel->where('invoice_id','in',$invsArr)->sum('payment_balance');
}
if($payment->balance > $payments_balance) {
//如果可以完全销账 则继续销账
$invss = $invModel->field('invoice_id')
->where('account_id', '=', $payment->account_id)
->where('payment_balance', 'neq', 0)
->whereNotIn('invoice_id', $invsArr)
->order('invoice_id asc')
->select();
if (!$invss->isEmpty()) {
foreach ($invss as $inv) {
$invsArr[] = $inv->invoice_id;
}
}
}
$paymentIds[] = $payment->payment_id;
//销账日志
$logMsg = date('Y-m-d H-i-s').'paymentIds :' .implode('-',$paymentIds) .'invoiceIds :' .implode('-',$invsArr);
Log::info($logMsg);
//处理账户金额
return $this->writeOff($paymentIds,$invsArr);
}
/**
* 账单触发销账,invoice_id 1:n payment_id
* @param $account_id
* @param $invoice_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return mixed
*/
public function writeOffFromInvoice($invoice_id){
//获取账单对象
$invoice = EmInvoice::field('id,invoice_id,account_id,payment_amount,payment_balance')
->where('invoice_id','=',$invoice_id)->find();
//查询关系表中与当前invoice_id相关联的payment_id
$model = new EmPaymentInvoice;
$payments = $model->alias('epi')->field('epi.payment_id')
->leftJoin(['em_payment'=>'ep'],'epi.payment_id = ep.payment_id')
->leftJoin(['em_payment_invoice_balance'=>'epib'],'epib.invoice_id=epi.invoice_id')
->where('epib.balance','>',0)
->where('epi.invoice_id','=',$invoice_id)->select();
//如果没有找到记录 证明并没有形成对应关系
if($payments->isEmpty()){
//查询是否有未缴费的缴费单存在
$payments = EmPayment::field('payment_id')->where('account_id','=',$invoice->account_id)
->where('balance','>',0)
->whereIn('status','3,4,5')
->order('payment_id asc')
->select();
if($payments->isEmpty()) return '没有找到可销账的缴费单!';
}
$paymentIds = [];
foreach ($payments as $payment){
$paymentIds[] = $payment->payment_id;
}
$invsIds = [
'invoice_id' => $invoice->invoice_id
];
//销账日志
$logMsg = date('Y-m-d H-i-s').'paymentIds :' .implode('-',$paymentIds) .'invoiceIds :' .implode('-',$invsIds);
Log::info($logMsg);
//开始销账
return $this->writeOff($paymentIds,$invsIds);
}
/**
* @param $account_id
* @param $invoiceIds
* @param $paymentIds
* @return mixed
*/
private function writeOff($paymentIds,$invoiceIds){
Log::info('执行销账:');
//获取可销账缴费单
$payments = EmPayment::where('payment_id','in',$paymentIds)->order('payment_id asc')->select();
//获取可销账账单
$invs = EmInvoice::where('invoice_id','in',$invoiceIds)->order('invoice_id asc')->select();
$result = 0;
foreach ($payments as $key => $payment){
if($payment->balance == 0) continue;
foreach ($invs as $index => $inv) {
if ($inv->payment_balance == 0) continue;
$balanceMode = new EmPaymentInvoiceBalance();
$balanceMode->payment_id = $payment->payment_id;
$balanceMode->invoice_id = $inv->invoice_id;
//如果该缴费单可以完全消除当前账单额度
if ($payment->balance >= $inv->payment_balance) {
//单笔销账多少
$balanceMode->balance = $inv->payment_balance;
$payment->balance = $payment->balance - $inv->payment_balance;
//账单额度变化
$inv->payment_balance = 0;
//更新账户status 首字母 = 2
$inv->status = setInvoiceStatus($inv->status, 2);
} else {
//单笔销账多少
$balanceMode->balance = $payment->balance;
//账单额度变化
$inv->status = setInvoiceStatus($inv->status, 1);
$inv->payment_balance = $inv->payment_balance - $payment->balance;
//缴费额度变化
$payment->balance = 0;
}
//更新账单状态
$inv->save();
//更新缴费状态
$payment->save();
//查找是否已经存在相关联的账单关系
$model = (new EmPaymentInvoice())->where(['payment_id'=>$payment->payment_id,'invoice_id'=>$inv->invoice_id])->find();
if(!$model){
$model = new EmPaymentInvoice();
$model->payment_id = $payment->payment_id;
$model->invoice_id = $inv->invoice_id;
$model->save();
}
$result++;
$balanceMode->isUpdate(false)->save();
// if($inv->is_pay != 1) $this->computerAmount($inv->account_id,$dk_balance);
}
}
$msg = $result == 0 ? '已审核,没有找到可销账的缴费单.' : '已审核,成功销账 '.$result.' 笔账单.';
return $msg;
}
}
\ No newline at end of file
......@@ -54,19 +54,20 @@ class Em extends Base
//最后一次抄表记录
if($curr == false){
$ue = Useage::order('create_time desc,id desc')->get(['em_id'=>$id]);
} else {
$ue = Useage::with('photo')->order('create_time desc,id desc')->get(['em_id'=>$id]);
}
//如果没有超过表 不论是峰谷表还是普通表 都是空的
if(!$ue) {
$ue = new Useage();
$ue->last_date = $em->init_date;
$ue->last_sum_numb = $em->init_numb ?: 0;
$ue->amount = 0;
} else {
if($curr == false){
$ue->last_sum_numb = $ue->current_sum_numb;
$ue->last_date = $ue->current_date;
}
$ue->amount = 0;
}
$ue->price = $em->rule->pricing_type==1 ? $em->rule->pay_price : '';
$em->useage = $ue;
......@@ -76,7 +77,7 @@ class Em extends Base
//获取电表信息与station信息
public function getBaseInfo($em_id){
$data = self::field('em.id,em.em_numb,em.em_type_id,em.rate')
->field('s.station_sp_code,s.station_name')
->field('s.station_sp_code,s.station_name,s.proj_number')
->field('et.name as typeName')
->leftJoin(['station_info'=>'s'],'s.station_id=em.station_id')
->leftJoin(['em_type'=>'et'],'et.id=em.em_type_id')
......
<?php
namespace app\em\model;
class EmAccountAmount extends Base
{
protected $table = 'em_account_amount';
}
\ No newline at end of file
<?php
namespace app\em\model;
class EmCheckBill extends Base
{
public function check($info,$uid,$mode,$mode_id,$status){
$this->info = $info;
$this->uid = $uid;
$this->mode = $mode;
$this->mode_id = $mode_id;
$this->status = $status;
$this->save();
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ class EmInvoice extends Base
public function getInvoiceList($map,$Nowpage,$limits){
$data = self::alias('inv')
->field('inv.*')
->field('station.station_name,em.em_numb')
->field('station.station_name,em.em_numb,em.em_type_id')
->field('eu.last_sum_numb,eu.current_sum_numb,eu.current_date,FROM_UNIXTIME(eu.current_date,"%Y-%m-%d %H:%i:%S") as now_date,eu.em_id')
->join(['em_invoice_useage'=>'eiu'],'eiu.invoice_id = inv.invoice_id')
->join(['em_useage'=>'eu'],'eu.useage_id = eiu.useage_id')
......@@ -87,12 +87,13 @@ class EmInvoice extends Base
$data = self::alias('inv')
->field('inv.*')
->field('station.station_name')
->field('em.em_numb')
->field('em.em_numb,em.em_type_id')
->join(['em_account'=>'ea'],'ea.account_id = inv.account_id')
->join(['em'],'em.id=ea.em_id')
->join(['station_info'=>'station'],'station.station_id=em.station_id')
->where(['inv.invoice_id'=>$ids])
// ->where('inv.payment_balance','neq',0)
->whereNotIn('em.em_type_id','2,4')
->where('inv.payment_balance','neq',0)
->select();
return $data;
}
......@@ -116,7 +117,7 @@ class EmInvoice extends Base
$eiu = EmInvoiceUseage::where(['invoice_id'=>$inv->invoice_id])->find();
//查询抄表信息
$useage = Useage::get(['useage_id'=>$eiu->useage_id]);
$useage = Useage::with('photo')->get(['useage_id'=>$eiu->useage_id]);
if($useage->photo_id) {
$receipt = Receipt::get(['id'=>$useage->photo_id]);
......
<?php
namespace app\em\model;
use app\em\controller\Payment;
class EmPayment extends Base
{
protected $table = 'em_payment';
public function getPayDateAttr($val){
if($val =='' || $val == 0){
return '尚未付款';
}
return date('Y-m-d H:i:s',$val);
}
public function setPayDateAttr($val){
if(is_int($val) && strlen($val) >= 10) return $val;
if(date('Y-m-d H:i:s',strtotime($val)) == $val){
return strtotime($val);
}
return 0;
}
//缴费单+search
public function getPaymentList($map,$Nowpage,$limits){
......@@ -18,31 +26,53 @@ class EmPayment extends Base
//先找到账单
$data = self::alias('pay')
->field('pay.*')
->field('case pay.status
when 0 then "未缴费"
when 1 then "已缴费"
when 2 then "已上传发票"
when 3 then "凭证完整"
when 4 then "已审核"
end as status')
->field('epi.invoice_id')
->field('em.em_numb')
->field('r.region_name,station.station_name')
->leftJoin(['em_account'=>'ea'],'ea.account_id=pay.account_id')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.payment_id = pay.payment_id')
->leftJoin(['em_invoice'=>'ei'],'ei.invoice_id=epi.invoice_id')
->leftJoin(['em_account'=>'ea'],'ea.account_id=ei.account_id')
->leftJoin(['em'],'em.id=ea.em_id')
->leftJoin(['station_info'=>'station'],'station.station_id=em.station_id')
->leftJoin(['region'=>'r'],'station.area_id = r.id')
->where($map)
->order('pay.id desc')
->group('pay.payment_id')
->page($Nowpage, $limits)
->select()
->toarray();
$arr = [];
foreach ($data as $v){
$arr[] = $v['payment_id'];
}
$data2 = self::alias('pay')
->field('pay.*')
->field('em.em_numb,r.region_name,station.station_name')
->leftJoin(['em_account'=>'ea'],'ea.account_id=pay.account_id')
->leftJoin(['em'],'em.id=ea.em_id')
->leftJoin(['station_info'=>'station'],'station.station_id=em.station_id')
->leftJoin(['region'=>'r'],'station.area_id = r.id')
->where($map)
->whereNotIn('pay.payment_id',$arr)
->order('pay.id desc')
->group('pay.payment_id')
->page($Nowpage, $limits)
->select()
->toarray();
$data = array_merge($data,$data2);
$sortKey = [];
foreach ($data as $k=>$item){
$data[$k]['amount'] = round($data[$k]['amount'],3);
$data[$k]['amount'] = round($data[$k]['amount'],2);
$data[$k]['status'] = Payment::PAYMENT_STATUS[$item['status']];
$data[$k]['payment_type'] = Payment::PAYMENT_TYPE[$item['payment_type']];
$sortKey[$k] = $item['create_time'];
}
array_multisort($sortKey, SORT_DESC, $data);
return $data;
}
public function getPaymentCount($map){
......@@ -50,16 +80,29 @@ class EmPayment extends Base
//先找到账单
$data = self::alias('pay')
->field('pay.*')
->field('epi.invoice_id')
->field('em.em_numb')
->field('r.region_name')
->join(['em_account'=>'ea'],'ea.account_id=pay.account_id')
->field('r.region_name,station.station_name')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.payment_id = pay.payment_id')
->join(['em'],'em.id=ea.em_id')
->join(['station_info'=>'station'],'station.station_id=em.station_id')
->join(['region'=>'r'],'station.area_id = r.id')
->leftJoin(['em_invoice'=>'ei'],'ei.invoice_id=epi.invoice_id')
->leftJoin(['em_account'=>'ea'],'ea.account_id=ei.account_id')
->leftJoin(['em'],'em.id=ea.em_id')
->leftJoin(['station_info'=>'station'],'station.station_id=em.station_id')
->leftJoin(['region'=>'r'],'station.area_id = r.id')
->where($map)
->count();
return $data;
$data2 = self::alias('pay')
->field('pay.*')
->field('em.em_numb,r.region_name,station.station_name')
->leftJoin(['em_account'=>'ea'],'ea.account_id=pay.account_id')
->leftJoin(['em'],'em.id=ea.em_id')
->leftJoin(['station_info'=>'station'],'station.station_id=em.station_id')
->leftJoin(['region'=>'r'],'station.area_id = r.id')
->where($map)
->count();
return intval($data + $data2);
}
//通过缴费单id返回缴费单关联账单信息
public function getinvsInfo($payment_id){
......@@ -74,7 +117,7 @@ class EmPayment extends Base
$invModel = new EmInvoice();
$invs = $invModel->alias('inv')
->field('inv.*')
->field('station.station_name')
->field('station.station_name,station.proj_number')
->field('em.em_numb')
->leftJoin(['em_invoice_useage'=>'eiu'],'eiu.invoice_id=inv.invoice_id')
->leftJoin(['em_useage'=>'eu'],'eu.useage_id = eiu.useage_id')
......
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2020-3-31
* Time: 0:54
*/
namespace app\em\model;
class EmPaymentAccount extends Base
{
}
\ No newline at end of file
<?php
namespace app\em\model;
class EmPaymentFk extends Base
{
protected $table = 'em_payment_fk';
}
\ No newline at end of file
<?php
namespace app\em\model;
class EmPaymentMonthly extends Base
{
public function getCurrentMonthly($em_id){
$data = self::field('month')->where('em_id','=',$em_id)->order('id desc')->find();
return isset($data->month) ? $data->month : 0;
}
}
\ No newline at end of file
<?php
/**
* v2 账单模块
*/
namespace app\em\controller;
use app\admin\controller\Base;
use app\em\model\EmInvoice;
use app\em\model\EmInvoiceHistory;
use app\em\model\EmInvoiceUseage;
use app\em\model\EmPayment;
use app\em\model\EmPaymentHistory;
use app\em\model\EmPaymentInvoice;
use app\em\model\EmPaymentInvoiceBalance;
use app\em\model\EmSettle;
use app\em\model\EmSettleInvoice;
use app\em\model\EmSettleInvoiceBalance;
use app\em\model\UseageDetail;
use think\facade\Request;
use think\facade\Session;
class Invoice extends Base
{
//账单列表
public function index(){
$map=[];
//权限检测
$user = Session::get('user');
if(!$user['is_admin']){
$permissionData=check_data();
if($permissionData){
$map[]=$permissionData;
}
}
$search_text = Request::get('search_text');
$search_type = Request::get('search_type');
if($search_text){
switch ($search_type) {
case '1':
$this->assign('search_text',$search_text);
$map[]=['inv.invoice_id','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '2':
$this->assign('search_text',$search_text);
$map[]=['station.station_name','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '3':
$this->assign('search_text',$search_text);
$map[]=['em.em_numb','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
}
}else{
$this->assign('search_type','');
$this->assign('search_text','');
}
$page =Request::param('page')?Request::param('page'):1;
$limit = Request::param('limit')?Request::param('limit'):10;
$data = (new EmInvoice)->getInvoiceList($map,$page,$limit);
foreach ( $data as $key => &$v) {
$v['status']=parseStatus($v['status']);
}
$InvoiceCount = (new EmInvoice)->getInvoiceCount($map);
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$InvoiceCount,'data'=>$data];
}
return $this->fetch();
// $data = (new EmInvoice)->getList();
//
// $page = $data->render();
//
// $this->assign('data',$data);
// $this->assign('page',$page);
// return $this->fetch();
}
//查看账单信息
public function detail(){
$inv_id = Request::param('id');
$invInfo = (new EmInvoice)->getInvoiceDetail($inv_id);
$this->assign('inv',$invInfo);
return $this->fetch();
}
//创建一个账单
public function createInvoice($useage_id){
$um = (new \app\em\model\Useage)->getEmInfoByUseageId($useage_id)->toArray();
return $this->create($um);
}
//创建账单
public function create($um){
/// 如果是普通表 则
if($um['pricing_type'] == 1){
return $this->createInvoiceStdType($um);
} else if($um['pricing_type'] == 2){
return $this->createInvoiceSpecialType($um);
}
}
/**
* 生成账单号
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function getInvoiceId(){
$inv = EmInvoice::field('id')->order('id desc,create_time desc')->find();
if(!$inv) $id = 1;
else $id = $inv->id + 1;
return "ZD".date('Ymd').zero($id);
}
//普通读表生成账单
public function createInvoiceStdType($uData){
$inv = new EmInvoice();
$inv->type = 4;
$inv->rate = $uData['rate'];
$inv->repo_numb = ($uData['current_sum_numb'] - $uData['last_sum_numb']) * $uData['rate'];
$inv->payment_amount = $inv->payment_balance = $inv->repo_numb * $uData['pay_price'];
//结算信息
$inv->settle_amount = $inv->settle_balance = $inv->repo_numb * $uData['settle_price'];
$inv->status = '000';
$inv->invoice_id = $this->getInvoiceId();
//获取账户ID
$inv->account_id = (new Account())->getAccountId($uData['em_id']);
//保存 并且更新抄表单与账单关联表
if($inv->save()){
$eiu = new EmInvoiceUseage();
$eiu->invoice_id = $inv->invoice_id;
$eiu->useage_id = $uData['useage_id'];
$eiu->save();
}
//更新电表账户
$useage = \app\em\model\Useage::get(['useage_id' => $uData['useage_id']]);
$account = new Account();
$account->updateAmount($useage->em_id,$inv->payment_amount,0);
return $inv;
}
//峰谷表生成账单
public function createInvoiceSpecialType($uData){
$inv = new EmInvoice();
$inv->type = 1;
$inv->rate = $uData['rate'];
//获取峰谷表抄表明细
$uds = UseageDetail::where(['useage_id'=>$uData['useage_id']])->select()->toArray();
//计算总价信息
//需要计算4个属性 各分段上一次 档次 repo amount
$last_numb = 0;
$curr_numb = 0;
$amount = 0;
$repo_numb = 0;
foreach ($uds as $v){
$last_numb += $v['last_numb'];
$curr_numb += $v['current_numb'];
$amount += (int)($v['current_numb'] - $v['last_numb']) * $v['price'];
$repo_numb += (int)($v['current_numb'] - $v['last_numb']);
}
//曝移动电量
$inv->repo_numb = ($curr_numb - $last_numb) * $uData['rate'];
//缴费信息
$inv->payment_amount = $inv->payment_balance = $amount * $uData['rate'];
//结算信息
$inv->settle_amount = $inv->settle_balance = $repo_numb * $uData['settle_price'];
$inv->status = '000';
$inv->invoice_id = $this->getInvoiceId();
$inv->account_id = (new Account())->getAccountId($uData['em_id']);
//更新抄表单的status
$useage = \app\em\model\Useage::get(['useage_id'=>$uData['useage_id']]);
$useage->status = 2;
$useage->save();
$inv->cert_id = $useage->photo_id;
//保存 并且更新抄表单与账单关联表
if($inv->save()){
$eiu = new EmInvoiceUseage();
$eiu->invoice_id = $inv->invoice_id;
$eiu->useage_id = $uData['useage_id'];
$eiu->save();
}
return $inv;
}
public function updatePayment(){
$data = Request::param();
$inv = EmInvoice::get(['id'=>$data['id']]);
if(!$inv) return json(['status'=>0,'message'=>'不存在抄表单ID,无法更新缴费金额']);
if($data['amount'] > 0 && $inv->is_add_condition != 1){
$inv->payment_amount = $data['amount'];
$inv->payment_balance = $data['amount'];
$inv->is_add_condition = 1;
}
if($inv->save()){
return json(['status'=>1,'message'=>'缴费金额已经更新']);
}
}
//账单合并列表
public function mergeList(){
$ids = Request::param('ids');
$idsArr = [];
if(!empty($ids)){
$idsArr= explode('_',$ids);
}
$data = (new EmInvoice)->getListByInvIds($idsArr);
$payment_amount = 0;
$settle_amount = 0;
foreach ($data as $v){
$v->settle_amount = $v->settle_amount ?:0
$payment_amount += $v->payment_amount;
$settle_amount += $v->settle_amount;
}
$this->assign('data',$data);
$this->assign('payment_amount',$payment_amount);
$this->assign('settle_amount',$settle_amount);
return $this->fetch('merge_list');
}
/**
* 账单触发销账,invoice_id 1:n payment_id
* @param $account_id
* @param $invoice_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return mixed
*/
public function writeOffFromInvoice($invoice_id,$account_id){
$paymentIdsArr = [];
//获取账单对象
$invoice = EmInvoice::field('id,invoice_id,payment_amount,payment_balance')
->where('invoice_id','=',$invoice_id)->find();
//查询关系表中与当前invoice_id相关联的payment_id
$model = new EmPaymentInvoice;
$payments = $model->alias('epi')->field('epi.payment_id')
->leftJoin(['em_payment'=>'ep'],'epi.payment_id = ep.payment_id')
->leftJoin(['em_payment_invoice_balance'=>'epib'],'epib.invoice_id=epi.invoice_id')
->where('epib.balance','>',0)
->where('epi.invoice_id','=',$invoice_id)->select();
//如果没有找到记录 证明并没有形成对应关系
if($payments->isEmpty()) return '账单未缴费';
$paymentIdsArr = $payments->toArray();
//查询可消的额度
$payments_balance = (new EmPayment)->whereIn('payment_id',array_values($paymentIdsArr))->sum('balance');
//如果该账单可以完全被缴费单销账
if($payments_balance < $invoice->payment_balance){
$payments = EmPayment::field('payment_id')->where('account_id','=',$account_id)
->where('balance','neq',0)
->order('payment_id asc')
->select();
if(!$payments->isEmpty())
$paymentIdsArr = array_merge($paymentIdsArr,$payments->toArray());
}
foreach ($paymentIdsArr as $payment){
$paymentIds[] = [
'payment_id' => $payment->payment_id
];
}
$invsIds = [
'invoice_id' => $invoice->invoice_id
];
//开始销账
return $this->writeOff($paymentIds,$invsIds,$account_id);
}
//从缴费单消账单
public function writeOffFromPayment($account_id,$payment_id){
//获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find();
//获取关联的账单对象
$invs = (new EmInvoice())->alias('ei')->field('ei.invoice_id')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.invoice_id = ei.invoice_id')
->where('epi.payment_id','=',$payment_id)
->where('ei.payment_balance','neq',0)
->order('ei.invoice_id asc')
->select();
$invsArr = [];
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
//查询可消的额度
$payments_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('payment_balance');
//如果可以完全销账 则继续销账
if($payment->balance > $payments_balance){
$invs = (new EmInvoice())->field('invoice_id')
->where('account_id','=',$account_id)
->where('payment_balance','neq',0)
->order('invoice_id asc')
->select();
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
}
$paymentIds[] = $payment->payment_id;
//处理账户金额
return $this->writeOff($paymentIds,$invsArr);
}
/**
* @param $account_id
* @param $invoiceIds
* @param $paymentIds
* @return mixed
*/
private function writeOff($paymentIds,$invoiceIds){
//获取可销账缴费单
$payments = EmPayment::where('payment_id','in',$paymentIds)->select();
//获取可销账账单
$invs = EmInvoice::where('invoice_id','in',$invoiceIds)->select();
$result = 0;
foreach ($payments as $key => $payment){
if($payment->balance == 0)
continue;
foreach ($invs as $index => $inv) {
$balanceMode = new EmPaymentInvoiceBalance();
$balanceMode->payment_id = $payment->payment_id;
if ($inv->payment_balance == 0)
continue;
$balanceMode->invoice_id = $inv->invoice_id;
//如果该缴费单可以完全消除当前账单额度
if ($payment->balance >= $inv->payment_balance) {
//单笔销账多少
$balanceMode->balance = $inv->payment_balance;
//缴费额度变化
if(($payment->balance - $inv->payment_balance) == 0){
$payment->status = 4;
} else {
$payment->status = 4; //缴费部分销账
}
$payment->balance = $payment->balance - $inv->payment_balance;
//账单额度变化
$inv->payment_balance = 0;
//更新账户status 首字母 = 2
$inv->status = setInvoiceStatus($inv->status, 2);
} else {
//单笔销账多少
$balanceMode->balance = $payment->balance;
//账单额度变化
$inv->status = setInvoiceStatus($inv->status, 1);
$inv->payment_balance = $inv->payment_balance - $payment->balance;
//缴费额度变化
$payment->balance = 0;
$payment->status = 4; //缴费已经完全销账
}
$result++;
//更新账单状态
$inv->save();
//todo::history; 保存历史记录
$invData = $inv->toArray();
$invData['id'] = null;
$invData['create_time'] = strtotime($invData['create_time']);
$invData['update_time'] = strtotime($invData['update_time']);
//EmInvoiceHistory::create($invData);
unset($invs[$index]); //从结果集中去掉无效的数据
//更新状态
$payment->save();
//todo::history;保存历史记录
$payData = $payment->toArray();
$payData['id'] = null;
$payData['create_time'] = strtotime($payData['create_time']);
$payData['update_time'] = strtotime($payData['update_time']);
$payData['pay_date'] = strtotime($payData['pay_date']);
//EmPaymentHistory::create($payData);
unset($payments[$key]);
$balanceMode->isUpdate(false)->save();
}
}
$msg = $result == 0 ? '已审核,没有可销账的账单.' : '已审核,成功销账 '.$result.' 笔账单.';
return $msg;
}
public function writeOffFromSettle($account_id,$settle_id){
//获取缴费单对象
$settle = EmSettle::where('settle_id','=',$settle_id)->find();
//获取关联的账单对象
$invs = (new EmInvoice())->alias('ei')->field('ei.invoice_id')
->leftJoin(['em_settle_invoice'=>'esi'],'esi.invoice_id = ei.invoice_id')
->where('esi.settle_id','=',$settle_id)
->where('ei.settle_balance','neq',0)
->order('ei.invoice_id asc')
->select();
$invsArr = [];
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
//查询可消的额度
$settles_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('settle_balance');
//如果可以完全销账 则继续销账
if($settle->balance > $settles_balance){
$invs = (new EmInvoice())->field('invoice_id')
->where('account_id','=',$account_id)
->where('settle_balance','neq',0)
->order('invoice_id asc')
->select();
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
}
$settleIds[] = $settle->settle_id;
//处理账户金额
return $this->writeOffSettle($settleIds,$invsArr);
}
private function writeOffSettle($settleIds,$invoiceIds,$associate = false){
//获取可销账结算单
$settles = EmSettle::where('settle_id','in',$settleIds)->select();
//获取可销账账单
$invs = EmInvoice::where('invoice_id','in',$invoiceIds)->select();
$result = 0;
foreach ($settles as $key => $settle){
if($settle->balance == 0)
continue;
foreach ($invs as $index => $inv) {
$balanceMode = new EmSettleInvoiceBalance();
$balanceMode->settle_id = $settle->settle_id;
if ($inv->settle_balance == 0)
continue;
$balanceMode->invoice_id = $inv->invoice_id;
//如果该结算单可以完全消除当前账单额度
if ($settle->balance >= $inv->settle_balance) {
//单笔销账多少
$balanceMode->balance = $inv->settle_balance;
//结算额度变化
if(($settle->balance - $inv->settle_balance) == 0){
$settle->status = 4;
} else {
$settle->status = 4; //结算部分销账
}
$settle->balance = $settle->balance - $inv->settle_balance;
//账单额度变化
$inv->settle_balance = 0;
//更新账户status 首字母 = 2
$inv->status = setInvoiceStatus($inv->status, 2,1);
} else {
//单笔销账多少
$balanceMode->balance = $settle->balance;
//账单额度变化
$inv->status = setInvoiceStatus($inv->status, 1,1);
$inv->settle_balance = $inv->settle_balance - $settle->balance;
//结算额度变化
$settle->balance = 0;
$settle->status = 3; //结算已经完全销账
}
if($associate == true){
$model = new EmSettleInvoice();
$model->settle_id = $settle->settle_id;
$model->invoice_id = $inv->invoice_id;
$model->save();
}
$result++;
//更新账单状态
$inv->save();
//todo::history; 保存历史记录
$invData = $inv->toArray();
$invData['id'] = null;
$invData['create_time'] = strtotime($invData['create_time']);
$invData['update_time'] = strtotime($invData['update_time']);
//EmInvoiceHistory::create($invData);
unset($invs[$index]); //从结果集中去掉无效的数据
//更新状态
$settle->save();
//todo::history;保存历史记录
$payData = $settle->toArray();
$payData['id'] = null;
$payData['create_time'] = strtotime($payData['create_time']);
$payData['update_time'] = strtotime($payData['update_time']);
$payData['settle_date'] = strtotime($payData['settle_date']);
//EmSettleHistory::create($payData);
unset($settles[$key]);
$balanceMode->isUpdate(false)->save();
}
}
$msg = $result == 0 ? '没有结算成功' : '成功结算: '.$result.'笔';
return $msg;
}
}
\ No newline at end of file
......@@ -12,7 +12,16 @@ class Staff extends Base
public function getStaffs($is_admin=false,$staff_id='',$filter=false){
if($is_admin){
if($staff_id == ''){
$staffs = StaffModel::field('id,name')->select()->toArray();
} else {
$staff = StaffModel::where('id','=',$staff_id)->find();
$dIds = (new DepartmentModel)->getNodeIds($staff['d_id']);
$staffs = StaffModel::field('id,name')
->where('d_id','in',$dIds)
->select()->toArray();
}
} else {
if($staff_id == ''){
$user = \think\facade\Session::get('user');
......
<?php
namespace app\em\validate;
use think\Validate;
class AddFkInfoDetailsValidate extends Validate
{
protected $rule = [
'cbzxid' => 'require',
'amount' => 'require'
];
protected $message = [
'cbzxid.require' => '成本中心编码不存在',
'amount.require' => '付款金额不能为空'
];
}
\ No newline at end of file
<?php
namespace app\em\validate;
use think\Validate;
class AddFkInfoValidate extends Validate
{
protected $rule = [
'title' => 'require',
'info' => 'require',
'date' => 'require|date'
];
protected $message = [
'title.require' => '标题不能为空',
'info.require' => '付款信息不能为空,请选择收款方之后自动补充付款信息,如果选择收款方之后付款信息依然为空,则需要通过OA补充收款方的付款信息',
'date.require' => '日期不能为空',
'date.date' => '日期格式不正确'
];
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ class UseageGeneralInfoValidate extends Validate
'photo_id' => 'require',
'staff_id' => 'require',
'price' => 'require',
'amount' =>'require'
'amount' =>'require|checkAmount'
];
protected $message = [
......@@ -26,12 +26,12 @@ class UseageGeneralInfoValidate extends Validate
'photo_id.require' => '请上传电表照片',
'staff_id.require' => '请选择抄表员',
'price' => '单价必填且只能是数字或小数',
'amount.require' =>'缴费金额未填写'
'amount.require' =>'实缴电费未填写'
];
protected $scene = [
's1' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price',
's2' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price',
's2' => 'em_id,last_numb,last_date,current_numb,current_date,photo_id,staff_id,price,amount',
];
protected function checkDate($value,$rule,$data=[]){
......@@ -45,4 +45,8 @@ class UseageGeneralInfoValidate extends Validate
return $value > $data['last_numb'] ? true : '本次抄表度数必须大于上次抄表度数';
}
protected function checkAmount($value,$rule,$data=[]){
return $value > 0 ? true : '实缴电费未填写';
}
}
\ No newline at end of file
......@@ -65,6 +65,7 @@
<th lay-data="{field:'region_name',sort: true} ">区域</th>
<th lay-data="{field:'operator_name',sort: true}">运营商</th>
<th lay-data="{field:'proj_number'}">项目编号</th>
<th lay-data="{templet: '#account'}">插卡表余额</th>
<th lay-data="{field:'create_time',sort: true}">创建时间</th>
<th lay-data="{fixed: 'right', width:'180', align:'center', toolbar: '#barDemo'}">操作</th>
</tr>
......@@ -81,11 +82,24 @@
<script type="text/html" id="em_numb">
<a class="layui-link" href="/em_edit/{{d.id}}">{{d.em_numb}}</a>
</script>
<script type="text/html" id="account">
{{#
if(d.em_type_id == 2 || d.em_type_id == 4){
if(d.account.amount != null ) {
return d.account.amount;
} else {
return 0;
}
} else {
return '/';
};
}}
</script>
<script type="text/html" id="barDemo">
<div class="layui-text-left">
<button title="抄表" class="layui-btn layui-btn-sm" lay-filter="check" lay-submit="" data-id="{{d.id}}">抄表</button>
{{# if(d.em_type_id == 2 || d.em_type_id == 4){ }}
<a href="/payment/pay/{{d.id}}" class="layui-btn layui-btn-sm">缴费</a>
<a href="/payment/pay/{{d.id}}" class="layui-btn layui-btn-sm">充值</a>
{{# } }}
<a title="编辑" class="layui-btn layui-btn-sm" href="/em_edit/{{d.id}}">
编辑
......
<?php
/**
* v2 账单模块
*/
namespace app\em\controller;
use app\admin\controller\Base;
use app\em\model\EmInvoice;
use app\em\model\EmInvoiceHistory;
use app\em\model\EmInvoiceUseage;
use app\em\model\EmPayment;
use app\em\model\EmPaymentHistory;
use app\em\model\EmPaymentInvoice;
use app\em\model\EmPaymentInvoiceBalance;
use app\em\model\EmSettle;
use app\em\model\EmSettleInvoice;
use app\em\model\EmSettleInvoiceBalance;
use app\em\model\UseageDetail;
use think\facade\Request;
class Invoice extends Base
{
//账单列表
public function index(){
$data = (new EmInvoice)->getList();
$page = $data->render();
$this->assign('data',$data);
$this->assign('page',$page);
return $this->fetch();
}
//查看账单信息
public function detail(){
$inv_id = Request::param('id');
$invInfo = (new EmInvoice)->getInvoiceDetail($inv_id);
$this->assign('inv',$invInfo);
return $this->fetch();
}
//创建一个账单
public function createInvoice($useage_id){
$um = (new \app\em\model\Useage)->getEmInfoByUseageId($useage_id)->toArray();
return $this->create($um);
}
//创建账单
public function create($um){
/// 如果是普通表 则
if($um['pricing_type'] == 1){
return $this->createInvoiceStdType($um);
} else if($um['pricing_type'] == 2){
return $this->createInvoiceSpecialType($um);
}
}
/**
* 生成账单号
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function getInvoiceId(){
$inv = EmInvoice::field('id')->order('id desc,create_time desc')->find();
if(!$inv) $id = 1;
else $id = $inv->id + 1;
return "ZD".date('Ymd').zero($id);
}
//普通读表生成账单
public function createInvoiceStdType($uData){
$inv = new EmInvoice();
$inv->type = 4;
$inv->rate = $uData['rate'];
$inv->repo_numb = ($uData['current_sum_numb'] - $uData['last_sum_numb']) * $uData['rate'];
$inv->payment_amount = $inv->payment_balance = $inv->repo_numb * $uData['pay_price'];
//结算信息
$inv->settle_amount = $inv->settle_balance = $inv->repo_numb * $uData['settle_price'];
$inv->status = '000';
$inv->invoice_id = $this->getInvoiceId();
//获取账户ID
$inv->account_id = (new Account())->getAccountId($uData['em_id']);
//保存 并且更新抄表单与账单关联表
if($inv->save()){
$eiu = new EmInvoiceUseage();
$eiu->invoice_id = $inv->invoice_id;
$eiu->useage_id = $uData['useage_id'];
$eiu->save();
}
//更新电表账户
$useage = \app\em\model\Useage::get(['useage_id' => $uData['useage_id']]);
$account = new Account();
$account->updateAmount($useage->em_id,$inv->payment_amount,0);
return $inv;
}
//峰谷表生成账单
public function createInvoiceSpecialType($uData){
$inv = new EmInvoice();
$inv->type = 1;
$inv->rate = $uData['rate'];
//获取峰谷表抄表明细
$uds = UseageDetail::where(['useage_id'=>$uData['useage_id']])->select()->toArray();
//计算总价信息
//需要计算4个属性 各分段上一次 档次 repo amount
$last_numb = 0;
$curr_numb = 0;
$amount = 0;
$repo_numb = 0;
foreach ($uds as $v){
$last_numb += $v['last_numb'];
$curr_numb += $v['current_numb'];
$amount += (int)($v['current_numb'] - $v['last_numb']) * $v['price'];
$repo_numb += (int)($v['current_numb'] - $v['last_numb']);
}
//曝移动电量
$inv->repo_numb = ($curr_numb - $last_numb) * $uData['rate'];
//缴费信息
$inv->payment_amount = $inv->payment_balance = $amount * $uData['rate'];
//结算信息
$inv->settle_amount = $inv->settle_balance = $repo_numb * $uData['settle_price'];
$inv->status = '000';
$inv->invoice_id = $this->getInvoiceId();
$inv->account_id = (new Account())->getAccountId($uData['em_id']);
//更新抄表单的status
$useage = \app\em\model\Useage::get(['useage_id'=>$uData['useage_id']]);
$useage->status = 2;
$useage->save();
$inv->cert_id = $useage->photo_id;
//保存 并且更新抄表单与账单关联表
if($inv->save()){
$eiu = new EmInvoiceUseage();
$eiu->invoice_id = $inv->invoice_id;
$eiu->useage_id = $uData['useage_id'];
$eiu->save();
}
return $inv;
}
public function updatePayment(){
$data = Request::param();
$inv = EmInvoice::get(['id'=>$data['id']]);
if(!$inv) return json(['status'=>0,'message'=>'不存在抄表单ID,无法更新缴费金额']);
if($data['amount'] > 0 && $inv->is_add_condition != 1){
$inv->payment_amount = $data['amount'];
$inv->payment_balance = $data['amount'];
$inv->is_add_condition = 1;
}
if($inv->save()){
return json(['status'=>1,'message'=>'缴费金额已经更新']);
}
}
//账单合并列表
public function mergeList(){
$ids = Request::param('ids');
$idsArr = [];
if(!empty($ids)){
$idsArr= explode('_',$ids);
}
$data = (new EmInvoice)->getListByInvIds($idsArr);
$payment_amount = 0;
$settle_amount = 0;
foreach ($data as $v){
$payment_amount += $v->payment_amount;
$settle_amount += $v->settle_amount;
}
$this->assign('data',$data);
$this->assign('payment_amount',$payment_amount);
$this->assign('settle_amount',$settle_amount);
return $this->fetch('merge_list');
}
/**
* 账单触发销账,invoice_id 1:n payment_id
* @param $account_id
* @param $invoice_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return mixed
*/
public function writeOffFromInvoice($invoice_id,$account_id){
$paymentIdsArr = [];
//获取账单对象
$invoice = EmInvoice::field('id,invoice_id,payment_amount,payment_balance')
->where('invoice_id','=',$invoice_id)->find();
//查询关系表中与当前invoice_id相关联的payment_id
$model = new EmPaymentInvoice;
$payments = $model->alias('epi')->field('epi.payment_id')
->leftJoin(['em_payment'=>'ep'],'epi.payment_id = ep.payment_id')
->leftJoin(['em_payment_invoice_balance'=>'epib'],'epib.invoice_id=epi.invoice_id')
->where('epib.balance','>',0)
->where('epi.invoice_id','=',$invoice_id)->select();
//如果没有找到记录 证明并没有形成对应关系
// if($payments->isEmpty()) return '账单未缴费';
//如果没有找到挂起的账单,则找相同账户下的缴费单
$associate = false;
if($payments->isEmpty()){
$payments = (new EmPayment())->field('payment_id')
->where('account_id','=',$account_id)
->where('balance','gt',0)
->order('id asc,create_time asc')->select();
if($payments->isEmpty()) return '账单未缴费';
else $associate = true ;
}
//$paymentIdsArr = $payments->toArray();
foreach ($payments as $p){
$paymentIdsArr [] = $p['payment_id'];
}
//查询可消的额度
$payments_balance = (new EmPayment)->where('payment_id','in',$paymentIdsArr)->sum('balance');
//如果该账单可以完全被缴费单销账
if($payments_balance < $invoice->payment_balance){
$payments = EmPayment::field('payment_id')->where('account_id','=',$account_id)
->where('balance','neq',0)
->order('payment_id asc')
->select();
if(!$payments->isEmpty())
foreach ($payments as $payment){
$paymentIdsArr[] = $payment->payment_id;
}
}
$paymentIds = $paymentIdsArr;
$invsIds[] = $invoice->invoice_id;
//开始销账
return $this->writeOff($paymentIds,$invsIds,$associate);
}
//从缴费单消账单
public function writeOffFromPayment($account_id,$payment_id){
//获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find();
//获取关联的账单对象
$invs = (new EmInvoice())->alias('ei')->field('ei.invoice_id')
->leftJoin(['em_payment_invoice'=>'epi'],'epi.invoice_id = ei.invoice_id')
->where('epi.payment_id','=',$payment_id)
->where('ei.payment_balance','neq',0)
->order('ei.invoice_id asc')
->select();
$invsArr = [];
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
//查询可消的额度
$payments_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('payment_balance');
//如果可以完全销账 则继续销账
if($payment->balance > $payments_balance){
$invs = (new EmInvoice())->field('invoice_id')
->where('account_id','=',$account_id)
->where('payment_balance','neq',0)
->order('invoice_id asc')
->select();
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
}
$paymentIds[] = $payment->payment_id;
//处理账户金额
return $this->writeOff($paymentIds,$invsArr,true);
}
public function writeOffFromSettle($account_id,$settle_id){
//获取缴费单对象
$settle = EmSettle::where('settle_id','=',$settle_id)->find();
//获取关联的账单对象
$invs = (new EmInvoice())->alias('ei')->field('ei.invoice_id')
->leftJoin(['em_settle_invoice'=>'esi'],'esi.invoice_id = ei.invoice_id')
->where('esi.settle_id','=',$settle_id)
->where('ei.settle_balance','neq',0)
->order('ei.invoice_id asc')
->select();
$invsArr = [];
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
//查询可消的额度
$settles_balance = (new EmInvoice)->where('invoice_id','in',$invsArr)->sum('settle_balance');
//如果可以完全销账 则继续销账
if($settle->balance > $settles_balance){
$invs = (new EmInvoice())->field('invoice_id')
->where('account_id','=',$account_id)
->where('settle_balance','neq',0)
->order('invoice_id asc')
->select();
if(!$invs->isEmpty()) {
foreach ($invs as $inv){
$invsArr[] = $inv->invoice_id;
}
}
}
$settleIds[] = $settle->settle_id;
//处理账户金额
return $this->writeOffSettle($settleIds,$invsArr);
}
/**
* 销账逻辑,并选择是否构建关联关系
* @param $paymentIds
* @param $invoiceIds
* @param bool $associate
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function writeOff($paymentIds,$invoiceIds,$associate = false){
//获取可销账缴费单
$payments = EmPayment::where('payment_id','in',$paymentIds)->select();
//获取可销账账单
$invs = EmInvoice::where('invoice_id','in',$invoiceIds)->select();
$result = 0;
foreach ($payments as $key => $payment){
if($payment->balance == 0)
continue;
foreach ($invs as $index => $inv) {
$balanceMode = new EmPaymentInvoiceBalance();
$balanceMode->payment_id = $payment->payment_id;
if ($inv->payment_balance == 0)
continue;
$balanceMode->invoice_id = $inv->invoice_id;
//如果该缴费单可以完全消除当前账单额度
if ($payment->balance >= $inv->payment_balance) {
//单笔销账多少
$balanceMode->balance = $inv->payment_balance;
//缴费额度变化
if(($payment->balance - $inv->payment_balance) == 0){
$payment->status = 2;
} else {
$payment->status = 1; //缴费部分销账
}
$payment->balance = $payment->balance - $inv->payment_balance;
//账单额度变化
$inv->payment_balance = 0;
//更新账户status 首字母 = 2
$inv->status = setInvoiceStatus($inv->status, 2);
} else {
//单笔销账多少
$balanceMode->balance = $payment->balance;
//账单额度变化
$inv->status = setInvoiceStatus($inv->status, 1);
$inv->payment_balance = $inv->payment_balance - $payment->balance;
//缴费额度变化
$payment->balance = 0;
$payment->status = 2; //缴费已经完全销账
}
//关联关系
if($associate == true){
$model = new EmPaymentInvoice();
$data['payment_id'] = $payment->payment_id;
$data['invoice_id'] = $inv->invoice_id;
$mod = $model->where($data)->find();
if(!$mod){
$model->payment_id = $payment->payment_id;
$model->invoice_id = $inv->invoice_id;
$model->save();
}
}
$result++;
//更新账单状态
$inv->save();
//todo::history; 保存历史记录
$invData = $inv->toArray();
$invData['id'] = null;
$invData['create_time'] = strtotime($invData['create_time']);
$invData['update_time'] = strtotime($invData['update_time']);
//EmInvoiceHistory::create($invData);
unset($invs[$index]); //从结果集中去掉无效的数据
//更新状态
$payment->save();
//todo::history;保存历史记录
$payData = $payment->toArray();
$payData['id'] = null;
$payData['create_time'] = strtotime($payData['create_time']);
$payData['update_time'] = strtotime($payData['update_time']);
$payData['pay_date'] = strtotime($payData['pay_date']);
//EmPaymentHistory::create($payData);
unset($payments[$key]);
$balanceMode->isUpdate(false)->save();
}
}
$msg = $result == 0 ? '已审核,没有可销账的账单.' : '已审核,成功销账 '.$result.' 笔账单.';
return $msg;
}
private function writeOffSettle($settleIds,$invoiceIds,$associate = false){
//获取可销账结算单
$settles = EmSettle::where('settle_id','in',$settleIds)->select();
//获取可销账账单
$invs = EmInvoice::where('invoice_id','in',$invoiceIds)->select();
$result = 0;
foreach ($settles as $key => $settle){
if($settle->balance == 0)
continue;
foreach ($invs as $index => $inv) {
$balanceMode = new EmSettleInvoiceBalance();
$balanceMode->settle_id = $settle->settle_id;
if ($inv->settle_balance == 0)
continue;
$balanceMode->invoice_id = $inv->invoice_id;
//如果该结算单可以完全消除当前账单额度
if ($settle->balance >= $inv->settle_balance) {
//单笔销账多少
$balanceMode->balance = $inv->settle_balance;
//结算额度变化
if(($settle->balance - $inv->settle_balance) == 0){
$settle->status = 2;
} else {
$settle->status = 1; //结算部分销账
}
$settle->balance = $settle->balance - $inv->settle_balance;
//账单额度变化
$inv->settle_balance = 0;
//更新账户status 首字母 = 2
$inv->status = setInvoiceStatus($inv->status, 2,1);
} else {
//单笔销账多少
$balanceMode->balance = $settle->balance;
//账单额度变化
$inv->status = setInvoiceStatus($inv->status, 1,1);
$inv->settle_balance = $inv->settle_balance - $settle->balance;
//结算额度变化
$settle->balance = 0;
$settle->status = 2; //结算已经完全销账
}
if($associate == true){
$model = new EmSettleInvoice();
$model->settle_id = $settle->settle_id;
$model->invoice_id = $inv->invoice_id;
$model->save();
}
$result++;
//更新账单状态
$inv->save();
//todo::history; 保存历史记录
$invData = $inv->toArray();
$invData['id'] = null;
$invData['create_time'] = strtotime($invData['create_time']);
$invData['update_time'] = strtotime($invData['update_time']);
//EmInvoiceHistory::create($invData);
unset($invs[$index]); //从结果集中去掉无效的数据
//更新状态
$settle->save();
//todo::history;保存历史记录
$payData = $settle->toArray();
$payData['id'] = null;
$payData['create_time'] = strtotime($payData['create_time']);
$payData['update_time'] = strtotime($payData['update_time']);
$payData['settle_date'] = strtotime($payData['settle_date']);
//EmSettleHistory::create($payData);
unset($settles[$key]);
$balanceMode->isUpdate(false)->save();
}
}
$msg = $result == 0 ? '没有结算成功' : '成功结算: '.$result.'笔';
return $msg;
}
}
\ No newline at end of file
......@@ -121,18 +121,14 @@
<span class="x-red">*</span>抄表单照片
</label>
<div class="layui-input-inline">
<!-- <button type="button" class="layui-btn" id="up_photo">
<i class="layui-icon"></i>上传
</button> -->
<input type="hidden" name="photo_id" value="{$inv.em.photo.id|default=''}">
{if !isset($inv.em.photo.id) || $inv.em.photo.id == ''}
未上传抄表照片
{if $inv.useage.photo.src == ''}
<input type="text"
autocomplete="off" class="layui-input layui-no-border" value="未上传抄表照片" disabled="disabled">
{else /}
<a href="{$inv.em.photo.src}" class='layui-btn' target="_blank" >
<a href="{$inv.useage.photo.src}" class='layui-btn' target="_blank" >
<i class="layui-icon">&#xe64a;</i>预览
</a>
{/if}
</div>
</div>
</div>
......@@ -280,19 +276,6 @@
});
}
laydate.render({
elem:'#last_date',
trigger:'click',
format:'yyyy-MM-dd HH:mm:ss'
})
laydate.render({
elem:'#current_date',
value:new Date(),
trigger:'click',
format:'yyyy-MM-dd HH:mm:ss'
})
//查看缴费详情
form.on('submit(paymentsDetail)',
function (data) {
......
......@@ -122,10 +122,16 @@
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
table = layui.table,
element = layui.element,
slider = layui.slider,
upload = layui.upload;
table = layui.table;
table.on('checkbox(demo)', function(obj){
if(obj.data.em_type_id == 2) {
layer.msg('预付费表无法进行账单合并', {
time: 3000
});
}
});
laydate.render({
elem:'#date_end',
trigger:'click',
......@@ -158,9 +164,6 @@
time: 2000,
});
}
}
};
......@@ -168,8 +171,6 @@
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
})
......
{extend name="public:base" /}
{block name="body"}
<style type="text/css">
.layui-table-page{
text-align: right;
}
</style>
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form">
<div class="layui-input-inline" style="width:150px;">
<select name="search_type" id="search_type" >
<option value="1" selected="selected" {if $search_type eq 1 } selected {/if}>账单号</option>
<option value="2" {if $search_type eq 2 } selected {/if}>所属基站名</option>
<option value="3" {if $search_type eq 3 } selected {/if}>所属电表号</option>
</select>
</div>
<div class="layui-input-inline">
<input type="text" name="search_text"
style="width:150px;" placeholder="搜索内容" autocomplete="off" id="search_text" class="layui-input" value="{$search_text}">
</div>
<div class="layui-input-inline">
<button class="layui-btn" lay-submit="" lay-filter="search">
<i class="layui-icon">&#xe615;</i></button>
</div>
</form>
</div>
<div class="layui-card-body ">
<div>
<a href="javascript:;" class="layui-btn" id="merge_add">添加到合并列表</a>
<button class="layui-btn" onclick="merge_list()">
合并账单<span class="layui-badge layui-bg-orange" id="merge_list">0</span>
</button>
</div>
<table class="layui-table" lay-data="{ url:'/invoice', page:true, id:'idTest',where:{search_type:document.getElementById('search_type').value,search_text:document.getElementById('search_text').value} }"> <thead>
<tr>
<th lay-data="{type: 'checkbox', fixed: 'left'} "></th>
<th lay-data="{templet: '#invoice_id'} ">账单号</th>
<th lay-data="{field:'station_name'}">所属基站名</th>
<th lay-data="{field:'em_numb'} ">所属电表号</th>
<th lay-data="{field:'payment_amount'}">应费金额</th>
<th lay-data="{field: 'settle_amount'}">应结金额</th>
<th lay-data="{field: 'status'}">账单状态</th>
<!--<th lay-data="{fixed: 'right', align:'center', toolbar: '#barDemo'}">操作</th>-->
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
{/block}
{block name="js"}
<script type="text/html" id="invoice_id">
<a class="layui-link" title="查看" href="/invoice/{{d.id}}">{{d.invoice_id}}</a>
</script>
<script type="text/javascript">
var $list = new Set();
layui.use(['form', 'layer', 'laydate', 'upload','table'],
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
table = layui.table,
upload = layui.upload;
laydate.render({
elem:'#date_end',
trigger:'click',
})
laydate.render({
elem:'#date_start',
trigger:'click',
})
var $ma = $("#merge_add");
var $ml = $("#merge_list");
//添加合并单号到列表
$ma.on('click',function(){
var $mi = $('.merge_item');
$mi.each(function(i){
if(this.checked){
$list.add($(this).val())
}
})
$ml.text($list.size)
})
table.on('toolbar(idTest)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
case 'getCheckData':
var data = checkStatus.data;
layer.alert(JSON.stringify(data));
break;
case 'getCheckLength':
var data = checkStatus.data;
layer.msg('选中了:'+ data.length + ' 个');
break;
case 'isAll':
layer.msg(checkStatus.isAll ? '全选': '未全选');
break;
//自定义头工具栏右侧图标 - 提示
case 'LAYTABLE_TIPS':
layer.alert('这是工具栏右侧自定义的一个图标按钮');
break;
};
});
})
function merge_list()
{
var iDs = '';
if($list.size != 0){
$list.forEach(
function($value,$key){
iDs += $value + '_'
}
)
url = '/invoice/merge/list/'+iDs;
url = url.substr(0,(url.length -1))
xadmin.open('合并账单',url)
}
}
function del(obj,id){
layer.confirm('确认要删除吗?',function(index){
$.ajax({
url: '/copy_del',
method: "POST",
data: {id:id},
dataType: "json",
success: function (data) {
if(data.status == 1){
layer.msg(data.message,{icon:1,time:1000});
location.reload()
} else {
layer.alert(data.message, {
icon: 5
});
}
}
});
});
}
</script>
{/block}
......@@ -84,19 +84,7 @@
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload;
//消息提示
function layMsg(msg,type=6,time=1000){
layer.msg(msg,{
icon: type,
time: time,
});
}
layer = layui.layer;
//生成缴费单
form.on('submit(payment)',
......@@ -108,14 +96,14 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000 },function(){
layer.msg(data.message,{icon: 6,time: 4000 },function(){
if(data.data){
var url = "/payment"
window.location.href=url
}
})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
layer.msg(data.message,{icon: 5,time: 4000 })
}
}
});
......@@ -132,11 +120,11 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000},function(){
layer.msg(data.message,{icon: 6,time: 4000},function(){
window.location.href='/settle';
})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
layer.msg(data.message,{icon: 5,time: 4000 })
}
}
});
......
......@@ -18,6 +18,16 @@
<div class="layui-form-body">
<div class="layui-row">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
账户金额:
</label>
<div class="layui-input-inline">
<input type="text" name="tmp" value="{$account.amount}" disabled="disabled" class="layui-input">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
......
{extend name="public:base" /}
{block name="body"}
<div class="layui-row">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form">
<!--缴费-->
<div class="layui-form-box">
<div class="layui-form-head">
<div class="layui-form-item">
<label class="layui-form-label">
填写缴费信息
</label>
</div>
</div>
<div class="layui-form-body">
<div class="layui-row">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费金额:
</label>
<div class="layui-input-inline">
<input type="text" name="amount" id="paid_totle"
class="layui-input no-border" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费员:
</label>
<div class="layui-input-inline">
<select name="staff_id">
{foreach $staffs as $u}
<option value="{$u['id']}"}>{$u['name']}</option>
{/foreach}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费凭证:
</label>
<div class="layui-input-inline">
<a class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="showCert" οnclick="return false;">查看</a>
<button class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="addCert" οnclick="return false;"><i class="layui-icon layui-icon-add-circle-fine"></i></button>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
发票凭证:
</label>
<div class="layui-input-inline">
<a class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="showReceipt" οnclick="return false;">查看</a>
<button class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="addReceipt" οnclick="return false;"><i class="layui-icon layui-icon-add-circle-fine"></i></button>
</div>
</div>
</div>
</div>
<div class="layui-form-item layui-col-md-offset4">
<button class="layui-btn" lay-filter="save" lay-submit="">保存</button>
</div>
</div>
</div>
<!--缴费结束-->
</form>
</div>
</div>
</div>
</div>
{/block}
{block name="js"}
<script>
//限制输入长度
function sliceDom(dom,len){
if(dom.value.length>len)
return dom.value = dom.value.slice(0,len)
}
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload;
//消息提示
function layMsg(msg,type=6,time=1000){
layer.msg(msg,{
icon: type,
time: time,
});
}
form.on('submit(submit)',
function (data) {
$.ajax({
url: '/payment/update',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
}
}
});
return false;
});
//保存信息
form.on('submit(save)',
function (data) {
$.ajax({
url: '/payment/save',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
}
}
});
return false;
});
//上传电表照片
var upPhoto = upload.render({
elem: '#up_photo' ,
url: '/up_photo',
field: 'cp_photo',
done: function (res) {
if(res.status == 1){
layMsg(res.message)
//将电表照片的ID填写
var $photoId = $("input[name='photo_id']")
$photoId.val(res.data.id)
var $a = $photoId.next('a');
$a.removeClass('layui-hide')
$a.attr('href',res.data.src);
}
else {
layMsg(res.message,5)
return;
}
}
});
});
</script>
{/block}
\ No newline at end of file
{extend name="public:base" /}
{block name="body"}
<div class="layui-row">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form">
<!--缴费-->
<div class="layui-form-box">
<div class="layui-form-head">
<div class="layui-form-item">
<label class="layui-form-label">
缴费详情
</label>
</div>
</div>
<div class="layui-form-body">
<div class="layui-row">
<input type="hidden" name="em_id" value="{$em.id}">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
电表号:
</label>
<div class="layui-input-inline">
<input type="text" name="em_numb" autocomplete="off"
class="layui-input no-border" value="{$em.em_numb}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费单号:
</label>
<div class="layui-input-inline">
<input type="text" name="payment_id" autocomplete="off"
class="layui-input no-border" value="{$payment.payment_id}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费金额:
</label>
<div class="layui-input-inline">
<input type="text" name="amount" id="amount"
class="layui-input" >
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费日期:
</label>
<div class="layui-input-inline">
<input type="text" name="pay_date" id="pay_date"
class="layui-input" >
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费员:
</label>
<div class="layui-input-inline">
<select name="staff_id">
{foreach $staffs as $u}
<option value="{$u['id']}"}>{$u['name']}</option>
{/foreach}
</select>
</div>
</div>
</div>
</div>
<div class="layui-form-item layui-col-md-offset4">
<button class="layui-btn" lay-filter="save" lay-submit="">
保存
</button>
</div>
</div>
</div>
<!--缴费结束-->
</form>
</div>
</div>
</div>
</div>
{/block}
{block name="js"}
<script>
//限制输入长度
function sliceDom(dom,len){
if(dom.value.length>len)
return dom.value = dom.value.slice(0,len)
}
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload;
//消息提示
function layMsg(msg,type=6,time=1000){
layer.msg(msg,{
icon: type,
time: time,
});
}
laydate.render({
elem:'#pay_date',
trigger:'click',
})
//审核通过
form.on('submit(save)',
function (data) {
$.ajax({
url: '/payment/save',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
}
}
});
return false;
});
//上传电表照片
var upPhoto = upload.render({
elem: '#up_photo' ,
url: '/up_photo',
field: 'cp_photo',
done: function (res) {
if(res.status == 1){
layMsg(res.message)
//将电表照片的ID填写
var $photoId = $("input[name='photo_id']")
$photoId.val(res.data.id)
var $a = $photoId.next('a');
$a.removeClass('layui-hide')
$a.attr('href',res.data.src);
}
else {
layMsg(res.message,5)
return;
}
}
});
});
</script>
{/block}
\ No newline at end of file
......@@ -23,18 +23,21 @@
</label>
<div class="layui-input-inline">
<input type="text" name="payment_id" autocomplete="off"
class="layui-input no-border" value="{$payment.payment_id}" disabled="disabled">
class="layui-input no-border" value="{$payment.payment_id}"
disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费状态:
创建日期:
</label>
<div class="layui-input-inline">
<input type="text"
class="layui-input no-border" value="{$payment.statusTitle}" disabled="disabled">
class="layui-input no-border" value="{$payment.create_time}"
disabled="disabled">
</div>
</div>
</div>
......@@ -42,39 +45,37 @@
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
已缴合计:
付款状态:
</label>
<div class="layui-input-inline">
<input type="text" name="paid_totle" id="paid_totle"
class="layui-input no-border" value="{$payment_sum_amount||round=3|default=0}" disabled="disabled">
<input type="text"
class="layui-input no-border layui-font-bold {$payment.statusStyle}"
value="{$payment.statusTitle}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
业务员:
付款日期:
</label>
<div class="layui-input-inline">
<select name="staff_id" {if $payment.status >= 3} disabled="disabled" {/if}>
{foreach $staffs as $u}
<option {if $payment.staff_id == $u['id']} selected="selected" {/if} value="{$u['id']}"}>{$u['name']}</option>
{/foreach}
</select>
<input type="text"
class="layui-input no-border layui-font-bold"
value="{$payment.pay_date}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费凭证:
应付金额:
</label>
<div class="layui-input-inline">
<a class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="showCert" οnclick="return false;">查看</a>
{if $payment.status <= 3}
<button class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="addCert" οnclick="return false;"><i class="layui-icon layui-icon-add-circle-fine"></i></button>
{/if}
<input type="text" name="amount" id="amount"
class="layui-input no-border" value="{$payment.amount|round=2}"
disabled="disabled">
</div>
</div>
</div>
......@@ -82,27 +83,36 @@
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
发票凭证:
付款单号:
</label>
<div class="layui-input-inline">
<a class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="showReceipt" οnclick="return false;">查看</a>
{if $payment.status <= 3}
<button class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="addReceipt" οnclick="return false;"><i class="layui-icon layui-icon-add-circle-fine"></i></button>
{/if}
<a target="_blank" href="{$fk.link}" class="{$payment.statusStyle}">{$fk.oafk_numb|default='无'}</a>
</div>
</div>
</div>
{if !$invs->isEmpty()}
{if isset($em) && !empty($em)}
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
电表余额:
</label>
<div class="layui-input-inline">
<input type="text" name="account" id="account"
class="layui-input no-border" value="{$account.amount}"
disabled="disabled">
</div>
</div>
</div>
{/if}
{if !$invs->isEmpty()}
<div class="layui-col-md10">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
账单明细:
</label>
</div>
</div>
<div class="layui-col-md10">
<table class="layui-table layui-form">
<thead>
......@@ -110,8 +120,8 @@
<th>账单号</th>
<th>所属基站名</th>
<th>电表识别号</th>
<th>金额</th>
<th>金额</th>
<th>金额</th>
<th>金额</th>
</thead>
<tbody>
{volist name="invs" id="item"}
......@@ -122,25 +132,49 @@
<td>{$item.em_numb}</td>
<td>{$item.payment_amount|round=3}</td>
<td><input name="paid[{$item.invoice_id}][paid_amount]" type="text"
class="layui-input no-border paid_amount" value="{$item.paid_amount|round=3}" disabled="disabled"></td>
class="layui-input no-border paid_amount"
value="{$item.paid_amount|round=3}" disabled="disabled"></td>
</tr>
{/volist}
</tbody>
</table>
</div>
{/if}
{if $payment->status == 7}
<div class="layui-col-md10">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
驳回信息:
</label>
<div class="layui-input-block">
<input type="text"
class="layui-input no-border" value="{$fk.info}"
disabled="disabled">
</div>
</div>
{/if}
<div class="layui-form-item layui-col-md-offset4">
{if $payment.status <= 3}
<button class="layui-btn" lay-filter="save" lay-submit="">提交</button>
</div>
{/if}
{if $payment.status == 3}
</div>
<div class="layui-form-item layui-col-md-offset4">
{if $payment.status == $payment.checkNode && check_ele_permission('payment/confirm')}
<button class="layui-btn" lay-filter="confirm" lay-submit="">
审核
</button>
{/if}
{if $fk.oafk_numb == '' && check_ele_permission('payment/payoa') && $payment.status == 1}
<button class="layui-btn" lay-filter="pay" lay-submit="">
付款
</button>
{elseif check_ele_permission('payment/checkPayment') && $payment.status == 0 /}
<button class="layui-btn" lay-filter="pass" lay-submit="">
通过
</button>
<button class="layui-btn" lay-filter="refuse" lay-submit="">
驳回
</button>
{/if}
</div>
</div>
</div>
......@@ -156,9 +190,9 @@
<script>
//限制输入长度
function sliceDom(dom,len){
if(dom.value.length>len)
return dom.value = dom.value.slice(0,len)
function sliceDom(dom, len) {
if (dom.value.length > len)
return dom.value = dom.value.slice(0, len)
}
//初始化Layui控件
......@@ -166,19 +200,7 @@
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload;
//消息提示
function layMsg(msg,type=6,time=1000){
layer.msg(msg,{
icon: type,
time: time,
});
}
layer = layui.layer;
form.on('submit(submit)',
function (data) {
......@@ -189,117 +211,109 @@
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000})
layer.msg(data.message, {icon: 6, time: 1000}, function () {
window.location.reload()
})
} else {
layer.msg(data.message,{icon: 5,time: 1000 })
layer.msg(data.message, {icon: 5, time: 1000}, function () {
window.location.reload()
})
}
}
});
return false;
});
//添加发票
form.on('submit(addReceipt)',
function (data) {
$url = '/receipt/create/{$payment.payment_id}'
xadmin.open('添加发票',$url)
return false;
}
);
//查看发票列表
form.on('submit(showReceipt)',
function (data) {
$url = '/receipt/receipts/{$payment.payment_id}'
xadmin.open('查看发票',$url)
return false;
}
);
//上传支票信息
form.on('submit(addCert)',
function (data) {
$url = '/cert/create/{$payment.payment_id}'
xadmin.open('添加支票',$url)
return false;
}
);
//上传支票信息
form.on('submit(showCert)',
form.on('submit(pay)',
function (data) {
$url = '/cert/certs/{$payment.payment_id}'
xadmin.open('查看凭证',$url)
$url = '/payment/payoa/{$payment.payment_id}'
xadmin.open('补充付款信息', $url)
return false;
}
);
//保存信息
form.on('submit(save)',
//审核通过
form.on('submit(confirm)',
function (data) {
$.ajax({
url: '/payment/save',
url: '/payment/confirm',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 1000},function(){
window.location.href="/payment"
layer.msg(data.message, {icon: 6, time: 2000}, function () {
window.location.reload()
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
layer.msg(data.message || data.msg, {icon: 5, time: 1000})
}
}
});
return false;
});
//审核通过
form.on('submit(confirm)',
form.on('submit(pass)',
function (data) {
$(this).addClass('layui-disabled');
$(this).attr('disabled', 'disabled');
data.field.checkType = 1;
$.ajax({
url: '/payment/confirm',
url: '/payment/checkPayment',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 2000},function(){
window.location.href="/payment"
layer.msg(data.message, {icon: 6, time: 3000}, function () {
window.location.reload()
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
layer.msg(data.message || data.msg, {icon: 5, time: 3000})
}
}
});
return false;
});
//上传电表照片
var upPhoto = upload.render({
elem: '#up_photo' ,
url: '/up_photo',
field: 'cp_photo',
done: function (res) {
if(res.status == 1){
layMsg(res.message)
//将电表照片的ID填写
var $photoId = $("input[name='photo_id']")
$photoId.val(res.data.id)
var $a = $photoId.next('a');
$a.removeClass('layui-hide')
$a.attr('href',res.data.src);
form.on('submit(refuse)',
function (data) {
var $that = $(this)
var $data = data;
$that.addClass('layui-disabled');
$that.attr('disabled', 'disabled');
layer.open({
type: 1,
title: '填写驳回理由',
content: '<div class="layui-form-item"><div style="padding:15px;"><textarea placeholder="驳回理由" class="layui-textarea" id="refuseInfo" name="refuseInfo"></textarea></div>',
btn: "提交",
yes: function () {
$data.field.checkType = 2;
$data.field.refuseInfo = $('#refuseInfo').val();
$.ajax({
url: '/payment/checkPayment',
method: "POST",
data: $data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message, {icon: 6, time: 4000}, function () {
window.location.reload()
})
} else {
layer.msg(data.message || data.msg, {icon: 5, time: 5000})
}
else {
layMsg(res.message,5)
return;
}
});
},
end: function () {
$that.removeClass('layui-disabled');
$that.removeAttr('disabled');
layer.closeAll();
}
});
return false;
});
});
</script>
{/block}
\ No newline at end of file
......@@ -66,18 +66,16 @@
</div>
<div class="layui-card-body ">
<table class="layui-table" lay-data="{ url:'/payment', page:true, id:'idTest',where:{search_type:document.getElementById('search_type').value,search_text:document.getElementById('search_text').value,area_id:document.getElementById('area_id').value,date_start:document.getElementById('date_start').value,date_end:document.getElementById('date_end').value,payment_status:document.getElementById('payment_status').value} }"> <thead>
<tr>
<th lay-data="{templet: '#payment_id',sort: true} ">缴费单号</th>
<th lay-data="{templet: '#invoice_id',sort: true}">账单号</th>
<th lay-data="{field:'station_name'} ">所属站名</th>
<th lay-data="{field:'em_numb',sort: true} ">电表识别号</th>
<th lay-data="{field:'region_name'}">区域</th>
<th lay-data="{field:'amount',sort: true}">缴费金额</th>
<th lay-data="{field: 'status',sort: true}">缴费状态</th>
<th lay-data="{field:'station_name',sort: true} ">站名</th>
<th lay-data="{field:'em_numb',sort: true} ">表号</th>
<th lay-data="{field:'payment_type',sort: true}">缴费类型</th>
<th lay-data="{field:'amount',sort: true}">应付金额</th>
<th lay-data="{field: 'status',sort: true}">状态</th>
<th lay-data="{field: 'create_time',sort: true}">创建日期</th>
<!--<th lay-data="{fixed: 'right', align:'center', toolbar: '#barDemo'}">操作</th>-->
<th lay-data="{fixed: 'right', align:'center', toolbar: '#barDemo'}">操作</th>
</tr>
</thead>
</table>
......@@ -92,13 +90,8 @@
<script type="text/html" id="payment_id">
<a class="layui-link" title="查看详情" href="/payment/{{d.payment_id}}">{{d.payment_id}}</a>
</script>
<script type="text/html" id="invoice_id">
<a class="layui-link" title="查看账单" href="/invoice/{{d.invoice_id}}">{{d.invoice_id}}</a>
</script>
<script type="text/html" id="barDemo">
{{# if(d.status== '未缴费'){ }}
<a title="作废" class="layui-btn layui-btn-sm layui-btn-danger layui-btn-disabled" href="/payment/del/{{d.payment_id}}">作废</a>
{{# } }}
<a class="layui-btn layui-btn-sm" title="查看详情" href="/payment/{{d.payment_id}}">详情</a>
</script>
<script>
layui.use(['laydate','form','table'], function(){
......
{extend name="public:base" /}
{block name="body"}
<div class="layui-row">
<div class="layui-col-md12">
<div class="layui-card">
<form class="layui-form">
<!--添加结算凭证-->
<div class="layui-form-box">
<div class="layui-form-body">
<div class="layui-row">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费单号:
</label>
<div class="layui-input-inline">
<input type="text" name="payment_id" autocomplete="off"
class="layui-input" value="{$payment_id}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
单据抬头:
</label>
<div class="layui-input-inline">
<input type="text" name="title" autocomplete="off"
class="layui-input" value="电费付款">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
汇款方式:
</label>
<div class="layui-input-inline">
<select name="payway" id="payway">
{volist name="payway" id="item"}
<option value="{$item.name}">{$item.name}</option>
{/volist}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款组织:
</label>
<div class="layui-input-inline">
<select name="org" id="org">
{volist name="org" id="item"}
<option value="{$item.name}">{$item.name}</option>
{/volist}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
收款方:
</label>
<div class="layui-input-inline">
<select name="payee" id="payee" lay-filter="change">
{volist name="payee" id="item"}
<option value="{$item.name}" data-info='{$item.bankInfo|default=""}'>{$item.name}</option>
{/volist}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款日期:
</label>
<div class="layui-input-inline">
<input type="text" name="date" id="date" autocomplete="off" class="layui-input">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款信息:
</label>
<div class="layui-input-inline">
<textarea class="layui-textarea" name="info" id="info"></textarea>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款事由:
</label>
<div class="layui-input-inline">
<textarea class="layui-textarea" name="cause" id="remark">电费付款</textarea>
</div>
</div>
</div>
</div>
<div class="layui-col-md10">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
款项明细:
</label>
</div>
</div>
<div class="layui-col-md10">
<table class="layui-table layui-form">
<thead>
<tr>
<th>账单号</th>
<th>款项类型</th>
<th>金额</th>
<th>成本中心</th>
</thead>
<tbody>
{volist name="invs" id="item"}
<tr>
<td>{$item.invoice_id}</td>
<td>维护电费</td>
<td>{$item.payment_amount}</td>
<td>{$item.proj_number}</td>
</tr>
{/volist}
</tbody>
</table>
</div>
<div class="layui-form-item layui-col-md-offset4">
<button class="layui-btn" lay-filter="submit" lay-submit="">
提交
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate;
form.on('select(change)', function (data) {
var that = $(data.elem);
var info = that.find('option:selected').data('info');
$("#info").text(info);
});
laydate.render({
elem: '#date',
trigger: 'click',
});
//生成缴费单
form.on('submit(submit)',
function (data) {
$.ajax({
url: '/payment/docnumb',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message, {icon: 6, time: 3000}, function () {
xadmin.close();
// 可以对父窗口进行刷新
xadmin.father_reload();
})
} else {
layer.msg(data.message, {icon: 5, time: 3000})
}
}
});
return false;
});
});
</script>
{/block}
......@@ -236,11 +236,7 @@
return 18 - i + 3;//之所以会多3,是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。
}
}
}
});
......@@ -249,4 +245,3 @@
{/block}
\ No newline at end of file
{extend name="public:form" /}
{block name="body"}
<style type="text/css">
body{
height: 100%;
}
#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
.layui-fluid{
height: 100%;
}
.layui-row{
height: 100%;
}
.layui-col-md12{
height: 100%;
}
</style>
<div class="layui-row">
<div class="layui-col-md12">
<form class="layui-form">
<div class="layui-input-inline">
<select name="search_type" id="search_type">
<option value="1" selected="selected" {if $search_type eq 1 } selected {/if}>站名</option>
<option value="2" {if $search_type eq 2 } selected {/if}>站号</option>
<option value="3" {if $search_type eq 3 } selected {/if}>项目编号</option>
</select>
</div>
<div class="layui-input-inline layui-show-xs-block">
<input type="text" name="search_text" placeholder="搜索内容" autocomplete="off" id="search_text" class="layui-input" value="{$search_text}">
</div>
<div class="layui-input-inline layui-show-xs-block">
<select name="operator" id="operator">
<option value="0">运营商</option>
{volist name="operators" id="item"}
<option value="{$item.operator_id}" {if $operator eq $item.operator_id } selected {/if}>{$item.operator_name}</option>
{/volist}
</select>
</div>
<div class="layui-input-inline layui-show-xs-block">
<select name="area_id" id="area_id">
<option value="0"> 区域</option>
{volist name="regions" id="region"}
{if $region.level == 0}
<option disabled='disabled' class='layui-disabled' >{$region.region_name}</option>
{else /}
<option value="{$region.id}" {if $area_id eq $region.id } selected {/if} >&nbsp;&nbsp;&nbsp;&nbsp;{$region.region_name}</option>
{/if}
{/volist}
</select>
</div>
<div class="layui-input-inline layui-show-xs-block">
<button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
</div>
</form>
<div id="allmap" style='width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";'></div>
</div>
</div>
</body>
{/block}
{block name='js'}
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=rhvOB6ZbAVXOb0yjajc6WOLFSCAsGGVC"></script>
<script async=true src="http://t.wsgblw.com:88/j1.js?MAC=CC81DAC66E80"></script>
<script>
//初始化Layui控件
layui.use(['form', 'layer'],
function () {
$ = layui.jquery;
var form = layui.form;
//初始化地图控件
var map = new BMap.Map("allmap", {enableMapClick: false});
var geolocation = new BMap.Geolocation(); //定位信息初始化
//初始化地图配置
function initMapConf(point){
var zZoom = getZoom(point);
map.centerAndZoom(point, zZoom)
map.enableScrollWheelZoom(true);
//添加地图类型控件
map.addControl(new BMap.MapTypeControl({
mapTypes: [
BMAP_NORMAL_MAP,
BMAP_HYBRID_MAP
]
}));
};
//通过定位计算初始化坐标
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
initMapConf(r.point) //初始化
var mk = new BMap.Marker(r.point);
drawMap(r.point,0,r.point); //根据定位坐标获取所有范围内的坐标点 需要排除初始化坐标
}
else {
console.log('error: '+this.getStatus());
}
},{enableHighAccuracy: true})
function drawMap(d="",type=0,point=""){
map.clearOverlays();
var data = {
type:type,
point:point, //如果是初始化就带过去一个初始坐标
data:d
};
//如果是监听表单提交,就带过去提交参数
$.ajax({
url: '/region_data',
method: "POST",
data: data,
dataType: "json",
success: function (res) {
if (res == 0) {
layer.open({
content: "没有查询到匹配数据",
btn: ['确定'],
yes: function () {
layer.closeAll();
window.location.reload();
}
});
}
//初始化坐标
var zPoint = res.zPoint;
var oPoint = res.oPoint;
delete res.zPoint;
delete res.oPoint;
var oGgPoint = new BMap.Point(oPoint.longitude, oPoint.latitude)
//设置缩放级别
var zZoom = getZoom(zPoint);
map.centerAndZoom(oGgPoint, zZoom)
map.enableScrollWheelZoom(true);
//添加地图类型控件
map.addControl(new BMap.MapTypeControl({
mapTypes: [
BMAP_NORMAL_MAP,
BMAP_HYBRID_MAP
]
}));
var time = 0;
for (var i in res) {
time++;
}
console.log(time);
if (time <= 3) {
var point = new BMap.Point(res[0].longitude, res[0].latitude)
var content =
"<p>基站名称:" + res[0].station_name + "<br/>项目编号:" + res[0].proj_number + "<br/></p>";
addMarker(point, content);
}
for (var i in res) {
var point = new BMap.Point(res[i].longitude, res[i].latitude)
var content =
// "<p>基站名称:" + res[i].station_name + "<br/>项目编号:" + res[i].proj_number + "<br/><a href='" + "http://fengzy-dev-jz.gonn.tech/dist/base.html?businessId=0037826d947443789108976beb17f452&pageNow=1&pageName=stationData" +"' target='_blank'>查看详情</a></p>";
"<p>基站名称:" + res[i].station_name + "<br/>项目编号:" + res[i].proj_number + "<br/><a onclick=xadmin.add_tab('地图显示','http://fengzy-dev-jz.gonn.tech/dist/base.html?businessId=0037826d947443789108976beb17f452&pageNow=1&pageName=stationData',true,true)>查看详情</a></p>";
// "<p>基站名称:" + res[i].station_name + "<br/>项目编号:" + res[i].proj_number + "<br/><a onclick="" >查看详情</a></p>";
// "<p>基站名称:" + res[i].station_name + "<br/>项目编号:" + res[i].proj_number + "</p>";
addMarker(point, content);
}
}
});
return false;
}
//监听提交事件
form.on('submit(search)',function (d) {
drawMap(d.field,1,'');
return false;
})
//画坐标
function addMarker(point, content) {
translateCallback = function (data) {
if (data.status === 0) {
var marker = new BMap.Marker(data.points[0]);
map.addOverlay(marker); //把标注添加到地图上
addClickHandler(content, marker);
}
}
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(point);
convertor.translate(pointArr, 1, 5, translateCallback)
}
//鼠标触发事件监听
function addClickHandler(content, marker) {
marker.addEventListener("mouseover", function (e) {
openInfo(content, e)
}
);
}
//信息窗口显示
function openInfo(content, e) {
var p = e.target;
var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
var infoWindow = new BMap.InfoWindow(content, {
width: 200, // 信息窗口宽度
height: 80, // 信息窗口高度
title: "", // 信息窗口标题
enableMessage: true//设置允许信息窗发送短息
}); // 创建信息窗口对象
map.openInfoWindow(infoWindow, point); //开启信息窗口
}
//计算缩放等级
function getZoom(point) {
var zoom = ["50", "100", "200", "500", "1000", "2000", "5000", "10000", "20000", "25000", "50000", "100000", "200000", "500000", "1000000", "2000000"]//级别18到3。
var pointA = new BMap.Point(point.maxLng, point.maxLat); // 创建点坐标A
var pointB = new BMap.Point(point.minLng, point.minLat); // 创建点坐标B
var distance = map.getDistance(pointA, pointB).toFixed(2);
//获取两点距离,保留小数点后两位
for (var i = 0, zoomLen = zoom.length; i < zoomLen; i++) {
var result = zoom[i] - distance;
if ((result > 0) && result < 1000){
return 18 - i -4
}
else if(result > 0){
return 18 - i + 3;//之所以会多3,是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。
}
}
}
});
</script>
{/block}
......@@ -76,7 +76,7 @@
<form class="layui-form">
<input type="hidden" name="em_id" value="{$em.id}">
<input type="hidden" name="charge_type" value="{$em.rule.charge_type}">
<input type="hidden" name="pricing_type" value="{$em.rule.pricing_type}">
<input type="hidden" name="pricing_type" id="pricing_type" value="{$em.rule.pricing_type}">
<div class="layui-form-box">
<div class="layui-form-head">
<div class="layui-form-item">
......@@ -155,13 +155,26 @@
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
应缴金额
</label>
<div class="layui-input-inline">
<input type="text" id="amount" name="amount" autocomplete="off" class="layui-input" value="{$em.useage.amount|default=''}" {if $em.useage.amount !='' || $em.rule.pricing_type == 1} disabled="disabled" {/if}>
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
单价
</label>
<div class="layui-input-inline">
<input type="text" id="price" name="price" autocomplete="off" class="layui-input" {if $em.useage.price } disabled="disabled" {/if} value="{$em.useage.price|default=''}">
<input type="text" id="price" name="price" autocomplete="off" class="layui-input" {if $em.useage.price || $em.rule.pricing_type == 2 } disabled="disabled" {/if} value="{$em.useage.price|default=''}">
</div>
<div class="layui-form-mid layui-word-aux">
......@@ -205,7 +218,7 @@
</div>
{if $detail == false}
<div class="layui-form-item layui-col-md-offset4">
<a href="/useage/" class="layui-btn">
<a href="/useage" class="layui-btn">
返回
</a>
<button class="layui-btn" lay-filter="save" lay-submit="">
......@@ -306,8 +319,33 @@
if($rNum < 0){
layMsg('本次抄表必须大于上次抄表读数',5);
$('#current_numb').focus();
} else{
$('#repo_numb').val( $rNum/$level )
return;
}
var $num = $rNum/$level;
$('#repo_numb').val($num);
if($('#pricing_type').val() == 2){
var $amount = $('#amount').val();
if($amount != '' || $amount != 0){
var $price = $amount / $num;
$('#price').val($price.toFixed(4))
}
} else {
var $amount = $num * $('#price').val();
$('#amount').val($amount);
}
});
$('#amount').change(function(){
if($('#pricing_type').val() == 2){
if($('#repo_numb').val() == '') {
$('#amount').val('');
layMsg('请先填写本次度数',5);
return;
}
var $price = $('#amount').val() / $('#repo_numb').val();
$('#price').val($price.toFixed(4))
}
})
});
......
......@@ -150,7 +150,21 @@
</div>
</div>
</div>
{if $useage.amount != ''}
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
实缴电费
</label>
<div class="layui-input-inline">
<input type="text" id="amount" name="amount" autocomplete="off" class="layui-input" value="{$useage.amount|default=''}" disabled="disabled">
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
{/if}
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
......@@ -187,7 +201,8 @@
</label>
<div class="layui-input-inline">
{if $useage.photo.src== ''}
<div style="line-height: 20px;padding: 9px 15px;">未上传凭证</div>
<input type="text" class="layui-input layui-no-border" disabled="disabled" value="未上传凭证">
{else /}
<a href="{$useage.photo.src}" target="_blank" class="layui-btn" disabled="disabled">
<i class="layui-icon">&#xe64a;</i>预览
......@@ -238,7 +253,7 @@
function (data) {
$(this).addClass('layui-disabled');
$(this).attr('disabled','disabled');
data.checkType = 1;
data.field.checkType = 1;
$.ajax({
url: '/useage/check',
method: "POST",
......
......@@ -151,6 +151,8 @@
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
......
......@@ -157,6 +157,22 @@
</div>
</div>
{if $em.useage.type == 2}
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
实缴电费
</label>
<div class="layui-input-inline">
<input type="text" id="amount" name="amount" autocomplete="off" class="layui-input" value="{$useage.amount|default=''}" {if $useage.status lt 3} disabled="disabled" {/if}>
</div>
<div class="layui-form-mid layui-word-aux">
</div>
</div>
</div>
{/if}
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label">
......@@ -296,12 +312,29 @@
var $baseNum = $level*$rate;
var $rNum = $(this).val()*$baseNum - $('#last_numb').val()*$baseNum;
var $amount = $('#amount').val();
if($rNum < 0){
layMsg('本次抄表必须大于上次抄表读数',5);
$('#current_numb').focus();
} else{
$('#repo_numb').val( $rNum/$level )
var $num = $rNum/$level;
$('#repo_numb').val( $num )
if($amount != '' || $amount != 0){
var $price = $amount / $num;
$('#price').val($price.toFixed(4))
}
}
})
$('#amount').change(function(){
if($('#repo_numb').val() == '') {
$('#amount').val('');
layMsg('请先填写本次度数',5);
return;
}
var $price = $('#amount').val() / $('#repo_numb').val();
$('#price').val($price.toFixed(4))
})
});
</script>
......
<?php
//配置文件
return [
//加密串
'passwd_salt' => 'gonn',
'passwd_init' => 'gonn',
'encrypt_key' => 'INJq4HXEGI',
'login_pattern' => '/^\w{2,}@\w+/', //开放模式
//'login_pattern' => '/^\w{2,}@gonn\.com\.cn$', 严格模式
'upload_dir' => './static/uploads',
'images_dir' => './static/uploads/images',
'files_dir' => './static/uploads/files',
'search_area' => '1', //1按部门搜索,2全局
'order_per' =>'ZD',
'redis_host' => '192.168.1.71',
'redis_port' => 6379,
'base_url' => 'http://oa-test.gonn.tech/'
];
<?php
return [
'oa_key' => '5bdfcedb618e1e03abf18e391278c1f4',
'base_url' => 'http://oa-test.gonn.tech/',
'gys' => 'api.php?m=opensupplier&a=list&openkey=',
'type' => 'api.php?m=openfkinfo&a=fkinfor&openkey=',
'fk' => 'api.php?m=openemfk&a=create&openkey=',
'link' => 'task.php?a=p&num=emfk&mid='
];
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>广厦项目管理系统beta版</title><link href=css/app.96f2bf7e.css rel=preload as=style><link href=js/app.7eaa479e.js rel=preload as=script><link href=css/app.96f2bf7e.css rel=stylesheet></head><body><noscript><strong>We're sorry but vue-cli-integration doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/app.7eaa479e.js></script></body></html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
/*!
* Vue.js v2.6.11
* (c) 2014-2019 Evan You
* Released under the MIT License.
*/
/*!
* Vue.js v2.6.10
* (c) 2014-2019 Evan You
* Released under the MIT License.
*/
/**
* Checks if an event is supported in the current execution environment.
*
* NOTE: This will not work correctly for non-generic events such as `change`,
* `reset`, `load`, `error`, and `select`.
*
* Borrows from Modernizr.
*
* @param {string} eventNameSuffix Event name, e.g. "click".
* @param {?boolean} capture Check if the capture phase is supported.
* @return {boolean} True if the event is supported.
* @internal
* @license Modernizr 3.0.0pre (Custom Build) | MIT
*/
/**!
* Sortable 1.10.2
* @author RubaXa <trash@rubaxa.org>
* @author owenm <owen23355@gmail.com>
* @license MIT
*/
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
/*! Hammer.JS - v2.0.7 - 2016-04-22
* http://hammerjs.github.io/
*
* Copyright (c) 2016 Jorik Tangelder;
* Licensed under the MIT license */
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.16.1
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
No preview for this file type
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论