Log.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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['type_id'] = $type_id;
  36. $where['status'] = '1,2';
  37. $data = Dever::db('account/info_log')->getCash($where);
  38. return $data;
  39. }
  40. # 获取日志列表
  41. public function getList($config_id, $info_id)
  42. {
  43. $where['config_id'] = $config_id;
  44. $where['info_id'] = $info_id;
  45. list($start, $end) = Dever::month();
  46. if ($start && $end) {
  47. $where['start'] = $start;
  48. $where['end'] = $end;
  49. }
  50. $data = Dever::db('account/info_log')->getData($where, function(&$info) {
  51. return $this->info($info);
  52. });
  53. return $data;
  54. }
  55. # 根据来源获取日志列表
  56. public function getListBySource($source, $source_id)
  57. {
  58. $where['source'] = $source;
  59. $where['source_id'] = $source_id;
  60. $data = Dever::db('account/info_log')->select($where, function(&$info) {
  61. return $this->info($info);
  62. });
  63. return $data;
  64. }
  65. # 获取日志详情
  66. public function getInfo($id)
  67. {
  68. $data = Dever::db('account/info_log')->find($id);
  69. $data = $this->info($data);
  70. return $data;
  71. }
  72. # 获取详情
  73. private function info($info)
  74. {
  75. $info['username'] = '无';
  76. $config = Dever::db('account/config')->find($info['config_id']);
  77. $project = Dever::db('account/config_project')->find($config['project_id']);
  78. //$source = Dever::db($project['source'])->find($info['uid']);
  79. if (strstr($info['source'], '/')) {
  80. $source = Dever::db($info['source'])->find($info['source_id']);
  81. if ($source) {
  82. $user = Dever::db($project['source'])->find($source['uid']);
  83. $info['username'] = $user['name'];
  84. $info['avatar'] = $user['avatar'];
  85. }
  86. }
  87. $info['config_name'] = $config['name'];
  88. $info['status_name'] = $this->status($info['type_id'], $info['status']);
  89. $info['type_name'] = Dever::load("account/config_type-one#name", $info['type_id']);
  90. $info['cdate_string'] = date('Y-m-d H:i', $info['cdate']);
  91. if ($info['audit_date']) {
  92. $info['audit_date_string'] = date('Y-m-d H:i', $info['audit_date']);
  93. } else {
  94. $info['audit_date_string'] = '-';
  95. }
  96. $info['fee'] = Dever::number($info['ycash'] - $info['cash']);
  97. $type = Dever::db('account/config_type')->one($info['type_id']);
  98. if ($type['type'] == 2) {
  99. $info['ycash'] = Dever::number(-1*$info['ycash']);
  100. $info['cash'] = Dever::number(-1*$info['cash']);
  101. $info['fee'] = Dever::number(-1*$info['fee']);
  102. }
  103. return $info;
  104. }
  105. # 获取状态名称
  106. public function status($type, $status)
  107. {
  108. if ($type == 2) {
  109. if ($status == 1) {
  110. $status_name = '待审核';
  111. } elseif ($status == 2) {
  112. $status_name = '已审核(待发放)';
  113. } elseif ($status == 3) {
  114. $status_name = '发放成功';
  115. } elseif ($status == 4) {
  116. $status_name = '审核驳回';
  117. } elseif ($status == 6) {
  118. $status_name = '已审核(待发放)';
  119. } else {
  120. $status_name = '发放失败';
  121. }
  122. } elseif ($status == 2) {
  123. $status_name = '已入账';
  124. } else {
  125. $status_name = '待入账';
  126. }
  127. return $status_name;
  128. }
  129. # 修改记录状态
  130. public function upStatus($id, $status, $cash = false, $update = array())
  131. {
  132. $info = Dever::db('account/info_log')->find($id);
  133. if ($info) {
  134. $update['where_id'] = $info['id'];
  135. $update['status'] = $status;
  136. $state = Dever::db('account/info_log')->update($update);
  137. if ($state && $status >= 4 && $cash) {
  138. $cash = $info['cash'];
  139. $update = array();
  140. $update['where_id'] = $info['info_id'];
  141. $update['set_cash'] = $cash;
  142. $update['set_col'] = $cash;
  143. $update['clear'] = true;
  144. $func = 'inc';
  145. Dever::db('account/info')->$func($update);
  146. }
  147. }
  148. }
  149. }