customerModel.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. class flow_customerClassModel extends flowModel
  3. {
  4. public $statearr,$statarr;
  5. public function initModel()
  6. {
  7. $this->statearr = c('array')->strtoarray('停用|#888888,启用|green');
  8. $this->statarr = c('array')->strtoarray('否|#888888,是|#ff6600');
  9. }
  10. //高级搜索下
  11. public function flowsearchfields()
  12. {
  13. $arr[] = array('name'=>'所属人...','fields'=>'uid');
  14. $arr[] = array('name'=>'创建人...','fields'=>'createid');
  15. return $arr;
  16. }
  17. public function flowrsreplace($rs, $lx=0)
  18. {
  19. if(isset($rs['status'])){
  20. if($rs['status']==0)$rs['ishui'] = 1;
  21. $zt = $this->statearr[$rs['status']];
  22. $rs['statuss'] = $rs['status'];
  23. $rs['status'] = '<font color="'.$zt[1].'">'.$zt[0].'</font>';
  24. }
  25. if(isset($rs['isstat'])){
  26. $stat = $this->statarr[$rs['isstat']];
  27. $rs['isstat'] = '<font color="'.$stat[1].'">'.$stat[0].'</font>';
  28. }
  29. if(isset($rs['isgys'])){
  30. $gys = $this->statarr[$rs['isgys']];
  31. $rs['isgys'] = '<font color="'.$gys[1].'">'.$gys[0].'</font>';
  32. }
  33. if($this->rock->arrvalue($rs,'htshu','0')==0)$rs['htshu']='';
  34. if($this->rock->arrvalue($rs,'moneyz','0')==0)$rs['moneyz']='';
  35. if($this->rock->arrvalue($rs,'moneyd','0')==0)$rs['moneyd']='';
  36. if($lx==1){
  37. //$rs['suoname'] = $this->adminmodel->getmou('name','id='.$rs['uid'].'');
  38. }
  39. //详情时,移动端
  40. if($lx==1 && $this->rock->ismobile()){
  41. if(!isempt($rs['mobile']))$rs['mobile']='<a onclick="return callPhone(this)" href="tel:'.$rs['mobile'].'">'.$rs['mobile'].'</a>';
  42. if(!isempt($rs['tel']))$rs['tel']='<a onclick="return callPhone(this)" href="tel:'.$rs['tel'].'">'.$rs['tel'].'</a>';
  43. }
  44. return $rs;
  45. }
  46. //是否有查看权限
  47. protected function flowisreadqx()
  48. {
  49. $bo = false;
  50. $shateid = ','.$this->rs['shateid'].',';
  51. if(contain($shateid,','.$this->adminid.','))$bo=true;
  52. return $bo;
  53. }
  54. protected function flowgetfields_qiyong($lx)
  55. {
  56. $arr = array();
  57. if($this->uid==$this->adminid){
  58. $arr['mobile'] = '手机号';
  59. $arr['tel'] = '电话';
  60. $arr['email'] = '邮箱';
  61. $arr['routeline'] = '交通路线';
  62. }
  63. return $arr;
  64. }
  65. protected function flowoptmenu($ors, $crs)
  66. {
  67. $zt = $ors['statusvalue'];
  68. $num = $ors['num'];
  69. if($num=='ztqh'){
  70. $this->update('`status`='.$zt.'', $this->id);
  71. }
  72. //共享
  73. if($num=='shate'){
  74. $cname = $crs['cname'];
  75. $cnameid = $crs['cnameid'];
  76. $this->update(array(
  77. 'shateid' => $cnameid,
  78. 'shate' => $cname,
  79. ), $this->id);
  80. $this->push($cnameid, '客户管理', ''.$this->adminname.'将一个客户【{name}】共享给你');
  81. }
  82. //取消共享
  83. if($num=='unshate'){
  84. $this->update(array(
  85. 'shateid' => '',
  86. 'shate' => '',
  87. ), $this->id);
  88. }
  89. //放入公海
  90. if($num=='ghnoup'){
  91. $this->update(array(
  92. 'isgh' => '1',
  93. 'uid' => 0,
  94. 'suoname'=>''
  95. ), $this->id);
  96. }
  97. }
  98. protected function flowbillwhere($uid, $lx)
  99. {
  100. return array(
  101. 'order' => '`status` desc,`optdt` desc',
  102. //'table' => '`[Q]'.$this->mtable.'` a left join `[Q]admin` b on a.`uid`=b.id',
  103. //'asqom' => 'a.',
  104. //'fields'=> 'a.*,b.name as suoname'
  105. );
  106. }
  107. //导入数据的测试显示
  108. public function flowdaorutestdata()
  109. {
  110. $barr = array(
  111. 'name' => '信呼',
  112. 'type' => '软件',
  113. 'laiyuan' => '网上开拓',
  114. 'unitname' => '厦门信呼科技有限公司',
  115. 'tel' => '0592-123456',
  116. 'mobile' => '15800000000',
  117. 'email' => 'admin@rockoa.com',
  118. 'address' => '福建厦门思明区软件园',
  119. 'linkname' => '磐石',
  120. 'isgh' => '是',
  121. );
  122. $barr1 = array(
  123. 'name' => '百度',
  124. 'type' => '搜索计算',
  125. 'laiyuan' => '电话联系',
  126. 'unitname' => '百度在线网络技术(北京)有限公司',
  127. 'tel' => '010-123456',
  128. 'mobile' => '15800000001',
  129. 'email' => 'admin@baidu.com',
  130. 'address' => '北京软件园百度大厦',
  131. 'linkname' => '李彦宏',
  132. 'isgh' => '否',
  133. );
  134. $barr2 = array(
  135. 'name' => '陈先生',
  136. 'type' => '个人',
  137. 'laiyuan' => '电话联系',
  138. 'unitname' => '',
  139. 'tel' => '010-123456',
  140. 'mobile' => '15800000002',
  141. 'email' => '1111@qq.com',
  142. 'address' => '福建厦门火车站',
  143. 'linkname' => '',
  144. 'isgh' => '否',
  145. );
  146. return array($barr,$barr1,$barr2);
  147. }
  148. public function flowdaorubefore($data)
  149. {
  150. $arr = array();
  151. $dbs = m('admin');
  152. foreach($data as $k=>$rs){
  153. $isgh = (arrvalue($rs,'isgh')=='是') ? 1: 0 ;
  154. $isstat = (arrvalue($rs,'isstat')=='是') ? 1: 0 ;
  155. if(isset($rs['status'])){
  156. $rs['status'] = (arrvalue($rs,'status')=='启用') ? 1: 0 ;
  157. }
  158. if(isset($rs['suoname'])){
  159. if($isgh==0){
  160. $urs = $dbs->geturs('name:'.$rs['suoname']);
  161. if($urs)$rs['uid'] = $urs['id'];
  162. }
  163. //unset($rs['suoname']);
  164. }
  165. $rs['isgh'] = $isgh;
  166. $rs['isstat'] = $isstat;
  167. if($isgh==1)$rs['uid'] = 0;
  168. $arr[] = $rs;
  169. }
  170. return $arr;
  171. }
  172. /**
  173. * 自动放入公海
  174. */
  175. public function addgonghai()
  176. {
  177. $tshu = (int)$this->option->getval('crmaddghai','0');
  178. if($tshu<=0)return;
  179. $sneuar = array();
  180. $rows = $this->getall('`uid`>0 and `htshu`=0 and `isgys`=0 and `id` not in(select `custid` from `[Q]custsale` where `state` in(1)) and `id` not in(select `custid` from `[Q]goodm` where `type`=2 and `status` in(0,1))','lastdt,optdt,id,name,uid,unitname');
  181. $dtobj = c('date');
  182. $addghs = array();
  183. foreach($rows as $k=>$rs){
  184. $lastdt = $rs['lastdt'];
  185. if(isempt($lastdt))$lastdt = $rs['optdt'];
  186. $jg = $dtobj->datediff('d', $lastdt, $this->rock->now);
  187. if($jg > $tshu){
  188. $sneuar[$rs['uid']][] = '['.$rs['name'].']超'.$jg.'天未跟进已放入公海库';
  189. $addghs[] = $rs['id'];
  190. }else{
  191. //要放入之前2天提醒
  192. $ts = $tshu - $jg;
  193. if($ts<3)$sneuar[$rs['uid']][] = '['.$rs['name'].']将'.$ts.'天后放入公海库';
  194. }
  195. }
  196. //通知给对应人
  197. $maxlen = 5;
  198. foreach($sneuar as $uid=>$ursa){
  199. $str = '';
  200. foreach($ursa as $k1=>$s1){
  201. if($str!='')$str.="\n";
  202. if($k1>=$maxlen){
  203. $str.='还有'.(count($ursa)-$maxlen).'条,点击查看更多';
  204. break;
  205. }
  206. $str.="".$s1."";
  207. }
  208. $this->pushs($uid, $str, '客户未跟进提醒', array(
  209. 'wxurl' => $this->getwxurl()
  210. ));
  211. }
  212. if($addghs){
  213. $sid = join(',', $addghs);
  214. $this->update("`uid`=0,`isgh`=1", "`id` in($sid)");
  215. }
  216. }
  217. //对外的详情页
  218. public function flowopenxiang($da, $xiangdata)
  219. {
  220. $zdarr = array('name','type','laiyuan','unitname','tel','mobile','sheng','shi','address','routeline','shibieid','openbank','cardid','explain','linkname');
  221. $slsts = array();
  222. foreach($xiangdata as $k=>$rs){
  223. if(in_array($rs['fields'], $zdarr)){
  224. $slsts[] = $rs;
  225. }
  226. }
  227. return array('xiangdata'=>$slsts,'modename'=>'客户详情');
  228. }
  229. }
粤ICP备19079148号