merchant.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. <?php
  2. /**
  3. * 机构管理界面
  4. *
  5. **by 好商城V3 www.33hao.com 运营版*/
  6. defined('InShopNC') or exit('Access Invalid!');
  7. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  8. require_once(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  9. require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
  10. class merchantControl extends SystemControl
  11. {
  12. const EXPORT_SIZE = 1000;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. Language::read('merchant');
  17. }
  18. /**
  19. * 机构列表
  20. */
  21. public function merchantOp()
  22. {
  23. $model_merchant = Model('merchant');
  24. if (trim($_GET['merchant_name']) != '') {
  25. $condition['name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
  26. Tpl::output('merchant_name', $_GET['merchant_name']);
  27. }
  28. $merchant_list = $model_merchant->getMerchantList($condition, 100, 'available_predeposit desc,merchant_state asc,mchid desc');
  29. $merchant_state_text = ['使用中', '已禁用'];
  30. Tpl::output('merchant_state_text', $merchant_state_text);
  31. Tpl::output('merchant_list', $merchant_list);
  32. Tpl::output('page', $model_merchant->showpage('2'));
  33. Tpl::showpage('merchant.index');
  34. }
  35. public function changeStateOp()
  36. {
  37. $mchid = intval($_GET['mchid']);
  38. $state = intval($_GET['state']);
  39. $model_merchant = Model('merchant');
  40. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  41. if (empty($merchant_info) || !in_array($state, [1, 2])) {
  42. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  43. }
  44. $resp = $model_merchant->editMerchant(['merchant_state' => $state], ['mchid' => $mchid]);
  45. if (!$resp) {
  46. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  47. }
  48. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  49. }
  50. /**
  51. * 新增机构
  52. */
  53. public function merchant_addOp()
  54. {
  55. if (chksubmit()) {
  56. /**
  57. * 验证
  58. */
  59. $obj_validate = new Validator();
  60. $obj_validate->validateparam = [
  61. ["input" => $_POST["name"], "require" => "true", "message" => '机构账号不能为空'],
  62. ["input" => $_POST["company_name"], "require" => "true", "message" => '机构公司名称不能为空'],
  63. ["input" => $_POST["password"], "require" => "true", "message" => '密码不能为空']
  64. ];
  65. $error = $obj_validate->validate();
  66. if ($error != '') {
  67. showMessage($error);
  68. } else {
  69. $name = trim($_POST['name']);
  70. $company_name = trim($_POST['company_name']);
  71. $pwd = trim($_POST['password']);
  72. $alarm_amount = $_POST['alarm_amount'] ?? 0;
  73. $model_merchant = Model('merchant');
  74. $model_member = Model('member');
  75. try {
  76. $trans = new trans_wapper($model_merchant, __METHOD__);
  77. $insert_member['member_name'] = md5($name . time());
  78. $insert_member['member_passwd'] = $pwd;
  79. $insert_id = $model_member->addMember($insert_member);
  80. if ($insert_id == false) {
  81. $trans->rollback();
  82. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  83. }
  84. $insert_array['name'] = $name;
  85. $insert_array['company_name'] = $company_name;
  86. $insert_array['org_pwd'] = $pwd;
  87. $insert_array['password'] = md5($pwd);
  88. $insert_array['admin_id'] = trim($insert_id);
  89. $insert_array['alarm_amount'] = $alarm_amount;
  90. $result = $model_merchant->addMerchant($insert_array);
  91. if ($result) {
  92. $url = [
  93. [
  94. 'url' => 'index.php?act=merchant&op=merchant',
  95. 'msg' => '返回机构列表',
  96. ],
  97. [
  98. 'url' => 'index.php?act=merchant&op=merchant_add',
  99. 'msg' => '继续新增机构',
  100. ],
  101. ];
  102. $this->log('添加机构:' . '[ ' . $_POST['name'] . ']', 1);
  103. showMessage('机构添加成功', $url);
  104. } else {
  105. showMessage('机构添加失败');
  106. }
  107. $trans->commit();
  108. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  109. } catch (Exception $e) {
  110. $trans->rollback();
  111. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  112. }
  113. }
  114. }
  115. Tpl::showpage('merchant.add');
  116. }
  117. public function merchant_editOp()
  118. {
  119. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  120. $model_merchant = Model('merchant');
  121. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  122. if (empty($merchant)) {
  123. showMessage('机构信息有误');
  124. }
  125. if (chksubmit()) {
  126. $update['company_name'] = trim($_POST['company_name']);
  127. $update['org_pwd'] = trim($_POST['password']);
  128. $update['password'] = md5($update['org_pwd']);
  129. $update['alarm_amount'] = $_POST['alarm_amount'] ?? 0;
  130. $update['credit_bonus'] = ncPriceFormat($_POST['credit_bonus']);
  131. $update['time_out'] = intval($_POST['time_out']);
  132. $update['quality'] = intval($_POST['quality']);
  133. $member_id = $merchant['admin_id'];
  134. try {
  135. $model_merchant = Model('merchant');
  136. $trans = new trans_wapper($model_merchant, __METHOD__);
  137. if ($merchant['credit_bonus'] == $update['credit_bonus']) {
  138. unset($update['credit_bonus']);
  139. } elseif ($merchant['credit_bonus'] > $update['credit_bonus']) {
  140. $credit_bonus = ncPriceFormat($merchant['credit_bonus'] - $update['credit_bonus']);
  141. $this->credit_save_money($credit_bonus, 2, $member_id);
  142. } elseif ($merchant['credit_bonus'] < $update['credit_bonus']) {
  143. $credit_bonus = ncPriceFormat($update['credit_bonus'] - $merchant['credit_bonus']);
  144. $this->credit_save_money($credit_bonus, 1, $member_id);
  145. }
  146. $result = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  147. if (!$result) {
  148. $trans->rollback();
  149. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  150. }
  151. $this->log('编辑机构:' . '[ ' . $merchant['name'] . ']', 1);
  152. $trans->commit();
  153. showMessage('机构编辑成功', 'index.php?act=merchant&op=merchant');
  154. } catch (Exception $e) {
  155. $trans->rollback();
  156. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  157. }
  158. }
  159. Tpl::output('merchant', $merchant);
  160. Tpl::showpage('merchant.edit');
  161. }
  162. private function credit_save_money($money, $operatetype, $member_id, $bz = '')
  163. {
  164. $obj_member = Model('member');
  165. $member_id = intval($member_id);
  166. $member_info = $obj_member->getMemberInfo(['member_id' => $member_id]);
  167. $admininfo = $this->getAdminInfo();
  168. switch ($operatetype) {
  169. case 1:
  170. $admin_act = "sys_add_money";
  171. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】,预存款【增加】,金额为" . $money;
  172. break;
  173. case 2:
  174. $admin_act = "sys_del_money";
  175. $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】,预存款【减少】,金额为" . $money;
  176. break;
  177. default:
  178. return [false, '调节类型错误'];
  179. break;
  180. }
  181. $model_pd = Model('predeposit');
  182. //调节预存款
  183. $data = [];
  184. $data['member_id'] = $member_info['member_id'];
  185. $data['member_name'] = $member_info['member_name'];
  186. $data['amount'] = $money;
  187. $data['order_sn'] = '';
  188. $data['admin_name'] = $admininfo['name'];
  189. $data['pdr_sn'] = '';
  190. $data['lg_desc'] = $bz ? $bz : '管理员操作客户授信,更改会员余额。';
  191. $model_pd->changePd($admin_act, $data);
  192. $this->log($log_msg, 1);
  193. return [true, 'success'];
  194. }
  195. public function priceOp()
  196. {
  197. $quality = $_GET['quality'] ? $_GET['quality'] : 1;
  198. if (chksubmit()) {
  199. $mchid = $_POST['mchid'];
  200. //合并表单数据
  201. $card_types = $_POST['cardtype'];
  202. $specs = $_POST['spec'];
  203. $prices = $_POST['price'];
  204. foreach ($card_types as $key => $card_type) {
  205. $data['card_type'] = $card_type;
  206. $data['spec'] = intval($specs[$key]);
  207. $data['price'] = ncPriceFormat($prices[$key]);
  208. $params[] = $data;
  209. }
  210. foreach ($params as $param) {
  211. if ($param['price'] > 0) {
  212. $insert['mchid'] = $mchid;
  213. $insert['spec'] = $param['spec'];
  214. $insert['price'] = $param['price'];
  215. $insert['card_types'] = $param['card_type'];
  216. $insert['quality'] = $quality;
  217. $inserts[] = $insert;
  218. }
  219. }
  220. try {
  221. $model_merchant = Model('merchant');
  222. $trans = new trans_wapper($model_merchant, __METHOD__);
  223. //删除旧费率
  224. $model_merchant->delPrices($mchid, $quality);
  225. //更新新费率
  226. if (!empty($inserts)) {
  227. $model_merchant->insertPrices($inserts);
  228. }
  229. $trans->commit();
  230. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  231. } catch (Exception $e) {
  232. $trans->rollback();
  233. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  234. }
  235. }
  236. $mchid = $_GET['mchid'] ?? 0;
  237. $goods = $this->GoodsFormat($mchid, $quality);
  238. Tpl::output('goods', $goods);
  239. Tpl::showpage('merchant.price');
  240. }
  241. private function GoodsFormat($mchid, $quality)
  242. {
  243. $all_spector = function () {
  244. global $config;
  245. $refill_specs = $config['refill_specs'];
  246. $all_type_specs = [];
  247. foreach ($refill_specs as $scard_type => $specs) {
  248. if ($scard_type == 'petrochina') { //中石油
  249. $card_type = 1;
  250. } elseif ($scard_type == 'sinopec') { //中石化
  251. $card_type = 2;
  252. } elseif ($scard_type == 'chinamobile') { //中国移动
  253. $card_type = 4;
  254. } elseif ($scard_type == 'chinaunicom') { //中国联通
  255. $card_type = 5;
  256. } elseif ($scard_type == 'chinatelecom') { //中国电信
  257. $card_type = 6;
  258. } else {
  259. continue;
  260. }
  261. $all_type_specs[$card_type] = $specs;
  262. }
  263. $result = [];
  264. foreach ($all_type_specs as $card_type => $specs) {
  265. foreach ($specs as $spec) {
  266. $result["{$card_type}-{$spec}"] = ['card_type' => $card_type, 'spec' => $spec];
  267. }
  268. }
  269. return $result;
  270. };
  271. $merch_spector = function ($mchid, $quality) {
  272. $model_merchant = Model('merchant');
  273. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => $quality])->select();
  274. $result = [];
  275. foreach ($items as $item) {
  276. $card_types = explode(',', $item['card_types']);
  277. foreach ($card_types as $card_type) {
  278. $value['spec'] = intval($item['spec']);
  279. $result["{$card_type}-{$value['spec']}"] = ['card_type' => $card_type,
  280. 'spec' => intval($item['spec']),
  281. 'price' => $item['price']];
  282. }
  283. }
  284. return $result;
  285. };
  286. $all_cardtype_specs = $all_spector();
  287. $merch_cardtype_specs = $merch_spector($mchid, $quality);
  288. $merger = function ($all_specs, $mech_specs) {
  289. $result = [];
  290. foreach ($all_specs as $cardtype_spec => $value) {
  291. $card_name = $this->scard_type($value['card_type']);
  292. $data = [];
  293. $data['goods_name'] = $card_name;
  294. $data['card_type'] = $value['card_type'];
  295. $data['spec'] = $value['spec'];
  296. if (array_key_exists($cardtype_spec, $mech_specs)) {
  297. $data['price'] = $mech_specs[$cardtype_spec]['price'];
  298. } else {
  299. $data['price'] = 0;
  300. }
  301. $result[$value['card_type']][] = $data;
  302. }
  303. return $result;
  304. };
  305. $result = $merger($all_cardtype_specs, $merch_cardtype_specs);
  306. return $result;
  307. }
  308. public function check_merchantOp()
  309. {
  310. $mchid = trim($_GET['mchid']);
  311. if (!$mchid) {
  312. echo '';
  313. die;
  314. }
  315. $model_merchant = Model('merchant');
  316. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*');
  317. if (empty($merchant_info)) {
  318. echo '';
  319. die;
  320. }
  321. echo 'true';
  322. }
  323. /**
  324. * ajax操作
  325. */
  326. public function ajaxOp()
  327. {
  328. $model_merchant = Model('merchant');
  329. switch ($_GET['branch']) {
  330. /**
  331. * 验证机构名称是否重复
  332. */
  333. case 'check_mch_name':
  334. $condition['name'] = $_GET['name'];
  335. $list = $model_merchant->getMerchantInfo($condition);
  336. if (empty($list)) {
  337. echo 'true';
  338. } else {
  339. echo 'false';
  340. }
  341. exit;
  342. /**
  343. * 验证机构是否存在
  344. */
  345. case 'check_merchant':
  346. $condition['mchid'] = intval($_GET['mchid']);
  347. $list = $model_merchant->getMerchantInfo($condition);
  348. if (!empty($list)) {
  349. echo 'true';
  350. } else {
  351. echo 'false';
  352. }
  353. exit;
  354. }
  355. }
  356. public function check_evidenceOp()
  357. {
  358. $status = $_GET['status'];
  359. $apply_id = intval($_GET['apply_id']);
  360. if ($apply_id > 0) {
  361. $model_merchant = Model('merchant');
  362. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  363. if (empty($evidence_info)) {
  364. showMessage('充值申请不存在');
  365. }
  366. if ($status == 'pass') {
  367. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
  368. } elseif ($status == 'unpass') {
  369. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
  370. } else {
  371. }
  372. }
  373. showMessage(L('nc_common_save_succ'), urlAdmin('refill_evidence', 'index'));
  374. }
  375. public function rechargeOp()
  376. {
  377. if (chksubmit()) {
  378. $mchid = $this->add_money();
  379. $model_merchant = Model('merchant');
  380. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  381. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  382. //更新预警短信通知限制
  383. $mch_cache = rcache("merchant-notify", 'refill-');
  384. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  385. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  386. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  387. }
  388. showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
  389. } else {
  390. $apply_id = $_GET['apply_id'];
  391. if (!empty($apply_id)) {
  392. $model_merchant = Model('merchant');
  393. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*,member.available_predeposit');
  394. Tpl::output('apply_id', $apply_id);
  395. Tpl::output('amount', $evidence_info['amount']);
  396. Tpl::output('available_predeposit', $evidence_info['available_predeposit']);
  397. }
  398. Tpl::showpage('recharge.add');
  399. }
  400. }
  401. public function recharge_manualOp()
  402. {
  403. $type = $_GET['type'] ?? $_POST['type'];
  404. if (chksubmit()) {
  405. $obj_validate = new Validator();
  406. if($type == 'add') {
  407. $obj_validate->validateparam = [
  408. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  409. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
  410. ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
  411. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
  412. ];
  413. } elseif ($type == 'edit') {
  414. $obj_validate->validateparam = [
  415. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  416. ["input" => $_POST["bank_username"], "require" => "true", "message" => '操作人姓名不能为空'],
  417. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
  418. ];
  419. }
  420. $error = $obj_validate->validate();
  421. if ($error != '') {
  422. showMessage($error);
  423. }
  424. $mchid = $_POST["mch_id"];
  425. $model_merchant = Model('merchant');
  426. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  427. if (!$merchant_info) {
  428. showMessage('对应机构不存在');
  429. }
  430. $pointsnum = $_POST['pointsnum'];
  431. $money = abs($pointsnum);
  432. if ($money == 0) {
  433. showMessage('预存金额错误');
  434. }
  435. if(!empty($_FILES['voucher']['name'])) {
  436. $upload = new UploadFile();
  437. $upload->set('default_dir',ATTACH_UPFILE);
  438. $result = $upload->upfile('voucher');
  439. if ($result){
  440. $_POST['voucher_name'] = $upload->file_name;
  441. }else {
  442. showMessage($upload->error);
  443. }
  444. }
  445. try {
  446. $model_merchant = Model('merchant');
  447. $trans = new trans_wapper($model_merchant, __METHOD__);
  448. $member_id = $merchant_info['admin_id'];
  449. if ($pointsnum > 0) {
  450. $bz = '管理员操作手动预存金额增加';
  451. $this->credit_save_money($money, 1, $member_id, $bz);
  452. } elseif ($pointsnum < 0) {
  453. $bz = '管理员操作手动预存金额减少';
  454. $this->credit_save_money($money, 2, $member_id, $bz);
  455. } else {
  456. showMessage('预存金额错误');
  457. }
  458. $result = $this->ct_refill_evidence($_POST, $merchant_info);
  459. if (!$result) {
  460. $trans->rollback();
  461. showMessage('操作失败', 'index.php?act=merchant&op=merchant');
  462. }
  463. $trans->commit();
  464. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  465. //更新预警短信通知限制
  466. $mch_cache = rcache("merchant-notify", 'refill-');
  467. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  468. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  469. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  470. }
  471. showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
  472. } catch (Exception $e) {
  473. $trans->rollback();
  474. showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
  475. }
  476. } else {
  477. $page = "recharge.manual.{$type}";
  478. Tpl::showpage($page);
  479. }
  480. }
  481. private function ct_refill_evidence($params, $merchant_info)
  482. {
  483. $admininfo = $this->getAdminInfo();
  484. $mem_info = Model('member')->getMemberInfo(['member_id' => $merchant_info['admin_id']]);
  485. $input['mchid'] = $merchant_info['mchid'];
  486. $input['mch_name'] = $merchant_info['name'];
  487. $input['member_id'] = $merchant_info['admin_id'];
  488. $input['amount'] = $params['pointsnum'];
  489. $input['bank_username'] = $params['bank_username'];
  490. $input['bank_name'] = $params['bank_name'] ?? '';
  491. $input['bz'] = $params['pointsdesc'];
  492. $input['voucher_name'] = $params['voucher_name'] ?? '/';
  493. $input['status'] = 2;
  494. $input['is_operation'] = 2;
  495. $input['add_time'] = $input['check_time'] = time();
  496. $input['after_available'] = ncPriceFormat($mem_info['available_predeposit'] + $params['pointsnum']);
  497. $input['admin_name'] = $admininfo['name'];
  498. $input['admin_id'] = $admininfo['id'];
  499. $input['add_type'] = 2;
  500. $model_merchant = Model('merchant');
  501. return $model_merchant->addRefillEvidence($input);
  502. }
  503. public function add_money()
  504. {
  505. $obj_validate = new Validator();
  506. $obj_validate->validateparam = [
  507. ["input" => $_POST["apply_id"], "require" => "true", "message" => Language::get('admin_points_member_error_again')],
  508. ["input" => $_POST["pointsnum"], "require" => "true", 'validator' => 'Compare', 'operator' => ' >= ', 'to' => 1, "message" => Language::get('admin_points_points_min_error')]
  509. ];
  510. $error = $obj_validate->validate();
  511. if ($error != '') {
  512. showMessage($error, '', '', 'error');
  513. }
  514. $money = abs(floatval($_POST['pointsnum']));
  515. $memo = trim($_POST['pointsdesc']);
  516. if ($money <= 0) {
  517. showMessage('输入的金额必需大于0', '', 'html', 'error');
  518. }
  519. $apply_id = intval($_POST['apply_id']);
  520. $model_merchant = Model('merchant');
  521. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  522. if (!is_array($evidence_info) || count($evidence_info) <= 0) {
  523. showMessage("无效的充值申请信息", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  524. }
  525. if ($evidence_info['status'] != 2) {
  526. showMessage("该充值申请未被审核通过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  527. }
  528. if ($evidence_info['is_operation'] == 2) {
  529. showMessage("该充值申请未已被预存过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  530. }
  531. //查询会员信息
  532. $obj_member = Model('member');
  533. $member_id = intval($evidence_info['member_id']);
  534. $member_info = $obj_member->getMemberInfo(['member_id' => $member_id]);
  535. $available_predeposit = floatval($member_info['available_predeposit']);
  536. $freeze_predeposit = floatval($member_info['freeze_predeposit']);
  537. if ($_POST['operatetype'] == 2 && $money > $available_predeposit) {
  538. showMessage(('预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  539. }
  540. if ($_POST['operatetype'] == 3 && $money > $available_predeposit) {
  541. showMessage(('可冻结预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  542. }
  543. if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit) {
  544. showMessage(('可恢复冻结预存款不足,会员当前冻结预存款') . $freeze_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  545. }
  546. $model_pd = Model('predeposit');
  547. $order_sn = $apply_id;
  548. $admininfo = $this->getAdminInfo();
  549. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
  550. $admin_act = 'sys_add_money';
  551. switch ($_POST['operatetype']) {
  552. case 1:
  553. $admin_act = "sys_add_money";
  554. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
  555. break;
  556. case 2:
  557. $admin_act = "sys_del_money";
  558. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
  559. break;
  560. default:
  561. showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
  562. break;
  563. }
  564. try {
  565. $trans = new trans_wapper($model_pd, __METHOD__);
  566. //扣除冻结的预存款
  567. $data = [];
  568. $data['member_id'] = $member_info['member_id'];
  569. $data['member_name'] = $member_info['member_name'];
  570. $data['amount'] = $money;
  571. $data['order_sn'] = $order_sn;
  572. $data['admin_name'] = $admininfo['name'];
  573. $data['pdr_sn'] = $order_sn;
  574. $data['lg_desc'] = $memo;
  575. $model_pd->changePd($admin_act, $data);
  576. $after_available = ncPriceFormat($available_predeposit + $evidence_info['amount']);
  577. $model_merchant->editRefillEvidence(
  578. ['apply_id' => $apply_id],
  579. ['is_operation' => 2, 'after_available' => $after_available, 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name']]
  580. );
  581. $trans->commit();
  582. $this->log($log_msg, 1);
  583. return $evidence_info['mchid'];
  584. } catch (Exception $e) {
  585. $trans->rollback();
  586. $this->log($log_msg, 0);
  587. showMessage($e->getMessage(), 'index.php?act=refill_evidence&op=index', 'html', 'error');
  588. exit;
  589. }
  590. }
  591. public function checkevidenceOp()
  592. {
  593. $apply_id = trim($_GET['apply_id']);
  594. if (!$apply_id) {
  595. echo '';
  596. die;
  597. }
  598. $model_merchant = Model('merchant');
  599. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
  600. if (empty($evidence_info)) {
  601. echo '';
  602. die;
  603. }
  604. echo 'true';
  605. }
  606. public function OrderQueryOp()
  607. {
  608. showMessage('操作成功', '');
  609. $model_vr_order = Model('vr_order');
  610. $condition['order_state'] = ORDER_STATE_SEND;
  611. $orders = $model_vr_order->getOrderList($condition);
  612. if (!empty($orders)) {
  613. foreach ($orders as $order) {
  614. $order_id = $order['order_id'];
  615. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  616. }
  617. }
  618. showMessage('操作成功', 'index.php?act=refill_order&op=index');
  619. }
  620. public function mch_notifyOp()
  621. {
  622. showMessage('操作成功', '');
  623. $model_refill_order = Model('refill_order');
  624. $condition['mch_notify_state'] = 0;
  625. $condition['inner_status'] = 0;
  626. $orders = $model_refill_order->getMerchantOrderList($condition, 1000, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  627. if (!empty($orders)) {
  628. foreach ($orders as $order) {
  629. $order_id = $order['order_id'];
  630. if ($order['order_state'] == ORDER_STATE_SEND) {
  631. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  632. } else {
  633. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  634. }
  635. }
  636. }
  637. showMessage('操作成功', 'index.php?act=refill_order&op=index');
  638. }
  639. public function notify_merchantOp()
  640. {
  641. showMessage('操作成功', '');
  642. $order_id = $_GET['order_id'];
  643. $mod_order = Model('vr_order');
  644. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  645. if ($order_info['order_state'] == ORDER_STATE_SEND) {
  646. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  647. } else {
  648. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  649. }
  650. showMessage('操作成功', '');
  651. }
  652. public function notify_manual_merchantOp()
  653. {
  654. showMessage('操作成功', '');
  655. $order_id = $_GET['order_id'];
  656. $type = $_GET['type'];
  657. $mod_order = Model('vr_order');
  658. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  659. if ((time() - $order_info['order_time']) < 3600) {
  660. showMessage('订单时间未超过1小时', 'index.php?act=refill_order&op=index');
  661. }
  662. if ($type == 'success') {
  663. refill\util::manual_success($order_id);
  664. } elseif ($type == 'cancel') {
  665. refill\util::manual_cancel($order_id);
  666. } else {
  667. showMessage('手动操作类型错误', 'index.php?act=refill_order&op=index');
  668. }
  669. showMessage('操作成功', '');
  670. }
  671. public function providerStatsOp()
  672. {
  673. $provider_model = Model('refill_provider');
  674. $condition = [];
  675. $provider_list = $provider_model->getProviderList($condition, 1000);
  676. $opened_text = ['使用中', '已禁用'];
  677. $type_text = ['油卡', '手机充值卡'];
  678. Tpl::output('opened_text', $opened_text);
  679. Tpl::output('type_text', $type_text);
  680. Tpl::output('provider_list', $provider_list);
  681. Tpl::output('show_page', $provider_model->showpage());
  682. Tpl::showpage('provider.stats');
  683. }
  684. public function provider_provinceOp()
  685. {
  686. $provider_model = Model('refill_provider');
  687. $provider_id = $_GET['id'] ?? $_POST['id'];
  688. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  689. if (empty($provider)) {
  690. showMessage('通道信息有误');
  691. }
  692. $operator = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
  693. if(chksubmit()) {
  694. foreach ($operator as $opr) {
  695. $key = $opr . '-province';
  696. $province = $_POST[$key];
  697. if($province == -1) {
  698. $updata[$opr] = -1;
  699. }else{
  700. $updata[$opr] = implode(',',$province);
  701. }
  702. }
  703. $resp = $provider_model->editProvider(['provinces' => serialize($updata)], ['provider_id' => $provider_id]);
  704. if ($resp) {
  705. showMessage('编辑成功', 'index.php?act=provider&op=index');
  706. } else {
  707. showMessage('编辑失败', "index.php?act=merchant&op=provider_province&id={$provider_id}");
  708. }
  709. } else {
  710. $data = unserialize($provider['provinces']);
  711. $provinces = [];
  712. $province = $provinces;
  713. foreach ($operator as $opr) {
  714. if(empty($data)) {
  715. $provinces[$opr] = [-1];
  716. } else {
  717. $provinces[$opr] = explode(',', $data[$opr]);
  718. }
  719. }
  720. $province_list = mtopcard\ProvinceList;
  721. Tpl::output('province_list', $province_list);
  722. Tpl::output('provider', $provider);
  723. Tpl::output('provinces', $provinces);
  724. Tpl::showpage('provider.province');
  725. }
  726. }
  727. public function changeProviderStateOp()
  728. {
  729. $provider_id = intval($_GET['id']);
  730. $state = intval($_GET['state']);
  731. $provider_model = Model('refill_provider');
  732. $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  733. if (empty($provider_info) || !in_array($state, [1, 2])) {
  734. showMessage('操作成功', 'index.php?act=provider&op=index');
  735. }
  736. $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
  737. if (!$resp) {
  738. showMessage('操作失败', 'index.php?act=provider&op=index', 'html', 'error');
  739. }
  740. showMessage('操作成功', 'index.php?act=provider&op=index');
  741. }
  742. /**
  743. * 新增通道
  744. */
  745. public function provider_addOp()
  746. {
  747. $provider_model = Model('refill_provider');
  748. if (chksubmit()) {
  749. $params = $_POST;
  750. unset($params['form_submit']);
  751. $result = $provider_model->addProvider($params);
  752. if ($result) {
  753. $url = [
  754. [
  755. 'url' => 'index.php?act=provider&op=index',
  756. 'msg' => '返回通道列表',
  757. ],
  758. [
  759. 'url' => 'index.php?act=merchant&op=provider_add',
  760. 'msg' => '继续新增通道',
  761. ],
  762. ];
  763. $this->log('添加通道:' . '[ ' . $_POST['name'] . ']', 1);
  764. showMessage('通道添加成功', $url);
  765. } else {
  766. showMessage('通道添加失败');
  767. }
  768. }
  769. Tpl::showpage('provider.add');
  770. }
  771. public function provider_editOp()
  772. {
  773. $provider_model = Model('refill_provider');
  774. if (chksubmit()) {
  775. $provider_id = intval($_POST['provider_id']) ?? '';
  776. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  777. if (empty($provider)) {
  778. showMessage('通道信息有误');
  779. }
  780. $params = $_POST;
  781. unset($params['form_submit']);
  782. if (empty($params)) {
  783. showMessage('通道编辑成功', 'index.php?act=provider&op=index');
  784. }
  785. $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
  786. if ($result) {
  787. $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
  788. showMessage('通道编辑成功', 'index.php?act=provider&op=index');
  789. } else {
  790. showMessage('通道编辑失败', "index.php?act=merchant&op=provider_edit&id={$provider_id}");
  791. }
  792. }
  793. $provider_id = intval($_GET['id']) ?? '';
  794. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  795. if (empty($provider)) {
  796. showMessage('通道信息有误');
  797. }
  798. $type_text = ['油卡', '手机充值卡'];
  799. Tpl::output('type_text', $type_text);
  800. Tpl::output('provider', $provider);
  801. Tpl::showpage('provider.edit');
  802. }
  803. public function provider_delOp()
  804. {
  805. $provider_model = Model('refill_provider');
  806. $provider_id = intval($_GET['id']) ?? '';
  807. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  808. if (empty($provider)) {
  809. showMessage('通道信息有误');
  810. }
  811. $result = $provider_model->delProvider(['provider_id' => $provider_id]);
  812. if ($result) {
  813. $this->log('删除通道:' . '[ ' . $provider['name'] . ']', 1);
  814. showMessage('通道删除成功', 'index.php?act=provider&op=index');
  815. } else {
  816. showMessage('通道删除失败', "index.php?act=provider&op=index");
  817. }
  818. }
  819. public function provider_amount_controlOp()
  820. {
  821. $type = $_GET['type'] ?? $_POST['type'];
  822. $form = $_GET['form'] ?? $_POST['form'];
  823. $rkey = $this->speed_key($type, $form);
  824. $quality = ['common' => 1, 'fast' => 2, 'card' => 3, 'third' => 4, 'slow' => 5 , 'slow6' => 6, 'slow2' => 7];
  825. if (chksubmit()) {
  826. $pids = $_POST['pid'];
  827. $names = $_POST['name'];
  828. $types = $_POST['types'];
  829. $amounts = $_POST['amount'];
  830. $speeds = $_POST['speed'];
  831. $sorts = $_POST['sort'];
  832. $openeds = $_POST['opened'];
  833. $hass = $_POST['has'];
  834. foreach ($pids as $key => $pid) {
  835. if ($hass[$key] == 0) {
  836. continue;
  837. }
  838. $data['pid'] = intval($pid);
  839. $data['name'] = $names[$key];
  840. $data['type'] = intval($types[$key]);
  841. $data['amount'] = intval($amounts[$key]);
  842. $data['speed'] = intval($speeds[$key]);
  843. $data['sort'] = intval($sorts[$key]);
  844. $data['opened'] = intval($openeds[$key]);
  845. $index = "{$data['type']}-{$data['amount']}";
  846. $result[$index][] = $data;
  847. }
  848. wcache($rkey, ['data' => serialize($result)], 'provider-');
  849. showMessage('编辑成功', 'index.php?act=provider&op=index');
  850. } else {
  851. $speed_limit = rcache($rkey, 'provider-');
  852. if (empty($speed_limit)) {
  853. $speed_limit = [];
  854. } else {
  855. $speed_limit = unserialize($speed_limit['data']);
  856. }
  857. $initialiser = function ($provider) {
  858. $data['pid'] = $provider['provider_id'];
  859. $data['name'] = $provider['name'];
  860. $data['speed'] = -1;
  861. $data['sort'] = 1;
  862. $data['opened'] = 1;
  863. return $data;
  864. };
  865. $providers = Model('')->table('refill_provider,store')
  866. ->field('refill_provider.*,store.store_name')
  867. ->join('inner')
  868. ->on('store.store_id=refill_provider.store_id')
  869. ->where(['type' => $type, 'qualitys' => ['like', '%' . $quality[$form] . '%']])
  870. ->limit(1000)
  871. ->order('opened asc , provider_id desc')
  872. ->select();
  873. if (empty($providers)) {
  874. showMessage('暂无相关通道', 'index.php?act=provider&op=index');
  875. }
  876. $formData = $this->formData($type, $form);
  877. $amounts = $formData['amounts'];
  878. $cfgs = $formData['cfgs'];
  879. $types = $formData['types'];
  880. foreach ($speed_limit as $key => $speed) {
  881. foreach ($speed as $value) {
  882. $speed_limit[$key][$value['pid']] = $value;
  883. }
  884. }
  885. $ProviderManager = new \refill\ProviderManager();
  886. $ProviderManager->load();
  887. $QPTA = $ProviderManager->getQPTA();
  888. $QPTA = $QPTA[$quality[$form]];
  889. foreach ($providers as $key => $provider) {
  890. $result = [];
  891. $pid = $provider['provider_id'];
  892. $name = $provider['name'];
  893. if (empty($cfgs) || !array_key_exists($name, $cfgs)) {
  894. unset($providers[$key]);
  895. continue;
  896. }
  897. foreach ($types as $type) {
  898. foreach ($amounts as $k => $amount) {
  899. $key = $type . '-' . $amount;
  900. if (is_array($speed_limit[$key]) && array_key_exists($pid, $speed_limit[$key])) {
  901. $speed = $speed_limit[$key][$pid];
  902. } else {
  903. $speed = $initialiser($provider);
  904. }
  905. if (is_array($QPTA["{$name}-{$type}-{$amount}"]) && array_key_exists("{$name}-{$type}-{$amount}", $QPTA)) {
  906. $speed['has'] = 1;
  907. } else {
  908. $speed['has'] = 0;
  909. }
  910. $result[] = $speed;
  911. }
  912. }
  913. $datas[$pid] = $result;
  914. }
  915. if (empty($datas)) {
  916. showMessage('暂无相关通道配置', 'index.php?act=provider&op=index');
  917. }
  918. Tpl::output('form', $formData);
  919. Tpl::output('datas', $datas);
  920. Tpl::output('providers', $providers);
  921. Tpl::showpage('provider.amount.control');
  922. }
  923. }
  924. private function speed_key($type, $form)
  925. {
  926. if ($type == 1) {
  927. $rkey = "channel-ctl-oil-{$form}-limit";
  928. } elseif ($type == 2) {
  929. $rkey = "channel-ctl-phone-{$form}-limit";
  930. } else {
  931. showMessage('类型有误', "index.php?act=provider&op=index");
  932. }
  933. Log::record($rkey, Log::DEBUG);
  934. return $rkey;
  935. }
  936. private function formData($type, $form)
  937. {
  938. global $config;
  939. $texts = [
  940. ["中石油", '中石化'], ['移动', '联通', '电信']
  941. ];
  942. $type_data = [[1, 2], [4, 5, 6]];
  943. $type_text = $texts[$type - 1];
  944. $type_data = $type_data[$type - 1];
  945. $amounts = [];
  946. if ($type == 1) {
  947. $amounts = $config['refill_oil_specs'];
  948. $cfgs = $config['oil_providers'];
  949. }
  950. if ($type == 2) {
  951. $amounts = $config['refill_phone_specs'];
  952. $cfgs = $config['phone_providers'];
  953. }
  954. foreach ($type_text as $key => $value) {
  955. foreach ($amounts as $amount) {
  956. $data['text'] = $value . '-' . $amount . '元';
  957. $data['type'] = $type_data[$key];
  958. $data['amount'] = $amount;
  959. $amountData[] = $data;
  960. }
  961. }
  962. foreach ($cfgs as $cfg) {
  963. $pcfgs[$cfg['name']] = $cfg;
  964. }
  965. return ['amountData' => $amountData, 'form' => $form, 'amounts' => $amounts, 'types' => $type_data, 'cfgs' => $pcfgs];
  966. }
  967. private function scard_type(int $card_type)
  968. {
  969. if ($card_type == 1) { //中石油
  970. return '中石油';
  971. } elseif ($card_type == 2) { //中石化
  972. return '中石化';
  973. } elseif ($card_type == 4) { //中国移动
  974. return '中国移动';
  975. } elseif ($card_type == 5) { //中国联通
  976. return '中国联通';
  977. } elseif ($card_type == 6) { //中国电信
  978. return '中国电信';
  979. } else {
  980. return 'unknown';
  981. }
  982. }
  983. private function quality_format($quality) {
  984. switch ($quality) {
  985. case 1:
  986. $text = "普充";
  987. break;
  988. case 2:
  989. $text = "快充";
  990. break;
  991. case 3:
  992. $text = "卡密";
  993. break;
  994. case 4:
  995. $text = "三方";
  996. break;
  997. case 5:
  998. $text = "慢充二十四小时";
  999. break;
  1000. case 6:
  1001. $text = "慢充六小时";
  1002. break;
  1003. case 7:
  1004. $text = "慢充两小时";
  1005. break;
  1006. default:
  1007. return '其他';
  1008. break;
  1009. }
  1010. return $text;
  1011. }
  1012. private function elapse_time($seconds)
  1013. {
  1014. $minutes = intval($seconds / 60);
  1015. $second = intval($seconds % 60);
  1016. if ($minutes >= 60) {
  1017. $minute = $minutes % 60;
  1018. $hours = intval($minutes / 60);
  1019. $result = "{$minute}m{$second}s";
  1020. } elseif ($minutes > 0) {
  1021. $result = "{$minutes}m{$second}s";
  1022. } else {
  1023. $result = "{$second}s";
  1024. }
  1025. if (isset($hours)) {
  1026. $result = "{$hours}h{$minute}m";
  1027. }
  1028. return $result;
  1029. }
  1030. public function OrderStatsCheckOp()
  1031. {
  1032. $stat_id = $_GET['stat_id'] ?? $_POST['stat_id'];
  1033. $mod_stat = Model('refill_stats');
  1034. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  1035. if (empty($stats_data)) {
  1036. showMessage('对应数据不存在', '');
  1037. }
  1038. $type = $stats_data['type'];
  1039. if (chksubmit()) {
  1040. $corder_success_count = $_POST['corder_success_count'];
  1041. $corder_success_amounts = $_POST['corder_success_amounts'];
  1042. $remark = $_POST['remark'];
  1043. $gap_order_count = $gap_success_amounts = 0;
  1044. if($type == 'provider') {
  1045. $gap_order_count = $corder_success_count - $stats_data['success_count'];
  1046. $gap_success_amounts = $corder_success_amounts - $stats_data['success_channel_amounts'];
  1047. }elseif ($type == 'merchant') {
  1048. $gap_order_count = $stats_data['success_count'] - $corder_success_count;
  1049. $gap_success_amounts = $stats_data['success_channel_amounts'] - $corder_success_amounts;
  1050. }else{
  1051. showMessage('对账数据类型错误', 'index.php?act=OrderStats&op=index');
  1052. }
  1053. $updata['corder_success_count'] = $corder_success_count;
  1054. $updata['corder_success_amounts'] = $corder_success_amounts;
  1055. $updata['gap_order_count'] = $gap_order_count;
  1056. $updata['gap_success_amounts'] = $gap_success_amounts;
  1057. $updata['remark'] = $remark;
  1058. if($gap_order_count == 0 && $gap_success_amounts == 0) {
  1059. $updata['check_status'] = 1;
  1060. }else{
  1061. $updata['check_status'] = 2;
  1062. }
  1063. $res = $mod_stat->edit($stat_id, $updata);
  1064. if ($res) {
  1065. showMessage('操作成功',"index.php?act=OrderStats&op=index&type={$type}");
  1066. } else {
  1067. showMessage('操作失败');
  1068. }
  1069. } else {
  1070. $type_text = ['provider' => '上游', 'merchant' => '商户'];
  1071. Tpl::output('stats_type', $type_text[$type]);
  1072. Tpl::showpage('order.stats.check');
  1073. }
  1074. }
  1075. public function OrderStatsReloadOp()
  1076. {
  1077. $stat_id = $_GET['stat_id'];
  1078. $mod_stat = Model('refill_stats');
  1079. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  1080. if (empty($stats_data)) {
  1081. showMessage('对应数据不存在', '');
  1082. }
  1083. showMessage('操作成功');
  1084. }
  1085. public function provider_evidenceOp()
  1086. {
  1087. $mod = Model('provider_evidence');
  1088. $condition = [];
  1089. if (trim($_GET['store_name']) != '') {
  1090. $condition['store_name'] = ['like', '%' . $_GET['store_name'] . '%'];
  1091. }
  1092. //上游充值申请列表
  1093. $evidence_list = $mod->getProviderEvidence($condition, 30);
  1094. Tpl::output('evidence_list', $evidence_list);
  1095. Tpl::output('page', $mod->showpage());
  1096. Tpl::showpage('merchant.provider.evidence_list');
  1097. }
  1098. public function provider_evidence_addOp()
  1099. {
  1100. $provider_model = Model('refill_provider');
  1101. if (chksubmit()) {
  1102. $obj_validate = new Validator();
  1103. $obj_validate->validateparam = [
  1104. ["input" => $_POST["provider_id"], "require" => "true", "message" => '上游通道不能为空'],
  1105. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
  1106. ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
  1107. ["input" => $_POST["to_bank_username"], "require" => "true", "message" => '上游开户人姓名不能为空'],
  1108. ["input" => $_POST["to_bank_name"], "require" => "true", "message" => '上游开户银行不能为空'],
  1109. ["input" => $_POST["amount"], "require" => "true", "message" => '预存金额不能为空']
  1110. ];
  1111. $error = $obj_validate->validate();
  1112. if ($error != '') {
  1113. showMessage($error);
  1114. }
  1115. $provider_id = $_POST["provider_id"];
  1116. $provider_info = $provider_model->table('refill_provider,store')
  1117. ->where((['provider_id' => $provider_id]))
  1118. ->field('refill_provider.*,store.store_name')
  1119. ->join('inner')
  1120. ->on('store.store_id=refill_provider.store_id')
  1121. ->find();
  1122. if (!$provider_info) {
  1123. showMessage('对应店铺不存在');
  1124. }
  1125. $amount = $_POST['amount'];
  1126. $money = abs($amount);
  1127. if ($money == 0) {
  1128. showMessage('申请金额错误');
  1129. }
  1130. if(!empty($_FILES['voucher']['name'])) {
  1131. $upload = new UploadFile();
  1132. $upload->set('default_dir',ATTACH_UPFILE.'/provider');
  1133. $result = $upload->upfile('voucher');
  1134. if ($result){
  1135. $_POST['voucher'] = $upload->file_name;
  1136. $input['voucher_name'] = $_POST['voucher'];
  1137. }else {
  1138. showMessage($upload->error);
  1139. }
  1140. }
  1141. $input['store_name'] = $provider_info['store_name'];
  1142. $input['store_id'] = $provider_info['store_id'];
  1143. $input['amount'] = $amount;
  1144. $input['bank_username'] = $_POST['bank_username'];
  1145. $input['bank_name'] = $_POST['bank_name'];
  1146. $input['to_bank_username'] = $_POST['to_bank_username'];
  1147. $input['to_bank_name'] = $_POST['to_bank_name'];
  1148. $input['add_time'] = time();
  1149. $mod = Model('provider_evidence');
  1150. $res = $mod->addProviderEvidence($input);
  1151. if ($res) {
  1152. showMessage('操作成功',"index.php?act=merchant&op=provider_evidence");
  1153. } else {
  1154. showMessage('操作失败');
  1155. }
  1156. } else {
  1157. $provider_list = Model('')->table('refill_provider,store')
  1158. ->field('refill_provider.*,store.store_name')
  1159. ->join('inner')
  1160. ->on('store.store_id=refill_provider.store_id')
  1161. ->limit(1000)
  1162. ->select();
  1163. Tpl::output('provider_list', $provider_list);
  1164. Tpl::showpage('provider.evidence.add');
  1165. }
  1166. }
  1167. }