invoiceReceivables.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. /**
  176. * 根据收款ID获取一条相关数据
  177. * @param string $irid
  178. * @param string $con 附加获取收款条件 可以为空
  179. * @return unknown[]|mixed[]|string[]
  180. */
  181. public function getInvoiceReceivablesByIrid($irid = "", $con = "") {
  182. Doo::loadClass ( 'XDeode' );
  183. $XDeode = new XDeode ( 5 );
  184. if (!is_numeric($irid))
  185. $irid = $this->authcode ( $irid );
  186. $detail = array ();
  187. if (! empty ( $irid ) && is_numeric ( $irid ))
  188. $detail = $this->getOne ( array (
  189. 'where' => " irid=" . $irid . $con,
  190. 'asArray' => TRUE
  191. ) );
  192. if (empty($detail))
  193. return $detail;
  194. $detail ['cid'] = '';
  195. $detail ['title'] = '';
  196. if ($detail ['receivablesCategory'] != "PUBLIC") {
  197. $category = explode ( ":", $detail ['receivablesCategory'] );
  198. $detail ['cid'] = $category [0];
  199. $detail ['title'] = $category [1];
  200. }
  201. $detail ['sid'] = '';
  202. $detail ['username'] = '';
  203. if ($detail ['receivablesStaff'] != "PUBLIC") {
  204. $staff = explode ( "-", $detail ['receivablesStaff'] );
  205. $detail ['sid'] = $staff [0];
  206. $detail ['username'] = $staff [1];
  207. }
  208. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  209. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  210. return $detail;
  211. }
  212. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  213. Doo::loadClass ( 'XDeode' );
  214. $XDeode = new XDeode ( 5 );
  215. $irid = $XDeode->decode ( $irid );
  216. $detail = array ();
  217. if (! empty ( $irid ) && is_numeric ( $irid )) {
  218. $detail = $this->getOne ( array (
  219. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  220. 'asArray' => TRUE
  221. ) );
  222. $detail ['sid'] = '';
  223. $detail ['username'] = '';
  224. if (! empty ( $detail ['receivablesStaff'] )) {
  225. $staff = explode ( "-", $detail ['receivablesStaff'] );
  226. $detail ['sid'] = $staff [0];
  227. $detail ['username'] = $staff [1];
  228. }
  229. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  230. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  231. }
  232. return $detail;
  233. }
  234. /**
  235. * 添加一个收款
  236. * @param array $item 收款相关数据
  237. * @return number 返回收款ID
  238. */
  239. public function addInvoiceReceivables($item = array()) {
  240. $lid = 0;
  241. if (is_array ( $item ) && ! empty ( $item )) {
  242. foreach ( $item as $key => $value ) {
  243. $this->$key = $value;
  244. }
  245. $lid = $this->insert ();
  246. }
  247. return $lid;
  248. }
  249. /**
  250. * 根据参数字段更新相应字段(主键ID必须传)
  251. * @param array $item 相关需要更新的字段信息
  252. * @return number 返回发票ID
  253. */
  254. public function setInvoiceReceivablesByCondition($item = array()) {
  255. $lid = 0;
  256. if (is_array ( $item ) && ! empty ( $item )) {
  257. foreach ( $item as $key => $value ) {
  258. $this->$key = $value;
  259. }
  260. $lid = $this->update ();
  261. }
  262. return $lid;
  263. }
  264. /**
  265. * 根据irid 获取一组收款数据
  266. * @param string $irid
  267. * @return unknown
  268. */
  269. public function getInvoiceReceivablesInIrid($irid = '') {
  270. if (empty ( $irid ))
  271. return array ();
  272. $list = $this->find ( array (
  273. 'where' => " irid in(" . $irid . ")",
  274. 'asArray' => TRUE
  275. ) );
  276. foreach ( $list as $key => $value ) {
  277. }
  278. return $list;
  279. }
  280. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc') {
  281. if (empty ( $limit ))
  282. return array ();
  283. $list = $this->find ( array (
  284. 'where' => $con, // " bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  285. 'limit' => $limit,
  286. $desc => 'irid',
  287. 'asArray' => TRUE
  288. ) );
  289. Doo::loadClass ( 'XDeode' );
  290. $XDeode = new XDeode ( 5 );
  291. Doo::loadModel ( 'invoice' );
  292. $invoice = new invoice ();
  293. Doo::loadModel ( 'invoiceROLog' );
  294. $invoiceROLog = new invoiceROLog ();
  295. foreach ( $list as $key => $value ) {
  296. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  297. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  298. if (isset ( $value ['iid'] ) && ! empty ( $value ['iid'] )) {
  299. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  300. $list [$key] ['irList'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  301. } else {
  302. $list [$key] ['iidKeyK'] = '';
  303. $list [$key] ['irList'] = array (
  304. 'invoiceSerial' => ''
  305. );
  306. }
  307. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  308. // $list [$key] ['sumPrice'] = 0;
  309. // if (! empty ( $list [$key] ['irList'] ))
  310. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  311. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  312. }
  313. return $list;
  314. }
  315. function delInvoiceReceivablesByIrid($irid = 0) {
  316. if (!empty($irid)&&is_numeric($irid))
  317. $this->delete(array('where'=>'irid='.$irid));
  318. }
  319. /**
  320. * 加密或解密指定字符串
  321. *
  322. * @param string $string 要加密或解密的字符串
  323. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  324. * @param string $key 加解密的key
  325. * @param $expiry 超时值
  326. *
  327. */
  328. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  329. $ckey_length = 4;
  330. if (! $key) {
  331. $key = $this->INVOICEKEY;
  332. }
  333. $key = md5 ( $key );
  334. $keya = md5 ( substr ( $key, 0, 16 ) );
  335. $keyb = md5 ( substr ( $key, 16, 16 ) );
  336. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  337. $cryptkey = $keya . md5 ( $keya . $keyc );
  338. $key_length = strlen ( $cryptkey );
  339. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  340. $string_length = strlen ( $string );
  341. $result = '';
  342. $box = range ( 0, 255 );
  343. $rndkey = array ();
  344. for($i = 0; $i <= 255; $i ++) {
  345. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  346. }
  347. for($j = $i = 0; $i < 256; $i ++) {
  348. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  349. $tmp = $box [$i];
  350. $box [$i] = $box [$j];
  351. $box [$j] = $tmp;
  352. }
  353. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  354. $a = ($a + 1) % 256;
  355. $j = ($j + $box [$a]) % 256;
  356. $tmp = $box [$a];
  357. $box [$a] = $box [$j];
  358. $box [$j] = $tmp;
  359. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  360. }
  361. if ($operation == 'DECODE') {
  362. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  363. return substr ( $result, 26 );
  364. } else {
  365. return '';
  366. }
  367. } else {
  368. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  369. }
  370. }
  371. }
  372. ?>