custractModel.php 4.9 KB

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