Log.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace Account\Lib;
  3. use Dever;
  4. class Log
  5. {
  6. # 创建钱包日志
  7. public function create($data)
  8. {
  9. if ($data['status'] == 2) {
  10. $admin = Dever::load('manage/auth.data');
  11. if ($admin) {
  12. $data['audit_admin'] = $admin['id'];
  13. }
  14. $data['audit_date'] = time();
  15. }
  16. $data['order_num'] = $this->createOrderNum();
  17. return Dever::db('account/info_log')->insert($data);
  18. }
  19. # 生成订单号
  20. private function createOrderNum()
  21. {
  22. $where['order_num'] = Dever::order('A');
  23. $state = Dever::db('account/info_log')->one($where);
  24. if (!$state) {
  25. return $where['order_num'];
  26. } else {
  27. return $this->createOrderNum();
  28. }
  29. }
  30. # 获取某个交易类型的审核中的金额
  31. public function getCash($config_id, $info_id, $type_id)
  32. {
  33. $where['config_id'] = $config_id;
  34. $where['info_id'] = $info_id;
  35. $where['status'] = '1,2';
  36. $data = Dever::db('account/info_log')->getCash($where);
  37. return $data;
  38. }
  39. # 获取日志列表
  40. public function getList($config_id, $info_id)
  41. {
  42. $where['config_id'] = $config_id;
  43. $where['info_id'] = $info_id;
  44. list($start, $end) = Dever::month();
  45. if ($start && $end) {
  46. $where['start'] = $start;
  47. $where['end'] = $end;
  48. }
  49. $data = Dever::db('account/info_log')->getData($where, function(&$info) {
  50. return $this->info($info);
  51. });
  52. return $data;
  53. }
  54. # 根据来源获取日志列表
  55. public function getListBySource($source, $source_id)
  56. {
  57. $where['source'] = $source;
  58. $where['source_id'] = $source_id;
  59. $data = Dever::db('account/info_log')->select($where, function(&$info) {
  60. return $this->info($info);
  61. });
  62. return $data;
  63. }
  64. # 获取日志详情
  65. public function getInfo($id)
  66. {
  67. $data = Dever::db('account/info_log')->find($id);
  68. $data = $this->info($data);
  69. return $data;
  70. }
  71. # 获取详情
  72. private function info($info)
  73. {
  74. $info['username'] = '无';
  75. $config = Dever::db('account/config')->find($info['config_id']);
  76. $project = Dever::db('account/config_project')->find($config['project_id']);
  77. //$source = Dever::db($project['source'])->find($info['uid']);
  78. if (strstr($info['source'], '/')) {
  79. $source = Dever::db($info['source'])->find($info['source_id']);
  80. if ($source) {
  81. $user = Dever::db($project['source'])->find($source['uid']);
  82. $info['username'] = $user['name'];
  83. $info['avatar'] = $user['avatar'];
  84. }
  85. }
  86. $info['config_name'] = $config['name'];
  87. $info['status_name'] = $this->status($info['type_id'], $info['status']);
  88. $info['type_name'] = Dever::load("account/config_type-one#name", $info['type_id']);
  89. $info['cdate_string'] = date('Y-m-d H:i', $info['cdate']);
  90. $info['fee'] = Dever::number($info['ycash'] - $info['cash']);
  91. $type = Dever::db('account/config_type')->one($info['type_id']);
  92. if ($type['type'] == 2) {
  93. $info['ycash'] = Dever::number(-1*$info['ycash']);
  94. $info['cash'] = Dever::number(-1*$info['cash']);
  95. $info['fee'] = Dever::number(-1*$info['fee']);
  96. }
  97. return $info;
  98. }
  99. # 获取状态名称
  100. public function status($type, $status)
  101. {
  102. if ($type == 2) {
  103. if ($status == 1) {
  104. $status_name = '待审核';
  105. } elseif ($status == 2) {
  106. $status_name = '已审核(待发放)';
  107. } elseif ($status == 3) {
  108. $status_name = '已审核(已发放)';
  109. } elseif ($status == 4) {
  110. $status_name = '审核驳回';
  111. } else {
  112. $status_name = '已作废';
  113. }
  114. } elseif ($status == 2) {
  115. $status_name = '已入账';
  116. } else {
  117. $status_name = '待入账';
  118. }
  119. return $status_name;
  120. }
  121. # 修改记录状态
  122. public function upStatus($id, $status, $cash = false, $update = array())
  123. {
  124. $info = Dever::db('account/info_log')->find($id);
  125. if ($info) {
  126. $update['where_id'] = $info['id'];
  127. $update['status'] = $status;
  128. $state = Dever::db('account/info_log')->update($update);
  129. if ($state && $status >= 4 && $cash) {
  130. $cash = $info['cash'];
  131. $update = array();
  132. $update['where_id'] = $info['info_id'];
  133. $update['set_cash'] = $cash;
  134. $update['set_col'] = $cash;
  135. $update['clear'] = true;
  136. $func = 'inc';
  137. Dever::db('account/info')->$func($update);
  138. }
  139. }
  140. }
  141. }