ReceiptAjaxController.php 16 KB

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