agent.php 6.2 KB

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