agent.php 6.4 KB

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