refill_refund.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. class refill_refundControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. $mod = Model('refill_refund');
  11. $condition = [];
  12. if(!empty($_GET['provider_id'])) {
  13. $condition['provider_id'] = $_GET['provider_id'];
  14. }
  15. if(!empty($_GET['mchid'])) {
  16. $condition['mchid'] = $_GET['mchid'];
  17. }
  18. if(!empty($_GET['card_no'])) {
  19. $condition['card_no'] = $_GET['card_no'];
  20. }
  21. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  22. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  23. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  24. $condition['refund_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  25. } elseif ($start_unixtime > 0) {
  26. $condition['refund_time'] = ['egt', $start_unixtime];
  27. } elseif ($end_unixtime > 0) {
  28. $condition['refund_time'] = ['lt', $end_unixtime];
  29. }
  30. $providers = [];
  31. $provider_list = $this->providers();
  32. foreach ($provider_list as $provider) {
  33. $providers[$provider['provider_id']] = $provider;
  34. }
  35. $merchants = [];
  36. $merchant_list = $this->merchants();
  37. foreach ($merchant_list as $value) {
  38. $merchants[$value['mchid']] = $value;
  39. }
  40. if($_GET['export'] == 1) {
  41. $this->RefillRefundExport($condition,$providers,$merchants);
  42. }else{
  43. $refund_list = $mod->getRefillRefundList($condition,50);
  44. $refund_list = $this->DataFormat($refund_list,$providers,$merchants);
  45. }
  46. Tpl::output('provider_list', $providers);
  47. Tpl::output('merchants', $merchants);
  48. Tpl::output('info_list', $refund_list);
  49. Tpl::output('show_page', $mod->showpage());
  50. Tpl::showpage('refill.refund');
  51. }
  52. private function DataFormat($refund_list,$providers,$merchants)
  53. {
  54. $providers[-1] = [
  55. 'name' => 'yezi',
  56. 'store_name' => '椰子退费'
  57. ];
  58. foreach ($refund_list as $key => $value) {
  59. $refund_list[$key]['provider_name'] = $providers[$value['provider_id']]['name'];
  60. $refund_list[$key]['store_name'] = $providers[$value['provider_id']]['store_name'];
  61. $refund_list[$key]['merchant_name'] = $merchants[$value['mchid']]['name'];
  62. $refund_list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
  63. $refund_list[$key]['card_type_text'] = $this->scard_type($value['card_type']);
  64. }
  65. return $refund_list;
  66. }
  67. private function RefillRefundExport($condition,$providers,$merchants)
  68. {
  69. $i = 0;
  70. $result = [];
  71. while (true) {
  72. $start = $i * 1000;
  73. $list = Model('')->table('refill_refund')->where($condition)->order('refund_time desc')->limit("{$start},1000")->select();
  74. if (empty($list)) {
  75. break;
  76. }
  77. $i++;
  78. foreach ($list as $value) {
  79. $result[] = $value;
  80. }
  81. }
  82. $result = $this->DataFormat($result,$providers,$merchants);
  83. $this->createExcel($result);
  84. }
  85. private function createExcel($data = array())
  86. {
  87. Language::read('export');
  88. import('libraries.excel');
  89. $excel_obj = new Excel();
  90. $excel_data = array();
  91. //设置样式
  92. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  93. //header
  94. $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道名称');
  95. $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道退款金额');
  96. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编码');
  97. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称');
  98. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构退款金额');
  99. $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款卡号');
  100. $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款卡类型');
  101. $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款面值');
  102. $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款日期');
  103. $excel_data[0][] = array('styleid' => 's_title', 'data' => '备注');
  104. //data
  105. foreach ((array)$data as $v) {
  106. $mch_name = $v['company_name'] ?? $v['name'];
  107. $tmp = array();
  108. $tmp[] = array('data' => "{$v['provider_name']}({$v['store_name']})");
  109. $tmp[] = array('data' => $v['channel_amount']);
  110. $tmp[] = array('data' => $v['mchid']);
  111. $tmp[] = array('data' => $mch_name);
  112. $tmp[] = array('data' => $v['mch_amount']);
  113. $tmp[] = array('data' => $v['card_no']);
  114. $tmp[] = array('data' => $v['card_type_text']);
  115. $tmp[] = array('data' => $v['refill_amount']);
  116. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['refund_time']));
  117. $tmp[] = array('data' => $v['bz']);
  118. $excel_data[] = $tmp;
  119. }
  120. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  121. $excel_obj->addArray($excel_data);
  122. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  123. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  124. exit;
  125. }
  126. public function addOp()
  127. {
  128. if (chksubmit()) {
  129. $obj_validate = new Validator();
  130. $obj_validate->validateparam = [
  131. ["input" => $_POST["mchid"], "require" => "true", "message" => '机构不能为空'],
  132. ["input" => $_POST["provider_id"], "require" => "true", "message" => '通道不能为空'],
  133. ["input" => $_POST["mch_amount"], "require" => "true", "message" => '机构退款金额不能为空'],
  134. ["input" => $_POST["channel_amount"], "require" => "true", "message" => '通道退款金额不能为空'],
  135. ["input" => $_POST["refund_time"], "require" => "true", "message" => '退款日期不能为空'],
  136. ["input" => $_POST["card_no"], "require" => "true", "message" => '退款卡号不能为空'],
  137. ["input" => $_POST["card_type"], "require" => "true", "message" => '卡类型不能为空'],
  138. ["input" => $_POST["refill_amount"], "require" => "true", "message" => '面值不能为空']
  139. ];
  140. $error = $obj_validate->validate();
  141. if ($error != '') {
  142. showMessage($error);
  143. } else {
  144. $merchant = Model('merchant')->getMerchantInfo(['mchid' => $_POST['mchid']]);
  145. if(empty($merchant)) {
  146. showMessage('此机构不存在!');
  147. }
  148. $provider = Model('refill_provider')->getProviderInfo(['provider_id' => $_POST['provider_id']]);
  149. if(empty($provider) && $_POST['provider_id'] != -1) {
  150. showMessage('此上游通道不存在!');
  151. }
  152. $mod = Model('refill_refund');
  153. $insert_array['mchid'] = $_POST['mchid'];
  154. $insert_array['provider_id'] = $_POST['provider_id'];
  155. $insert_array['mch_amount'] = $_POST['mch_amount'];
  156. $insert_array['channel_amount'] = $_POST['channel_amount'];
  157. $insert_array['refund_time'] = strtotime($_POST['refund_time']);
  158. $insert_array['card_no'] = $_POST['card_no'];
  159. $insert_array['card_type'] = $_POST['card_type'];
  160. $insert_array['refill_amount'] = $_POST['refill_amount'];
  161. $insert_array['bz'] = $_POST['bz'] ?? '';
  162. $insert_array['add_time'] = time();
  163. $result = $mod->addRefund($insert_array);
  164. if ($result) {
  165. showMessage('添加成功', 'index.php?act=refill_refund&op=index');
  166. } else {
  167. showMessage('添加失败');
  168. }
  169. }
  170. }
  171. else
  172. {
  173. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  174. $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.provider_id,store.store_name')->join('inner')
  175. ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
  176. Tpl::output('provider_list', $provider_list);
  177. Tpl::output('merchant_list', $merchant_list);
  178. Tpl::showpage('refill.refund.add');
  179. }
  180. }
  181. public function editOp()
  182. {
  183. $id = $_GET['id'] ?? $_POST['id'];
  184. $mod = Model('refill_refund');
  185. $refund_info = $mod->getRefundInfo(['id' => $id]);
  186. if (empty($refund_info)) {
  187. showMessage('退款信息不存在');
  188. }
  189. if (chksubmit()) {
  190. $obj_validate = new Validator();
  191. $obj_validate->validateparam = [
  192. ["input" => $_POST["mchid"], "require" => "true", "message" => '机构不能为空'],
  193. ["input" => $_POST["provider_id"], "require" => "true", "message" => '通道不能为空'],
  194. ["input" => $_POST["mch_amount"], "require" => "true", "message" => '机构退款金额不能为空'],
  195. ["input" => $_POST["channel_amount"], "require" => "true", "message" => '通道退款金额不能为空'],
  196. ["input" => $_POST["refund_time"], "require" => "true", "message" => '退款日期不能为空'],
  197. ["input" => $_POST["card_no"], "require" => "true", "message" => '退款卡号不能为空'],
  198. ["input" => $_POST["card_type"], "require" => "true", "message" => '卡类型不能为空'],
  199. ["input" => $_POST["refill_amount"], "require" => "true", "message" => '面值不能为空']
  200. ];
  201. $error = $obj_validate->validate();
  202. if ($error != '') {
  203. showMessage($error);
  204. exit;
  205. }
  206. $update['mchid'] = trim($_POST['mchid']);
  207. $update['provider_id'] = trim($_POST['provider_id']);
  208. $update['mch_amount'] = trim($_POST['mch_amount']);
  209. $update['channel_amount'] = trim($_POST['channel_amount']);
  210. $update['refund_time'] = strtotime($_POST['refund_time']);
  211. $update['card_no'] = trim($_POST['card_no']);
  212. $update['card_type'] = trim($_POST['card_type']);
  213. $update['refill_amount'] = trim($_POST['refill_amount']);
  214. $update['bz'] = $_POST['bz'] ?? '';
  215. $result = $mod->editRefund($update, ['id' => $id]);
  216. if (!$result) {
  217. showMessage('编辑失败');
  218. }
  219. showMessage('编辑成功','index.php?act=refill_refund&op=index');
  220. }
  221. else
  222. {
  223. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  224. $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.provider_id,store.store_name')->join('inner')
  225. ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
  226. Tpl::output('provider_list', $provider_list);
  227. Tpl::output('merchant_list', $merchant_list);
  228. Tpl::output('refund_info', $refund_info);
  229. Tpl::showpage('refill.refund.edit');
  230. }
  231. }
  232. public function delOp()
  233. {
  234. $id = $_GET['id'];
  235. $mod = Model('refill_refund');
  236. $provider_info = $mod->getRefundInfo(['id' => $id]);
  237. if (empty($provider_info)) {
  238. showMessage('退款信息不存在');
  239. }
  240. $result = $mod->DelRefund(['id' => $id]);
  241. if (!$result) {
  242. showMessage('删除失败');
  243. }
  244. showMessage('删除成功','index.php?act=refill_refund&op=index');
  245. }
  246. }