ReceiptAjaxController.php 16 KB

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