TemplateTag.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. // register global/PHP functions to be used with your template files
  3. // You can move this to common.conf.php $config['TEMPLATE_GLOBAL_TAGS'] = array('isset', 'empty');
  4. // Every public static methods in TemplateTag class (or tag classes from modules) are available in templates without the need to define in TEMPLATE_GLOBAL_TAGS
  5. Doo::conf ()->TEMPLATE_GLOBAL_TAGS = array (
  6. 'isTimeTR',
  7. 'isInvoiceNew',
  8. 'isHRNew',
  9. 'upper',
  10. 'tofloat',
  11. 'sample_with_args',
  12. 'debug',
  13. 'url',
  14. 'url2',
  15. 'function_deny',
  16. 'isset',
  17. 'empty',
  18. 'make_date',
  19. 'inarray',
  20. 'getGlobals',
  21. 'countArray',
  22. 'isInvoiceMoldShow',
  23. 'isReceiptAuthorityShow',
  24. 'isInvoiceAggregateCompanyShow',
  25. 'forMatAccess',
  26. 'isShowMenu',
  27. 'isStaffCompleteMsg',
  28. 'isInvoiceCategoryShow',
  29. 'isReceiptTrainShow',
  30. 'isPaymentsShow',
  31. 'isUrlEncode',
  32. 'isGHNews'
  33. );
  34. function isGHNews($staffGH){
  35. $BuildUrl = 'http://gh.cld.smartcost.com.cn';
  36. //$url = $BuildUrl. '/mcm/authorize/receiptNewsTip?staffGH='. urlencode($staffGH);
  37. //echo $url;
  38. $url = $BuildUrl. '/mcm/authorize/receiptNewsTip';
  39. $data=array("staffGH"=>$_COOKIE ['staffGH']);
  40. $result = json_decode(curl_request($url,$data), true);
  41. return $result['count'];
  42. // print_r($result);
  43. // $isNews=false;
  44. // if($result['falg'])
  45. // $isNews=true;
  46. // return $isNews;
  47. }
  48. function isUrlEncode($url){
  49. Doo::loadClass ( 'auth' );
  50. $auth = new auth ( );
  51. $staffGH=$auth->yundanran_auth($url,'DECODE',"GH");
  52. $staffGH=$auth->yundanran_auth($staffGH,'',"GH");
  53. return urlencode($staffGH);
  54. }
  55. function isStaffCompleteMsg(){
  56. //检测用户信息完成
  57. Doo::loadModel ( 'staff' );
  58. $staff = new staff ();
  59. $isStaffCompleteMsg=false;
  60. if (!isset($_COOKIE ["staff"]))
  61. return false;
  62. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  63. if(!empty($detail))
  64. $isStaffCompleteMsg=true;
  65. return $isStaffCompleteMsg;
  66. }
  67. function forMatAccess($access=array()){
  68. $html='';
  69. $accessMsg = array (
  70. 'INFORMATION' => '信息中心',
  71. 'DIRECTORIES' => '通讯录',
  72. 'LOCK' => '在线锁库',
  73. 'RECEIPTS' => '报销单',
  74. 'INVOICE' => '发票申请',
  75. 'HR' => '人资管理',
  76. 'BUILD'=>'建筑计价'
  77. );
  78. if (empty($access))
  79. return '';
  80. foreach ($access as $value){
  81. $html.=$accessMsg[$value].'&nbsp;&nbsp;';
  82. }
  83. return $html;
  84. }
  85. function countArray($list=array(),$count=0){
  86. return count($list)+$count;
  87. }
  88. function isTimeTR($day = 3,$cTime) {
  89. $flag=false;
  90. $thenTime=time();
  91. $futureTime=strtotime('+'.$day.' day',strtotime($cTime));
  92. if($thenTime<$futureTime)
  93. $flag=true;
  94. return $flag;
  95. }
  96. function isShowMenu($menu=''){
  97. Doo::loadModel ( 'staff' );
  98. $staff = new staff ();
  99. $st = $staff->getStaffBySid( $_COOKIE ["staff"] );
  100. $cldAccess=array();
  101. if (!empty($st['cldAccess']))
  102. $cldAccess=json_decode($st['cldAccess'],true);
  103. Doo::loadModel ( "staffManage" );
  104. $staffManage = new staffManage ();
  105. $smList=$staffManage->getInvoiceCMByStaff($_COOKIE ["staff"]);
  106. //是否有登陆者需要审批的员工
  107. $list=array();
  108. if ($menu=='HR'){
  109. Doo::loadClass ( 'XDeode' );
  110. $XDeode = new XDeode ( 5 );
  111. $uid = $XDeode->decode ( $_COOKIE ["staff"] );
  112. $list=$staff->find ( array (
  113. 'asc' => 'sid',
  114. 'where' => "(pendStatus= '2' or pendStatus='3' or pendStatus='5') and ( pendingApprovalsLeave='".$uid."' or pendingApprovals='".$uid."') ",
  115. 'asArray' => TRUE
  116. ) );
  117. }
  118. if (in_array($menu,$cldAccess)||($st['sid']==superHR&&$menu=='HR')||(count($list)>0&&$menu=='HR')){
  119. return true;
  120. }
  121. if (empty($cldAccess)){
  122. return false;
  123. }
  124. return false;
  125. }
  126. function isHRNew(){
  127. Doo::loadModel ( 'staff' );
  128. $staff = new staff ();
  129. Doo::loadClass ( 'XDeode' );
  130. $XDeode = new XDeode ( 5 );
  131. $uid = $XDeode->decode ( $_COOKIE ["staff"] );
  132. $list=$staff->find ( array (
  133. 'asc' => 'sid',
  134. 'where' => "(pendStatus= '2' or pendStatus='3' or pendStatus='5' or pendStatus='6') and ( pendingApprovalsLeave='".$uid."' or pendingApprovals='".$uid."') ",
  135. 'asArray' => TRUE
  136. ) );
  137. return count($list);
  138. }
  139. function isInvoiceNew($type = "GLOBAL") {
  140. Doo::loadModel ( 'invoice' );
  141. $invoice = new invoice ();
  142. Doo::loadModel ( 'invoiceReceivables' );
  143. $invoiceReceivables = new invoiceReceivables ();
  144. Doo::loadModel ( 'staff' );
  145. $staff = new staff ();
  146. Doo::loadModel ( "invoiceManage" );
  147. $execute = new invoiceManage ();
  148. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  149. $exeGlobal=$execute->getInvoiceByStaff($st[0]['sid']);
  150. // 我的发票待处理
  151. $pendingInvoice = $invoice->getOne ( array (//or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  152. 'where' => "(status=3 or status=4 ) and isDelete=0 and sid=" . $st[0]['sid'],
  153. 'desc' => 'iid',
  154. 'asArray' => TRUE
  155. ) );
  156. // 我的收款待入账
  157. // $myClaim = $invoiceReceivables->getOne ( array (
  158. // 'where' => " receivablesStaff like '" . $st[0]['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0",
  159. // 'desc' => 'irid',
  160. // 'asArray' => TRUE
  161. // ) );
  162. // 发票审批
  163. $approval = $invoice->getOne ( array (
  164. 'where' => 'status=1 and pendingApprovals=' . $st[0]['sid'],
  165. 'desc' => 'iid',
  166. 'asArray' => true
  167. ) );
  168. // 发票邮寄
  169. $post = $invoice->getOne ( array (
  170. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  171. 'asArray' => TRUE
  172. ) );
  173. // 发票打印
  174. $print = $invoice->getOne ( array (
  175. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st[0]['sid'] . "\",%'",
  176. 'desc' => 'iid',
  177. 'asArray' => TRUE
  178. ) );
  179. // 发票退票 printStatus=1 and
  180. $untread = $invoice->getOne ( array (
  181. 'where' => " untreadStatus=1 and status=2 ",
  182. 'asArray' => TRUE
  183. ) );
  184. $new = array (
  185. 'GLOBAL' => FALSE,
  186. 'pendingInvoice' => FALSE,
  187. 'myClaim' => FALSE,
  188. 'approval' => FALSE,
  189. 'post' => FALSE,
  190. 'print' => FALSE,
  191. 'untread' => FALSE
  192. );
  193. //|| ! empty ( $myClaim )
  194. if (!empty($exeGlobal)){
  195. if (! empty ( $pendingInvoice ))
  196. $new ['GLOBAL'] = TRUE;
  197. foreach ($exeGlobal as $value){
  198. if ($value['mold']=='发票审批'){
  199. if(! empty ( $approval )){
  200. $new ['GLOBAL'] = TRUE;
  201. break;
  202. }
  203. }
  204. if ($value['mold']=='发票打印'){
  205. if(! empty ( $print )){
  206. $new ['GLOBAL'] = TRUE;
  207. break;
  208. }
  209. }
  210. if ($value['mold']=='发票邮寄'){
  211. if(! empty ( $post )){
  212. $new ['GLOBAL'] = TRUE;
  213. break;
  214. }
  215. }
  216. if ($value['mold']=='发票退票'){
  217. if(! empty ( $untread )){
  218. $new ['GLOBAL'] = TRUE;
  219. break;
  220. }
  221. }
  222. }
  223. // print_r($exeGlobal);die;
  224. // if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  225. // $new ['GLOBAL'] = TRUE;
  226. }else{
  227. if (! empty ( $pendingInvoice ) )
  228. $new ['GLOBAL'] = TRUE;
  229. }
  230. if (! empty ( $pendingInvoice ))
  231. $new ['pendingInvoice'] = TRUE;
  232. if (! empty ( $myClaim ))
  233. $new ['myClaim'] = TRUE;
  234. if (! empty ( $approval ))
  235. $new ['approval'] = TRUE;
  236. if (! empty ( $post ))
  237. $new ['post'] = TRUE;
  238. if (! empty ( $print ))
  239. $new ['print'] = TRUE;
  240. if (! empty ( $untread ))
  241. $new ['untread'] = TRUE;
  242. return $new [$type];
  243. }
  244. /**
  245. * 是否有查看汇总的权限
  246. * @param unknown $sid
  247. */
  248. function isInvoiceCategoryShow($sid){
  249. Doo::loadModel ( "invoiceCategoryManage" );
  250. $invoiceCategoryManage = new invoiceCategoryManage ();
  251. $icm=$invoiceCategoryManage->getInvoiceCMByStaff($sid);
  252. if (!empty($icm))
  253. return true;
  254. else
  255. return false;
  256. }
  257. /**
  258. * 是否有查看培训班结算营收的权限
  259. * @param unknown $sid
  260. */
  261. function isReceiptTrainShow($sid){
  262. Doo::loadModel ( "receiptTrainManage" );
  263. $invoiceCategoryManage = new receiptTrainManage ();
  264. $icm=$invoiceCategoryManage->getInvoiceCMByStaff($sid);
  265. if (!empty($icm))
  266. return true;
  267. else
  268. return false;
  269. }
  270. /**
  271. * 是否有查看日常收支的权限
  272. */
  273. function isPaymentsShow($sid){
  274. Doo::loadModel ( "execute" );
  275. $execute = new execute ();
  276. $list = $execute->find ( array (
  277. 'where' => '(staff like \'%["' . $sid . '%\' ) and mold="日常收支"',
  278. 'asArray' => true
  279. ) );
  280. if (empty($list)){
  281. return false;
  282. }else {
  283. return true;
  284. }
  285. }
  286. /**
  287. * 是否有查看应收款的权限
  288. * @param unknown $sid
  289. */
  290. function isInvoiceAggregateCompanyShow($sid){
  291. Doo::loadModel ( "invoiceCompanyManage" );
  292. $receiptAuthorityManage = new invoiceCompanyManage ();
  293. $icm=$receiptAuthorityManage->getInvoiceCMByStaff($sid);
  294. if (!empty($icm))
  295. return true;
  296. else
  297. return false;
  298. }
  299. /**
  300. * 是否有查看报销单汇总的权限
  301. * @param unknown $sid
  302. */
  303. function isReceiptAuthorityShow($sid){
  304. Doo::loadModel ( "receiptAuthorityManage" );
  305. $receiptAuthorityManage = new receiptAuthorityManage ();
  306. $icm=$receiptAuthorityManage->getInvoiceCMByStaff($sid);
  307. if (!empty($icm))
  308. return true;
  309. else
  310. return false;
  311. }
  312. function isInvoiceCompanyShow($sid){
  313. }
  314. /**
  315. * 判断发票的审批权限
  316. * @param number $sid 用户ID
  317. * @param string $mold 项目类型
  318. * @return boolean
  319. */
  320. function isInvoiceMoldShow($sid = 0, $mold = '') {
  321. if (! empty ( $sid ) && ! empty ( $mold )) {
  322. Doo::loadModel ( "invoiceManage" );
  323. $invoiceManage = new invoiceManage ();
  324. $imList = $invoiceManage->getInvoiceByMold ( $mold );
  325. $list = array ();
  326. foreach ( $imList ['staffList'] as $k => $v ) {
  327. array_push ( $list, $v [0] );
  328. }
  329. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  330. $fileInvoice = json_decode ( $fileInvoice, true );
  331. $delIM = array ();
  332. if (isset ( $fileInvoice [$mold] ))
  333. $delIM = explode ( ',', $fileInvoice [$mold] );
  334. foreach ( $delIM as $key => $value ) {
  335. if (! empty ( $value ))
  336. array_push ( $list, $value );
  337. }
  338. $list = array_unique ( $list );
  339. return inarray ( $sid, $list );
  340. } else
  341. return false;
  342. }
  343. function getGlobals($var) {
  344. if ($var == 'NEW')
  345. getReceiptCount ();
  346. elseif ($var == 'NEW2')
  347. getExeCount ();
  348. // echo $GLOBALS[$var].'/'.$var.'<br/>';
  349. return $GLOBALS [$var];
  350. }
  351. function inarray($v1, $v2) {
  352. return in_array ( $v1, $v2 );
  353. }
  354. function make_date() {
  355. return date ( "Y-m" );
  356. }
  357. function upper($str) {
  358. return strtoupper ( $str );
  359. }
  360. function tofloat($str) {
  361. return sprintf ( "%.2f", $str );
  362. }
  363. function sample_with_args($str, $prefix) {
  364. return $str . ' with args: ' . $prefix;
  365. }
  366. function debug($var) {
  367. if (! empty ( $var )) {
  368. echo '<pre>';
  369. print_r ( $var );
  370. echo '</pre>';
  371. }
  372. }
  373. // This will be called when a function NOT Registered is used in IF or ElseIF statment
  374. function function_deny($var = null) {
  375. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  376. exit ();
  377. }
  378. // Build URL based on route id
  379. function url($id, $param = null, $addRootUrl = false) {
  380. Doo::loadHelper ( 'DooUrlBuilder' );
  381. // param pass in as string with format
  382. // 'param1=>this_is_my_value, param2=>something_here'
  383. if ($param != null) {
  384. $param = explode ( ', ', $param );
  385. $param2 = null;
  386. foreach ( $param as $p ) {
  387. $splited = explode ( '=>', $p );
  388. $param2 [$splited [0]] = $splited [1];
  389. }
  390. return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
  391. }
  392. return DooUrlBuilder::url ( $id, null, $addRootUrl );
  393. }
  394. // Build URL based on controller and method name
  395. function url2($controller, $method, $param = null, $addRootUrl = false) {
  396. Doo::loadHelper ( 'DooUrlBuilder' );
  397. // param pass in as string with format
  398. // 'param1=>this_is_my_value, param2=>something_here'
  399. if ($param != null) {
  400. $param = explode ( ', ', $param );
  401. $param2 = null;
  402. foreach ( $param as $p ) {
  403. $splited = explode ( '=>', $p );
  404. $param2 [$splited [0]] = $splited [1];
  405. }
  406. return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
  407. }
  408. return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
  409. }
  410. /**
  411. * 获得正在审批的费用单数量
  412. */
  413. function getReceiptCount() {
  414. $status = 2;
  415. $year = date ( 'Y' );
  416. Doo::loadModel ( 'receipt' );
  417. $receipt = new receipt ();
  418. Doo::loadClass ( 'XDeode' );
  419. $XDeode = new XDeode ( 5 );
  420. Doo::loadModel ( 'verify' );
  421. $verify = new verify ();
  422. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  423. $vidList = array ();
  424. $verifyDetail = $verify->find ( array (
  425. 'where' => ' (staff not like "%\"' . $st [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $st [0] ['sid'] . '\",%" or staff like "%\"' . $st [0] ['sid'] . '\_%" )',
  426. 'asArray' => true
  427. ) );
  428. foreach ( $verifyDetail as $key => $value ) {
  429. array_push ( $vidList, $value ['vid'] );
  430. }
  431. $vid = implode ( ",", $vidList );
  432. if (empty ( $verifyDetail ))
  433. $vid = 0;
  434. $dateCondition = " and Year(date) =" . $year;
  435. $approvalCondition = ' and (nowStaff like "%,' . $st[0]['sid'] . '%" or nowStaff like "%' . $st[0]['sid'] . ',%" or nowStaff=' . $st[0]['sid'] . ' ) ';
  436. $receiptList = $receipt->find ( array (
  437. 'where' => ' status=' . $status . $dateCondition . $approvalCondition. ' and verify in (' . $vid . ')',
  438. 'desc' => 'rid',
  439. 'asArray' => true
  440. ) );
  441. $GLOBALS ['NEW'] = count ( $receiptList );
  442. }
  443. /**
  444. * 获得执行费用的数量
  445. */
  446. function getExeCount() {
  447. Doo::loadModel ( 'receipt' );
  448. $receipt = new receipt ();
  449. Doo::loadClass ( 'XDeode' );
  450. $XDeode = new XDeode ( 5 );
  451. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  452. $receiptList = $receipt->find ( array (
  453. 'where' => '(executeCopy like \'%["' . $st[0]['sid'] . '%\' and executeStaff NOT LIKE \'%' . $st[0]['sid'] . '%\' ) and (status=1 or status=6)',
  454. 'desc' => 'rid',
  455. 'asArray' => true
  456. ) );
  457. $GLOBALS ['NEW2'] = count ( $receiptList );
  458. }
  459. /**
  460. * curl 获取接口数据,data为空时为GET方法,有值则为POST方法
  461. *
  462. * @param $url
  463. * @param string $data
  464. * @return mixed|string
  465. */
  466. function curl_request($url, $data = '') {
  467. $curl = curl_init();
  468. curl_setopt($curl, CURLOPT_URL, $url);
  469. curl_setopt($curl, CURLOPT_HEADER, 0);
  470. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  471. if($data) {
  472. curl_setopt($curl, CURLOPT_POST, 1);
  473. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  474. }
  475. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  476. $data = curl_exec($curl);
  477. curl_close($curl);
  478. return $data;
  479. }
  480. ?>