agent.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * 应用上的接口文件,读取数据显示
  4. */
  5. class agentModel extends Model
  6. {
  7. public $agentnum = '';
  8. public $agentid = '0';
  9. public $modeid = 3;
  10. public $page = 1;
  11. public $loadci = 1;
  12. public $limit = 10; //默认加载的条数
  13. public $user_id = 0;
  14. public $event = '';
  15. public $agentrs;
  16. public $moders;
  17. public $flow = null;
  18. public $tongmode = true;
  19. public function getdatas($uid, $lx, $p){}
  20. /**
  21. * 从新接口方法
  22. * $rows 要展示数据 $rowd 原始数据
  23. */
  24. protected function agentrows($rows, $rowd, $uid){return $rows;}
  25. protected function agenttotals($uid){return array();}
  26. protected function agentdata($uid, $lx){return false;}
  27. protected $showuface = true;//是否显示对应人员头像
  28. public function gettotal()
  29. {
  30. return array(
  31. 'stotal' => 0,
  32. 'titles' => ''
  33. );
  34. }
  35. public function getagentinfor($num)
  36. {
  37. $this->agentnum = $num;
  38. $this->agentrs = m('im_group')->getone("`num`='$num'");
  39. $this->moders = m('flow_set')->getone("`num`='$num'");
  40. if($this->agentrs){
  41. $this->agentid = $this->agentrs['id'];
  42. }
  43. if($this->moders){
  44. $this->modeid = $this->moders['id'];
  45. $this->flow = m('flow')->initflow($num);
  46. $this->flow->ismobile = 1;
  47. }
  48. }
  49. public function getdata($uid, $num, $lx, $page)
  50. {
  51. $this->tongmode = true;
  52. if(!isempt($lx)){
  53. $lxa = explode('|', $lx);
  54. if(isset($lxa[1]) && !isempt($lxa[1])){
  55. if($lxa[1] != $num)$this->tongmode = false;
  56. $num = $lxa[1];
  57. $lx = $lxa[0];
  58. }
  59. }
  60. $this->loadci = (int)$this->rock->get('loadci','0');
  61. $this->getagentinfor($num);
  62. $this->page = $page;
  63. $this->user_id = $uid;
  64. $this->event = $lx;
  65. $narr = $this->agentdata($uid, $lx);
  66. $lx = $this->event;
  67. if(!$narr)$narr = $this->getdatalimit($uid, $lx);
  68. $arr = array(
  69. 'wdtotal' => 0,
  70. 'event' => $lx,
  71. 'num' => $num,
  72. 'rows' => array(),
  73. 'rowd' => array(),
  74. 'page' => $page,
  75. 'limit' => $this->limit,
  76. 'agentid' => $this->agentid,
  77. 'count' => 0,
  78. 'maxpage' => 0
  79. );
  80. if(is_array($narr))foreach($narr as $k=>$v)$arr[$k]=$v;
  81. $barr = $this->agentrows($arr['rows'],$arr['rowd'], $uid);
  82. if(isset($barr['rows'])){
  83. foreach($barr as $k=>$v)$arr[$k]=$v;
  84. $barr = $barr['rows'];
  85. }
  86. $arr['rows'] = $this->showrowsface($barr);
  87. $arr['stotal'] = $this->agenttotals($uid);
  88. unset($arr['rowd']);
  89. return $arr;
  90. }
  91. //状态切换读取一般用于有流程
  92. protected function agentrows_status($rows, $rowd){
  93. foreach($rowd as $k=>$rs){
  94. if($this->flow){
  95. $rows[$k]['modename'] = $this->moders['name'];
  96. $rows[$k]['modenum'] = $this->moders['num'];
  97. if(isset($rs['status'])){
  98. $zts = $this->flow->getstatus($rs);
  99. $rows[$k]['statustext'] = $zts[0];
  100. $rows[$k]['statuscolor'] = $zts[1];
  101. if($rs['status']==5)$rows[$k]['ishui'] = 1;
  102. }
  103. }
  104. }
  105. return $rows;
  106. }
  107. /**
  108. * 应用上获取数据
  109. */
  110. public function getdatalimit($uid, $lx)
  111. {
  112. if(!$this->flow)return array();
  113. $nas = $this->flow->billwhere($uid, $lx);
  114. $_wehs = $nas['where'];
  115. $where = '1=1 '.$_wehs.'';
  116. $fields = '*';
  117. $order = '';
  118. $_tabsk = $nas['table'];
  119. if(contain($_tabsk,' ')){
  120. $tables = $_tabsk;
  121. $table = $this->flow->mtable;
  122. }else{
  123. $table = $_tabsk;
  124. $tables = $this->rock->T($table);
  125. }
  126. if(!isempt($nas['order']))$order = $nas['order'];
  127. if(!isempt($nas['fields']))$fields = $nas['fields'];
  128. $arr = m($table)->getlimit($where, $this->page, $fields, $order, $this->limit, $tables);
  129. $rows = $arr['rows'];
  130. $row = array();
  131. $summarx= $this->flow->moders['summarx'];
  132. if(isempt($summarx))$summarx = 'cont:'.$this->flow->moders['summary'].'';
  133. $suarr = $this->zhaiyaoar($summarx);
  134. $rows = $this->flow->viewjinfields($rows);//禁看字段处理
  135. foreach($rows as $k=>$rs){
  136. $jarr = array();
  137. $rs = $this->flow->flowrsreplace($rs, 2);
  138. if(isset($rs['id']))$jarr['id'] = $rs['id'];
  139. if(isset($rs['uid']))$jarr['uid'] = $rs['uid'];
  140. if(isset($rs['ishui']))$jarr['ishui'] = $rs['ishui'];
  141. foreach($suarr as $f=>$nr){
  142. $str = $this->rock->reparr($nr, $rs);
  143. if($f=='cont')$str = $this->contreplaces($str);
  144. $jarr[$f] = $str;
  145. }
  146. $rows[$k] = $rs;
  147. $ors = $this->flow->flowrsreplace_we($jarr, $rs);
  148. if(!$this->tongmode){
  149. if(!isset($ors['modenum']))$ors['modenum'] = $this->moders['num'];
  150. if(!isset($ors['modename']))$ors['modename'] = $this->moders['name'];
  151. }
  152. $row[] = $ors;
  153. }
  154. $arr['rows'] = $row;
  155. $arr['rowd'] = $rows;
  156. return $arr;
  157. }
  158. private function zhaiyaoar($str)
  159. {
  160. $stra = explode("\n", $str);
  161. $arr = array();
  162. foreach($stra as $nr){
  163. if(strpos($nr,'title:')===0)$arr['title'] = substr($nr, 6);
  164. if(strpos($nr,'optdt:')===0)$arr['optdt'] = substr($nr, 6);
  165. if(strpos($nr,'cont:')===0)$arr['cont'] = substr($nr, 5);
  166. }
  167. if(!$arr)$arr['cont'] = $str;
  168. return $arr;
  169. }
  170. private function contreplaces($str)
  171. {
  172. $stra = explode('[br]', $str);
  173. $s1 = '';
  174. foreach($stra as $s){
  175. $a1 = explode(':', $s);
  176. if(isset($a1[1]) && $a1[1]==''){
  177. }else{
  178. $s1.='$%#'.$s.'';
  179. }
  180. }
  181. if($s1!=''){
  182. $s1 = str_replace('$%#', "\n", substr($s1, 3));
  183. }
  184. return $s1;
  185. }
  186. /**
  187. * 显示人员对应头像
  188. */
  189. private function showrowsface($rows)
  190. {
  191. if(!$this->showuface)return $rows;
  192. $uids = '0';
  193. foreach($rows as $k=>$rs){
  194. if(isset($rs['uid']))$uids .=','.$rs['uid'].'';
  195. }
  196. if($uids!='0'){
  197. $adb = m('admin');
  198. $uarr = $this->db->getarr('[Q]admin','id in('.$uids.')','`face`,`name`');
  199. foreach($rows as $k=>$rs){
  200. if(!isset($rs['uid']))continue;
  201. if(isset($uarr[$rs['uid']])){
  202. $rows[$k]['face'] = $adb->getface($uarr[$rs['uid']]['face']);
  203. }
  204. }
  205. }
  206. return $rows;
  207. }
  208. }
粤ICP备19079148号