custractModel.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. $newid = m('custfina')->insert($arr);
  102. if($this->rs['type']=='0'){
  103. m('flow')->submit('custfina', $newid, '提交');
  104. }else{
  105. m('flow')->submit('custfinb', $newid, '提交');
  106. }
  107. }
  108. }
  109. }
  110. /**
  111. * 客户合同到期提醒
  112. */
  113. public function custractdaoqi()
  114. {
  115. $dt = $this->rock->date;
  116. $rows = $this->getall("status=1 and `enddt` is not null and `enddt`>='$dt'",'uid,num,custname,enddt','`uid`');
  117. $txlist = m('option')->getval('crmtodo','0,3,7,15,30');//提醒的时间
  118. $txarr = explode(',', $txlist);
  119. $dtobj = c('date');
  120. $txrows = array();
  121. foreach($rows as $k=>$rs){
  122. $jg = $dtobj->datediff('d', $dt, $rs['enddt']);
  123. $uid= $rs['uid'];
  124. if(in_array($jg, $txarr)){
  125. $strs = ''.$jg.'天后('.$rs['enddt'].')';
  126. if($jg==1)$strs='明天';
  127. if($jg==0)$strs='今天';
  128. if(!isset($txrows[$uid]))$txrows[$uid]='';
  129. $txrows[$uid] .= '客户['.$rs['custname'].']的[合同:'.$rs['num'].']将在'.$strs.'到期;';
  130. }
  131. }
  132. foreach($txrows as $uid=>$cont){
  133. $this->push($uid, '客户,CRM', $cont, '客户合同到期提醒');
  134. }
  135. }
  136. //对外的详情页
  137. public function flowopenxiang($da, $xiangdata)
  138. {
  139. $zdarr = array('num','custname','type','fenlei','signdt','money','startdt','enddt','explain');
  140. $slsts = array();
  141. foreach($xiangdata as $k=>$rs){
  142. if(in_array($rs['fields'], $zdarr)){
  143. $slsts[] = $rs;
  144. }
  145. }
  146. //相关文件
  147. $filedata = array();
  148. $htfileid = arrvalue($da,'htfileid');
  149. if($htfileid){
  150. $filedata = m('file')->getall('id in('.$htfileid.')','id,filename,filesizecn,fileext');
  151. }
  152. return array('xiangdata'=>$slsts,'filedata'=>$filedata);
  153. }
  154. }
粤ICP备19079148号