agent.php 5.9 KB

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