agent.php 5.8 KB

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