customerAction.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. class customerClassAction extends Action
  3. {
  4. public function custtotalbefore($table)
  5. {
  6. $where = '';
  7. $uid = $this->adminid;
  8. $lx = $this->post('atype');
  9. $month = $this->month = $this->post('month',date('Y-m'));
  10. $key = $this->post('key');
  11. if($lx=='my'){
  12. $where=' and `id`='.$uid.'';
  13. }
  14. if($lx=='down'){
  15. $s = m('admin')->getdownwheres('id', $uid, 0);
  16. $where =' and ('.$s.' or `id`='.$uid.')';
  17. }
  18. if($lx!='my' && $lx!='down'){
  19. $where = m('admin')->getcompanywhere(5);
  20. }
  21. if($key!=''){
  22. $where .= m('admin')->getkeywhere($key);
  23. }
  24. return array(
  25. 'fields'=> 'id,name,deptname',
  26. 'where' => $where,
  27. );
  28. }
  29. public function custtotalafter($table,$rows)
  30. {
  31. $crm = m('crm');
  32. foreach($rows as $k=>$rs){
  33. $rows[$k]['month'] = $this->month;
  34. $toarr = $crm->moneytotal($rs['id'], $this->month);
  35. foreach($toarr as $f=>$v){
  36. if($v==0)$v='';
  37. $rows[$k][$f] = $v;
  38. }
  39. }
  40. return array(
  41. 'rows' => $rows
  42. );
  43. }
  44. public function custtotalgebefore($table)
  45. {
  46. return 'and 1=2';
  47. }
  48. public function custtotalgeafter($t, $rows)
  49. {
  50. $rows = array();
  51. $crm = m('crm');
  52. $dtobj = c('date');
  53. $uid = $this->post('uid', $this->adminid);
  54. $urs = m('admin')->getone($uid, 'name,deptname');
  55. $start = $this->post('startdt', date('Y-01'));
  56. $end = $this->post('enddt', date('Y-m'));
  57. $jgm = $dtobj->datediff('m', $start.'-01', $end.'-01');
  58. for($i=0; $i<=$jgm; $i++){
  59. $month = $dtobj->adddate($end.'-01', 'm', 0-$i, 'Y-m');
  60. $arr['month'] = $month;
  61. $arr['name'] = $urs['name'];
  62. $arr['deptname']= $urs['deptname'];
  63. $toarr = $crm->moneytotal($uid, $month);
  64. foreach($toarr as $f=>$v){
  65. if($v==0)$v='';
  66. $arr[$f] = $v;
  67. }
  68. $rows[] = $arr;
  69. }
  70. $barr['rows'] = $rows;
  71. $barr['totalCount'] = count($rows);
  72. return $barr;
  73. }
  74. //客户转移
  75. public function movecustAjax()
  76. {
  77. $sid = c('check')->onlynumber($this->post('sid'));
  78. $toid = (int)$this->post('toid');
  79. if($sid==''||$sid=='')return;
  80. m('crm')->movetouser($this->adminid, $sid, $toid);
  81. }
  82. public function retotalAjax()
  83. {
  84. m('crm')->custtotal();
  85. }
  86. //批量添加客户
  87. public function addplcustAjax()
  88. {
  89. $rows = c('html')->importdata('type,name,unitname,laiyuan,linkname,tel,mobile,email,address','type,name');
  90. $oi = 0;
  91. $db = m('customer');
  92. foreach($rows as $k=>$rs){
  93. $rs['adddt'] = $this->now;
  94. $rs['optdt'] = $this->now;
  95. $rs['status'] = 1;
  96. $rs['uid'] = $this->adminid;
  97. $rs['createid'] = $this->adminid;
  98. $rs['optname'] = $this->adminname;
  99. $rs['createname'] = $this->adminname;
  100. $db->insert($rs);
  101. $oi++;
  102. }
  103. backmsg('','成功导入'.$oi.'条数据');
  104. }
  105. //分配客户
  106. public function distcustAjax()
  107. {
  108. $sid = c('check')->onlynumber($this->post('sid','0'));
  109. $sname = $this->post('sname');
  110. $snid = $this->post('snid');
  111. $lx = $this->post('lx');
  112. $uarr['uid'] = 0;
  113. if($lx==1 && $snid!='' && $sname!=''){
  114. $uarr['uid'] = $snid;
  115. $uarr['suoname'] = $sname;
  116. $uarr['isgh'] = '0';
  117. m('crm')->update($uarr, "`id` in($sid)");
  118. }
  119. if($lx==0){
  120. m('crm')->update($uarr, "`id` in($sid)");
  121. }
  122. echo 'ok';
  123. }
  124. }