Log.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 getList($config_id, $info_id)
  32. {
  33. $where['config_id'] = $config_id;
  34. $where['info_id'] = $info_id;
  35. list($start, $end) = Dever::month();
  36. if ($start && $end) {
  37. $where['start'] = $start;
  38. $where['end'] = $end;
  39. }
  40. $data = Dever::db('account/info_log')->getData($where, function(&$info) {
  41. return $this->info($info);
  42. });
  43. return $data;
  44. }
  45. # 根据来源获取日志列表
  46. public function getListBySource($source, $source_id)
  47. {
  48. $where['source'] = $source;
  49. $where['source_id'] = $source_id;
  50. $data = Dever::db('account/info_log')->select($where, function(&$info) {
  51. return $this->info($info);
  52. });
  53. return $data;
  54. }
  55. # 获取日志详情
  56. public function getInfo($id)
  57. {
  58. $data = Dever::db('account/info_log')->find($id);
  59. $data = $this->info($data);
  60. return $data;
  61. }
  62. # 获取详情
  63. private function info($info)
  64. {
  65. $info['username'] = '无';
  66. $config = Dever::db('account/config')->find($info['config_id']);
  67. $project = Dever::db('account/config_project')->find($config['project_id']);
  68. $source = Dever::db($project['source'])->find($info['uid']);
  69. if ($source) {
  70. $info['username'] = $source[$project['source_name']];
  71. }
  72. $info['config_name'] = $config['name'];
  73. $info['status_name'] = $this->status($info['type_id'], $info['status']);
  74. $info['type_name'] = Dever::load("account/config_type-one#name", $info['type_id']);
  75. $info['cdate_string'] = date('Y-m-d H:i', $info['cdate']);
  76. $info['fee'] = Dever::number($info['ycash'] - $info['cash']);
  77. $type = Dever::db('account/config_type')->one($info['type_id']);
  78. if ($type['type'] == 2) {
  79. $info['ycash'] = Dever::number(-1*$info['ycash']);
  80. $info['cash'] = Dever::number(-1*$info['cash']);
  81. $info['fee'] = Dever::number(-1*$info['fee']);
  82. }
  83. return $info;
  84. }
  85. # 获取状态名称
  86. public function status($type, $status)
  87. {
  88. if ($type == 2) {
  89. if ($status == 1) {
  90. $status_name = '待审核';
  91. } elseif ($status == 2) {
  92. $status_name = '已审核(待发放)';
  93. } elseif ($status == 3) {
  94. $status_name = '已审核(已发放)';
  95. } else {
  96. $status_name = '已作废';
  97. }
  98. } elseif ($status == 2) {
  99. $status_name = '已入账';
  100. } else {
  101. $status_name = '待入账';
  102. }
  103. return $status_name;
  104. }
  105. }