custractModel.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. class flow_custractClassModel extends flowModel
  3. {
  4. public function initModel(){
  5. $this->typearr = array('收款合同','付款合同');
  6. $this->typesarr = array('收','付');
  7. $this->statearr = c('array')->strtoarray('待生效|blue,生效中|green,已过期|#888888');
  8. $this->dtobj = c('date');
  9. $this->crmobj = m('crm');
  10. $this->goodmobj = m('goodm');
  11. $this->wherejoin['custfina'] = 'htid';
  12. }
  13. //作废或删除时
  14. protected function flowzuofeibill($sm)
  15. {
  16. m('goodm')->update('`custractid`=0', "`custractid`='".$this->id."'");//销售单取消关联合同
  17. $xiaoid = (int)arrvalue($this->rs,'xiaoid','0');
  18. }
  19. public function flowrsreplace($rs, $lx=0){
  20. $type = $rs['type'];
  21. $rs['type'] = $this->typearr[$type];
  22. $statetext = '';
  23. $dt = $this->rock->date;
  24. $htstatus = 0;
  25. if($rs['startdt']>$dt){
  26. $statetext='待生效';
  27. }else if($rs['startdt']<=$dt && $rs['enddt']>=$dt){
  28. $jg = $this->dtobj->datediff('d', $dt, $rs['enddt']);
  29. $statetext='<font color=green>生效中</font><br><font color=#888888>'.$jg.'天过期</font>';
  30. if($jg==0)$statetext='<font color=green>今日到期</font>';
  31. $htstatus = 1;
  32. }else if($rs['enddt']<$dt){
  33. $statetext='<font color=#888888>已过期</font>';
  34. $rs['ishui'] = 1;
  35. $htstatus = 2;
  36. }
  37. $rs['statetext'] = $statetext;
  38. $nrss = $this->crmobj->ractmoney($rs);
  39. $ispay = $nrss[0];
  40. $moneys = $nrss[1];
  41. $dsmoney = '';
  42. $ts = $this->typesarr[$type];
  43. if($ispay==1){
  44. $dsmoney = '<font color=green>已全部'.$ts.'款</font>';
  45. }else{
  46. $dsmoney = '待'.$ts.'<font color=#ff6600>'.$moneys.'</font>';
  47. }
  48. if(isset($rs['xiaoid']) && $rs['xiaoid']>0){
  49. $xiaors = $this->goodmobj->getone("`id`='".$rs['xiaoid']."' and `status`<>5");
  50. if($xiaors){
  51. if($lx==1){
  52. $dsmoney.=',销售单:<a href="'.$this->getxiangurl('custxiao',$rs['xiaoid'],'auto').'">'.$xiaors['num'].'</a>';
  53. }else{
  54. $dsmoney.=',销售单:<br>'.$xiaors['num'].'';
  55. }
  56. }else{
  57. $this->update('`xiaoid`=0', $rs['id']);
  58. }
  59. }
  60. $rs['moneys'] = $dsmoney;
  61. $rs['htstatus'] = $htstatus;
  62. return $rs;
  63. }
  64. protected function flowbillwhere($uid, $lx)
  65. {
  66. $month = $this->rock->post('dt');
  67. $where = '';
  68. if($month!=''){
  69. $where =" and `signdt` like '$month%'";
  70. }
  71. return array(
  72. 'where' => $where,
  73. 'order' => '`optdt` desc',
  74. //'orlikefields' => 'custname'
  75. );
  76. }
  77. protected function flowoptmenu($ors, $arrs)
  78. {
  79. //创建待收付款单
  80. if($ors['num']=='cjdaishou'){
  81. $moneys = m('crm')->getmoneys($this->rs['id']);
  82. $money = $this->rs['money'] - $moneys;
  83. if($money > 0){
  84. $arr['htid'] = $this->rs['id'];
  85. $arr['htnum'] = $this->rs['num'];
  86. $arr['uid'] = $this->rs['uid'];
  87. $arr['custid'] = $this->rs['custid'];
  88. $arr['custname']= $this->rs['custname'];
  89. $arr['dt'] = $this->rock->date;
  90. $arr['optdt'] = $this->rock->now;
  91. $arr['createdt']= $this->rock->now;
  92. $arr['optname'] = $this->adminname;
  93. $arr['createname']= $this->adminname;
  94. $arr['createid'] = $this->adminid;
  95. //$arr['optid'] = $this->adminid;
  96. $arr['type'] = $this->rs['type'];
  97. $arr['explain'] = $arrs['sm'];
  98. $arr['money'] = $money;
  99. m('custfina')->insert($arr);
  100. }
  101. }
  102. }
  103. /**
  104. * 客户合同到期提醒
  105. */
  106. public function custractdaoqi()
  107. {
  108. $dt = $this->rock->date;
  109. $rows = $this->getall("status=1 and `enddt` is not null and `enddt`>='$dt'",'uid,num,custname,enddt','`uid`');
  110. $txlist = m('option')->getval('crmtodo','0,3,7,15,30');//提醒的时间
  111. $txarr = explode(',', $txlist);
  112. $dtobj = c('date');
  113. $txrows = array();
  114. foreach($rows as $k=>$rs){
  115. $jg = $dtobj->datediff('d', $dt, $rs['enddt']);
  116. $uid= $rs['uid'];
  117. if(in_array($jg, $txarr)){
  118. $strs = ''.$jg.'天后('.$rs['enddt'].')';
  119. if($jg==1)$strs='明天';
  120. if($jg==0)$strs='今天';
  121. if(!isset($txrows[$uid]))$txrows[$uid]='';
  122. $txrows[$uid] .= '客户['.$rs['custname'].']的[合同:'.$rs['num'].']将在'.$strs.'到期;';
  123. }
  124. }
  125. foreach($txrows as $uid=>$cont){
  126. $this->push($uid, '客户,CRM', $cont, '客户合同到期提醒');
  127. }
  128. }
  129. //对外的详情页
  130. public function flowopenxiang($da, $xiangdata)
  131. {
  132. $zdarr = array('num','custname','type','fenlei','signdt','money','startdt','enddt','explain');
  133. $slsts = array();
  134. foreach($xiangdata as $k=>$rs){
  135. if(in_array($rs['fields'], $zdarr)){
  136. $slsts[] = $rs;
  137. }
  138. }
  139. //相关文件
  140. $filedata = array();
  141. $htfileid = arrvalue($da,'htfileid');
  142. if($htfileid){
  143. $filedata = m('file')->getall('id in('.$htfileid.')','id,filename,filesizecn,fileext');
  144. }
  145. return array('xiangdata'=>$slsts,'filedata'=>$filedata);
  146. }
  147. }