refill_evidence.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. class refill_evidenceControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. /**
  9. * 充值申请列表
  10. */
  11. public function indexOp()
  12. {
  13. $model_merchant = Model('merchant');
  14. $condition = [];
  15. if (trim($_GET['mchid']) != '') {
  16. $condition['mchid'] = $_GET['mchid'];
  17. }
  18. $state_sel = intval($_REQUEST['state_sel']);
  19. if ($state_sel == 1) {
  20. $condition['check_time'] = 0;
  21. $condition['status'] = 1;
  22. } elseif ($state_sel == 2) {
  23. $condition['check_time'] = ['gt', 0];
  24. $condition['status'] = 2;
  25. } elseif ($state_sel == 3) {
  26. $condition['check_time'] = ['gt', 0];
  27. $condition['status'] = 3;
  28. }
  29. if (!empty($_GET['add_type'])) {
  30. $condition['add_type'] = intval($_GET['add_type']);
  31. }
  32. if (!empty($_GET['is_bank'])) {
  33. $condition['is_bank'] = intval($_GET['is_bank']);
  34. }
  35. if (!empty($_GET['receive_bank'])) {
  36. $condition['receive_bank'] = intval($_GET['receive_bank']);
  37. }
  38. $export = $_GET['export'] ?? 0;
  39. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  40. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  41. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  42. $condition['add_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  43. } elseif ($start_unixtime > 0) {
  44. $condition['add_time'] = ['egt', $start_unixtime];
  45. } elseif ($end_unixtime > 0) {
  46. $condition['add_time'] = ['lt', $end_unixtime];
  47. }
  48. $merchant_list = $this->merchants();
  49. //充值申请列表
  50. if(!empty($export)) {
  51. $evidence_list = $this->GetExportData($condition);
  52. } else {
  53. $evidence_list = $model_merchant->getRefillEvidence($condition, 20, 'refill_evidence.*,member.available_predeposit', 'refill_evidence.add_time desc', '', true);
  54. }
  55. $evidence_list = $this->formatData($evidence_list, $merchant_list);
  56. $counts = Model('')->table('refill_evidence')
  57. ->field('sum(amount) as amounts,status,add_type')
  58. ->where($condition)
  59. ->group('status,add_type')
  60. ->select();
  61. $success_amount = $send_amount = $cancel_amount = $mch_amount = $system_amount = $system_edit_amount = 0;
  62. foreach ($counts as $count) {
  63. if($count['status'] == merchantModel::status_applying) {
  64. $send_amount += $count['amounts'];
  65. }elseif ($count['status'] == merchantModel::status_passed) {
  66. $success_amount += $count['amounts'];
  67. if($count['add_type'] == merchantModel::type_mch_deposit) {
  68. $mch_amount += $count['amounts'];
  69. }elseif ($count['add_type'] == merchantModel::type_adm_deposit) {
  70. $system_amount += $count['amounts'];
  71. }elseif ($count['add_type'] == merchantModel::type_adm_adjust) {
  72. $system_edit_amount += $count['amounts'];
  73. }
  74. }elseif ($count['status'] == merchantModel::status_denied) {
  75. $cancel_amount += $count['amounts'];
  76. }
  77. }
  78. $stats['send_amount'] = $send_amount;
  79. $stats['success_amount'] = $success_amount;
  80. $stats['cancel_amount'] = $cancel_amount;
  81. $stats['mch_amount'] = $mch_amount;
  82. $stats['system_amount'] = $system_amount;
  83. $stats['system_edit_amount'] = $system_edit_amount;
  84. if(!empty($export)) {
  85. $result['data'] = $evidence_list;
  86. $result['stats'] = $stats;
  87. echo(json_encode($result));
  88. return;
  89. }
  90. global $config;
  91. $receive_bank_text = $config['receive_bank'][COMPANY_NAME];
  92. Tpl::output('merchant_list', $merchant_list);
  93. Tpl::output('stats', $stats);
  94. Tpl::output('receive_bank_text', $receive_bank_text);
  95. Tpl::output('evidence_list', $evidence_list);
  96. Tpl::output('page', $model_merchant->showpage());
  97. Tpl::showpage('merchant.refill.evidence_list');
  98. }
  99. public function formatData($data, $merchant_list)
  100. {
  101. $status_text = [merchantModel::status_applying =>'申请中', merchantModel::status_passed => '已通过', merchantModel::status_denied => '已驳回'];
  102. $operation_text = [merchantModel::oper_undeposited => '未预存', merchantModel::oper_deposited => '已预存'];
  103. $add_type_text = self::ADD_TYPE_TEXT;
  104. $is_bank_text = ['否','是'];
  105. $merchants = [];
  106. foreach ($merchant_list as $value) {
  107. $merchants[$value['mchid']] = $value;
  108. }
  109. foreach ($data as $key => $value) {
  110. $data[$key]['add_time'] = date('Y-m-d H:i', $value['add_time']);
  111. $data[$key]['check_time'] = !empty($value['check_time']) ? date('Y-m-d H:i', $value['check_time']) : '/';
  112. $data[$key]['status_text'] = $status_text[$value['status']];
  113. $data[$key]['operation_text'] = $operation_text[$value['is_operation']];
  114. $data[$key]['add_type_text'] = $add_type_text[$value['add_type']];
  115. $data[$key]['is_bank_text'] = $is_bank_text[$value['is_bank']];
  116. $data[$key]['company_name'] = $merchants[$value['mchid']]['company_name'] ?? $merchants[$value['mchid']]['name'];
  117. }
  118. return $data;
  119. }
  120. private function GetExportData($condition): array
  121. {
  122. $i = 0;
  123. $result = [];
  124. while (true) {
  125. $start = $i * 1000;
  126. $list = Model('')->table('refill_evidence,member')->join('inner')->on('member.member_id=refill_evidence.member_id')
  127. ->field('refill_evidence.*,member.available_predeposit')->where($condition)->limit("{$start},1000")->master(true)->select();
  128. if (empty($list)) {
  129. break;
  130. }
  131. $i++;
  132. foreach ($list as $value) {
  133. $result[] = $value;
  134. }
  135. }
  136. return $result;
  137. }
  138. public function refill_evidence_editOp()
  139. {
  140. $apply_id = $_GET['apply_id'] ?? $_POST['apply_id'];
  141. $model_merchant = Model('merchant');
  142. if(chksubmit())
  143. {
  144. $data = [];
  145. if(!empty($_POST['bz'])) {
  146. $data['bz'] = $_POST['bz'];
  147. }
  148. if(!empty($_POST['add_type'])) {
  149. $data['add_type'] = $_POST['add_type'];
  150. }
  151. if (empty($data)) {
  152. showMessage('编辑成功', 'index.php?act=refill_evidence&op=index');
  153. }
  154. $resp = $model_merchant->editRefillEvidence(['apply_id' => $apply_id], $data);
  155. if ($resp) {
  156. showMessage('编辑成功', 'index.php?act=refill_evidence&op=index');
  157. } else {
  158. showMessage('编辑失败', "index.php?act=refill_evidence&op=refill_evidence_edit&apply_id={$apply_id}");
  159. }
  160. }
  161. else
  162. {
  163. $merchant_list = $this->merchants();
  164. $evidence_info = $model_merchant->getRefillEvidence(['apply_id' => $apply_id], 20, 'refill_evidence.*', 'refill_evidence.add_time desc', '', true);
  165. $evidence_info = $this->formatData($evidence_info, $merchant_list);
  166. if (empty($evidence_info)) {
  167. showMessage('充值申请不存在', 'index.php?act=refill_evidence&op=index');
  168. }
  169. Tpl::output('evidence_info', $evidence_info[0]);
  170. Tpl::showpage('refill.evidence.edit');
  171. }
  172. }
  173. }