merchant_info.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/PHPExcel/PHPExcel.php');
  3. class merchant_infoControl extends SystemControl
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function indexOp()
  10. {
  11. $mod = Model('merchant_info');
  12. $condition = [];
  13. if(!empty($_GET['mchid'])) {
  14. $condition['mchid'] = $_GET['mchid'];
  15. }
  16. $merchants = [];
  17. $merchant_list = $this->merchants();
  18. foreach ($merchant_list as $key => $value) {
  19. $merchants[$value['mchid']] = $value;
  20. }
  21. $info_list = $mod->getMerchantInfoList($condition,50);
  22. foreach ($info_list as $key => $value) {
  23. $info_list[$key]['merchant_name'] = $merchants[$value['mchid']]['name'];
  24. $info_list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
  25. }
  26. Tpl::output('merchants', $merchants);
  27. Tpl::output('info_list', $info_list);
  28. Tpl::output('page', $mod->showpage());
  29. Tpl::showpage('merchant.info');
  30. }
  31. public function addOp()
  32. {
  33. if (chksubmit()) {
  34. $obj_validate = new Validator();
  35. $obj_validate->validateparam = [
  36. ["input" => $_POST["mchid"], "require" => "true", "message" => '机构不能为空'],
  37. ["input" => $_POST["bank_name"], "require" => "true", "message" => '收款银行名称不能为空'],
  38. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人名称不能为空'],
  39. ["input" => $_POST["bank_card_no"], "require" => "true", "message" => '收款卡号不能为空']
  40. ];
  41. $error = $obj_validate->validate();
  42. if ($error != '') {
  43. showMessage($error);
  44. } else {
  45. $merchant = Model('merchant')->getMerchantInfo(['mchid' => $_POST['mchid']]);
  46. if(empty($merchant)) {
  47. showMessage('此机构不存在!');
  48. }
  49. $mod = Model('merchant_info');
  50. $insert_array['mchid'] = $_POST['mchid'];
  51. $insert_array['bank_name'] = $_POST['bank_name'];
  52. $insert_array['bank_username'] = $_POST['bank_username'];
  53. $insert_array['bank_card_no'] = $_POST['bank_card_no'];
  54. $insert_array['bz'] = $_POST['bz'] ?? '';
  55. $result = $mod->addInfo($insert_array);
  56. if ($result) {
  57. showMessage('添加成功', 'index.php?act=merchant_info&op=index');
  58. } else {
  59. showMessage('添加失败');
  60. }
  61. }
  62. }
  63. else
  64. {
  65. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  66. Tpl::output('merchant_list', $merchant_list);
  67. Tpl::showpage('merchant.info.add');
  68. }
  69. }
  70. public function editOp()
  71. {
  72. $info_id = $_GET['info_id'] ?? $_POST['info_id'];
  73. $mod = Model('merchant_info');
  74. $merchant_info = $mod->getMerchantInfo(['info_id' => $info_id]);
  75. if (empty($merchant_info)) {
  76. showMessage('机构信息不存在');
  77. }
  78. if (chksubmit()) {
  79. $update['bank_name'] = trim($_POST['bank_name']);
  80. $update['bank_username'] = trim($_POST['bank_username']);
  81. $update['bank_card_no'] = trim($_POST['bank_card_no']);
  82. $update['bz'] = trim($_POST['bz']) ?? '';
  83. $result = $mod->editMerchantInfo($update, ['info_id' => $info_id]);
  84. if (!$result) {
  85. showMessage('编辑失败');
  86. }
  87. showMessage('编辑成功','index.php?act=merchant_info&op=index');
  88. }
  89. else
  90. {
  91. Tpl::output('info', $merchant_info);
  92. Tpl::showpage('merchant.info.edit');
  93. }
  94. }
  95. public function delOp()
  96. {
  97. $info_id = $_GET['info_id'];
  98. $mod = Model('merchant_info');
  99. $merchant_info = $mod->getMerchantInfo(['info_id' => $info_id]);
  100. if (empty($merchant_info)) {
  101. showMessage('机构信息不存在');
  102. }
  103. $result = $mod->DelMerchantInfo(['info_id' => $info_id]);
  104. if (!$result) {
  105. showMessage('删除失败');
  106. }
  107. showMessage('删除成功','index.php?act=merchant_info&op=index');
  108. }
  109. public function merchant_evidenceOp()
  110. {
  111. $mod = Model('merchant_evidence');
  112. $condition = [];
  113. if (trim($_GET['company_name']) != '') {
  114. $condition['company_name'] = ['like', '%' . $_GET['company_name'] . '%'];
  115. }
  116. if (trim($_GET['to_bank_username']) != '') {
  117. $condition['to_bank_username'] = ['like', '%' . $_GET['to_bank_username'] . '%'];
  118. }
  119. if (trim($_GET['to_bank_name']) != '') {
  120. $condition['to_bank_name'] = ['like', '%' . $_GET['to_bank_name'] . '%'];
  121. }
  122. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  123. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  124. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  125. $condition['apply_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  126. } elseif ($start_unixtime > 0) {
  127. $condition['apply_time'] = ['egt', $start_unixtime];
  128. } elseif ($end_unixtime > 0) {
  129. $condition['apply_time'] = ['lt', $end_unixtime];
  130. }
  131. if(!empty($_GET['export'])) {
  132. $this->MerchantEvidenceExport($condition);
  133. }
  134. //上游充值申请列表
  135. $evidence_list = $mod->getMerchantEvidence($condition, 30, '*', 'apply_time desc');
  136. $stats = $mod->field('sum(amount) as amounts')->where($condition)->find();
  137. Tpl::output('amounts', $stats['amounts']);
  138. Tpl::output('evidence_list', $evidence_list);
  139. Tpl::output('page', $mod->showpage());
  140. Tpl::showpage('merchant.evidence.list');
  141. }
  142. public function importOp()
  143. {
  144. if(chksubmit()) {
  145. $merchant = [];
  146. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  147. foreach ($merchant_list as $key => $value) {
  148. $merchant[$value['mchid']] = $value['company_name'];
  149. }
  150. if(empty($merchant)) {
  151. showMessage('机构通道为空,不可导入');
  152. }
  153. //得到导入文件
  154. $filename = $_FILES['csv']['name'];
  155. $tmp_name = $_FILES['csv']['tmp_name'];
  156. $extend = strrchr($filename,'.');
  157. $extendLower = strtolower($extend);
  158. if (!in_array($extendLower, ['.xls', '.xlsx', '.csv']))
  159. {
  160. showMessage('文件格式有误');
  161. }
  162. $filePath = BASE_ROOT_PATH . '/data/upload/upfile/provider/';
  163. /** Error reporting */
  164. error_reporting(E_ALL);
  165. //注意设置时区
  166. $time=date("m-d-H-i-s");//去当前上传的时间
  167. //根据当前时间外加后五位产生一个 防止多个用户同时操作产生的重复概率
  168. $randnum = 'MerchantEvidenceImport_'.$time.str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  169. //上传后的文件名
  170. $name=$randnum.$extendLower;
  171. $upload_filename=$filePath.$name;//上传后的文件名地址
  172. $result=move_uploaded_file($tmp_name,$upload_filename);
  173. if(!$result){
  174. showMessage('上传失败,稍后再试!');
  175. }
  176. $fileType = PHPExcel_IOFactory::identify($upload_filename);
  177. $objReader = PHPExcel_IOFactory::createReader($fileType);
  178. $objPHPExcel = $objReader->load($upload_filename);
  179. $time = time();
  180. $mod = Model('merchant_evidence');
  181. foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
  182. {
  183. foreach ($sheet->getRowIterator() as $row)
  184. {
  185. $index = $row->getRowIndex();
  186. if ($index == 1) continue;
  187. $items = [];
  188. foreach ($row->getCellIterator() as $cell) {
  189. $data = $cell->getValue();
  190. $items[] = $data;
  191. }
  192. if(empty($items) || count($items) < 7){
  193. Log::record("items empty or length err",LOG::DEBUG);
  194. continue;
  195. }
  196. $mchid = intval($items[0]);
  197. $params = [
  198. 'mchid' => $mchid,
  199. 'company_name' => $merchant[$mchid],
  200. 'amount' => $items[1] ?? '',
  201. 'bank_username' => trim($items[4]) ?? '',
  202. 'bank_name' => trim($items[5]) ?? '',
  203. 'to_bank_username' => trim($items[2]) ?? '',
  204. 'to_bank_name' => trim($items[3]) ?? '',
  205. 'apply_time' => strtotime($items[6]) ?? '',
  206. 'add_time' => $time
  207. ];
  208. if(!empty($items[7])) {
  209. $params['bz'] = $items[7];
  210. }
  211. $json_txt = json_encode($params);
  212. Log::record("import data: {$json_txt}",LOG::DEBUG);
  213. if(empty($params['mchid']) || empty($params['company_name'])) {
  214. Log::record("merchant evidence import err,not find merchant info, mchid: {$mchid}, amount: {$params['amount']}",LOG::DEBUG);
  215. }
  216. $res = $mod->addMerchantEvidence($params);
  217. if(!$res){
  218. Log::record("merchant evidence import err, mchid: {$mchid}, amount: {$params['amount']}",LOG::DEBUG);
  219. showMessage('导入失败');
  220. }
  221. }
  222. }
  223. showMessage('操作完成');
  224. exit;
  225. }
  226. else
  227. {
  228. Tpl::showpage('merchant.evidence.import');
  229. }
  230. }
  231. public function apply_delOp()
  232. {
  233. $apply_id = $_GET['apply_id'] ?? $_POST['apply_id'];
  234. $mod = Model('merchant_evidence');
  235. $provider_evidence_info = $mod->getMerchantEvidenceInfo(['apply_id' => $apply_id]);
  236. if (empty($provider_evidence_info)) {
  237. showMessage('申请信息不存在');
  238. }
  239. $result = $mod->DelMerchantEvidence(['apply_id' => $apply_id]);
  240. if (!$result) {
  241. showMessage('删除失败');
  242. }
  243. showMessage('删除成功','index.php?act=merchant_info&op=merchant_evidence');
  244. }
  245. private function MerchantEvidenceExport($condition)
  246. {
  247. $i = 0;
  248. $result = [];
  249. while (true) {
  250. $start = $i * 1000;
  251. $evidence_list = Model('')->table('merchant_evidence')->where($condition)->order('apply_time desc')->limit("{$start},1000")->select();
  252. if (empty($evidence_list)) {
  253. break;
  254. }
  255. $i++;
  256. foreach ($evidence_list as $value) {
  257. $result[] = $value;
  258. }
  259. }
  260. $this->createExcel($result);
  261. }
  262. private function createExcel($data = array())
  263. {
  264. Language::read('export');
  265. import('libraries.excel');
  266. $excel_obj = new Excel();
  267. $excel_data = array();
  268. //设置样式
  269. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  270. //header
  271. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构公司名称');
  272. $excel_data[0][] = array('styleid' => 's_title', 'data' => '申请金额');
  273. $excel_data[0][] = array('styleid' => 's_title', 'data' => '收款银行开户人姓名');
  274. $excel_data[0][] = array('styleid' => 's_title', 'data' => '收款银行名称');
  275. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构转账银行开户人姓名');
  276. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构转账银行名称');
  277. $excel_data[0][] = array('styleid' => 's_title', 'data' => '申请日期');
  278. $excel_data[0][] = array('styleid' => 's_title', 'data' => '备注');
  279. //data
  280. foreach ((array)$data as $v) {
  281. $tmp = array();
  282. $tmp[] = array('data' => $v['company_name']);
  283. $tmp[] = array('data' => $v['amount']);
  284. $tmp[] = array('data' => $v['bank_username']);
  285. $tmp[] = array('data' => $v['bank_name']);
  286. $tmp[] = array('data' => $v['to_bank_username']);
  287. $tmp[] = array('data' => $v['to_bank_name']);
  288. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['apply_time']));
  289. $tmp[] = array('data' => $v['bz']);
  290. $excel_data[] = $tmp;
  291. }
  292. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  293. $excel_obj->addArray($excel_data);
  294. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  295. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  296. exit;
  297. }
  298. }