merchant.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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. require_once(BASE_HELPER_PATH . '/task/task_helper.php');
  11. class merchantControl extends SystemControl
  12. {
  13. const EXPORT_SIZE = 1000;
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. Language::read('merchant');
  18. }
  19. /**
  20. * 机构列表
  21. */
  22. public function merchantOp()
  23. {
  24. $model_merchant = Model('merchant');
  25. if (trim($_GET['merchant_name']) != '') {
  26. $condition['company_name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
  27. }
  28. $merchant_list = $model_merchant->getMerchantList($condition, 100, 'available_predeposit desc,merchant_state asc,mchid desc', true);
  29. foreach ($merchant_list as $key => $merchant) {
  30. $merchant_list[$key]['available_predeposit'] = number_format(($merchant['available_predeposit'] - $merchant['credit_bonus']),4,'.',',');
  31. $merchant_list[$key]['credit_bonus'] = $merchant['credit_bonus'];
  32. }
  33. $merchant_state_text = ['使用中', '已禁用'];
  34. Tpl::output('merchant_state_text', $merchant_state_text);
  35. Tpl::output('merchant_list', $merchant_list);
  36. Tpl::output('page', $model_merchant->showpage('2'));
  37. Tpl::showpage('merchant.index');
  38. }
  39. public function changeStateOp()
  40. {
  41. $mchid = intval($_GET['mchid']);
  42. $state = intval($_GET['state']);
  43. $model_merchant = Model('merchant');
  44. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  45. if (empty($merchant_info) || !in_array($state, [1, 2])) {
  46. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  47. }
  48. $resp = $model_merchant->editMerchant(['merchant_state' => $state], ['mchid' => $mchid]);
  49. if (!$resp) {
  50. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  51. }
  52. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  53. }
  54. public function AllCloseMerchantOp()
  55. {
  56. $model_merchant = Model('merchant');
  57. $resp = $model_merchant->editMerchant(['merchant_state' => 2], ['mchid' => ['gt',0]]);
  58. showMessage('操作成功');
  59. }
  60. public function merchant_addOp()
  61. {
  62. if (chksubmit())
  63. {
  64. $obj_validate = new Validator();
  65. $obj_validate->validateparam = [
  66. ["input" => $_POST["name"], "require" => "true", "message" => '机构账号不能为空'],
  67. ["input" => $_POST["company_name"], "require" => "true", "message" => '机构公司名称不能为空'],
  68. ["input" => $_POST["password"], "require" => "true", "message" => '密码不能为空']
  69. ];
  70. $error = $obj_validate->validate();
  71. if ($error != '') {
  72. showMessage($error);
  73. }
  74. else
  75. {
  76. try
  77. {
  78. $name = trim($_POST['name']);
  79. $company_name = trim($_POST['company_name']);
  80. $pwd = trim($_POST['password']);
  81. $alarm_amount = $_POST['alarm_amount'] ?? 0;
  82. $model_merchant = Model('merchant');
  83. $model_member = Model('member');
  84. $trans = new trans_wapper($model_merchant, __METHOD__);
  85. $insert_member['member_name'] = md5($name . time());
  86. $insert_member['member_passwd'] = $pwd;
  87. $insert_id = $model_member->addMember($insert_member);
  88. if ($insert_id == false) {
  89. $trans->rollback();
  90. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  91. }
  92. $insert_array['name'] = $name;
  93. $insert_array['company_name'] = $company_name;
  94. $insert_array['org_pwd'] = $pwd;
  95. $insert_array['password'] = md5($pwd);
  96. $insert_array['admin_id'] = trim($insert_id);
  97. $insert_array['alarm_amount'] = $alarm_amount;
  98. $result = $model_merchant->addMerchant($insert_array);
  99. if ($result > 0) {
  100. $helper = new refill\divert_account();
  101. $helper->init_member($insert_id);
  102. $ret = true;
  103. } else {
  104. $ret = false;
  105. }
  106. if($ret)
  107. {
  108. $trans->commit();
  109. $url = [[
  110. 'url' => 'index.php?act=merchant&op=merchant',
  111. 'msg' => '返回机构列表',
  112. ], [
  113. 'url' => 'index.php?act=merchant&op=merchant_add',
  114. 'msg' => '继续新增机构',
  115. ]];
  116. $this->log('添加机构:' . '[ ' . $_POST['name'] . ']', 1);
  117. showMessage('机构添加成功', $url);
  118. } else {
  119. $trans->rollback();
  120. showMessage('机构添加失败');
  121. }
  122. }
  123. catch (Exception $e) {
  124. $trans->rollback();
  125. showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
  126. }
  127. }
  128. }
  129. Tpl::showpage('merchant.add');
  130. }
  131. public function merchant_editOp()
  132. {
  133. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  134. $model_merchant = Model('merchant');
  135. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
  136. if (empty($merchant)) {
  137. showMessage('机构信息有误');
  138. }
  139. if (chksubmit())
  140. {
  141. $update_credit_bonus = ncPriceFormat($_POST['credit_bonus']);
  142. $operatetype = $_POST['operatetype'];
  143. if ($update_credit_bonus > 0) {
  144. if ($merchant['credit_bonus'] + $update_credit_bonus < 0) {
  145. showMessage('授信金额调整后不能小于0');
  146. }
  147. if ($operatetype == 'add') {
  148. $update['credit_bonus'] = ['exp', 'credit_bonus+' . $update_credit_bonus];
  149. } elseif ($operatetype == 'del') {
  150. $update['credit_bonus'] = ['exp', 'credit_bonus-' . $update_credit_bonus];
  151. }
  152. }
  153. $update['company_name'] = trim($_POST['company_name']);
  154. $update['org_pwd'] = trim($_POST['password']);
  155. $update['password'] = md5($update['org_pwd']);
  156. $update['alarm_amount'] = $_POST['alarm_amount'] ?? 0;
  157. $day_timeout = intval($_POST['day_timeout']);
  158. $night_timeout = intval($_POST['night_timeout']);
  159. if($day_timeout <= 0) {
  160. $day_timeout = 180;
  161. }
  162. if($night_timeout <= 0) {
  163. $day_timeout = 180;
  164. }
  165. $update['day_timeout'] = $day_timeout;
  166. $update['night_timeout'] = $night_timeout;
  167. if(refill\functional::isDay()) {
  168. $update['time_out'] = intval($_POST['day_timeout']);
  169. } else {
  170. $update['time_out'] = intval($_POST['night_timeout']);
  171. }
  172. $member_id = $merchant['admin_id'];
  173. $model_merchant = Model('merchant');
  174. $trans = new trans_wapper($model_merchant, __METHOD__);
  175. try {
  176. if ($update_credit_bonus > 0) {
  177. $this->credit_save_money($update_credit_bonus, $operatetype, $member_id);
  178. }
  179. $result = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  180. if (!$result) {
  181. $trans->rollback();
  182. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  183. }
  184. $trans->commit();
  185. $this->log('编辑机构:' . '[ ' . $merchant['name'] . ']', 1);
  186. showMessage('机构编辑成功', 'index.php?act=merchant&op=merchant');
  187. } catch (Exception $e) {
  188. $trans->rollback();
  189. showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
  190. }
  191. }
  192. Tpl::output('merchant', $merchant);
  193. Tpl::showpage('merchant.edit');
  194. }
  195. public function priceOp()
  196. {
  197. $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. $extra_prices = $_POST['extra_price'];
  205. $max_inprices = $_POST['max_inprice'];
  206. foreach ($card_types as $key => $card_type) {
  207. $data['card_type'] = $card_type;
  208. $data['spec'] = intval($specs[$key]);
  209. $data['price'] = ncPriceFormat($prices[$key]);
  210. $data['extra_price'] = ncPriceFormat($extra_prices[$key]);
  211. $data['max_inprice'] = ncPriceFormat($max_inprices[$key]);
  212. $params[] = $data;
  213. }
  214. foreach ($params as $param) {
  215. if ($param['price'] > 0) {
  216. $insert['mchid'] = $mchid;
  217. $insert['spec'] = $param['spec'];
  218. $insert['price'] = $param['price'];
  219. $insert['extra_price'] = $param['extra_price'];
  220. $insert['max_inprice'] = $param['max_inprice'];
  221. $insert['card_types'] = $param['card_type'];
  222. $insert['quality'] = $quality;
  223. $inserts[] = $insert;
  224. }
  225. }
  226. $model_merchant = Model('merchant');
  227. $trans = new trans_wapper($model_merchant, __METHOD__);
  228. try {
  229. //删除旧费率
  230. $res = $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality]);
  231. if(!$res) {
  232. $trans->rollback();
  233. showMessage('删除旧费率失败');
  234. }
  235. $ret = true;
  236. //更新新费率
  237. if (!empty($inserts)) {
  238. $ret = $model_merchant->insertPrices($inserts);
  239. }
  240. if($ret) {
  241. $trans->commit();
  242. showMessage('操作成功');
  243. }else{
  244. $trans->rollback();
  245. showMessage('更新费率失败');
  246. }
  247. } catch (Exception $e) {
  248. $trans->rollback();
  249. Log::record("merchant_price update err: {$e->getMessage()}", Log::ERR);
  250. showMessage('操作失败');
  251. }
  252. }
  253. $mchid = $_GET['mchid'] ?? 0;
  254. $goods = $this->GoodsFormat($mchid, $quality);
  255. Tpl::output('goods', $goods);
  256. Tpl::showpage('merchant.price');
  257. }
  258. public function third_merchant_priceOp()
  259. {
  260. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  261. $mod = Model('thrid_refill');
  262. if (chksubmit()) {
  263. //合并表单数据
  264. $card_types = $_POST['cardtype'];
  265. $specs = $_POST['spec'];
  266. $prices = $_POST['price'];
  267. $pcodes = $_POST['pcode'];
  268. $quality = 1;
  269. $params = [];
  270. foreach ($card_types as $key => $card_type) {
  271. $data['card_type'] = $card_type;
  272. $data['spec'] = intval($specs[$key]);
  273. $data['price'] = ncPriceFormat($prices[$key]);
  274. $data['pcode'] = $pcodes[$key];
  275. $params[] = $data;
  276. }
  277. $model_merchant = Model('merchant');
  278. $trans = new trans_wapper($model_merchant, __METHOD__);
  279. try {
  280. foreach ($params as $param) {
  281. $insert = [];
  282. if ($param['price'] > 0) {
  283. $insert['mchid'] = $mchid;
  284. $insert['spec'] = $param['spec'];
  285. $insert['price'] = $param['price'];
  286. $insert['card_types'] = $param['card_type'];
  287. $insert['quality'] = $quality;
  288. $insert['pcode'] = $param['pcode'];
  289. }
  290. //删除旧费率
  291. $res = $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality, 'pcode' => $param['pcode']]);
  292. if(!$res) {
  293. $trans->rollback();
  294. showMessage('删除旧费率失败');
  295. }
  296. $ret = true;
  297. //更新新费率
  298. if (!empty($insert)) {
  299. $ret = $model_merchant->table('merchant_price')->insert($insert);
  300. }
  301. if(!$ret) {
  302. $trans->rollback();
  303. showMessage('更新费率失败');
  304. }
  305. }
  306. $trans->commit();
  307. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  308. } catch (Exception $e) {
  309. $trans->rollback();
  310. Log::record("merchant_price pcode update err: {$e->getMessage()}", Log::ERR);
  311. showMessage('操作失败');
  312. }
  313. } else {
  314. $condition = [];
  315. if (!empty($_GET['system_code'])) {
  316. $condition['system_code'] = $_GET['system_code'];
  317. }
  318. if (trim($_GET['product_name']) != '') {
  319. $condition['product_name'] = ['like', '%' . $_GET['product_name'] . '%'];
  320. }
  321. $third_product = $mod->getProductList($condition, 30);
  322. $model_merchant = Model('merchant');
  323. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => 1, 'card_types' => mtopcard\ThirdRefillCard])->select();
  324. $goods = [];
  325. foreach ($items as $item) {
  326. $goods[$item['pcode']] = $item['price'];
  327. }
  328. Tpl::output('third_product', $third_product);
  329. Tpl::output('goods', $goods);
  330. Tpl::output('page', $mod->showpage());
  331. Tpl::showpage('third.merchant.price');
  332. }
  333. }
  334. private function GoodsFormat($mchid, $quality)
  335. {
  336. $all_spector = function ($quality) {
  337. global $config;
  338. $refill_specs = $config['refill_specs'];
  339. $all_type_specs = [];
  340. foreach ($refill_specs as $scard_type => $specs) {
  341. $card_type = mtopcard\topcard_type($scard_type);
  342. if (in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  343. if ($quality == refill\Quality::Quick) {
  344. $specs = array_merge($config['refill_phone_small_specs'], $specs);
  345. }
  346. }
  347. $all_type_specs[$card_type] = $specs;
  348. }
  349. $result = [];
  350. foreach ($all_type_specs as $card_type => $specs) {
  351. foreach ($specs as $spec) {
  352. $result["{$card_type}-{$spec}"] = ['card_type' => $card_type, 'spec' => $spec];
  353. }
  354. }
  355. return $result;
  356. };
  357. $merch_spector = function ($mchid, $quality) {
  358. $model_merchant = Model('merchant');
  359. $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => $quality])->select();
  360. $result = [];
  361. foreach ($items as $item) {
  362. $card_types = explode(',', $item['card_types']);
  363. foreach ($card_types as $card_type) {
  364. $value['spec'] = intval($item['spec']);
  365. $result["{$card_type}-{$value['spec']}"] = ['card_type' => $card_type,
  366. 'spec' => intval($item['spec']),
  367. 'price' => $item['price'],
  368. 'extra_price' => $item['extra_price'],
  369. 'max_inprice' => $item['max_inprice']
  370. ];
  371. }
  372. }
  373. return $result;
  374. };
  375. $all_cardtype_specs = $all_spector($quality);
  376. $merch_cardtype_specs = $merch_spector($mchid, $quality);
  377. $merger = function ($all_specs, $mech_specs) {
  378. $result = [];
  379. foreach ($all_specs as $cardtype_spec => $value) {
  380. $card_name = $this->scard_type($value['card_type']);
  381. $data = [];
  382. $data['goods_name'] = $card_name;
  383. $data['card_type'] = $value['card_type'];
  384. $data['spec'] = $value['spec'];
  385. if (array_key_exists($cardtype_spec, $mech_specs)) {
  386. $data['price'] = $mech_specs[$cardtype_spec]['price'];
  387. $data['extra_price'] = $mech_specs[$cardtype_spec]['extra_price'];
  388. $data['max_inprice'] = $mech_specs[$cardtype_spec]['max_inprice'];
  389. } else {
  390. $data['price'] = 0;
  391. $data['extra_price'] = 0;
  392. $data['max_inprice'] = 0;
  393. }
  394. $result[$value['card_type']][] = $data;
  395. }
  396. return $result;
  397. };
  398. return $merger($all_cardtype_specs, $merch_cardtype_specs);
  399. }
  400. public function check_merchantOp()
  401. {
  402. $mchid = trim($_GET['mchid']);
  403. if (!$mchid) {
  404. echo '';
  405. die;
  406. }
  407. $model_merchant = Model('merchant');
  408. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*');
  409. if (empty($merchant_info)) {
  410. echo '';
  411. die;
  412. }
  413. echo 'true';
  414. }
  415. /**
  416. * ajax操作
  417. */
  418. public function ajaxOp()
  419. {
  420. $model_merchant = Model('merchant');
  421. switch ($_GET['branch']) {
  422. /**
  423. * 验证机构名称是否重复
  424. */
  425. case 'check_mch_name':
  426. $condition['name'] = $_GET['name'];
  427. $list = $model_merchant->getMerchantInfo($condition);
  428. if (empty($list)) {
  429. echo 'true';
  430. } else {
  431. echo 'false';
  432. }
  433. break;
  434. /**
  435. * 验证机构是否存在
  436. */
  437. case 'check_merchant':
  438. $condition['mchid'] = intval($_GET['mchid']);
  439. $list = $model_merchant->getMerchantInfo($condition);
  440. if (!empty($list)) {
  441. echo 'true';
  442. } else {
  443. echo 'false';
  444. }
  445. }
  446. }
  447. public function check_evidenceOp()
  448. {
  449. $status = $_GET['status'];
  450. $apply_id = intval($_GET['apply_id']);
  451. if ($apply_id > 0) {
  452. $model_merchant = Model('merchant');
  453. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
  454. if (empty($evidence_info)) {
  455. showMessage('充值申请不存在');
  456. }
  457. if ($status == 'pass') {
  458. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
  459. } elseif ($status == 'unpass') {
  460. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
  461. } else {
  462. showMessage('审核类型错误');
  463. }
  464. }
  465. showMessage(L('nc_common_save_succ'), urlAdmin('refill_evidence', 'index'));
  466. }
  467. //处理充值申请
  468. public function rechargeOp()
  469. {
  470. if (chksubmit()) {
  471. $mchid = $this->add_money();
  472. $model_merchant = Model('merchant');
  473. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  474. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  475. //更新预警短信通知限制
  476. $mch_cache = rcache("merchant-notify", 'refill-');
  477. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  478. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  479. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  480. }
  481. showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
  482. } else {
  483. $apply_id = $_GET['apply_id'];
  484. if (!empty($apply_id)) {
  485. $model_merchant = Model('merchant');
  486. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*,member.available_predeposit');
  487. Tpl::output('apply_id', $apply_id);
  488. Tpl::output('amount', $evidence_info['amount']);
  489. Tpl::output('available_predeposit', $evidence_info['available_predeposit']);
  490. }
  491. global $config;
  492. Tpl::output('receive_bank', $config['receive_bank'][COMPANY_NAME]);
  493. Tpl::showpage('recharge.add');
  494. }
  495. }
  496. public function recharge_manualOp()
  497. {
  498. $type = $_GET['type'] ?? $_POST['type'];
  499. if (chksubmit()) {
  500. $add_type = '';
  501. $obj_validate = new Validator();
  502. if ($type == 'add') {
  503. $add_type = '加款';
  504. $obj_validate->validateparam = [
  505. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  506. ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
  507. ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
  508. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空'],
  509. ["input" => $_POST["receive_bank"], "require" => "true", "message" => '请选择收款银行']
  510. ];
  511. } elseif ($type == 'edit') {
  512. $add_type = '调款';
  513. $obj_validate->validateparam = [
  514. ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
  515. ["input" => $_POST["bank_username"], "require" => "true", "message" => '操作人姓名不能为空'],
  516. ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
  517. ];
  518. }
  519. $operatetype = $_POST['operatetype'];
  520. $error = $obj_validate->validate();
  521. if ($error != '') {
  522. showMessage($error);
  523. }
  524. $mchid = $_POST["mch_id"];
  525. $model_merchant = Model('merchant');
  526. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  527. if (!$merchant_info) {
  528. showMessage('对应机构不存在');
  529. }
  530. $pointsnum = $_POST['pointsnum'];
  531. $money = abs($pointsnum);
  532. if ($money == 0) {
  533. showMessage('预存金额错误');
  534. }
  535. if (!empty($_FILES['voucher']['name'])) {
  536. $upload = new UploadFile();
  537. $upload->set('default_dir', ATTACH_UPFILE);
  538. $result = $upload->upfile('voucher');
  539. if ($result) {
  540. $_POST['voucher_name'] = $upload->file_name;
  541. } else {
  542. showMessage($upload->error);
  543. }
  544. }
  545. try {
  546. $model_merchant = Model('merchant');
  547. $trans = new trans_wapper($model_merchant, __METHOD__);
  548. $member_id = $merchant_info['admin_id'];
  549. if ($operatetype == 'add') {
  550. $bz = "管理员{$add_type}操作,手动增加预存金额";
  551. $this->credit_save_money($money, 'add', $member_id, $bz);
  552. $_POST['pointsnum'] = $money;
  553. } elseif ($operatetype == 'del') {
  554. $bz = "管理员{$add_type}操作,手动减少预存金额";
  555. $this->credit_save_money($money, 'del', $member_id, $bz);
  556. $_POST['pointsnum'] = -($money);
  557. } else {
  558. showMessage('预存类型错误');
  559. }
  560. $result = $this->ct_refill_evidence($_POST, $merchant_info);
  561. if (!$result) {
  562. $trans->rollback();
  563. showMessage('操作失败', 'index.php?act=merchant&op=merchant');
  564. }
  565. $trans->commit();
  566. if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
  567. //更新预警短信通知限制
  568. $mch_cache = rcache("merchant-notify", 'refill-');
  569. $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
  570. $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
  571. wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
  572. }
  573. showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
  574. } catch (Exception $e) {
  575. $trans->rollback();
  576. showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
  577. }
  578. } else {
  579. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  580. $model_merchant = Model('merchant');
  581. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  582. if (empty($merchant)) {
  583. showMessage('机构信息有误');
  584. }
  585. Tpl::output('merchant', $merchant);
  586. global $config;
  587. Tpl::output('receive_bank', $config['receive_bank'][COMPANY_NAME]);
  588. $page = "recharge.manual.{$type}";
  589. Tpl::showpage($page);
  590. }
  591. }
  592. private function ct_refill_evidence($params, $merchant_info)
  593. {
  594. $admininfo = $this->getAdminInfo();
  595. $mem_info = Model('member')->getMemberInfo(['member_id' => $merchant_info['admin_id']]);
  596. $input['mchid'] = $merchant_info['mchid'];
  597. $input['mch_name'] = $merchant_info['name'];
  598. $input['member_id'] = $merchant_info['admin_id'];
  599. $input['amount'] = $params['pointsnum'];
  600. $input['bank_username'] = $params['bank_username'];
  601. $input['bank_name'] = $params['bank_name'] ?? '';
  602. $input['bz'] = $params['pointsdesc'];
  603. $input['voucher_name'] = $params['voucher_name'] ?? '/';
  604. $input['status'] = 2;
  605. $input['is_operation'] = 2;
  606. $input['add_time'] = $input['check_time'] = time();
  607. $input['after_available'] = ncPriceFormat($mem_info['available_predeposit'] + $params['pointsnum']);
  608. $input['admin_name'] = $admininfo['name'];
  609. $input['admin_id'] = $admininfo['id'];
  610. $input['add_type'] = $params['add_type'];
  611. $input['receive_bank'] = $params['receive_bank'] ?? 0;
  612. if ($params['type'] == 'add') {
  613. $input['is_bank'] = 1;
  614. }
  615. $model_merchant = Model('merchant');
  616. return $model_merchant->addRefillEvidence($input);
  617. }
  618. public function add_money()
  619. {
  620. $obj_validate = new Validator();
  621. $obj_validate->validateparam = [
  622. ["input" => $_POST["apply_id"], "require" => "true", "message" => Language::get('admin_points_member_error_again')],
  623. ["input" => $_POST["pointsnum"], "require" => "true", 'validator' => 'Compare', 'operator' => ' >= ', 'to' => 1, "message" => Language::get('admin_points_points_min_error')],
  624. ["input" => $_POST["receive_bank"], "require" => "true", "message" => '请选择收款银行']
  625. ];
  626. $error = $obj_validate->validate();
  627. if ($error != '') {
  628. showMessage($error, '', '', 'error');
  629. }
  630. $money = abs(floatval($_POST['pointsnum']));
  631. $memo = trim($_POST['pointsdesc']);
  632. if ($money <= 0) {
  633. showMessage('输入的金额必需大于0', '', 'html', 'error');
  634. }
  635. $apply_id = intval($_POST['apply_id']);
  636. $model_merchant = Model('merchant');
  637. $receive_bank = $_POST['receive_bank'] ?? 0;
  638. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
  639. if (!is_array($evidence_info) || count($evidence_info) <= 0) {
  640. showMessage("无效的充值申请信息", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  641. }
  642. if ($evidence_info['status'] != 2) {
  643. showMessage("该充值申请未被审核通过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  644. }
  645. if ($evidence_info['is_operation'] == 2) {
  646. showMessage("该充值申请未已被预存过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
  647. }
  648. //查询会员信息
  649. $obj_member = Model('member');
  650. $member_id = intval($evidence_info['member_id']);
  651. $member_info = $obj_member->getMemberInfo(['member_id' => $member_id], '*', true);
  652. $available_predeposit = floatval($member_info['available_predeposit']);
  653. $freeze_predeposit = floatval($member_info['freeze_predeposit']);
  654. if ($_POST['operatetype'] == 3 && $money > $available_predeposit) {
  655. showMessage(('可冻结预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  656. }
  657. if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit) {
  658. showMessage(('可恢复冻结预存款不足,会员当前冻结预存款') . $freeze_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
  659. }
  660. $model_pd = Model('predeposit');
  661. $order_sn = $apply_id;
  662. $admininfo = $this->getAdminInfo();
  663. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
  664. $admin_act = 'sys_add_money';
  665. switch ($_POST['operatetype']) {
  666. case 1:
  667. $admin_act = "sys_add_money";
  668. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
  669. break;
  670. case 2:
  671. $admin_act = "sys_del_money";
  672. $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
  673. break;
  674. default:
  675. showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
  676. break;
  677. }
  678. try {
  679. $trans = new trans_wapper($model_pd, __METHOD__);
  680. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true,true);
  681. if ($evidence_info['is_operation'] == 2) {
  682. $trans->commit();
  683. showMessage('已经处理', 'index.php?act=refill_evidence&op=index', 'html', 'error');
  684. }
  685. //扣除冻结的预存款
  686. $data = [];
  687. $data['member_id'] = $member_info['member_id'];
  688. $data['member_name'] = $member_info['member_name'];
  689. $data['amount'] = $money;
  690. $data['order_sn'] = $order_sn;
  691. $data['admin_name'] = $admininfo['name'];
  692. $data['pdr_sn'] = $order_sn;
  693. $data['lg_desc'] = $memo;
  694. $isRefill = $model_pd->isRefill($data['member_id']);
  695. $model_pd->changePd($admin_act, $data,$isRefill);
  696. $after_available = ncPriceFormat($available_predeposit + $evidence_info['amount']);
  697. $model_merchant->editRefillEvidence(
  698. ['apply_id' => $apply_id],
  699. [
  700. 'is_operation' => 2, 'after_available' => $after_available,
  701. 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'],
  702. 'receive_bank' => $receive_bank
  703. ]
  704. );
  705. $trans->commit();
  706. $this->log($log_msg, 1);
  707. return $evidence_info['mchid'];
  708. } catch (Exception $e) {
  709. $trans->rollback();
  710. $this->log($log_msg, 0);
  711. showMessage($e->getMessage(), 'index.php?act=refill_evidence&op=index', 'html', 'error');
  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. $cond = [
  975. 'type' => $stats_data['type'],
  976. 'time_stamp' => $stats_data['time_stamp'],
  977. 'cid' => $stats_data['cid'],
  978. 'order_time_type' => $stats_data['order_time_type']
  979. ];
  980. $manager = new task\manager();
  981. $task = $manager->add_task('order_stat_reload',$cond,0,3600);
  982. if ($task->completed() && $task->success()) {
  983. showMessage('操作成功');
  984. } else {
  985. showMessage("操作成功,后台任务已开始重新统计,请稍后查看新数据");
  986. }
  987. }
  988. public function merchant_ctlOp()
  989. {
  990. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  991. $model_merchant = Model('merchant');
  992. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
  993. if (empty($merchant)) {
  994. showMessage('机构信息有误');
  995. }
  996. $qualitys = [
  997. refill\Quality::Normal, refill\Quality::Quick, refill\Quality::CardKey, refill\Quality::ThirdShop,
  998. refill\Quality::SlowTwentyFour, refill\Quality::SlowSix, refill\Quality::SlowTwo, refill\Quality::SlowFortyEight,
  999. refill\Quality::SlowSeventyTwo, refill\Quality::Fastest
  1000. ];
  1001. if(chksubmit())
  1002. {
  1003. $intercept_data = function (){
  1004. $intercept_cfg['is_transfer'] = intval($_POST['is_transfer']) === 1;
  1005. if (!empty($_POST['card_states'])) {
  1006. foreach ($_POST['card_states'] as $card_state)
  1007. {
  1008. $card_states[] = intval($card_state);
  1009. }
  1010. $intercept_cfg['card_states'] = $card_states;
  1011. }
  1012. if (!empty($_POST['card_types'])) {
  1013. foreach ($_POST['card_types'] as $card_type)
  1014. {
  1015. $card_types[] = intval($card_type);
  1016. }
  1017. $intercept_cfg['card_types'] = $card_types;
  1018. }
  1019. return serialize($intercept_cfg);
  1020. };
  1021. $retry_times_data = function ($qualitys){
  1022. $qualities = [];
  1023. foreach ($qualitys as $quality) {
  1024. $quality = intval($quality);
  1025. $day_secs_key = "{$quality}-day_secs";
  1026. $night_secs_key = "{$quality}-night_secs";
  1027. $times_key = "{$quality}-times";
  1028. if(!empty($_POST[$day_secs_key]) && !empty($_POST[$night_secs_key]) && !empty($_POST[$times_key])) {
  1029. $qualities[$quality] = ['day_secs' => intval($_POST[$day_secs_key]), 'night_secs' => intval($_POST[$night_secs_key]), 'times' => intval($_POST[$times_key])];
  1030. }
  1031. }
  1032. $retry_times_cfg['qualities'] = $qualities;
  1033. $ratio = floatval($_POST['ratio']) ?? 0;
  1034. $period = intval($_POST['period']) ?? 0;
  1035. $profit_ratio = floatval($_POST['profit_ratio']) ?? 0;
  1036. $retry_times_cfg['lower_ratio'] = ['ratio' => $ratio, 'period' => $period];
  1037. $retry_times_cfg['profit_ratio'] = $profit_ratio;
  1038. return serialize($retry_times_cfg);
  1039. };
  1040. $update['quality'] = intval($_POST['quality']);
  1041. $update['oil_quality'] = intval($_POST['oil_quality']);
  1042. $update['intercept_cfg'] = $intercept_data();
  1043. $update['retry_times_cfg'] = $retry_times_data($qualitys);
  1044. $resp = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  1045. if ($resp) {
  1046. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  1047. } else {
  1048. showMessage('操作失败');
  1049. }
  1050. }
  1051. else
  1052. {
  1053. foreach ($qualitys as $value) {
  1054. $quality[$value] = $this->quality_format($value,mtopcard\ChinaMobileCard);
  1055. }
  1056. Tpl::output('intercept', $this->merchant_intercept($merchant));
  1057. Tpl::output('retry_times', $this->merchant_retry_times($merchant));
  1058. Tpl::output('merchant', $merchant);
  1059. Tpl::output('quality', $quality);
  1060. Tpl::output('card_state', mtopcard\CardState);
  1061. Tpl::showpage('merchant.ctl');
  1062. }
  1063. }
  1064. private function merchant_intercept($merchant)
  1065. {
  1066. $intercept_cfg = $merchant['intercept_cfg'];
  1067. if (empty($intercept_cfg)) {
  1068. $intercept_cfg = ['card_states' => [], 'is_transfer' => 0];
  1069. } else {
  1070. $intercept_cfg = unserialize($intercept_cfg);
  1071. }
  1072. return $intercept_cfg;
  1073. }
  1074. private function merchant_retry_times($merchant)
  1075. {
  1076. $retry_times_cfg = $merchant['retry_times_cfg'];
  1077. if (empty($retry_times_cfg)) {
  1078. $retry_times_cfg = [];
  1079. } else {
  1080. $retry_times_cfg = unserialize($retry_times_cfg);
  1081. }
  1082. return $retry_times_cfg;
  1083. }
  1084. }