UserBank.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class UserBank extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'user_id' => input('uid/d',0),
  12. 'card' => input('card','','trim'),
  13. 'card_name' => input('cardName','','trim'),
  14. 'address' => input('address','','trim'),
  15. 'type' => input('type','','trim'),
  16. 'certificate' => input('certificate','','trim'),
  17. 'use' => input('use','','trim'),
  18. 'remark' => input('remark','','trim'),
  19. ];
  20. $result = validate('UserBank')->check($data,[],'');
  21. if(true !== $result){
  22. HelpHander::error(validate('UserBank')->getError());
  23. }
  24. $ubase = Db::name('user_bank')->where('user_id',$data['user_id'])->find();
  25. if($ubase){ // 修改
  26. $data['update_time'] = date('Y-m-d H:i:s');
  27. $res = Db::name('user_bank')->where('id',$ubase['id'])->update($data);
  28. } else {// 新增
  29. $data['create_time'] = date('Y-m-d H:i:s');
  30. $data['update_time'] = date('Y-m-d H:i:s');
  31. $res = Db::name('user_bank')->insert($data);
  32. }
  33. if(!$res){
  34. HelpHander::error('操作失败');
  35. }
  36. return true;
  37. }
  38. public function lists($page,$size,$name,$payType,$companyId,$orgId){
  39. $uids = model('User')->getAdminUsers();
  40. if($uids){
  41. $map[] = ['u.id','not in',$uids];
  42. }
  43. if($name){
  44. $map[] = ['ui.name','like','%'.$name.'%'];
  45. }
  46. if($payType >= 0){
  47. $map[] = ['ui.pay_type','=',$payType];
  48. }
  49. if($companyId >= 0){
  50. $map[] = ['ui.company_id','=',$companyId];
  51. }
  52. $map[] = ['u.del','=',0];
  53. $map[] = ['r.type','=',3];
  54. $map[] = ['r.org_id','=',$orgId];
  55. $lists = Db::name('user_info')
  56. ->alias('ui')
  57. ->join('user u','ui.user_id = u.id')
  58. ->join('user_roles ur','ur.user_id = u.id')
  59. ->join('roles r','ur.roles_id = r.id')
  60. ->join('user_bank ub','ub.user_id = ui.user_id','left')
  61. ->where($map)
  62. ->field('u.enable,ui.user_id as uid,ui.name,ui.gender,ui.pay_type,ui.is_working,ub.*')
  63. ->page($page,$size)
  64. ->order('ui.sorts3 asc,u.id desc')
  65. ->select();
  66. $lists = $lists?$lists:[];
  67. $total = Db::name('user_info')
  68. ->alias('ui')
  69. ->join('user u','ui.user_id = u.id')
  70. ->join('user_roles ur','ur.user_id = u.id')
  71. ->join('roles r','ur.roles_id = r.id')
  72. ->join('user_bank ub','ub.user_id = ui.user_id','left')
  73. ->where($map)
  74. ->count();
  75. $data = [
  76. 'total' => $total,
  77. 'list' => $lists?$lists:[]
  78. ];
  79. return $data;
  80. }
  81. public function export($id){
  82. $info = model('SalaryRecord')->info($id);
  83. if($info['type'] == 5){ // 退休
  84. $lists = Db::name('user_retired_salary')
  85. ->alias('ur')
  86. ->join('user_info ui','ui.user_id = ur.user_id')
  87. ->join('user_bank ub','ub.user_id = ur.user_id','left')
  88. ->where('ur.salary_record_id',$id)
  89. ->field('ur.salary,ub.*,ui.name')
  90. ->order('ui.sorts3 asc,ur.id desc')
  91. ->select();
  92. } else {
  93. $lists = Db::name('salary_record_log')
  94. ->alias('ur')
  95. ->join('user_info ui','ui.user_id = ur.user_id')
  96. ->join('user_bank ub','ub.user_id = ur.user_id','left')
  97. ->where('ur.salary_record_id',$id)
  98. ->field('ur.salary,ub.*,ui.name')
  99. ->order('ui.sorts3 asc,ur.id desc')
  100. ->select();
  101. }
  102. $lists = $lists?$lists:[];
  103. foreach ($lists as $k=>$v){
  104. $lists[$k]['sn'] = $k+1;
  105. }
  106. if(in_array($info['type'],[1,2,5,6,8])){ // 中心
  107. $columns[] = ["title" => "账号","key" => "card"];
  108. $columns[] = ["title" => "户名","key" => "name"];
  109. $columns[] = ["title" => "金额","key" => "salary"];
  110. $columns[] = ["title" => "账号所属省份","key" => "address"];
  111. $columns[] = ["title" => "证件类型","key" => "type"];
  112. $columns[] = ["title" => "证件号码","key" => "certificate"];
  113. $columns[] = ["title" => "用途","key" => "use"];
  114. $columns[] = ["title" => "附言","key" => "remark"];
  115. }else{ // 新华
  116. $columns[] = ["title" => "序号","key" => "sn"];
  117. $columns[] = ["title" => "账号","key" => "card"];
  118. $columns[] = ["title" => "户名","key" => "name"];
  119. $columns[] = ["title" => "金额","key" => "salary"];
  120. $columns[] = ["title" => "跨行标识","key" => "address"];
  121. $columns[] = ["title" => "行名","key" => "type"];
  122. $columns[] = ["title" => "联行行号","key" => "certificate"];
  123. $columns[] = ["title" => "摘要","key" => "use"];
  124. $columns[] = ["title" => "备注","key" => "remark"];
  125. }
  126. $data = [
  127. 'columns' => $columns,
  128. 'list' => $lists
  129. ];
  130. return $data;
  131. }
  132. }