custractModel.php 4.8 KB

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