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