merchant_info.php 13 KB

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