提交 4881b3fb authored 作者: chengye's avatar chengye

project init

上级 eb109369
......@@ -2,15 +2,15 @@
/.idea
/vendor
/phpmyadmin
/.travis.yml
/.user.ini
/build.php
/CHANGELOG.md
/index.html
/LICENSE.txt
/phpinfo.php
/README.md
/think
.travis.yml
.user.ini
build.php
CHANGELOG.md
index.html
LICENSE.txt
phpinfo.php
README.md
think
/config/database.php
/config/cache.php
/config/session.php
......
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2020-11-8
* Time: 21:44
*/
return [
'maintenance' => false
];
\ No newline at end of file
......@@ -45,6 +45,7 @@ class Base extends Controller
$this->redirect('/login');
}
if(!$user['is_admin']){
if(config('main.maintenance') === true) die("电费系统维护...");
$this->authCheck($user['user_id']);
}
}
......
差异被折叠。
......@@ -20,7 +20,7 @@ class Login extends Controller
{
public function index()
{
$baseUrl = config('admin.base_url');
$baseUrl = config('admin.oa_url');
echo '<script type="text/javascript">top.location.href="'.$baseUrl.'";</script>';
}
......@@ -166,4 +166,4 @@ class Login extends Controller
$strs="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
return substr(str_shuffle($strs),mt_rand(0,strlen($strs)-11),$length);
}
}
\ No newline at end of file
}
......@@ -21,6 +21,7 @@ class SingleSign {
else throw new Exception("redis connect faild");
}
$sid = Cookie::get('PHPSESSID');
if(!empty($sid)) Cookie::set('PHPSESSID',$sid,['expire'=>time()+3600]);
}
......@@ -61,14 +62,17 @@ class SingleSign {
//获取userid
public function getUserId($user=[]){
if(!$user['is_admin']){
// if(!$user['is_admin']){
if($user['is_admin'] && $user['username']=='admin') return 9999;
$email = $user['username'].'@gonn.com.cn';
$staff = StaffModel::where(['email'=>$email])->find();
if($staff) return $staff->id;
else throw new Exception('user id not found');
} else {
return 8;
}
//}
//else {
// return 8;
// }
}
//将加密串保存到redis
......@@ -88,4 +92,4 @@ class SingleSign {
if($this->instence->set($sid,'')) return true;
return false;
}
}
\ No newline at end of file
}
......@@ -24,4 +24,4 @@ class NavModel
}
}
\ No newline at end of file
}
......@@ -16,14 +16,22 @@
<ul class="sub-menu">
{foreach $child['children'] as $grandson}
<li>
<a onclick="xadmin.add_tab('{$grandson['title']}','/{$grandson['nav_url']}',true)">
<i class="iconfont">&#xe6a7;</i>
{if stripos($grandson['nav_url'],'http') !== false }
<a onclick="xadmin.add_tab('{$grandson['title']}','{$grandson['nav_url']}',true)">
{else /}
<a onclick="xadmin.add_tab('{$grandson['title']}','/{$grandson['nav_url']}',true)">
{/if}
- <i class="iconfont">&#xe6a7;</i>
<cite>{$grandson['title']}</cite></a>
</li>
{/foreach}
</ul>
{else /}
<a onclick="xadmin.add_tab('{$child['title']}','/{$child['nav_url']}',true)">
{if stripos($child['nav_url'],'http') !== false }
<a onclick="xadmin.add_tab('{$child['title']}','{$child['nav_url']}',true)">
{else /}
<a onclick="xadmin.add_tab('{$child['title']}','/{$child['nav_url']}',true)">
{/if}
<i class="iconfont">&#xe6a7;</i>
<cite>{$child['title']}</cite></a>
{/if}
......
......@@ -15,9 +15,61 @@
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-form-box">
<div class="layui-form-head">
</div>
<ul class="layui-timeline">
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">2020/8/26</h3>
<p><strong>账单列表功能更新:升级"合并账单"功能</strong></p>
<ul>
<li>"合并账单" 支持类似购物车功能.</li>
<li>支持跨分页,关键字搜索,之后勾选账单均可添加到 "合并账单" 进行合并操作.</li>
<li>支持 "合并账单" 中删除账单之后,列表对应取消勾选状态.</li>
<li>"账单合并" 中金额均保留三位小数(四舍五入)</li>
</ul>
<p><strong>缴费单下推付款更新:优化下推付款细节</strong></p>
<ul>
<li>下推付款在选择"收款方"之后,会自动将"收款方"银行账号列表写入到"收款信息"列表中,手动选择即可,不再支持手动改写"收款信息".
</ul>
</div>
</li>
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">2020/9/15</h3>
<p><strong>原"基站管理系统"已下线,所有基站业务请到项目管理系统中管理.</strong></p>
</div>
</li>
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">2020/11/08</h3>
<p><strong>电费账单可支持"部分缴费"业务</strong></p>
<ul>
<li>在账单合并下推缴费时,可填入本次缴费金额,缴费金额不能大于账单金额,且不能为0.</li>
</ul>
</div>
</li>
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">2021/1/04</h3>
<p><strong>电费支持合并充值功能</strong></p>
<ul>
<li>将原缴费列表拆分成,充值列表与缴费列表,充值列表负责插卡表缴费业务,缴费列表负责后付费缴费业务.</li>
<li>合并充值操作同账单合并一致,且只有当充值单状态为<strong style="color:red">"未提交"</strong>状态,方可合并充值。</li>
</ul>
<p><strong>新增缴费/充值"作废"功能</strong></p>
<ul>
<li>如果缴费或充值信息有误,在下推付款单之前可选择作废,自动解除与账单等关联关系,如不显示该按钮,请申请权限。</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
......@@ -26,4 +78,4 @@
</div>
<div id="tab_show"></div>
</div>
</div>
\ No newline at end of file
</div>
......@@ -60,12 +60,8 @@
<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;
......@@ -183,4 +179,4 @@
}
</script>
{/block}
\ No newline at end of file
{/block}
......@@ -37,6 +37,28 @@ class Staff
]);
}
public function getCurrentStaffByEmail(){
$email = request()->get('email');
//如果不是超级管理员
$staff = Db::table('staff')
->field('staff.id,name,email,d_id,iden_id,si.title as iden_name')
->leftJoin(['staff_identity'=>'si'],'si.id = staff.iden_id')
->where('staff.email','=',$email)
->find();
if(!$staff)
throw new StaffIsNotFoundException;
$staff_roles = Db::table('staff_role')->where('staff_id', '=', $staff['id'])->column('role_id');
$staff['roles'] = implode(',',$staff_roles);
return json([
'code' => 200,
'message' => 'ok',
'data' => $staff
]);
}
//获取员工列表信息
public function getStaffs(){
$staffs = Db::table('staff')
......
......@@ -26,6 +26,11 @@ class Assign
return (new Staff)->getCurrentStaff($id);
}
public function getCurrentStaffByEmail($email){
$this->token->check();
return (new Staff)->getCurrentStaffByEmail($email);
}
public function getStaffs(){
$this->token->check();
return (new Staff)->getStaffs();
......@@ -85,5 +90,8 @@ class Assign
$this->token->check();
return (new BasicInfor)->getDataPermission($uid);
}
}
\ No newline at end of file
public function getDataPermissionByEmail($email){
$this->token->check();
return (new BasicInfor)->getDataPermissionByEmail($email);
}
}
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2021-1-20
* Time: 23:09
*/
namespace app\api\controller\v2\common;
use think\Controller;
use think\Db;
class Contract extends Controller
{
public $pmsdb;
public function initialize()
{
$this->pmsdb = Db::connect([
'type' => config('pms.type'),
'hostname' => config('pms.host'),
'database' => config('pms.dbname'),
'username' => config('pms.dbuser'),
'password' => config('pms.dbpasswd'),
'hostport' => config('pms.dbport'),
'charset' => config('pms.dbcharset'),
]);
}
public function proj(){
$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' => ''
]);
$proj_code = $data['proj_code'];
if (empty($proj_code)) {
return json([
'code' => 202,
'message' => 'Not valid parameter project_code',
]);
}
//查询pms库
$sql = 'SELECT
pp.FIELD_VALUE as htname
FROM
pms_instance_field pp,
pms_field ppf
WHERE
pp.FIELD_ID = ppf.BUSINESS_ID
AND ppf.SPECIAL_TAG = \'contractNumber\'
AND pp.INSTANCE_ID IN (
SELECT
pi.BUSINESS_ID
FROM
pms_instance pi,
pms_instance_field pif,
pms_template t,
pms_field f
WHERE
pi.TEMPLATE_ID = t.BUSINESS_ID
AND pi.BUSINESS_ID = pif.INSTANCE_ID
AND t.DEL_FLAG = 0
AND f.DEL_FLAG = 0
AND t.FLAG = 2
AND f.FLAG = 1
AND t.BUSINESS_ID = f.TEMPLATE_ID
AND f.BUSINESS_ID = pif.FIELD_ID
AND f.SPECIAL_TAG = \'projectNumber\'
AND pif.FIELD_VALUE = \''.$proj_code.'\'
)';
$data = $this->pmsdb->query($sql);
if(!$data || !isset($data[0]) || empty($data[0])) {
return json([
'code' => 201,
'message' => '404',
'data' => '',
]);
}
return json([
'code' => 200,
'message' => 'SUCCESS',
'data' => $data[0],
]);
}
}
\ No newline at end of file
......@@ -14,7 +14,10 @@ use app\em\model\EmInvoice;
use app\em\model\EmPayment;
use app\em\model\EmPaymentFk;
use app\em\model\EmPaymentInvoice;
use app\em\model\EmPaymentInvoiceBalance;
use think\facade\Log;
use think\Db;
class Payment
{
......@@ -41,25 +44,33 @@ class Payment
//更新payment状态
private function update($numb,$status,$mes='')
{
$paymentFk = (new EmPaymentFk())->get(['oafk_numb' => $numb]);
$payment = (new EmPayment())->get(['payment_id' => $paymentFk->payment_id]);
//更新账户余额
$paymentIds = (new EmPaymentFk())->where(['oafk_numb' => $numb])->column('payment_id');
if($payment->account_id != ''){
(new Account())->computerAmountFromPay($payment->account_id,$payment->amount);
$payments = (new EmPayment())->where(['payment_id'=>$paymentIds])->select();
//更新账户余额
$count = 0;
foreach ($payments as $payment){
if($payment->status != $status) {
if($payment->account_id != ''){
(new Account())->computerAmountFromPay($payment->account_id,$payment->amount);
}
$res = (new WriteOff())->writeOffFromPayment($payment->payment_id);
Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb . $res);
$payment->status = $status;
$payment->pay_date = time();
$payment->save();
$count ++ ;
}
}
$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,
'message' => '销账成功 '.$count.' 笔账单已经付款.',
'data' => ''
]);
}
......@@ -77,6 +88,9 @@ class Payment
//删除payment_invoice表
$invoices = (new EmPaymentInvoice())->where('payment_id', '=', $paymentFk->payment_id)->delete();
(new EmPaymentInvoiceBalance())->where('payment_id', '=', $paymentFk->payment_id)->update(['status' => 2]);
//Db::table('em_payment_invoice_balance')->where('payment_id', '=', $payment->payment_id)->update(['status' => 2]);
$message = ' 缴费单: '.$paymentFk->payment_id. '缴费单已作废';
Log::record(date('Y-m-d H:i:s').$message);
return json(
......@@ -85,10 +99,9 @@ class Payment
'message' => $message,
'data' => ''
]);
}
private function checkKey($key)
public function checkKey($key)
{
if (empty($key)) {
return '秘钥不能为空';
......@@ -121,4 +134,4 @@ class Payment
public function commonCheckKey($key){
return $this->checkKey($key);
}
}
\ No newline at end of file
}
差异被折叠。
<?php
/**
* 权限服务,用来提供权限查询
* 返回根据条件查询的权限数据
*/
namespace app\api\service;
use think\Db;
class Authority
{
/**
* 返回数据权限json字符串
* @param $param
* @return array|\PDOStatement|string|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function authorities($param){
$type = 0;
if(stripos($param,'@')) $type = 1;
$uid = $type === 0 ? $param : $this->parseIdFromEmail($param);
$data = db::name('permission_data')->field('permission_ids')->where(['s_id' => $uid])->find();
if (!$data) {
$staff = db::name('staff')->field('d_id')->where(['id' => $uid])->find();
if ($staff && $staff['d_id'] !== 0) {
$data['permission_ids'] = json_encode(['department_id', 'in', $staff['d_id']]); //返回标准数据格式
}
}
return json_decode($data['permission_ids'],true);
}
//通过email返回用户Id
public function parseIdFromEmail($email){
$staff = Db::name('staff')->field('id')->where('email','=',$email)->find();
return $staff['id'];
}
}
\ No newline at end of file
<?php
/**
* 项目服务
* 1.默认返回所有项目编码 名称 部门 区域
* 2.根据条件返回相关项目列表数据
* 3.根据权限返回相关列表数据
*/
namespace app\api\service;
class Project
{
/**
* @param array $conditions
* @param array $authority
* /**
* 查询项目列表
*/
protected function getProjectsByConditions($conditions = [],$authority = []){
}
/**
* 获取所有项目信息
*/
protected function getAllProjects($conditions = [],$authority = []){
}
/**
* 查询单个项目信息
*/
protected function getProject(){
}
/**
* 解析sql条件
* @param array $conditions
*/
protected function parseConditions($conditions = []){
if(empty($conditions) || !is_array($conditions)) return [];
}
}
\ No newline at end of file
......@@ -70,6 +70,8 @@ function curlGet($url=''){
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
$tmpInfo = curl_exec($curl); //返回api的json对象
......@@ -79,6 +81,7 @@ function curlGet($url=''){
}
function httpPOST($url , $post_data = array()){
$post_data = http_build_query($post_data);
$headers = array('Content-Type: application/x-www-form-urlencoded');
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
......@@ -86,8 +89,8 @@ function httpPOST($url , $post_data = array()){
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_POSTFIELDS, $post_data); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 300); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
......@@ -358,4 +361,20 @@ function check_ele_permission($path){
}
return false;
}
\ No newline at end of file
}
function getProjUrl($proj_code){
$pmsdb = Db::connect([
'type' => config('pms.type'),
'hostname' => config('pms.host'),
'database' => config('pms.dbname'),
'username' => config('pms.dbuser'),
'password' => config('pms.dbpasswd'),
'hostport' => config('pms.dbport'),
'charset' => config('pms.dbcharset'),
]);
$sql = 'select INSTANCE_ID from pms_instance_field where DEL_FLAG = 0 and FIELD_VALUE = \''.$proj_code.'\'';
$res = $pmsdb->query($sql);
if($res) $link = 'http://jz.gonn.com.cn/page/index.html#/instances/project/list/detail?pId='.$res[0]['INSTANCE_ID'].'&translation=detail';
return $res ? $link : '';
}
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2021-1-3
* Time: 12:51
*/
namespace app\em\controller;
use app\admin\controller\Base;
use app\admin\model\ElectricMeter;
use app\em\model\EmPayment;
use app\em\model\Staff;
use think\facade\Request;
class Charge extends Base
{
public function index(){
$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':
if(strstr($search_text,',')){
$searchArr = explode(',',$search_text);
$map[]=['pay.payment_id','in',$searchArr];
} else {
$map[]=['pay.payment_id','=',"$search_text"];
}
break;
case '2':
$map[]=['epi.invoice_id','like',"%$search_text%"];
break;
case '3':
$map[]=['em.em_numb','like',"%$search_text%"];
break;
case '4':
$map[]=['station.station_name','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
}
}
$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 ?: '');
//区域
$area_id = Request::get('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'));
//区间查询
if( !empty($dateStart) && !empty($dateEnd) ){
$map[] = ['pay.create_time','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[] = ['pay.create_time','>',$dateStart];
$this->assign('date_start',Request::get('date_start'));
$this->assign('date_end','');
} elseif (empty($dateStart) && !empty($dateEnd)){
$map[] = ['pay.create_time','<',$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;
$region=new ElectricMeter();
$paymentModel = new EmPayment();
$data = $paymentModel->getPaymentList($map,$page,$limit,$where='pay.payment_type in (2,4)');
$PaymentCount = (new EmPayment())->getPaymentCount($map,$where='pay.payment_type in (2,4)');
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$PaymentCount,'data'=>$data];
}
$this->assign('regions',getTree($region->regions()));
return $this->fetch();
}
public function merge(){
$pids = Request::param('pids');
$pids = str_replace('_',',',$pids);
$payments = (new EmPayment)->getPaymentsByPids($pids);
$paymentCtl = new Payment();
$pidstr = '';
//查看是否已经下推过付款单
foreach ($payments as $payment){
if($paymentCtl->checkFkStatus($payment['payment_id'])) return json(['status'=>0,'message'=>'该缴费单已经创建付款单无法再次创建.']);
$pidstr .= $payment->payment_id .',';
}
//获取当前登录人信息
$staff = new Staff();
if($this->user['is_admin'] == 1){
$staff = $staff->get(['name' => $this->user['name']]);
} else {
$staff = $staff->get($this->uid);
}
$payway = $paymentCtl->getFkInfo(1);
$org = $paymentCtl->getFkInfo(2);
$this->assign('payments',$payments);
$this->assign('payee',$paymentCtl->getGys($staff->email));
$this->assign('org',$org);
$this->assign('date',date('Y-m-d H:i:s'));
$this->assign('payway',$payway);
$this->assign('pids',rtrim($pidstr,','));
return $this->fetch('payment/pay_merge');
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ use app\admin\model\ElectricMeterType;
use app\admin\model\OperatorModel;
use app\admin\model\StaffModel;
use app\em\model\Dc;
use app\em\model\EmAccount;
use app\em\model\EmList;
use app\em\model\EmRule;
use app\em\validate\EmAddBaseInfoValidate;
......@@ -81,6 +82,11 @@ class Em extends Base
$emModel = new EmList();
$list = $emModel->getEmList($map,$page,$limit);
foreach ($list as $index => $item){
$list[$index]['projUrl'] = getProjUrl($item['proj_number']);
}
$emCount= $emModel->getEmListCount($map);
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$emCount,'data'=>$list];
......@@ -163,6 +169,7 @@ class Em extends Base
//保存电表 缴费结算信息 与机房信息
private function storeAll($data){
//保存机房数据
$init_amount = $data['init_amount'];
$dcModel = New Dc();
if($dcModel->save($data)){
$data['dc_id'] = $dcModel->id;
......@@ -175,6 +182,9 @@ class Em extends Base
$emRuleModel = new EmRule();
if($emRuleModel->save($data)){
(new Account())->createAccount($emRuleModel->em_id);
$account = EmAccount::get(['em_id'=>$emRuleModel->em_id]);
$account->amount += $init_amount;
$account->save();
return json(['status'=>1,'message'=>'添加电表成功']);
} else {
$emModel->delete();
......@@ -252,15 +262,15 @@ class Em extends Base
if(!$em || !isset($em->rule)){
return false;
}
if($em->rule->charge_type == 1)
if(!isset($em->rule->settle_price) || empty($em->rule->settle_price) || !isset($em->rule->pay_price) || empty($em->rule->pay_price)){
if($em->rule->charge_type == 1) {
if (!is_numeric($em->rule->pay_price) || !is_numeric($em->rule->settle_price) || $em->rule->pay_price == 0 || $em->rule->settle_price == 0) {
return false;
} else {
return true;
}
}
else {
if(!isset($em->rule->settle_price) || empty($em->rule->settle_price)){
if(!is_numeric($em->rule->settle_price) || $em->rule->settle_price == 0){
return false;
} else {
return true;
......@@ -276,4 +286,4 @@ class Em extends Base
if(!$res) return json(['status'=>0,'msg'=>'电表基本信息不完整,请先补充信息再进行抄表']);
return json(['status'=>1,'message'=>'']);
}
}
\ No newline at end of file
}
......@@ -59,6 +59,11 @@ class Invoice extends Base
$map[]=['em.em_numb','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
case '4':
$this->assign('search_text',$search_text);
$map[]=['station.proj_number','like',"%$search_text%"];
$this->assign('search_type',$search_type);
break;
}
}else{
$this->assign('search_type','');
......@@ -117,7 +122,7 @@ class Invoice extends Base
//查看账单信息
public function detail(){
$inv_id = Request::param('id');
$invInfo = (new EmInvoice)->getInvoiceDetail($inv_id);
$this->assign('inv',$invInfo);
return $this->fetch();
......@@ -286,13 +291,12 @@ class Invoice extends Base
$settle_amount = 0;
foreach ($data as $v){
$v->settle_amount = $v->settle_amount ?:0;
$v->payment_amount = is_numeric($v->payment_amount) ? $v->payment_amount : (float)$v->payment_amount;
$payment_amount += $v->payment_amount;
$payment_amount += $v->payment_balance;
$settle_amount += $v->settle_amount;
}
$this->assign('data',$data);
$this->assign('payment_amount',$payment_amount);
$this->assign('settle_amount',$settle_amount);
$this->assign('payment_amount',round($payment_amount,3));
$this->assign('settle_amount',round($settle_amount,3));
return $this->fetch('merge_list');
}
......@@ -429,4 +433,4 @@ class Invoice extends Base
$eModel->delete();
}
}
\ No newline at end of file
}
......@@ -85,6 +85,10 @@ class Useage extends Base
$limit = Request::param('limit')?Request::param('limit'):10;
$data = (new \app\em\model\Useage)->getCopyList($map,$page,$limit);
foreach ($data as $index => $item){
$list[$index]['projUrl'] = getProjUrl($item['proj_number']);
}
$copyCount = (new \app\em\model\Useage)->getCopyListCount($map);
if(Request::param('page')){
return ['code'=>0,'msg'=>'','count'=>$copyCount,'data'=>$data];
......@@ -143,9 +147,10 @@ class Useage extends Base
}
//保存抄表单
public function store(){
public function store($data = null){
//获取表单数据
$data = Request::post();
if($data === null) $data = Request::post();
$useage_id = isset($data['useage_id']) ? $data['useage_id'] : '';
$action = '新增';
//数据验证
......@@ -269,8 +274,9 @@ class Useage extends Base
} else {
$this->assign('staffs',(new Staff())->getStaffs($user['is_admin']));
}
$useage->price = $useage->pricing_type == 1 ? $useage->pay_price : $useage->price;
//$useage->price = $useage->pricing_type == 1 ? $useage->pay_price : $useage->price;
$useage->price = $useage->price ?: $useage->pay_price;
$useage->repo_numb = round(round($useage->current_sum_numb - $useage->last_sum_numb,2) * $useage->rate,2);
$this->assign('em',$em);
......@@ -305,7 +311,7 @@ class Useage extends Base
//找出电表最后一条数据
$lastModel = (new \app\em\model\Useage())->where('em_id','=',$uModel->em_id)
->order('id desc')->find();
->order('current_date desc')->find();
if($lastModel->status == 2) return json(['status'=>0,'message'=>"单号不是最新的抄表记录且最新的抄表记录已经审核无法操作,请联系管理员"]);
if($uModel->id != $lastModel->id){
return json(['status'=>0,'message'=>"抄表单号不是最新的抄表记录无法操作,请联系管理员"]);
......@@ -318,4 +324,4 @@ class Useage extends Base
$user = Session::get('user');
(new EmCheckBill)->check(Request::param('refuseInfo'),$user['user_id'],Request::controller(),$usage_id,$status);
}
}
\ No newline at end of file
}
差异被折叠。
......@@ -11,7 +11,64 @@ use think\facade\Log;
class WriteOff extends Controller
{
//新的预交费销账逻辑 支持部分销账
public function writeOffFromPaymentBalance($payment_id){
Log::info('触发销账:{$payment_id}');
//获取缴费单对象
$payment = EmPayment::where('payment_id','=',$payment_id)->find();
$invBalanceModel = new EmPaymentInvoiceBalance();
$invs = $invBalanceModel->alias('a')->field('a.*')
->join(['em_payment_invoice'=>'b'],'b.invoice_id = a.invoice_id')
->where('b.payment_id','=',$payment_id)
->where('a.balance','neq',0)
->where('a.status','eq',0)
->order('a.invoice_id asc')
->select();
if($invs->isEmpty()) {
if($payment->payment_type == 1 || $payment->payment_type == 3) return '销账异常,没有找到匹配的账单';
}
$result = 0;
foreach ($invs as $inv){
//查询账单信息
$invModel = EmInvoice::get(['invoice_id'=>$inv->invoice_id]);
//更新账单余额
$invModel->payment_balance = $invModel->payment_balance - $inv->balance;
//缴费状态 1默认缴费
$status = 1;
//已缴清
if($invModel->payment_balance == 0) $status = 2;
//更新缴费状态
$invModel->status = setInvoiceStatus($invModel->status,$status,0);
$invModel->save();
//更新缴费单余额
$payment->balance = $payment->balance - $inv->balance;
if($payment->balance == 0) $payment->status = 1;
$payment->save();
//更新缴费明细状态为生效
$inv->status = 1;
$inv->save();
$result ++ ;
}
return '已审核,成功销账 '.$result.' 笔账单.';
}
public function writeOffFromPayment($payment_id){
return $this->writeOffFromPaymentBalance($payment_id);
$invBalanceModel = new EmPaymentInvoiceBalance();
$invBalances = $invBalanceModel->alias('a')->field('a.invoice_id')
->join(['em_payment_invoice'=>'b'],'b.invoice_id = a.invoice_id')
->where('a.payment_id','=',$payment_id)
->where('a.balance','neq',0)
->where('a.status','eq',0)
->order('a.invoice_id asc')
->select();
Log::info('触发销账:{$payment_id}');
//获取缴费单对象
......@@ -74,6 +131,7 @@ class WriteOff extends Controller
->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')
......@@ -89,7 +147,13 @@ class WriteOff extends Controller
->order('payment_id asc')
->select();
if($payments->isEmpty()) return '没有找到可销账的缴费单!';
}
} */
$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;
......@@ -130,7 +194,7 @@ class WriteOff extends Controller
$balanceMode = new EmPaymentInvoiceBalance();
$balanceMode->payment_id = $payment->payment_id;
$balanceMode->invoice_id = $inv->invoice_id;
$balanceMode->status = 1;
//如果该缴费单可以完全消除当前账单额度
if ($payment->balance >= $inv->payment_balance) {
//单笔销账多少
......@@ -150,7 +214,6 @@ class WriteOff extends Controller
$inv->payment_balance = $inv->payment_balance - $payment->balance;
//缴费额度变化
$payment->balance = 0;
}
//更新账单状态
......
......@@ -6,4 +6,10 @@ use think\Model;
class Base extends Model
{
protected $autoWriteTimestamp = true;
public function getUidAttr($val){
if (empty($val)) return '';
$staff = Staff::field('name as uname')->find($val);
return $staff->uname;
}
}
\ No newline at end of file
......@@ -32,18 +32,18 @@ class EmInvoice extends Base
public function getInvoiceList($map,$Nowpage,$limits){
$data = self::alias('inv')
->field('inv.*')
->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')
->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')
->field('station.station_name,station.proj_number,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,eu.price')
->leftJoin(['em_invoice_useage'=>'eiu'],'eiu.invoice_id = inv.invoice_id')
->leftJoin(['em_useage'=>'eu'],'eu.useage_id = eiu.useage_id')
->leftJoin(['em'],'em.id=inv.em_id')
->leftJoin(['station_info'=>'station'],'station.station_id=em.station_id')
->where($map)
->page($Nowpage, $limits)
->order('inv.id desc')
->select()
->toarray();
->toArray();
$step = 100000;
......@@ -63,6 +63,7 @@ class EmInvoice extends Base
} else {
$item['sett_amount'] = round($item['settle_amount'] - $item['settle_balance'],3);
}
$item['projUrl'] = getProjUrl($item['proj_number']);
$item['repo_numb'] = ($item['current_sum_numb'] * $step - $item['last_sum_numb'] * $step ) * $item['rate'] / $step;
}
......@@ -100,37 +101,31 @@ class EmInvoice extends Base
//账单详情
public function getInvoiceDetail($id){
//当前账单对象
if(strstr($id,'ZD')){
$inv = self::alias('in')
->field('in.*,r.src')
->leftJoin(['receipt'=>'r'],'r.id = in.cert_id')
->get(['invoice_id'=>$id]);
} else {
$inv = self::alias('in')
->field('in.*,r.src')
->leftJoin(['receipt'=>'r'],'r.id = in.cert_id')
->get($id);
}
$where = null;
if(strstr($id,'ZD')) $where = ['invoice_id'=>$id];
else $where = $id;
$inv = self::alias('in')
->field('in.*,r.src')
->leftJoin(['receipt'=>'r'],'r.id = in.cert_id')
->get($where);
//查询抄表单ID
$eiu = EmInvoiceUseage::where(['invoice_id'=>$inv->invoice_id])->find();
//查询抄表信息
//查询对应抄表单
$uModel = Useage::get(['useage_id'=>$eiu->useage_id]);
if(isset($uModel->cert_id) && $uModel->cert_id != ''){
$useage = Useage::with('photo')->get(['useage_id'=>$eiu->useage_id]);
if($useage->photo_id) {
$receipt = Receipt::get(['id'=>$useage->photo_id]);
if($receipt) $useage['photo'] = $receipt;
}
} else {
$useage = $uModel;
$useage['photo'] = [];
$photo_id = $inv->cert_id ?: $uModel->photo_id;
//如果存在附件ID 则找到附件信息
if($photo_id) {
$receipt = Receipt::get($photo_id) ;
$inv->receipt = $receipt;
}
//获取电表信息
$em = Em::with('rule')->field('id,station_id,em_numb,em_type_id,rate')->where(['id'=>$useage->em_id])->find();
$em = Em::with('rule')->field('id,station_id,em_numb,em_type_id,rate')->where(['id'=>$inv->em_id])->find();
$emr = EmRule::field('charge_type,pay_price,settle_price')->where(['em_id'=>$em->id])->order('id desc,create_time desc')->find();
//电表类型
......@@ -150,80 +145,11 @@ class EmInvoice extends Base
$inv->em = $em;
$inv->em->emr = $emr;
$inv->station = $station;
$inv->useage = $useage;
$inv->useage = $uModel;
$inv->payStatus = getInvoicesStatusName($inv->status,0);
$inv->settleStatus = getInvoicesStatusName($inv->status,1);
//峰谷表
if($inv['type'] != 5){
$ud = UseageDetail::field('*,case type
when 1 then "尖峰段"
when 2 then "峰段"
when 3 then "谷段"
when 4 then "平段"
else "普通" end as typeName
')
->where(['useage_id'=>$useage->useage_id])->select();
$totle = [];
$totle['typeName'] = '汇总';
$totle['rate'] = $inv->rate;
$totle['last_numb'] = $inv->rate;
$totle['price'] = '/';
$totle['status'] = parseStatus($inv->status,1);
$totle['current_numb'] = 0;
$totle['repo_numb'] = 0;
$totle['amount'] = $totle['settle_amount'] = 0;
$totle['settle_price'] = ($inv->em->emr->settle_price?:0) * $inv->em->rate;
$totle['settle_status'] = parseStatus($inv->status,2);
//峰谷表与普通抄表
if($ud) {
foreach ($ud as $u){
$u->rate = $inv->rate;
$u->repo_numb = $u->current_numb - $u->last_numb;
$u->amount = $u->repo_numb * $u->price;
$totle['last_numb'] += $u->last_numb;
$totle['current_numb'] += $u->current_numb;
$totle['repo_numb'] += $u->repo_numb;
$totle['amount'] += $u->amount;
$totle['settle_amount'] += $u->repo_numb*$totle['settle_price'];
if($inv->em->emr->settle_price != ''){
$totle['settle_amount'] = $totle['repo_numb'] * $totle['settle_price'];
}
else{
$totle['settle_amount'] = $inv->settle_amount ?: 0;
}
}
$inv->useage->ud = $ud;
} else { //包年包月
$totle['price'] = $inv->em->emr->price;
$totle['settle_price'] = $inv->em->emr->settle_price;
$totle['last_numb'] = $inv->useage->last_numb;
$totle['current_numb'] = $inv->useage->current_numb;
$totle['repo_numb'] = $totle['current_numb']-$totle['last_numb'];
$totle['amount'] = $totle['repo_numb'] * $totle['price'];
if($inv->em->emr->settle_price != ''){
$totle['settle_amount'] = $totle['repo_numb'] * $totle['settle_price'];
}
else{
$totle['settle_amount'] = $inv->settle_amount ?: 0;
}
}
$inv->useage->totle = $totle;
} else {
$totle = [];
if($inv->em->emr->settle_price != ''){
$totle['settle_amount'] = $inv->em->emr->settle_price * $inv->repo_numb ;
$totle['settle_amount'] = round($totle['settle_amount'],3);
}
else{
$totle['settle_amount'] = 0;
}
}
if($inv->payment_balance == 0){
$inv->paid_amount = $inv->payment_amount;
} else {
......@@ -242,4 +168,4 @@ class EmInvoice extends Base
public function photo(){
return $this->belongsTo('Receipt','cert_id');
}
}
\ No newline at end of file
}
<?php
namespace app\em\model;
class EmInvoice extends Base
{
protected $table = 'em_invoice';
/**
* 首页列表
* @param int $page
* @return \think\Paginator
* @throws \think\exception\DbException
*/
public function getList($page = 0){
$config = !empty($config) ?: [
'list_rows'=>30,
'page'=> $page,
'type' => '\app\extend\PageLayUi',
'var_page' => 'page'
];
$data = self::alias('inv')
->field('inv.*')
->field('station.station_name')
->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')
->leftJoin(['em'],'em.id=eu.em_id')
->leftJoin(['station_info'=>'station'],'station.station_id=em.station_id')
->paginate($config);
return $data;
}
//账单查询+search
public function getInvoiceList($map,$Nowpage,$limits){
$data = self::alias('inv')
->field('inv.*')
->field('station.station_name,station.proj_number,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,eu.price')
->join(['em_invoice_useage'=>'eiu'],'eiu.invoice_id = inv.invoice_id')
->join(['em_useage'=>'eu'],'eu.useage_id = eiu.useage_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($map)
->page($Nowpage, $limits)
->order('inv.id desc')
->select()
->toArray();
$step = 100000;
foreach ($data as &$item){
if($item['payment_balance'] == 0){
$item['paid_amount'] = $item['payment_amount'] ;
} else {
if(!is_numeric($item['payment_amount']) || !is_numeric($item['payment_balance'])){
$item['payment_amount'] = (float)$item['payment_amount'];
$item['payment_balance'] = (float)$item['payment_balance'];
}
$item['paid_amount'] = round($item['payment_amount'] - $item['payment_balance'],3);
}
if($item['settle_balance'] == 0){
$item['sett_amount'] = $item['settle_amount'] ;
} else {
$item['sett_amount'] = round($item['settle_amount'] - $item['settle_balance'],3);
}
$item['projUrl'] = getProjUrl($item['proj_number']);
$item['repo_numb'] = ($item['current_sum_numb'] * $step - $item['last_sum_numb'] * $step ) * $item['rate'] / $step;
}
return $data;
}
public function getInvoiceCount($map){
$data = self::alias('inv')
->field('inv.*')
->field('station.station_name,em.em_numb')
->field('eu.last_sum_numb,eu.current_sum_numb,eu.current_date')
->join(['em_account'=>'ea'],'ea.account_id = inv.account_id')
->join(['em'],'em.id=ea.em_id')
->join(['em_invoice_useage'=>'eiu'],'eiu.invoice_id = inv.invoice_id')
->join(['em_useage'=>'eu'],'eu.useage_id = eiu.useage_id')
->join(['station_info'=>'station'],'station.station_id=em.station_id')
->where($map)
->count();
return $data;
}
//通过invoice_id查询列表数据
public function getListByInvIds($ids){
$data = self::alias('inv')
->field('inv.*')
->field('station.station_name')
->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])
->whereNotIn('em.em_type_id','2,4')
->where('inv.payment_balance','neq',0)
->select();
return $data;
}
//账单详情
public function getInvoiceDetail($id){
//当前账单对象
$where = null;
if(strstr($id,'ZD')) $where = ['invoice_id'=>$id];
else $where = $id;
$inv = self::alias('in')
->field('in.*,r.src')
->leftJoin(['receipt'=>'r'],'r.id = in.cert_id')
->get($where);
$eiu = EmInvoiceUseage::where(['invoice_id'=>$inv->invoice_id])->find();
//查询对应抄表单
$uModel = Useage::get(['useage_id'=>$eiu->useage_id]);
$photo_id = $inv->cert_id ?: $uModel->photo_id;
//如果存在附件ID 则找到附件信息
if($photo_id) {
$receipt = Receipt::get($photo_id) ;
$inv->receipt = $receipt;
}
//获取电表信息
$em = Em::with('rule')->field('id,station_id,em_numb,em_type_id,rate')->where(['id'=>$inv->em_id])->find();
$emr = EmRule::field('charge_type,pay_price,settle_price')->where(['em_id'=>$em->id])->order('id desc,create_time desc')->find();
//电表类型
$emt = EmType::field('name as typeName')->where(['id'=>$em->em_type_id])->find();
$em->typeName = $emt['typeName'];
if($emr->charge_type == 1){
$em->chargeType = '读表';
} else if($emr->charge_type == 2){
$em->chargeType = '包月';
} else if($emr->charge_type == 3){
$em->chargeType = '包年';
}
//获取基站信息
$station = Station::field('station_name,station_sp_code')->where(['station_id'=>$em->station_id])->find();
//组合
$inv->em = $em;
$inv->em->emr = $emr;
$inv->station = $station;
$inv->useage = $uModel;
$inv->payStatus = getInvoicesStatusName($inv->status,0);
$inv->settleStatus = getInvoicesStatusName($inv->status,1);
if($inv->payment_balance == 0){
$inv->paid_amount = $inv->payment_amount;
} else {
$inv->paid_amount = $inv->payment_amount - $inv->payment_balance;
}
if($inv->settle_balance == 0){
$inv->sett_amount = $inv->settle_amount;
} else {
$inv->sett_amount = $inv->settle_amount - $inv->settle_balance;
}
return $inv;
}
public function photo(){
return $this->belongsTo('Receipt','cert_id');
}
}
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论