refill_refund.php 12 KB

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