ReceiptAjaxController.php 16 KB

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