ReceiptAjaxController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptAjaxController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  18. public function beforeRun($resource, $action) {
  19. Doo::loadClass ( 'XDeode' );
  20. $XDeode = new XDeode ( 5 );
  21. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  22. // 单独判断公司汇总的访问权限
  23. if ($action == 'companyCategoryCollect') {
  24. Doo::loadModel ( "receiptAuthorityManage" );
  25. $invoiceCompanyManage = new receiptAuthorityManage ();
  26. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  27. if (empty ( $icm ))
  28. die ( 'illegal request' );
  29. }
  30. Doo::loadModel ( 'staff' );
  31. $staff = new staff ();
  32. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  33. $accessModular = 'RECEIPTSAJAX';//是否已经开放的方法
  34. $accessAuthority = 'RECEIPTS';//容许访问的权限
  35. if (empty ( $detail ['cldAccessArray'] ))
  36. die ( 'illegal request' );
  37. else {
  38. if (in_array ( $accessAuthority, $detail ['cldAccessArray'] )) {
  39. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  40. $flag = true;
  41. } else {
  42. $flag = false;
  43. }
  44. } else {
  45. die ( 'illegal request' );
  46. }
  47. }
  48. if (! $flag)
  49. die ( 'illegal request' );
  50. }
  51. function __construct() {
  52. if (isset ( $_COOKIE ["staff"] )) {
  53. if (! empty ( $_COOKIE ["staff"] )) {
  54. Doo::loadModel ( 'staff' );
  55. Doo::loadModel ( 'verify' );
  56. $verify = new verify ();
  57. $staff = new staff ();
  58. Doo::loadModel ( "execute" );
  59. $execute = new execute ();
  60. $verifyList = $verify->find ( array (
  61. 'select' => 'staff',
  62. 'asArray' => true
  63. ) );
  64. $list = array ();
  65. // 判断角色的审批权限
  66. foreach ( $verifyList as $key => $value ) {
  67. $ver = json_decode ( $value ['staff'] );
  68. foreach ( $ver as $k => $v ) {
  69. if ($v [1] == 'ROLE') {
  70. $roleList = json_decode ( $v [3] );
  71. foreach ( $roleList as $t => $g ) {
  72. $gList = explode ( "_", $g );
  73. array_push ( $list, $gList [0] );
  74. // print_r($list);
  75. }
  76. } else
  77. array_push ( $list, $v [0] );
  78. }
  79. }
  80. // 判断执行人的审批权限
  81. $executeList = $execute->find ( array (
  82. 'select' => 'staff',
  83. 'asArray' => true
  84. ) );
  85. $list2 = array ();
  86. foreach ( $executeList as $key => $value ) {
  87. $ver = json_decode ( $value ['staff'] );
  88. foreach ( $ver as $k => $v ) {
  89. array_push ( $list2, $v [0] );
  90. }
  91. }
  92. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  93. $eidList = array_filter ( explode ( ",", $eidList ) );
  94. $this->executeId = array_merge ( $list2, $eidList );
  95. $this->verifyId = $list;
  96. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] )[0];
  97. // 检测用户信息完成
  98. $this->data ['isStaffCompleteMsg'] = false;
  99. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  100. if (! empty ( $detail ))
  101. $this->data ['isStaffCompleteMsg'] = true;
  102. return "/";
  103. }
  104. }
  105. Doo::loadCore ( 'uri/DooUriRouter' );
  106. $router = new DooUriRouter ();
  107. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  108. if ($routeRs ['1'] != "login") {
  109. header ( 'Content-Type:text/html;charset=utf-8' );
  110. @header ( "Location: /login" );
  111. }
  112. }
  113. /**
  114. * 默认获得属于自己和所在办事处10条最新的数据
  115. */
  116. function ajaxGetReceiptTrainLoan(){
  117. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : $this->staff['sid'];
  118. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : $this->staff['cid'];
  119. $limit = $this->get_args ( 'limit' ) ? $this->get_args ( 'limit' ) : '30';
  120. $status=8;
  121. Doo::loadModel ( 'receipt' );
  122. $receipt = new receipt ();
  123. $list=$receipt->getReceiptLoanByStatus($sid,$cid,$status,$limit);
  124. echo json_encode ( array (
  125. 'status' => 1,
  126. 'receiptLoanList' => $list
  127. ) );
  128. }
  129. /**
  130. * 获得费用详情
  131. */
  132. function ajaxGetReceiptDetailByJson() {
  133. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  134. Doo::loadClass ( 'XDeode' );
  135. $XDeode = new XDeode ( 5 );
  136. $rid = $XDeode->decode ( $ridKey );
  137. Doo::loadModel ( 'receipt' );
  138. $receipt = new receipt ();
  139. $detail = $receipt->getReceiptByRid ( $rid );
  140. echo json_encode ( array (
  141. 'status' => 1,
  142. 'detail' => $detail
  143. ) );
  144. }
  145. /**
  146. * 更新费用的汇款金额
  147. */
  148. function ajaxSetRceiptAmountByRid(){
  149. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  150. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  151. if (empty($ridKey)||empty($amount)){
  152. echo json_encode ( array (
  153. 'status' => 2
  154. ) );
  155. die;
  156. }
  157. Doo::loadClass ( 'XDeode' );
  158. $XDeode = new XDeode ( 5 );
  159. $rid = $XDeode->decode ( $ridKey );
  160. Doo::loadModel ( 'receipt' );
  161. $receipt = new receipt ();
  162. $detail=$receipt->getReceiptByRid($rid);
  163. if (empty($detail)){
  164. echo json_encode ( array (
  165. 'status' => 2
  166. ) );
  167. die;
  168. }
  169. if ($detail['status']!=2){
  170. echo json_encode ( array (
  171. 'status' => 2
  172. ) );
  173. die;
  174. }
  175. $receipt = new receipt ();
  176. $receipt->amount = $amount;
  177. $receipt->update ( array (
  178. 'where' => ' rid = ' . $rid
  179. ) );
  180. echo json_encode ( array (
  181. 'status' => 1
  182. ) );
  183. }
  184. function setWXMsg($rid, $type) {
  185. Doo::loadModel ( "receipt" );
  186. $receipt = new receipt ();
  187. $receiptDetail = $receipt->getOne ( array (
  188. 'where' => 'rid=' . $rid,
  189. 'asArray' => true
  190. ) );
  191. if (! empty ( $receiptDetail )) {
  192. Doo::loadModel ( 'staff' );
  193. $staff = new staff ();
  194. $staffmsg = $staff->getOne ( array (
  195. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  196. 'asArray' => TRUE
  197. ) );
  198. if (! empty ( $staffmsg ['wxid'] )) {
  199. require_once (SITE_PATH . '/protected/class/client.php');
  200. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  201. $user = $staffmsg ['wxid'];
  202. $receiptName = '';
  203. $msg = '';
  204. switch ($receiptDetail ['Rtype']) {
  205. case 0 :
  206. $receiptName = '报销';
  207. break;
  208. case 1 :
  209. $receiptName = '借款';
  210. break;
  211. case 2 :
  212. $receiptName = '对公汇款';
  213. break;
  214. }
  215. switch ($type) {
  216. case 1 :
  217. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  218. break;
  219. case 2 :
  220. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  221. break;
  222. case 3 :
  223. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  224. break;
  225. }
  226. // $result = $client->SendMsg ( $user, $msg, 'text' );
  227. }
  228. }
  229. }
  230. // Email发送函数
  231. function SMail($toemail, $subject, $contents) {
  232. Doo::loadClass ( 'class.phpmailer' );
  233. $mail = new PHPMailer ();
  234. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  235. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  236. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  237. $mail->Password = "cDO1GjtY1seH"; // 密码
  238. $mail->CharSet = "UTF8";
  239. $mail->SMTPAuth = true;
  240. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  241. $mail->Mailer = "smtp";
  242. $mail->Port = 25;
  243. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  244. $mail->MsgHTML ( $contents );
  245. $mail->AddAddress ( $toemail );
  246. $mail->CharSet = "UTF-8";
  247. return $mail->Send ();
  248. }
  249. function swfupload() {
  250. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  251. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  252. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  253. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  254. header ( "HTTP/1.1 500 Internal Server Error" );
  255. echo "POST exceeded maximum allowed size.";
  256. exit ( 0 );
  257. }
  258. // Settings
  259. $save_path = DOO::conf ()->SITE_PATH . "upload/swfupload/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  260. $upload_name = "Filedata";
  261. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  262. $extension_whitelist = array (
  263. "doc",
  264. "txt",
  265. "jpg",
  266. "gif",
  267. "png"
  268. ); // Allowed file extensions
  269. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  270. // Other variables
  271. $MAX_FILENAME_LENGTH = 260;
  272. $file_name = "";
  273. $file_extension = "";
  274. $uploadErrors = array (
  275. 0 => "文件上传成功",
  276. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  277. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  278. 3 => "上传的文件仅为部分文件",
  279. 4 => "没有文件上传",
  280. 6 => "缺少临时文件夹"
  281. );
  282. $nk = time ();
  283. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  284. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  285. echo "文件无法保存.";
  286. exit ( 0 );
  287. }
  288. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  289. echo json_encode ( array (
  290. 'filename' => $file_name,
  291. 'id' => $nk
  292. ) );
  293. exit ( 0 );
  294. }
  295. function _GetFileEXT($filename) {
  296. $pics = explode ( '.', $filename );
  297. $num = count ( $pics );
  298. return $pics [$num - 1];
  299. }
  300. /**
  301. * 获取get或者POST值
  302. * @param string $name 属性名称
  303. * @return fixed 值
  304. */
  305. function get_args($name) {
  306. if (isset ( $_GET [$name] )) {
  307. if (is_array ( $_GET [$name] ))
  308. return $_GET [$name];
  309. else
  310. return addslashes ( $_GET [$name] );
  311. } elseif (isset ( $_POST [$name] )) {
  312. if (is_array ( $_POST [$name] ))
  313. return $_POST [$name];
  314. else
  315. return addslashes ( $_POST [$name] );
  316. } else
  317. return false;
  318. }
  319. function num_to_rmb($num) {
  320. $c1 = "零壹贰叁肆伍陆柒捌玖";
  321. $c2 = "分角元拾佰仟万拾佰仟亿";
  322. // 精确到分后面就不要了,所以只留两个小数位
  323. $num = round ( $num, 2 );
  324. // 将数字转化为整数
  325. $num = $num * 100;
  326. if (strlen ( $num ) > 10) {
  327. return "金额太大,请检查";
  328. }
  329. $i = 0;
  330. $c = "";
  331. while ( 1 ) {
  332. if ($i == 0) {
  333. // 获取最后一位数字
  334. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  335. } else {
  336. $n = $num % 10;
  337. }
  338. // 每次将最后一位数字转化为中文
  339. $p1 = substr ( $c1, 3 * $n, 3 );
  340. $p2 = substr ( $c2, 3 * $i, 3 );
  341. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  342. $c = $p1 . $p2 . $c;
  343. } else {
  344. $c = $p1 . $c;
  345. }
  346. $i = $i + 1;
  347. // 去掉数字最后一位了
  348. $num = $num / 10;
  349. // echo $num.'</br>';
  350. $num = ( int ) $num;
  351. // $num =floor($num);
  352. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  353. // echo $num.'</br>';
  354. // 结束循环
  355. if ($num == 0) {
  356. break;
  357. }
  358. }
  359. // echo $c.'</br>';
  360. $j = 0;
  361. $slen = strlen ( $c );
  362. while ( $j < $slen ) {
  363. // utf8一个汉字相当3个字符
  364. $m = substr ( $c, $j, 6 );
  365. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  366. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  367. $left = substr ( $c, 0, $j );
  368. $right = substr ( $c, $j + 3 );
  369. $c = $left . $right;
  370. $j = $j - 3;
  371. $slen = $slen - 3;
  372. }
  373. $j = $j + 3;
  374. }
  375. // 这个是为了去掉类似23.0中最后一个“零”字
  376. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  377. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  378. }
  379. // 将处理的汉字加上“整”
  380. if (empty ( $c )) {
  381. return "零元整";
  382. } else {
  383. return $c . "整";
  384. }
  385. }
  386. /**
  387. * 获得分页数据
  388. * @param unknown_type $table
  389. * @param unknown_type $condition
  390. * @param unknown_type $on_page
  391. * @param unknown_type $page_size
  392. */
  393. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  394. $page_c = "";
  395. $page ['previous'] = $this->get_previous ( $on_page );
  396. $page ['on_page'] = $on_page;
  397. $total_count = $this->get_table_count ( $table, $condition );
  398. $total = intval ( $total_count / $page_size );
  399. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  400. $page ['total_data'] = $total_count;
  401. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  402. $i = 1;
  403. $page_max = 1;
  404. $page_width = 3;
  405. if ($on_page >= $page_width) {
  406. $page_max = intval ( $on_page / $page_width ) + 1;
  407. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  408. }
  409. for(; $i <= $page ['total_page']; $i ++) {
  410. if ($i == $on_page)
  411. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  412. else
  413. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  414. if ($i == ($page_width * $page_max))
  415. break;
  416. }
  417. $page ['page'] = $page_c;
  418. $page ['lower'] = (-- $on_page) * $page_size;
  419. return $page;
  420. }
  421. /**
  422. * 获取总页数
  423. * @param unknown_type $table
  424. * @param unknown_type $condition
  425. */
  426. public function get_table_count($table = "", $condition = "") {
  427. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  428. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  429. // echo $sql;die;
  430. $query = Doo::db ()->query ( $sql );
  431. $result = $query->fetch ();
  432. return $result ['count'];
  433. }
  434. /**
  435. * 获取上一页
  436. * @param unknown_type $on_page
  437. */
  438. function get_previous($on_page = 1) {
  439. return $on_page != 0 ? $on_page - 1 : $on_page;
  440. }
  441. }
  442. ?>