merchant.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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. $model_merchant = Model('merchant');
  77. $model_member = Model('member');
  78. $trans = new trans_wapper($model_merchant, __METHOD__);
  79. try
  80. {
  81. $name = trim($_POST['name']);
  82. $company_name = trim($_POST['company_name']);
  83. $pwd = trim($_POST['password']);
  84. $alarm_amount = $_POST['alarm_amount'] ?? 0;
  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. $update['manual_recharge'] = $_POST['manual_recharge'];
  158. $day_timeout = intval($_POST['day_timeout']);
  159. $night_timeout = intval($_POST['night_timeout']);
  160. if($day_timeout <= 0) {
  161. $day_timeout = 180;
  162. }
  163. if($night_timeout <= 0) {
  164. $day_timeout = 180;
  165. }
  166. $update['day_timeout'] = $day_timeout;
  167. $update['night_timeout'] = $night_timeout;
  168. if(refill\functional::isDay()) {
  169. $update['time_out'] = intval($_POST['day_timeout']);
  170. } else {
  171. $update['time_out'] = intval($_POST['night_timeout']);
  172. }
  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. break;
  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. }
  447. }
  448. public function check_evidenceOp()
  449. {
  450. $status = $_GET['status'];
  451. $apply_id = intval($_GET['apply_id']);
  452. if ($apply_id > 0) {
  453. $model_merchant = Model('merchant');
  454. $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
  455. if (empty($evidence_info)) {
  456. showMessage('充值申请不存在');
  457. }
  458. if ($status == 'pass') {
  459. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
  460. } elseif ($status == 'unpass') {
  461. $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
  462. } else {
  463. showMessage('审核类型错误');
  464. }
  465. }
  466. showMessage(L('nc_common_save_succ'), urlAdmin('refill_evidence', 'index'));
  467. }
  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', true);
  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. $trans = new trans_wapper($model_merchant, __METHOD__);
  547. try {
  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. $trans = new trans_wapper($model_pd, __METHOD__);
  679. try {
  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, 'order_state' => ORDER_STATE_SEND]);
  751. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0, 'is_retrying' => 0]);
  752. if (empty($refill_info) || empty($order_info)) {
  753. showMessage('订单不存在,或不符合条件');
  754. }
  755. $fetch_order_ids = $this->check_fetch_order($order_id);
  756. if (in_array($order_id, $fetch_order_ids)) {
  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. $this->manual_log_record($refill_info, $type);
  767. showMessage('操作成功');
  768. }
  769. private function manual_log_record($order, $oper_type)
  770. {
  771. $admininfo = $this->getAdminInfo();
  772. $cur_time = time();
  773. $bz = "手动处理订单,操作者:{$admininfo['name']}";
  774. $ins = [
  775. 'order_id' => $order['order_id'], 'order_sn' => $order['order_sn'],'order_time' => $order['order_time'], 'notify_time' => $order['notify_time'],
  776. 'manual_type' => $oper_type, 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'], 'act_time' => $cur_time, 'bz' => $bz
  777. ];
  778. Model('refill_buyback')->insert($ins);
  779. }
  780. public function provider_provinceOp()
  781. {
  782. $provider_model = Model('refill_provider');
  783. $provider_id = $_GET['id'] ?? $_POST['id'];
  784. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  785. if (empty($provider)) {
  786. showMessage('通道信息有误');
  787. }
  788. $operator = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
  789. if (chksubmit()) {
  790. foreach ($operator as $opr) {
  791. $key = $opr . '-province';
  792. $province = $_POST[$key];
  793. if ($province == -1) {
  794. $updata[$opr] = -1;
  795. } else {
  796. $updata[$opr] = implode(',', $province);
  797. }
  798. }
  799. $resp = $provider_model->editProvider(['provinces' => serialize($updata)], ['provider_id' => $provider_id]);
  800. if ($resp) {
  801. showMessage('编辑成功', 'index.php?act=provider&op=index');
  802. } else {
  803. showMessage('编辑失败', "index.php?act=merchant&op=provider_province&id={$provider_id}");
  804. }
  805. } else {
  806. $data = unserialize($provider['provinces']);
  807. $provinces = [];
  808. foreach ($operator as $opr) {
  809. if (empty($data)) {
  810. $provinces[$opr] = [-1];
  811. } else {
  812. $provinces[$opr] = explode(',', $data[$opr]);
  813. }
  814. }
  815. $province_list = mtopcard\ProvinceList;
  816. Tpl::output('province_list', $province_list);
  817. Tpl::output('provider', $provider);
  818. Tpl::output('provinces', $provinces);
  819. Tpl::showpage('provider.province');
  820. }
  821. }
  822. public function changeProviderStateOp()
  823. {
  824. $provider_id = intval($_GET['id']);
  825. $state = intval($_GET['state']);
  826. $provider_model = Model('refill_provider');
  827. $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  828. if (empty($provider_info) || !in_array($state, [1, 2])) {
  829. showMessage('操作成功', 'index.php?act=provider&op=index');
  830. }
  831. $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
  832. if (!$resp) {
  833. showMessage('操作失败', 'index.php?act=provider&op=index', 'html', 'error');
  834. }
  835. showMessage('操作成功', 'index.php?act=provider&op=index');
  836. }
  837. /**
  838. * 新增通道
  839. */
  840. public function provider_addOp()
  841. {
  842. $provider_model = Model('refill_provider');
  843. if (chksubmit()) {
  844. $params = $_POST;
  845. unset($params['form_submit']);
  846. $result = $provider_model->addProvider($params);
  847. if ($result) {
  848. $url = [
  849. [
  850. 'url' => 'index.php?act=provider&op=index',
  851. 'msg' => '返回通道列表',
  852. ],
  853. [
  854. 'url' => 'index.php?act=merchant&op=provider_add',
  855. 'msg' => '继续新增通道',
  856. ],
  857. ];
  858. $this->log('添加通道:' . '[ ' . $_POST['name'] . ']', 1);
  859. showMessage('通道添加成功', $url);
  860. } else {
  861. showMessage('通道添加失败');
  862. }
  863. }
  864. Tpl::showpage('provider.add');
  865. }
  866. public function provider_editOp()
  867. {
  868. $provider_model = Model('refill_provider');
  869. if (chksubmit()) {
  870. $provider_id = intval($_POST['provider_id']) ?? '';
  871. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  872. if (empty($provider)) {
  873. showMessage('通道信息有误');
  874. }
  875. $params = $_POST;
  876. unset($params['form_submit']);
  877. if (empty($params)) {
  878. showMessage('通道编辑成功', 'index.php?act=provider&op=index');
  879. }
  880. $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
  881. if ($result) {
  882. $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
  883. showMessage('通道编辑成功', 'index.php?act=provider&op=index');
  884. } else {
  885. showMessage('通道编辑失败', "index.php?act=merchant&op=provider_edit&id={$provider_id}");
  886. }
  887. }
  888. $provider_id = intval($_GET['id']) ?? '';
  889. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  890. if (empty($provider)) {
  891. showMessage('通道信息有误');
  892. }
  893. $type_text = ['油卡', '手机充值卡'];
  894. Tpl::output('type_text', $type_text);
  895. Tpl::output('provider', $provider);
  896. Tpl::showpage('provider.edit');
  897. }
  898. public function provider_delOp()
  899. {
  900. $provider_model = Model('refill_provider');
  901. $provider_id = intval($_GET['id']) ?? '';
  902. $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
  903. if (empty($provider)) {
  904. showMessage('通道信息有误');
  905. }
  906. $result = $provider_model->delProvider(['provider_id' => $provider_id]);
  907. if ($result) {
  908. $this->log('删除通道:' . '[ ' . $provider['name'] . ']', 1);
  909. showMessage('通道删除成功', 'index.php?act=provider&op=index');
  910. } else {
  911. showMessage('通道删除失败', "index.php?act=provider&op=index");
  912. }
  913. }
  914. public function OrderStatsCheckOp()
  915. {
  916. $stat_id = $_GET['stat_id'] ?? $_POST['stat_id'];
  917. $mod_stat = Model('refill_stats');
  918. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  919. if (empty($stats_data)) {
  920. showMessage('对应数据不存在', '');
  921. }
  922. $type = $stats_data['type'];
  923. if (chksubmit()) {
  924. $corder_success_count = $_POST['corder_success_count'] ?? 0;
  925. $corder_success_amounts = $_POST['corder_success_amounts'] ?? 0;
  926. $corder_success_refill_amounts = $_POST['corder_success_refill_amounts'] ?? 0;
  927. $refund = $_POST['refund'] ?? 0;
  928. $remark = $_POST['remark'];
  929. $gap_order_count = $gap_success_amounts = $gap_success_refill_amounts = 0;
  930. if ($type == 'provider') {
  931. if (!empty($corder_success_amounts)) {
  932. $gap_success_amounts = $corder_success_amounts - $stats_data['success_channel_amounts'];
  933. }
  934. if (!empty($corder_success_count)) {
  935. $gap_order_count = $corder_success_count - $stats_data['success_count'];
  936. }
  937. } elseif ($type == 'merchant') {
  938. if (!empty($corder_success_count)) {
  939. $gap_order_count = $stats_data['success_count'] - $corder_success_count;
  940. }
  941. if (!empty($corder_success_amounts)) {
  942. $gap_success_amounts = $stats_data['success_channel_amounts'] - $corder_success_amounts;
  943. }
  944. } else {
  945. showMessage('对账数据类型错误', 'index.php?act=OrderStats&op=index');
  946. }
  947. if (!empty($corder_success_refill_amounts)) {
  948. $gap_success_refill_amounts = $corder_success_refill_amounts - $stats_data['success_refill_amounts'];
  949. }
  950. $updata['corder_success_count'] = $corder_success_count;
  951. $updata['corder_success_amounts'] = $corder_success_amounts;
  952. $updata['corder_success_refill_amounts'] = $corder_success_refill_amounts;
  953. $updata['gap_order_count'] = $gap_order_count;
  954. $updata['gap_success_amounts'] = $gap_success_amounts;
  955. $updata['gap_success_refill_amounts'] = $gap_success_refill_amounts;
  956. $updata['remark'] = $remark;
  957. $updata['refund'] = $refund;
  958. if (!empty($corder_success_count) && !empty($corder_success_amounts) && !empty($corder_success_refill_amounts)) {
  959. if ($gap_order_count == 0 && $gap_success_amounts == 0 && $gap_success_refill_amounts == 0) {
  960. $updata['check_status'] = 1;
  961. } else {
  962. $updata['check_status'] = 2;
  963. }
  964. }
  965. $res = $mod_stat->edit($stat_id, $updata);
  966. if ($res) {
  967. showMessage('操作成功', "index.php?act=OrderStats&op=index&type={$type}&cid={$stats_data['cid']}&order_time_type={$stats_data['order_time_type']}");
  968. } else {
  969. showMessage('操作失败');
  970. }
  971. } else {
  972. $type_text = ['provider' => '上游', 'merchant' => '商户'];
  973. Tpl::output('stats_type', $type_text[$type]);
  974. Tpl::output('stats_data', $stats_data);
  975. Tpl::showpage('order.stats.check');
  976. }
  977. }
  978. public function OrderStatsReloadOp()
  979. {
  980. $stat_id = $_GET['stat_id'];
  981. $mod_stat = Model('refill_stats');
  982. $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
  983. if (empty($stats_data)) {
  984. showMessage('对应数据不存在', '');
  985. }
  986. $cond = [
  987. 'type' => $stats_data['type'],
  988. 'time_stamp' => $stats_data['time_stamp'],
  989. 'cid' => $stats_data['cid'],
  990. 'order_time_type' => $stats_data['order_time_type']
  991. ];
  992. $manager = new task\manager();
  993. $task = $manager->add_task('order_stat_reload',$cond,0,3600);
  994. if ($task->completed() && $task->success()) {
  995. showMessage('操作成功');
  996. } else {
  997. showMessage("操作成功,后台任务已开始重新统计,请稍后查看新数据");
  998. }
  999. }
  1000. public function merchant_ctlOp()
  1001. {
  1002. $mchid = $_GET['mchid'] ?? $_POST['mchid'];
  1003. $model_merchant = Model('merchant');
  1004. $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
  1005. if (empty($merchant)) {
  1006. showMessage('机构信息有误');
  1007. }
  1008. $qualitys = [
  1009. refill\Quality::Normal, refill\Quality::Quick, refill\Quality::CardKey, refill\Quality::ThirdShop,
  1010. refill\Quality::SlowTwentyFour, refill\Quality::SlowSix, refill\Quality::SlowTwo, refill\Quality::SlowFortyEight,
  1011. refill\Quality::SlowSeventyTwo, refill\Quality::Fastest
  1012. ];
  1013. if(chksubmit())
  1014. {
  1015. $intercept_data = function (){
  1016. $intercept_cfg['is_transfer'] = intval($_POST['is_transfer']) === 1;
  1017. if (!empty($_POST['card_states'])) {
  1018. foreach ($_POST['card_states'] as $card_state)
  1019. {
  1020. $card_states[] = intval($card_state);
  1021. }
  1022. $intercept_cfg['card_states'] = $card_states;
  1023. }
  1024. if (!empty($_POST['card_types'])) {
  1025. foreach ($_POST['card_types'] as $card_type)
  1026. {
  1027. $card_types[] = intval($card_type);
  1028. }
  1029. $intercept_cfg['card_types'] = $card_types;
  1030. }
  1031. return serialize($intercept_cfg);
  1032. };
  1033. $retry_times_data = function ($qualitys){
  1034. $qualities = [];
  1035. foreach ($qualitys as $quality) {
  1036. $quality = intval($quality);
  1037. $day_secs_key = "{$quality}-day_secs";
  1038. $night_secs_key = "{$quality}-night_secs";
  1039. $times_key = "{$quality}-times";
  1040. if(!empty($_POST[$day_secs_key]) && !empty($_POST[$night_secs_key]) && !empty($_POST[$times_key])) {
  1041. $qualities[$quality] = ['day_secs' => intval($_POST[$day_secs_key]), 'night_secs' => intval($_POST[$night_secs_key]), 'times' => intval($_POST[$times_key])];
  1042. }
  1043. }
  1044. $retry_times_cfg['qualities'] = $qualities;
  1045. $ratio = floatval($_POST['ratio']) ?? 0;
  1046. $period = intval($_POST['period']) ?? 0;
  1047. $profit_ratio = floatval($_POST['profit_ratio']) ?? 0;
  1048. $retry_times_cfg['lower_ratio'] = ['ratio' => $ratio, 'period' => $period];
  1049. $retry_times_cfg['profit_ratio'] = $profit_ratio;
  1050. $profit_formula = $_POST['profit_formula'] ?? '';
  1051. $retry_times_cfg['profit_formula'] = $profit_formula;
  1052. return serialize($retry_times_cfg);
  1053. };
  1054. $update['quality'] = intval($_POST['quality']);
  1055. $update['oil_quality'] = intval($_POST['oil_quality']);
  1056. $update['intercept_cfg'] = $intercept_data();
  1057. $update['retry_times_cfg'] = $retry_times_data($qualitys);
  1058. $resp = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
  1059. if ($resp) {
  1060. showMessage('操作成功', 'index.php?act=merchant&op=merchant');
  1061. } else {
  1062. showMessage('操作失败');
  1063. }
  1064. }
  1065. else
  1066. {
  1067. foreach ($qualitys as $value) {
  1068. $quality[$value] = $this->quality_format($value,mtopcard\ChinaMobileCard);
  1069. }
  1070. Tpl::output('intercept', $this->merchant_intercept($merchant));
  1071. Tpl::output('retry_times', $this->merchant_retry_times($merchant));
  1072. Tpl::output('merchant', $merchant);
  1073. Tpl::output('quality', $quality);
  1074. Tpl::output('card_state', mtopcard\CardState);
  1075. Tpl::showpage('merchant.ctl');
  1076. }
  1077. }
  1078. private function merchant_intercept($merchant)
  1079. {
  1080. $intercept_cfg = $merchant['intercept_cfg'];
  1081. if (empty($intercept_cfg)) {
  1082. $intercept_cfg = ['card_states' => [], 'is_transfer' => 0];
  1083. } else {
  1084. $intercept_cfg = unserialize($intercept_cfg);
  1085. }
  1086. return $intercept_cfg;
  1087. }
  1088. private function merchant_retry_times($merchant)
  1089. {
  1090. $retry_times_cfg = $merchant['retry_times_cfg'];
  1091. if (empty($retry_times_cfg)) {
  1092. $retry_times_cfg = [];
  1093. } else {
  1094. $retry_times_cfg = unserialize($retry_times_cfg);
  1095. }
  1096. return $retry_times_cfg;
  1097. }
  1098. }