merchant_info.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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'] = $_GET['company_name'];
  114. }
  115. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  116. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  117. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  118. $condition['apply_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  119. } elseif ($start_unixtime > 0) {
  120. $condition['apply_time'] = ['egt', $start_unixtime];
  121. } elseif ($end_unixtime > 0) {
  122. $condition['apply_time'] = ['lt', $end_unixtime];
  123. }
  124. if(!empty($_GET['export'])) {
  125. $this->MerchantEvidenceExport($condition);
  126. }
  127. //上游充值申请列表
  128. $evidence_list = $mod->getMerchantEvidence($condition, 30, '*', 'apply_time desc');
  129. $stats = $mod->field('sum(amount) as amounts')->where($condition)->find();
  130. Tpl::output('amounts', $stats['amounts']);
  131. Tpl::output('evidence_list', $evidence_list);
  132. Tpl::output('page', $mod->showpage());
  133. Tpl::showpage('merchant.evidence.list');
  134. }
  135. public function importOp()
  136. {
  137. if(chksubmit()) {
  138. $merchant = [];
  139. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  140. foreach ($merchant_list as $key => $value) {
  141. $merchant[$value['mchid']] = $value['company_name'];
  142. }
  143. if(empty($merchant)) {
  144. showMessage('机构通道为空,不可导入');
  145. }
  146. //得到导入文件
  147. $filename = $_FILES['csv']['name'];
  148. $tmp_name = $_FILES['csv']['tmp_name'];
  149. $extend = strrchr($filename,'.');
  150. $extendLower = strtolower($extend);
  151. if (!in_array($extendLower, ['.xls', '.xlsx', '.csv']))
  152. {
  153. showMessage('文件格式有误');
  154. }
  155. $filePath = BASE_ROOT_PATH . '/data/upload/upfile/provider/';
  156. /** Error reporting */
  157. error_reporting(E_ALL);
  158. //注意设置时区
  159. $time=date("m-d-H-i-s");//去当前上传的时间
  160. //根据当前时间外加后五位产生一个 防止多个用户同时操作产生的重复概率
  161. $randnum = 'MerchantEvidenceImport_'.$time.str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  162. //上传后的文件名
  163. $name=$randnum.$extendLower;
  164. $upload_filename=$filePath.$name;//上传后的文件名地址
  165. $result=move_uploaded_file($tmp_name,$upload_filename);
  166. if(!$result){
  167. showMessage('上传失败,稍后再试!');
  168. exit;
  169. }
  170. $fileType = PHPExcel_IOFactory::identify($upload_filename);
  171. $objReader = PHPExcel_IOFactory::createReader($fileType);
  172. $objPHPExcel = $objReader->load($upload_filename);
  173. $time = time();
  174. $mod = Model('merchant_evidence');
  175. foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
  176. {
  177. foreach ($sheet->getRowIterator() as $row)
  178. {
  179. $index = $row->getRowIndex();
  180. if ($index == 1) continue;
  181. $items = [];
  182. foreach ($row->getCellIterator() as $cell) {
  183. $data = $cell->getValue();
  184. $items[] = $data;
  185. }
  186. $mchid = intval($items[0]);
  187. $params = [
  188. 'mchid' => $mchid,
  189. 'company_name' => $merchant[$mchid],
  190. 'amount' => $items[1] ?? '',
  191. 'bank_username' => trim($items[4]) ?? '',
  192. 'bank_name' => trim($items[5]) ?? '',
  193. 'to_bank_username' => trim($items[2]) ?? '',
  194. 'to_bank_name' => trim($items[3]) ?? '',
  195. 'apply_time' => strtotime($items[6]) ?? '',
  196. 'add_time' => $time
  197. ];
  198. if(!empty($items[7])) {
  199. $params['bz'] = $items[7];
  200. }
  201. $json_txt = json_encode($params);
  202. Log::record("import data: {$json_txt}",LOG::DEBUG);
  203. if(empty($params['store_id']) || empty($params['store_name'])) {
  204. Log::record("merchant evidence import err,not find store info, mchid: {$mchid}, amount: {$params['amount']}",LOG::DEBUG);
  205. }
  206. $res = $mod->addMerchantEvidence($params);
  207. if(!$res){
  208. Log::record("merchant evidence import err, mchid: {$mchid}, amount: {$params['amount']}",LOG::DEBUG);
  209. }
  210. }
  211. }
  212. showMessage('操作完成');
  213. exit;
  214. }
  215. else
  216. {
  217. Tpl::showpage('merchant.evidence.import');
  218. }
  219. }
  220. public function apply_delOp()
  221. {
  222. $apply_id = $_GET['apply_id'] ?? $_POST['apply_id'];
  223. $mod = Model('merchant_evidence');
  224. $provider_evidence_info = $mod->getMerchantEvidenceInfo(['apply_id' => $apply_id]);
  225. if (empty($provider_evidence_info)) {
  226. showMessage('申请信息不存在');
  227. }
  228. $result = $mod->DelMerchantEvidence(['apply_id' => $apply_id]);
  229. if (!$result) {
  230. showMessage('删除失败');
  231. }
  232. showMessage('删除成功','index.php?act=merchant_info&op=merchant_evidence');
  233. }
  234. private function MerchantEvidenceExport($condition)
  235. {
  236. $i = 0;
  237. $result = [];
  238. while (true) {
  239. $start = $i * 1000;
  240. $evidence_list = Model('')->table('merchant_evidence')->where($condition)->order('apply_time desc')->limit("{$start},1000")->select();
  241. if (empty($evidence_list)) {
  242. break;
  243. }
  244. $i++;
  245. foreach ($evidence_list as $value) {
  246. $result[] = $value;
  247. }
  248. }
  249. $this->createExcel($result);
  250. }
  251. private function createExcel($data = array())
  252. {
  253. Language::read('export');
  254. import('libraries.excel');
  255. $excel_obj = new Excel();
  256. $excel_data = array();
  257. //设置样式
  258. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  259. //header
  260. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构公司名称');
  261. $excel_data[0][] = array('styleid' => 's_title', 'data' => '申请金额');
  262. $excel_data[0][] = array('styleid' => 's_title', 'data' => '收款银行开户人姓名');
  263. $excel_data[0][] = array('styleid' => 's_title', 'data' => '收款银行名称');
  264. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构转账银行开户人姓名');
  265. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构转账银行名称');
  266. $excel_data[0][] = array('styleid' => 's_title', 'data' => '申请日期');
  267. $excel_data[0][] = array('styleid' => 's_title', 'data' => '备注');
  268. //data
  269. foreach ((array)$data as $v) {
  270. $tmp = array();
  271. $tmp[] = array('data' => $v['company_name']);
  272. $tmp[] = array('data' => $v['amount']);
  273. $tmp[] = array('data' => $v['bank_username']);
  274. $tmp[] = array('data' => $v['bank_name']);
  275. $tmp[] = array('data' => $v['to_bank_username']);
  276. $tmp[] = array('data' => $v['to_bank_name']);
  277. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['apply_time']));
  278. $tmp[] = array('data' => $v['bz']);
  279. $excel_data[] = $tmp;
  280. }
  281. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  282. $excel_obj->addArray($excel_data);
  283. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  284. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  285. exit;
  286. }
  287. }