merchant.php 49 KB

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