invoiceReceivables.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. /**
  4. * 发票审批相关信息及其操作业务逻辑
  5. * @author CP.
  6. * @version 1.0
  7. * @namespace invoice
  8. * @package invoiceModel
  9. */
  10. class invoiceReceivables extends DooModel {
  11. private $INVOICEKEY = "APPROVAL";
  12. public $irid;
  13. public $bindStatus;
  14. public $iid;
  15. public $receivablesPrice;
  16. public $receivablesSerial;
  17. public $receivablesMessage;
  18. public $receivablesBank;
  19. public $receivablesDate;
  20. public $receivablesCategory;
  21. public $receivablesStaff;
  22. public $inputStaff;
  23. public $source;
  24. public $date;
  25. public $confirmTime;
  26. public $bindDate;
  27. public $_table = 'CLD_invoiceReceivables';
  28. public $_primarykey = 'irid';
  29. public $_fields = array (
  30. 'irid',
  31. 'bindStatus',
  32. 'iid',
  33. 'receivablesPrice',
  34. 'receivablesSerial',
  35. 'receivablesMessage',
  36. 'receivablesBank',
  37. 'receivablesDate',
  38. 'receivablesCategory',
  39. 'receivablesStaff',
  40. 'inputStaff',
  41. 'source',
  42. 'date',
  43. 'confirmTime',
  44. 'bindDate'
  45. );
  46. /**
  47. * 获取最新几条收款包括最新的一条操作日志
  48. * @param number $limit
  49. * @return unknown
  50. */
  51. public function getInvoiceReceivablesByNew($limit = 4) {
  52. $list = $this->find ( array (
  53. 'desc' => 'irid',
  54. 'limit' => $limit,
  55. 'asArray' => TRUE
  56. ) );
  57. Doo::loadModel ( 'invoiceROLog' );
  58. $invoiceROLog = new invoiceROLog ();
  59. foreach ( $list as $key => $value ) {
  60. $list [$key] ['invoiceROLog'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  61. }
  62. return $list;
  63. }
  64. public function getInvoiceReceivablesByClaim($cid = 0, $sid = 0) {
  65. if (empty ( $sid )) {
  66. $list ['csClaim'] = $this->find ( array (
  67. 'where' => "receivablesCategory='public' and receivablesStaff='public' and bindStatus=0",
  68. 'desc' => 'irid',
  69. 'asArray' => TRUE
  70. ) );
  71. foreach ( $list ['csClaim'] as $key => $value ) {
  72. $list ['csClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  73. // $list ['csClaim'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  74. }
  75. $list ['sClaim'] = $this->find ( array (
  76. 'where' => "receivablesCategory!='public' and receivablesStaff='public' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  77. 'desc' => 'irid',
  78. 'asArray' => TRUE
  79. ) );
  80. foreach ( $list ['sClaim'] as $key => $value ) {
  81. $list ['sClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  82. }
  83. $list ['arClaim'] = $this->find ( array (
  84. 'where' => "receivablesCategory!='public' and receivablesStaff!='public' and receivablesCategory like '" . $cid . ":%' and receivablesStaff like '" . $sid . "-%' and bindStatus=0",
  85. 'desc' => 'irid',
  86. 'asArray' => TRUE
  87. ) );
  88. foreach ( $list ['arClaim'] as $key => $value ) {
  89. $staff = explode ( "-", $value ['receivablesStaff'] );
  90. $list ['arClaim'] [$key] ['sid'] = $staff [0];
  91. $list ['arClaim'] [$key] ['username'] = $staff [1];
  92. }
  93. }
  94. if (! empty ( $cid ) && ! empty ( $sid )) {
  95. $list ['myClaim'] = $this->find ( array (
  96. 'where' => " receivablesStaff like '" . $sid . "-%' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  97. 'desc' => 'irid',
  98. 'asArray' => TRUE
  99. ) );
  100. foreach ( $list ['myClaim'] as $key => $value ) {
  101. $list ['myClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  102. $staff = explode ( "-", $value ['receivablesStaff'] );
  103. $list ['myClaim'] [$key] ['sid'] = $staff [0];
  104. $list ['myClaim'] [$key] ['username'] = $staff [1];
  105. }
  106. $list ['bindClaim'] = $this->find ( array (
  107. 'where' => " bindStatus=1 and receivablesStaff like '" . $sid . "-%' ",
  108. 'desc' => 'irid',
  109. 'limit' => 3,
  110. 'asArray' => TRUE
  111. ) );
  112. Doo::loadModel ( 'invoice' );
  113. $invoice = new invoice ();
  114. Doo::loadClass ( 'XDeode' );
  115. $XDeode = new XDeode ( 5 );
  116. foreach ( $list ['bindClaim'] as $key => $value ) {
  117. $id = $invoice->getInvoiceByIid ( $value ['iid'] );
  118. $id ['iidKeyUrl'] = $XDeode->encode ( $id ['iid'] );
  119. $list ['bindClaim'] [$key] ['invoice'] = $id;
  120. $list ['bindClaim'] [$key] ['iridKeyUrl'] = $XDeode->encode ( $value ['irid'] );
  121. }
  122. }
  123. return $list;
  124. }
  125. /**
  126. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  127. * @param string $iid 发票ID
  128. * @param string $bindStatus
  129. * @return mixed
  130. */
  131. public function getInvoiceReceivablesByIid($iid = "", $bindStatus = "All") {
  132. Doo::loadClass ( 'XDeode' );
  133. $XDeode = new XDeode ( 5 );
  134. $iid = $this->authcode ( $iid );
  135. $list = array ();
  136. if (! empty ( $iid ) && is_numeric ( $iid )) {
  137. $sql = '';
  138. if ($bindStatus == 1)
  139. $sql = " and bindStatus=1";
  140. elseif ($bindStatus == 0)
  141. $sql = " and bindStatus=0";
  142. $list = $this->find ( array (
  143. 'where' => " iid=" . $iid . $sql,
  144. 'asArray' => TRUE
  145. ) );
  146. }
  147. foreach ( $list as $key => $value ) {
  148. $list [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  149. $staff = explode ( "-", $value ['receivablesStaff'] );
  150. $list [$key] ['sid'] = $staff [0];
  151. $list [$key] ['username'] = $staff [1];
  152. $list [$key] ['iridKey'] = $XDeode->encode ( $value ['irid'] );
  153. }
  154. return $list;
  155. }
  156. public function getInvoiceReceivablesInIridString($iridString = "") {
  157. $list = array ();
  158. if (! empty ( $iridString ))
  159. $list = $this->find ( array (
  160. 'where' => " irid in ( " . $iridString . " )",
  161. 'asArray' => TRUE
  162. ) );
  163. $price=0;
  164. $serial=0;
  165. Doo::loadClass ( 'XDeode' );
  166. $XDeode = new XDeode ( 5 );
  167. foreach ($list as $key=>$value){
  168. $price+=$value['receivablesPrice'];
  169. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  170. }
  171. if (!empty($list))
  172. $list[0]['sumPrice']=$price;
  173. return $list;
  174. }
  175. public function getInvoiceReceivablesByIrid($irid = "") {
  176. Doo::loadClass ( 'XDeode' );
  177. $XDeode = new XDeode ( 5 );
  178. $irid = $this->authcode ( $irid );
  179. $detail = array ();
  180. if (! empty ( $irid ) && is_numeric ( $irid ))
  181. $detail = $this->getOne ( array (
  182. 'where' => " irid=" . $irid,
  183. 'asArray' => TRUE
  184. ) );
  185. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  186. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  187. return $detail;
  188. }
  189. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  190. Doo::loadClass ( 'XDeode' );
  191. $XDeode = new XDeode ( 5 );
  192. $irid = $XDeode->decode ( $irid );
  193. $detail = array ();
  194. if (! empty ( $irid ) && is_numeric ( $irid )) {
  195. $detail = $this->getOne ( array (
  196. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  197. 'asArray' => TRUE
  198. ) );
  199. $detail ['sid'] = '';
  200. $detail ['username'] = '';
  201. if (! empty ( $detail ['receivablesStaff'] )) {
  202. $staff = explode ( "-", $detail ['receivablesStaff'] );
  203. $detail ['sid'] = $staff [0];
  204. $detail ['username'] = $staff [1];
  205. }
  206. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  207. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  208. }
  209. return $detail;
  210. }
  211. /**
  212. * 添加一个收款
  213. * @param array $item 收款相关数据
  214. * @return number 返回收款ID
  215. */
  216. public function addInvoiceReceivables($item = array()) {
  217. $lid = 0;
  218. if (is_array ( $item ) && ! empty ( $item )) {
  219. foreach ( $item as $key => $value ) {
  220. $this->$key = $value;
  221. }
  222. $lid = $this->insert ();
  223. }
  224. return $lid;
  225. }
  226. /**
  227. * 根据参数字段更新相应字段(主键ID必须传)
  228. * @param array $item 相关需要更新的字段信息
  229. * @return number 返回发票ID
  230. */
  231. public function setInvoiceReceivablesByCondition($item = array()) {
  232. $lid = 0;
  233. if (is_array ( $item ) && ! empty ( $item )) {
  234. foreach ( $item as $key => $value ) {
  235. $this->$key = $value;
  236. }
  237. $lid = $this->update ();
  238. }
  239. return $lid;
  240. }
  241. /**
  242. * 根据irid 获取一组收款数据
  243. * @param string $irid
  244. * @return unknown
  245. */
  246. public function getInvoiceReceivablesInIrid($irid = '') {
  247. if (empty($irid))
  248. return array();
  249. $list = $this->find ( array (
  250. 'where' => " irid in(" . $irid . ")",
  251. 'asArray' => TRUE
  252. ) );
  253. foreach ($list as $key=>$value){
  254. }
  255. return $list;
  256. }
  257. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc') {
  258. if (empty ( $limit ))
  259. return array ();
  260. $list = $this->find ( array (
  261. 'where' => $con,//" bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  262. 'limit' => $limit,
  263. $desc => 'irid',
  264. 'asArray' => TRUE
  265. ) );
  266. Doo::loadClass ( 'XDeode' );
  267. $XDeode = new XDeode ( 5 );
  268. Doo::loadModel ( 'invoice' );
  269. $invoice = new invoice ();
  270. Doo::loadModel ( 'invoiceROLog' );
  271. $invoiceROLog = new invoiceROLog ();
  272. foreach ( $list as $key => $value ) {
  273. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  274. if (isset($value ['iid'])&&!empty($value ['iid'])){
  275. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  276. $list [$key] ['irList'] = $invoice->getInvoiceByIid( $value ['iid'] );
  277. }else{
  278. $list [$key] ['iidKeyK']='';
  279. $list [$key] ['irList']=array('invoiceSerial'=>'');
  280. }
  281. $list [$key]['irolg']=$invoiceROLog->getInvoiceROLogByIrid($value ['irid'],'desc');
  282. // $list [$key] ['sumPrice'] = 0;
  283. // if (! empty ( $list [$key] ['irList'] ))
  284. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  285. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  286. }
  287. return $list;
  288. }
  289. /**
  290. * 加密或解密指定字符串
  291. *
  292. * @param string $string 要加密或解密的字符串
  293. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  294. * @param string $key 加解密的key
  295. * @param $expiry 超时值
  296. *
  297. */
  298. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  299. $ckey_length = 4;
  300. if (! $key) {
  301. $key = $this->INVOICEKEY;
  302. }
  303. $key = md5 ( $key );
  304. $keya = md5 ( substr ( $key, 0, 16 ) );
  305. $keyb = md5 ( substr ( $key, 16, 16 ) );
  306. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  307. $cryptkey = $keya . md5 ( $keya . $keyc );
  308. $key_length = strlen ( $cryptkey );
  309. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  310. $string_length = strlen ( $string );
  311. $result = '';
  312. $box = range ( 0, 255 );
  313. $rndkey = array ();
  314. for($i = 0; $i <= 255; $i ++) {
  315. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  316. }
  317. for($j = $i = 0; $i < 256; $i ++) {
  318. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  319. $tmp = $box [$i];
  320. $box [$i] = $box [$j];
  321. $box [$j] = $tmp;
  322. }
  323. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  324. $a = ($a + 1) % 256;
  325. $j = ($j + $box [$a]) % 256;
  326. $tmp = $box [$a];
  327. $box [$a] = $box [$j];
  328. $box [$j] = $tmp;
  329. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  330. }
  331. if ($operation == 'DECODE') {
  332. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  333. return substr ( $result, 26 );
  334. } else {
  335. return '';
  336. }
  337. } else {
  338. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  339. }
  340. }
  341. }
  342. ?>