finaModel.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class finaClassModel extends Model
  3. {
  4. public function initModel()
  5. {
  6. $this->settable('fininfom');
  7. }
  8. //统计我未还款
  9. public function totaljie($uid, $id=0)
  10. {
  11. $where = 'and id<>'.$id.'';
  12. $to1 = floatval($this->getmou('sum(money)money',"`uid`='$uid' and `type`=2 and `status`=1"));
  13. $to2 = floatval($this->getmou('sum(money)money',"`uid`='$uid' and `type`=3 and `status`<>5 $where"));
  14. $to = $to1-$to2;
  15. return $to;
  16. }
  17. public function getjkdwhere()
  18. {
  19. return '(select `uid` from `[Q]fininfom` where `type`=2 and `status`=1)';
  20. }
  21. //统计
  22. public function totalfkd($rows, $uids)
  23. {
  24. $carr = $barr = array();
  25. //借款
  26. $hkto = $this->db->getall("select uid,sum(money)money from `[Q]fininfom` where `uid` in($uids) and `type`=2 and `status`=1 group by `uid`");
  27. foreach($hkto as $k=>$rs)$carr[$rs['uid']] = $rs['money'];
  28. //还的
  29. $hkto = $this->db->getall("select uid,sum(money)money from `[Q]fininfom` where `uid` in($uids) and `type`=3 and `status`=1 group by `uid`");
  30. foreach($hkto as $k=>$rs)$barr[$rs['uid']] = $rs['money'];
  31. foreach($rows as $k=>$rs){
  32. $uid = $rs['id'];
  33. $moneyjk = floatval(arrvalue($carr, $uid, 0));
  34. $moneyhk = floatval(arrvalue($barr, $uid, 0));
  35. $moneyhx = $moneyjk - $moneyhk;
  36. if($moneyjk==0)$moneyjk='';
  37. if($moneyhk==0)$moneyhk='';
  38. if($moneyhx==0)$moneyhx='';
  39. $rows[$k]['moneyjk'] = $moneyjk;
  40. $rows[$k]['moneyhk'] = $moneyhk;
  41. $rows[$k]['moneyhx'] = $moneyhx;
  42. }
  43. return $rows;
  44. }
  45. //获取当前账套
  46. public function getzhangtao($lx=0)
  47. {
  48. $dt = $this->rock->date;
  49. $where= m('admin')->getcompanywhere(3);
  50. if($lx==0)$where.=" and `startdt`<='$dt' and `enddt`>='$dt'";
  51. $rows = m('finzhang')->getall("status=1 ".$where."",'*','sort, startdt desc');
  52. $arr = array();
  53. foreach($rows as $k=>$rs){
  54. $arr[] = array(
  55. 'value' => $rs['id'],
  56. 'name' => $rs['name'],
  57. 'subname' => $rs['startdt'].'→'.$rs['enddt'],
  58. );
  59. }
  60. return $arr;
  61. }
  62. //获取财务帐号
  63. public function getaccount()
  64. {
  65. $where= m('admin')->getcompanywhere(3);
  66. $rows = m('finount')->getall("status=1 ".$where."",'*','sort');
  67. $arr = array();
  68. foreach($rows as $k=>$rs){
  69. $arr[] = array(
  70. 'value' => $rs['id'],
  71. 'name' => $rs['name'],
  72. );
  73. }
  74. return $arr;
  75. }
  76. //更新财务帐号金额
  77. public function updatemoney($accid='')
  78. {
  79. $where= '';
  80. if(!isempt($accid))$where=' and `accountid`='.$accid.'';
  81. $rows = $this->db->getall('SELECT accountid,SUM(money)money FROM `[Q]finjibook` where `status`=1 '.$where.' group by accountid');
  82. $db = m('finount');
  83. $ids= '0';
  84. foreach($rows as $k=>$rs){
  85. $db->update('`money`='.$rs['money'].'', $rs['accountid']);
  86. $ids.=','.$rs['accountid'].'';
  87. }
  88. if(isempt($accid))$db->update('`money`=0', '`id` not in('.$ids.')');
  89. }
  90. }
粤ICP备19079148号