TemplateTag.php 15 KB

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