customerAction.php 3.3 KB

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