ReceiptAjaxController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. function ajaxItineraryDate(){
  114. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : '';
  115. Doo::loadClass ( 'receipt.func' );
  116. $falt=_verifyItineraryDate($date,$this->staff['sid']);
  117. echo json_encode ( array (
  118. 'status' => $falt
  119. ) );
  120. }
  121. /**
  122. * 默认获得属于自己和所在办事处10条最新的数据
  123. */
  124. function ajaxGetReceiptTrainLoan(){
  125. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : $this->staff['sid'];
  126. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : $this->staff['cid'];
  127. $limit = $this->get_args ( 'limit' ) ? $this->get_args ( 'limit' ) : '30';
  128. $status=8;
  129. Doo::loadModel ( 'receipt' );
  130. $receipt = new receipt ();
  131. $list=$receipt->getReceiptLoanByStatus($sid,$cid,$status,$limit);
  132. echo json_encode ( array (
  133. 'status' => 1,
  134. 'receiptLoanList' => $list
  135. ) );
  136. }
  137. /**
  138. * 获得费用详情
  139. */
  140. function ajaxGetReceiptDetailByJson() {
  141. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  142. Doo::loadClass ( 'XDeode' );
  143. $XDeode = new XDeode ( 5 );
  144. $rid = $XDeode->decode ( $ridKey );
  145. Doo::loadModel ( 'receipt' );
  146. $receipt = new receipt ();
  147. $detail = $receipt->getReceiptByRid ( $rid );
  148. $payment=$this->_getReceiptTrainPayment($detail ['invoiceTrainId'],$detail ['trainLoanRid'],$rid);
  149. $detail['payment']=$payment;
  150. Doo::loadClass ( 'authcode.func' );
  151. $detail['paymentAuthCode']=authcode($payment,'');
  152. echo json_encode ( array (
  153. 'status' => 1,
  154. 'detail' => $detail
  155. ) );
  156. }
  157. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  158. // 收入合计
  159. Doo::loadModel ( 'invoiceTraining' );
  160. $invoiceTraining = new invoiceTraining ();
  161. Doo::loadModel ( 'receipt' );
  162. $receipt = new receipt ();
  163. $invoiceTrainingDetail = array (
  164. 'invoiceArriveAmount' => '0.00',
  165. 'RIAmount' => '0.00',
  166. 'invoiceTotalAmount' => '0.00',
  167. 'invoiceCompanyAmount' => '0.00',
  168. 'invoiceArriveAmountM'=>'0.00',
  169. 'invoiceCompanyAmountM'=>'0.00'
  170. );
  171. if ($invoiceTrainId != 0) {
  172. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  173. }
  174. $invoiceArriveAmount = $RIAmount = 0;
  175. if (! empty ( $invoiceTrainingDetail )) {
  176. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  177. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  178. }
  179. // 备用金
  180. $sum = 0;
  181. if (! empty ( $trainLoanRid )) {
  182. //$receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  183. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  184. foreach ($receiptLoanList as $key=>$value){
  185. $sum+=$value['sum'];
  186. }
  187. //$sum = $receiptLoanDetailBak ['sum'];
  188. }
  189. // 支出项金额详情
  190. // 项目金额合计
  191. Doo::loadModel ( 'RItem' );
  192. $RItem = new RItem ();
  193. Doo::loadModel ( 'accountItem' );
  194. $accountItem = new accountItem ();
  195. // 讲师获得
  196. Doo::loadModel ( 'RILecturer' );
  197. $RILecturer = new RILecturer ();
  198. $RItemList = $RItem->getRItemByRid ($rid );
  199. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  200. // 支出项金额详情
  201. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  202. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  203. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  204. return $payment;
  205. }
  206. /**
  207. * 更新费用的汇款金额
  208. */
  209. function ajaxSetRceiptAmountByRid(){
  210. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  211. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  212. if (empty($ridKey)||empty($amount)){
  213. echo json_encode ( array (
  214. 'status' => 2
  215. ) );
  216. die;
  217. }
  218. Doo::loadClass ( 'XDeode' );
  219. $XDeode = new XDeode ( 5 );
  220. $rid = $XDeode->decode ( $ridKey );
  221. Doo::loadModel ( 'receipt' );
  222. $receipt = new receipt ();
  223. $detail=$receipt->getReceiptByRid($rid);
  224. if (empty($detail)){
  225. echo json_encode ( array (
  226. 'status' => 2
  227. ) );
  228. die;
  229. }
  230. if ($detail['status']!=2){
  231. echo json_encode ( array (
  232. 'status' => 2
  233. ) );
  234. die;
  235. }
  236. $receipt = new receipt ();
  237. $receipt->amount = $amount;
  238. $receipt->update ( array (
  239. 'where' => ' rid = ' . $rid
  240. ) );
  241. echo json_encode ( array (
  242. 'status' => 1
  243. ) );
  244. }
  245. function setWXMsg($rid, $type) {
  246. Doo::loadModel ( "receipt" );
  247. $receipt = new receipt ();
  248. $receiptDetail = $receipt->getOne ( array (
  249. 'where' => 'rid=' . $rid,
  250. 'asArray' => true
  251. ) );
  252. if (! empty ( $receiptDetail )) {
  253. Doo::loadModel ( 'staff' );
  254. $staff = new staff ();
  255. $staffmsg = $staff->getOne ( array (
  256. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  257. 'asArray' => TRUE
  258. ) );
  259. if (! empty ( $staffmsg ['wxid'] )) {
  260. require_once (SITE_PATH . '/protected/class/client.php');
  261. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  262. $user = $staffmsg ['wxid'];
  263. $receiptName = '';
  264. $msg = '';
  265. switch ($receiptDetail ['Rtype']) {
  266. case 0 :
  267. $receiptName = '报销';
  268. break;
  269. case 1 :
  270. $receiptName = '借款';
  271. break;
  272. case 2 :
  273. $receiptName = '对公汇款';
  274. break;
  275. }
  276. switch ($type) {
  277. case 1 :
  278. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  279. break;
  280. case 2 :
  281. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  282. break;
  283. case 3 :
  284. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  285. break;
  286. }
  287. // $result = $client->SendMsg ( $user, $msg, 'text' );
  288. }
  289. }
  290. }
  291. // Email发送函数
  292. function SMail($toemail, $subject, $contents) {
  293. Doo::loadClass ( 'class.phpmailer' );
  294. $mail = new PHPMailer ();
  295. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  296. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  297. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  298. $mail->Password = "cDO1GjtY1seH"; // 密码
  299. $mail->CharSet = "UTF8";
  300. $mail->SMTPAuth = true;
  301. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  302. $mail->Mailer = "smtp";
  303. $mail->Port = 25;
  304. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  305. $mail->MsgHTML ( $contents );
  306. $mail->AddAddress ( $toemail );
  307. $mail->CharSet = "UTF-8";
  308. return $mail->Send ();
  309. }
  310. function swfupload() {
  311. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  312. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  313. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  314. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  315. header ( "HTTP/1.1 500 Internal Server Error" );
  316. echo "POST exceeded maximum allowed size.";
  317. exit ( 0 );
  318. }
  319. // Settings
  320. $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)
  321. $upload_name = "Filedata";
  322. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  323. $extension_whitelist = array (
  324. "doc",
  325. "txt",
  326. "jpg",
  327. "gif",
  328. "png"
  329. ); // Allowed file extensions
  330. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  331. // Other variables
  332. $MAX_FILENAME_LENGTH = 260;
  333. $file_name = "";
  334. $file_extension = "";
  335. $uploadErrors = array (
  336. 0 => "文件上传成功",
  337. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  338. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  339. 3 => "上传的文件仅为部分文件",
  340. 4 => "没有文件上传",
  341. 6 => "缺少临时文件夹"
  342. );
  343. $nk = time ();
  344. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  345. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  346. echo "文件无法保存.";
  347. exit ( 0 );
  348. }
  349. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  350. echo json_encode ( array (
  351. 'filename' => $file_name,
  352. 'id' => $nk
  353. ) );
  354. exit ( 0 );
  355. }
  356. function _GetFileEXT($filename) {
  357. $pics = explode ( '.', $filename );
  358. $num = count ( $pics );
  359. return $pics [$num - 1];
  360. }
  361. /**
  362. * 获取get或者POST值
  363. * @param string $name 属性名称
  364. * @return fixed 值
  365. */
  366. function get_args($name) {
  367. if (isset ( $_GET [$name] )) {
  368. if (is_array ( $_GET [$name] ))
  369. return $_GET [$name];
  370. else
  371. return addslashes ( $_GET [$name] );
  372. } elseif (isset ( $_POST [$name] )) {
  373. if (is_array ( $_POST [$name] ))
  374. return $_POST [$name];
  375. else
  376. return addslashes ( $_POST [$name] );
  377. } else
  378. return false;
  379. }
  380. function num_to_rmb($num) {
  381. $c1 = "零壹贰叁肆伍陆柒捌玖";
  382. $c2 = "分角元拾佰仟万拾佰仟亿";
  383. // 精确到分后面就不要了,所以只留两个小数位
  384. $num = round ( $num, 2 );
  385. // 将数字转化为整数
  386. $num = $num * 100;
  387. if (strlen ( $num ) > 10) {
  388. return "金额太大,请检查";
  389. }
  390. $i = 0;
  391. $c = "";
  392. while ( 1 ) {
  393. if ($i == 0) {
  394. // 获取最后一位数字
  395. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  396. } else {
  397. $n = $num % 10;
  398. }
  399. // 每次将最后一位数字转化为中文
  400. $p1 = substr ( $c1, 3 * $n, 3 );
  401. $p2 = substr ( $c2, 3 * $i, 3 );
  402. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  403. $c = $p1 . $p2 . $c;
  404. } else {
  405. $c = $p1 . $c;
  406. }
  407. $i = $i + 1;
  408. // 去掉数字最后一位了
  409. $num = $num / 10;
  410. // echo $num.'</br>';
  411. $num = ( int ) $num;
  412. // $num =floor($num);
  413. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  414. // echo $num.'</br>';
  415. // 结束循环
  416. if ($num == 0) {
  417. break;
  418. }
  419. }
  420. // echo $c.'</br>';
  421. $j = 0;
  422. $slen = strlen ( $c );
  423. while ( $j < $slen ) {
  424. // utf8一个汉字相当3个字符
  425. $m = substr ( $c, $j, 6 );
  426. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  427. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  428. $left = substr ( $c, 0, $j );
  429. $right = substr ( $c, $j + 3 );
  430. $c = $left . $right;
  431. $j = $j - 3;
  432. $slen = $slen - 3;
  433. }
  434. $j = $j + 3;
  435. }
  436. // 这个是为了去掉类似23.0中最后一个“零”字
  437. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  438. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  439. }
  440. // 将处理的汉字加上“整”
  441. if (empty ( $c )) {
  442. return "零元整";
  443. } else {
  444. return $c . "整";
  445. }
  446. }
  447. /**
  448. * 获得分页数据
  449. * @param unknown_type $table
  450. * @param unknown_type $condition
  451. * @param unknown_type $on_page
  452. * @param unknown_type $page_size
  453. */
  454. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  455. $page_c = "";
  456. $page ['previous'] = $this->get_previous ( $on_page );
  457. $page ['on_page'] = $on_page;
  458. $total_count = $this->get_table_count ( $table, $condition );
  459. $total = intval ( $total_count / $page_size );
  460. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  461. $page ['total_data'] = $total_count;
  462. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  463. $i = 1;
  464. $page_max = 1;
  465. $page_width = 3;
  466. if ($on_page >= $page_width) {
  467. $page_max = intval ( $on_page / $page_width ) + 1;
  468. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  469. }
  470. for(; $i <= $page ['total_page']; $i ++) {
  471. if ($i == $on_page)
  472. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  473. else
  474. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  475. if ($i == ($page_width * $page_max))
  476. break;
  477. }
  478. $page ['page'] = $page_c;
  479. $page ['lower'] = (-- $on_page) * $page_size;
  480. return $page;
  481. }
  482. /**
  483. * 获取总页数
  484. * @param unknown_type $table
  485. * @param unknown_type $condition
  486. */
  487. public function get_table_count($table = "", $condition = "") {
  488. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  489. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  490. // echo $sql;die;
  491. $query = Doo::db ()->query ( $sql );
  492. $result = $query->fetch ();
  493. return $result ['count'];
  494. }
  495. /**
  496. * 获取上一页
  497. * @param unknown_type $on_page
  498. */
  499. function get_previous($on_page = 1) {
  500. return $on_page != 0 ? $on_page - 1 : $on_page;
  501. }
  502. }
  503. ?>