123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329 |
- <?php
- /**
- * 机构管理界面
- *
- **by 好商城V3 www.33hao.com 运营版*/
- defined('InShopNC') or exit('Access Invalid!');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
- require_once(BASE_HELPER_PATH . '/stat_helper.php');
- class merchantControl extends SystemControl
- {
- const EXPORT_SIZE = 1000;
- public function __construct()
- {
- parent::__construct();
- Language::read('merchant');
- }
- /**
- * 机构列表
- */
- public function merchantOp()
- {
- $model_merchant = Model('merchant');
- if (trim($_GET['merchant_name']) != '') {
- $condition['company_name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
- }
- $merchant_list = $model_merchant->getMerchantList($condition, 100, 'available_predeposit desc,merchant_state asc,mchid desc', true);
- foreach ($merchant_list as $key => $merchant) {
- $merchant_list[$key]['available_predeposit'] = $merchant['available_predeposit'] - $merchant['credit_bonus'];
- }
- $merchant_state_text = ['使用中', '已禁用'];
- Tpl::output('merchant_state_text', $merchant_state_text);
- Tpl::output('merchant_list', $merchant_list);
- Tpl::output('page', $model_merchant->showpage('2'));
- Tpl::showpage('merchant.index');
- }
- public function changeStateOp()
- {
- $mchid = intval($_GET['mchid']);
- $state = intval($_GET['state']);
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
- if (empty($merchant_info) || !in_array($state, [1, 2])) {
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- }
- $resp = $model_merchant->editMerchant(['merchant_state' => $state], ['mchid' => $mchid]);
- if (!$resp) {
- showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
- }
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- }
- /**
- * 新增机构
- */
- public function merchant_addOp()
- {
- if (chksubmit()) {
- /**
- * 验证
- */
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => $_POST["name"], "require" => "true", "message" => '机构账号不能为空'],
- ["input" => $_POST["company_name"], "require" => "true", "message" => '机构公司名称不能为空'],
- ["input" => $_POST["password"], "require" => "true", "message" => '密码不能为空']
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- } else {
- $name = trim($_POST['name']);
- $company_name = trim($_POST['company_name']);
- $pwd = trim($_POST['password']);
- $alarm_amount = $_POST['alarm_amount'] ?? 0;
- $model_merchant = Model('merchant');
- $model_member = Model('member');
- try {
- $trans = new trans_wapper($model_merchant, __METHOD__);
- $insert_member['member_name'] = md5($name . time());
- $insert_member['member_passwd'] = $pwd;
- $insert_id = $model_member->addMember($insert_member);
- if ($insert_id == false) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
- }
- $insert_array['name'] = $name;
- $insert_array['company_name'] = $company_name;
- $insert_array['org_pwd'] = $pwd;
- $insert_array['password'] = md5($pwd);
- $insert_array['admin_id'] = trim($insert_id);
- $insert_array['alarm_amount'] = $alarm_amount;
- $result = $model_merchant->addMerchant($insert_array);
- if ($result) {
- $url = [
- [
- 'url' => 'index.php?act=merchant&op=merchant',
- 'msg' => '返回机构列表',
- ],
- [
- 'url' => 'index.php?act=merchant&op=merchant_add',
- 'msg' => '继续新增机构',
- ],
- ];
- $this->log('添加机构:' . '[ ' . $_POST['name'] . ']', 1);
- showMessage('机构添加成功', $url);
- } else {
- showMessage('机构添加失败');
- }
- $trans->commit();
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
- }
- }
- }
- Tpl::showpage('merchant.add');
- }
- public function merchant_editOp()
- {
- $mchid = $_GET['mchid'] ?? $_POST['mchid'];
- $model_merchant = Model('merchant');
- $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
- if (empty($merchant)) {
- showMessage('机构信息有误');
- }
- if (chksubmit()) {
- $update_credit_bonus = ncPriceFormat($_POST['credit_bonus']);
- if ($update_credit_bonus > 0) {
- if ($merchant['credit_bonus'] + $update_credit_bonus < 0) {
- showMessage('授信金额调整后不能小于0');
- }
- $operatetype = $_POST['operatetype'];
- if ($operatetype == 'add') {
- $update['credit_bonus'] = ['exp', 'credit_bonus+' . $update_credit_bonus];
- } elseif ($operatetype == 'del') {
- $update['credit_bonus'] = ['exp', 'credit_bonus-' . $update_credit_bonus];
- }
- }
- $update['company_name'] = trim($_POST['company_name']);
- $update['org_pwd'] = trim($_POST['password']);
- $update['password'] = md5($update['org_pwd']);
- $update['alarm_amount'] = $_POST['alarm_amount'] ?? 0;
- $update['time_out'] = intval($_POST['time_out']);
- $update['quality'] = intval($_POST['quality']);
- $update['oil_quality'] = intval($_POST['oil_quality']);
- $member_id = $merchant['admin_id'];
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- if ($update_credit_bonus > 0) {
- $this->credit_save_money($update_credit_bonus, $operatetype, $member_id);
- }
- $result = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
- if (!$result) {
- $trans->rollback();
- showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
- }
- $trans->commit();
- $this->log('编辑机构:' . '[ ' . $merchant['name'] . ']', 1);
- showMessage('机构编辑成功', 'index.php?act=merchant&op=merchant');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
- }
- }
- Tpl::output('merchant', $merchant);
- Tpl::showpage('merchant.edit');
- }
- private function credit_save_money($money, $operatetype, $member_id, $bz = '')
- {
- $obj_member = Model('member');
- $member_id = intval($member_id);
- $member_info = $obj_member->getMemberInfo(['member_id' => $member_id], '*', true);
- $admininfo = $this->getAdminInfo();
- $bz = $bz == '' ? '管理员更改客户授信' : $bz;
- switch ($operatetype) {
- case 'add':
- $admin_act = "sys_add_money";
- $log_msg = "管理员【{$admininfo['name']}】操作会员{$member_id}授信:【{$member_info['member_name']}】,预存款【增加】,金额为{$money}。备注:{$bz}。";
- break;
- case 'del':
- $admin_act = "sys_del_money";
- $log_msg = "管理员【{$admininfo['name']}】操作会员{$member_id}授信:【{$member_info['member_name']}】,预存款【减少】,金额为{$money}。备注:{$bz}。";
- break;
- default:
- return [false, '调节类型错误'];
- }
- $model_pd = Model('predeposit');
- //调节预存款
- $data = [];
- $data['member_id'] = $member_info['member_id'];
- $data['member_name'] = $member_info['member_name'];
- $data['amount'] = $money;
- $data['order_sn'] = '';
- $data['admin_name'] = $admininfo['name'];
- $data['pdr_sn'] = '';
- $data['lg_desc'] = $bz;
- $isRefill = $model_pd->isRefill($data['member_id']);
- $model_pd->changePd($admin_act, $data,$isRefill);
- $this->log($log_msg, 1);
- return [true, 'success'];
- }
- public function priceOp()
- {
- $quality = $_GET['quality'] ?? 1;
- if (chksubmit()) {
- $mchid = $_POST['mchid'];
- //合并表单数据
- $card_types = $_POST['cardtype'];
- $specs = $_POST['spec'];
- $prices = $_POST['price'];
- $extra_prices = $_POST['extra_price'];
- foreach ($card_types as $key => $card_type) {
- $data['card_type'] = $card_type;
- $data['spec'] = intval($specs[$key]);
- $data['price'] = ncPriceFormat($prices[$key]);
- $data['extra_price'] = ncPriceFormat($extra_prices[$key]);
- $params[] = $data;
- }
- foreach ($params as $param) {
- if ($param['price'] > 0) {
- $insert['mchid'] = $mchid;
- $insert['spec'] = $param['spec'];
- $insert['price'] = $param['price'];
- $insert['extra_price'] = $param['extra_price'];
- $insert['card_types'] = $param['card_type'];
- $insert['quality'] = $quality;
- $inserts[] = $insert;
- }
- }
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- //删除旧费率
- $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality]);
- //更新新费率
- if (!empty($inserts)) {
- $model_merchant->insertPrices($inserts);
- }
- $trans->commit();
- showMessage('操作成功');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败');
- }
- }
- $mchid = $_GET['mchid'] ?? 0;
- $goods = $this->GoodsFormat($mchid, $quality);
- Tpl::output('goods', $goods);
- Tpl::showpage('merchant.price');
- }
- public function third_merchant_priceOp()
- {
- $mchid = $_GET['mchid'] ?? $_POST['mchid'];
- $mod = Model('thrid_refill');
- if (chksubmit()) {
- //合并表单数据
- $card_types = $_POST['cardtype'];
- $specs = $_POST['spec'];
- $prices = $_POST['price'];
- $pcodes = $_POST['pcode'];
- $quality = 1;
- $params = [];
- foreach ($card_types as $key => $card_type) {
- $data['card_type'] = $card_type;
- $data['spec'] = intval($specs[$key]);
- $data['price'] = ncPriceFormat($prices[$key]);
- $data['pcode'] = $pcodes[$key];
- $params[] = $data;
- }
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- foreach ($params as $param) {
- $insert = [];
- if ($param['price'] > 0) {
- $insert['mchid'] = $mchid;
- $insert['spec'] = $param['spec'];
- $insert['price'] = $param['price'];
- $insert['card_types'] = $param['card_type'];
- $insert['quality'] = $quality;
- $insert['pcode'] = $param['pcode'];
- }
- //删除旧费率
- $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality, 'pcode' => $param['pcode']]);
- //更新新费率
- if (!empty($insert)) {
- $model_merchant->table('merchant_price')->insert($insert);
- }
- }
- $trans->commit();
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
- }
- } else {
- $condition = [];
- if (!empty($_GET['system_code'])) {
- $condition['system_code'] = $_GET['system_code'];
- }
- if (trim($_GET['product_name']) != '') {
- $condition['product_name'] = ['like', '%' . $_GET['product_name'] . '%'];
- }
- $third_product = $mod->getProductList($condition, 30);
- $model_merchant = Model('merchant');
- $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => 1, 'card_types' => mtopcard\ThirdRefillCard])->select();
- $goods = [];
- foreach ($items as $item) {
- $goods[$item['pcode']] = $item['price'];
- }
- Tpl::output('third_product', $third_product);
- Tpl::output('goods', $goods);
- Tpl::output('page', $mod->showpage());
- Tpl::showpage('third.merchant.price');
- }
- }
- private function GoodsFormat($mchid, $quality)
- {
- $all_spector = function ($quality) {
- global $config;
- $refill_specs = $config['refill_specs'];
- $all_type_specs = [];
- foreach ($refill_specs as $scard_type => $specs) {
- if ($scard_type == 'petrochina') { //中石油
- $card_type = 1;
- } elseif ($scard_type == 'sinopec') { //中石化
- $card_type = 2;
- } elseif ($scard_type == 'chinamobile') { //中国移动
- $card_type = 4;
- } elseif ($scard_type == 'chinaunicom') { //中国联通
- $card_type = 5;
- } elseif ($scard_type == 'chinatelecom') { //中国电信
- $card_type = 6;
- } else {
- continue;
- }
- if (in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
- if ($quality == refill\Quality::Quick) {
- $specs = array_merge($config['refill_phone_small_specs'], $specs);
- }
- }
- $all_type_specs[$card_type] = $specs;
- }
- $result = [];
- foreach ($all_type_specs as $card_type => $specs) {
- foreach ($specs as $spec) {
- $result["{$card_type}-{$spec}"] = ['card_type' => $card_type, 'spec' => $spec];
- }
- }
- return $result;
- };
- $merch_spector = function ($mchid, $quality) {
- $model_merchant = Model('merchant');
- $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid, 'quality' => $quality])->select();
- $result = [];
- foreach ($items as $item) {
- $card_types = explode(',', $item['card_types']);
- foreach ($card_types as $card_type) {
- $value['spec'] = intval($item['spec']);
- $result["{$card_type}-{$value['spec']}"] = ['card_type' => $card_type,
- 'spec' => intval($item['spec']),
- 'price' => $item['price'],
- 'extra_price' => $item['extra_price']
- ];
- }
- }
- return $result;
- };
- $all_cardtype_specs = $all_spector($quality);
- $merch_cardtype_specs = $merch_spector($mchid, $quality);
- $merger = function ($all_specs, $mech_specs) {
- $result = [];
- foreach ($all_specs as $cardtype_spec => $value) {
- $card_name = $this->scard_type($value['card_type']);
- $data = [];
- $data['goods_name'] = $card_name;
- $data['card_type'] = $value['card_type'];
- $data['spec'] = $value['spec'];
- if (array_key_exists($cardtype_spec, $mech_specs)) {
- $data['price'] = $mech_specs[$cardtype_spec]['price'];
- $data['extra_price'] = $mech_specs[$cardtype_spec]['extra_price'];
- } else {
- $data['price'] = 0;
- $data['extra_price'] = 0;
- }
- $result[$value['card_type']][] = $data;
- }
- return $result;
- };
- return $merger($all_cardtype_specs, $merch_cardtype_specs);
- }
- public function check_merchantOp()
- {
- $mchid = trim($_GET['mchid']);
- if (!$mchid) {
- echo '';
- die;
- }
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*');
- if (empty($merchant_info)) {
- echo '';
- die;
- }
- echo 'true';
- }
- /**
- * ajax操作
- */
- public function ajaxOp()
- {
- $model_merchant = Model('merchant');
- switch ($_GET['branch']) {
- /**
- * 验证机构名称是否重复
- */
- case 'check_mch_name':
- $condition['name'] = $_GET['name'];
- $list = $model_merchant->getMerchantInfo($condition);
- if (empty($list)) {
- echo 'true';
- } else {
- echo 'false';
- }
- exit;
- /**
- * 验证机构是否存在
- */
- case 'check_merchant':
- $condition['mchid'] = intval($_GET['mchid']);
- $list = $model_merchant->getMerchantInfo($condition);
- if (!empty($list)) {
- echo 'true';
- } else {
- echo 'false';
- }
- exit;
- }
- }
- public function check_evidenceOp()
- {
- $status = $_GET['status'];
- $apply_id = intval($_GET['apply_id']);
- if ($apply_id > 0) {
- $model_merchant = Model('merchant');
- $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
- if (empty($evidence_info)) {
- showMessage('充值申请不存在');
- }
- if ($status == 'pass') {
- $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 2, 'check_time' => time()]);
- } elseif ($status == 'unpass') {
- $model_merchant->editRefillEvidence(['apply_id' => $apply_id], ['status' => 3, 'check_time' => time()]);
- } else {
- }
- }
- showMessage(L('nc_common_save_succ'), urlAdmin('refill_evidence', 'index'));
- }
- public function rechargeOp()
- {
- if (chksubmit()) {
- $mchid = $this->add_money();
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
- if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
- //更新预警短信通知限制
- $mch_cache = rcache("merchant-notify", 'refill-');
- $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
- $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
- wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
- }
- showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
- } else {
- $apply_id = $_GET['apply_id'];
- if (!empty($apply_id)) {
- $model_merchant = Model('merchant');
- $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*,member.available_predeposit');
- Tpl::output('apply_id', $apply_id);
- Tpl::output('amount', $evidence_info['amount']);
- Tpl::output('available_predeposit', $evidence_info['available_predeposit']);
- }
- global $config;
- Tpl::output('receive_bank', $config['receive_bank'][COMPANY_NAME]);
- Tpl::showpage('recharge.add');
- }
- }
- public function recharge_manualOp()
- {
- $type = $_GET['type'] ?? $_POST['type'];
- if (chksubmit()) {
- $add_type = '';
- $obj_validate = new Validator();
- if ($type == 'add') {
- $add_type = '加款';
- $obj_validate->validateparam = [
- ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
- ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人姓名不能为空'],
- ["input" => $_POST["bank_name"], "require" => "true", "message" => '开户银行不能为空'],
- ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空'],
- ["input" => $_POST["receive_bank"], "require" => "true", "message" => '请选择收款银行']
- ];
- } elseif ($type == 'edit') {
- $add_type = '调款';
- $obj_validate->validateparam = [
- ["input" => $_POST["mch_id"], "require" => "true", "message" => '机构号不能为空'],
- ["input" => $_POST["bank_username"], "require" => "true", "message" => '操作人姓名不能为空'],
- ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
- ];
- }
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- }
- $mchid = $_POST["mch_id"];
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
- if (!$merchant_info) {
- showMessage('对应机构不存在');
- }
- $pointsnum = $_POST['pointsnum'];
- $money = abs($pointsnum);
- if ($money == 0) {
- showMessage('预存金额错误');
- }
- if (!empty($_FILES['voucher']['name'])) {
- $upload = new UploadFile();
- $upload->set('default_dir', ATTACH_UPFILE);
- $result = $upload->upfile('voucher');
- if ($result) {
- $_POST['voucher_name'] = $upload->file_name;
- } else {
- showMessage($upload->error);
- }
- }
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- $member_id = $merchant_info['admin_id'];
- if ($pointsnum > 0) {
- $bz = "管理员{$add_type}操作,手动增加预存金额";
- $this->credit_save_money($money, 'add', $member_id, $bz);
- } elseif ($pointsnum < 0) {
- $bz = "管理员{$add_type}操作,手动减少预存金额";
- $this->credit_save_money($money, 'del', $member_id, $bz);
- } else {
- showMessage('预存金额错误');
- }
- $result = $this->ct_refill_evidence($_POST, $merchant_info);
- if (!$result) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=merchant&op=merchant');
- }
- $trans->commit();
- if ($merchant_info['alarm_amount'] < $merchant_info['available_predeposit']) {
- //更新预警短信通知限制
- $mch_cache = rcache("merchant-notify", 'refill-');
- $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
- $caches[$mchid] = ['last_time' => 0, 'send_count' => 0];
- wcache("merchant-notify", ['data' => serialize($caches)], 'refill-');
- }
- showMessage('操作成功', 'index.php?act=refill_evidence&op=index');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
- }
- } else {
- $mchid = $_GET['mchid'] ?? $_POST['mchid'];
- $model_merchant = Model('merchant');
- $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
- if (empty($merchant)) {
- showMessage('机构信息有误');
- }
- Tpl::output('merchant', $merchant);
- global $config;
- Tpl::output('receive_bank', $config['receive_bank'][COMPANY_NAME]);
- $page = "recharge.manual.{$type}";
- Tpl::showpage($page);
- }
- }
- private function ct_refill_evidence($params, $merchant_info)
- {
- $admininfo = $this->getAdminInfo();
- $mem_info = Model('member')->getMemberInfo(['member_id' => $merchant_info['admin_id']]);
- $input['mchid'] = $merchant_info['mchid'];
- $input['mch_name'] = $merchant_info['name'];
- $input['member_id'] = $merchant_info['admin_id'];
- $input['amount'] = $params['pointsnum'];
- $input['bank_username'] = $params['bank_username'];
- $input['bank_name'] = $params['bank_name'] ?? '';
- $input['bz'] = $params['pointsdesc'];
- $input['voucher_name'] = $params['voucher_name'] ?? '/';
- $input['status'] = 2;
- $input['is_operation'] = 2;
- $input['add_time'] = $input['check_time'] = time();
- $input['after_available'] = ncPriceFormat($mem_info['available_predeposit'] + $params['pointsnum']);
- $input['admin_name'] = $admininfo['name'];
- $input['admin_id'] = $admininfo['id'];
- $input['add_type'] = $params['add_type'];
- $input['receive_bank'] = $params['receive_bank'] ?? 0;
- if ($params['type'] == 'add') {
- $input['is_bank'] = 1;
- }
- $model_merchant = Model('merchant');
- return $model_merchant->addRefillEvidence($input);
- }
- public function add_money()
- {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => $_POST["apply_id"], "require" => "true", "message" => Language::get('admin_points_member_error_again')],
- ["input" => $_POST["pointsnum"], "require" => "true", 'validator' => 'Compare', 'operator' => ' >= ', 'to' => 1, "message" => Language::get('admin_points_points_min_error')],
- ["input" => $_POST["receive_bank"], "require" => "true", "message" => '请选择收款银行']
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error, '', '', 'error');
- }
- $money = abs(floatval($_POST['pointsnum']));
- $memo = trim($_POST['pointsdesc']);
- if ($money <= 0) {
- showMessage('输入的金额必需大于0', '', 'html', 'error');
- }
- $apply_id = intval($_POST['apply_id']);
- $model_merchant = Model('merchant');
- $receive_bank = $_POST['receive_bank'] ?? 0;
- $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true);
- if (!is_array($evidence_info) || count($evidence_info) <= 0) {
- showMessage("无效的充值申请信息", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
- }
- if ($evidence_info['status'] != 2) {
- showMessage("该充值申请未被审核通过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
- }
- if ($evidence_info['is_operation'] == 2) {
- showMessage("该充值申请未已被预存过", "index.php?act=merchant&op=recharge&apply_id={$apply_id}", '', 'error');
- }
- //查询会员信息
- $obj_member = Model('member');
- $member_id = intval($evidence_info['member_id']);
- $member_info = $obj_member->getMemberInfo(['member_id' => $member_id], '*', true);
- $available_predeposit = floatval($member_info['available_predeposit']);
- $freeze_predeposit = floatval($member_info['freeze_predeposit']);
- // if ($_POST['operatetype'] == 2 && $money > $available_predeposit) {
- // showMessage(('预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
- // }
- if ($_POST['operatetype'] == 3 && $money > $available_predeposit) {
- showMessage(('可冻结预存款不足,会员当前预存款') . $available_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
- }
- if ($_POST['operatetype'] == 4 && $money > $freeze_predeposit) {
- showMessage(('可恢复冻结预存款不足,会员当前冻结预存款') . $freeze_predeposit, 'index.php?act=predeposit&op=predeposit_add', '', 'error');
- }
- $model_pd = Model('predeposit');
- $order_sn = $apply_id;
- $admininfo = $this->getAdminInfo();
- $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
- $admin_act = 'sys_add_money';
- switch ($_POST['operatetype']) {
- case 1:
- $admin_act = "sys_add_money";
- $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
- break;
- case 2:
- $admin_act = "sys_del_money";
- $log_msg = "管理员【" . $admininfo['name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
- break;
- default:
- showMessage('操作失败', 'index.php?act=refill_evidence&op=index');
- break;
- }
- try {
- $trans = new trans_wapper($model_pd, __METHOD__);
- //扣除冻结的预存款
- $data = [];
- $data['member_id'] = $member_info['member_id'];
- $data['member_name'] = $member_info['member_name'];
- $data['amount'] = $money;
- $data['order_sn'] = $order_sn;
- $data['admin_name'] = $admininfo['name'];
- $data['pdr_sn'] = $order_sn;
- $data['lg_desc'] = $memo;
- $isRefill = $model_pd->isRefill($data['member_id']);
- $model_pd->changePd($admin_act, $data,$isRefill);
- $after_available = ncPriceFormat($available_predeposit + $evidence_info['amount']);
- $model_merchant->editRefillEvidence(
- ['apply_id' => $apply_id],
- [
- 'is_operation' => 2, 'after_available' => $after_available,
- 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'],
- 'receive_bank' => $receive_bank
- ]
- );
- $trans->commit();
- $this->log($log_msg, 1);
- return $evidence_info['mchid'];
- } catch (Exception $e) {
- $trans->rollback();
- $this->log($log_msg, 0);
- showMessage($e->getMessage(), 'index.php?act=refill_evidence&op=index', 'html', 'error');
- exit;
- }
- }
- public function checkevidenceOp()
- {
- $apply_id = trim($_GET['apply_id']);
- if (!$apply_id) {
- echo '';
- die;
- }
- $model_merchant = Model('merchant');
- $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
- if (empty($evidence_info)) {
- echo '';
- die;
- }
- echo 'true';
- }
- public function notify_merchantOp()
- {
- $order_id = $_GET['order_id'];
- $mod_order = Model('vr_order');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0, 'is_retrying' => 0]);
- if (empty($refill_info)) {
- showMessage('订单不存在,或不符合条件', '');
- }
- if ($order_info['order_state'] == ORDER_STATE_SEND) {
- QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
- } else {
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
- }
- showMessage('操作成功', '');
- }
- public function notify_manual_merchantOp()
- {
- $order_id = $_GET['order_id'];
- $type = $_GET['type'];
- $mod_order = Model('vr_order');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0, 'is_retrying' => 0]);
- if (empty($refill_info)) {
- showMessage('订单不存在,或不符合条件', '');
- }
- $check_fetch_order = $this->check_fetch_order($order_info['order_sn']);
- if ($check_fetch_order == false) {
- showMessage('此订单不可手动操作,请联系抢单人员操作!');
- }
- if ($type == 'success') {
- refill\util::manual_success($order_id);
- } elseif ($type == 'cancel') {
- refill\util::manual_cancel($order_id);
- } else {
- showMessage('手动操作类型错误', 'index.php?act=refill_order&op=index');
- }
- showMessage('操作成功', '');
- }
- public function providerStatsOp()
- {
- $provider_model = Model('refill_provider');
- $condition = [];
- $provider_list = $provider_model->getProviderList($condition, 1000);
- $opened_text = ['使用中', '已禁用'];
- $type_text = ['油卡', '手机充值卡'];
- Tpl::output('opened_text', $opened_text);
- Tpl::output('type_text', $type_text);
- Tpl::output('provider_list', $provider_list);
- Tpl::output('show_page', $provider_model->showpage());
- Tpl::showpage('provider.stats');
- }
- public function provider_provinceOp()
- {
- $provider_model = Model('refill_provider');
- $provider_id = $_GET['id'] ?? $_POST['id'];
- $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
- if (empty($provider)) {
- showMessage('通道信息有误');
- }
- $operator = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
- if (chksubmit()) {
- foreach ($operator as $opr) {
- $key = $opr . '-province';
- $province = $_POST[$key];
- if ($province == -1) {
- $updata[$opr] = -1;
- } else {
- $updata[$opr] = implode(',', $province);
- }
- }
- $resp = $provider_model->editProvider(['provinces' => serialize($updata)], ['provider_id' => $provider_id]);
- if ($resp) {
- showMessage('编辑成功', 'index.php?act=provider&op=index');
- } else {
- showMessage('编辑失败', "index.php?act=merchant&op=provider_province&id={$provider_id}");
- }
- } else {
- $data = unserialize($provider['provinces']);
- $provinces = [];
- foreach ($operator as $opr) {
- if (empty($data)) {
- $provinces[$opr] = [-1];
- } else {
- $provinces[$opr] = explode(',', $data[$opr]);
- }
- }
- $province_list = mtopcard\ProvinceList;
- Tpl::output('province_list', $province_list);
- Tpl::output('provider', $provider);
- Tpl::output('provinces', $provinces);
- Tpl::showpage('provider.province');
- }
- }
- public function changeProviderStateOp()
- {
- $provider_id = intval($_GET['id']);
- $state = intval($_GET['state']);
- $provider_model = Model('refill_provider');
- $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
- if (empty($provider_info) || !in_array($state, [1, 2])) {
- showMessage('操作成功', 'index.php?act=provider&op=index');
- }
- $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
- if (!$resp) {
- showMessage('操作失败', 'index.php?act=provider&op=index', 'html', 'error');
- }
- showMessage('操作成功', 'index.php?act=provider&op=index');
- }
- /**
- * 新增通道
- */
- public function provider_addOp()
- {
- $provider_model = Model('refill_provider');
- if (chksubmit()) {
- $params = $_POST;
- unset($params['form_submit']);
- $result = $provider_model->addProvider($params);
- if ($result) {
- $url = [
- [
- 'url' => 'index.php?act=provider&op=index',
- 'msg' => '返回通道列表',
- ],
- [
- 'url' => 'index.php?act=merchant&op=provider_add',
- 'msg' => '继续新增通道',
- ],
- ];
- $this->log('添加通道:' . '[ ' . $_POST['name'] . ']', 1);
- showMessage('通道添加成功', $url);
- } else {
- showMessage('通道添加失败');
- }
- }
- Tpl::showpage('provider.add');
- }
- public function provider_editOp()
- {
- $provider_model = Model('refill_provider');
- if (chksubmit()) {
- $provider_id = intval($_POST['provider_id']) ?? '';
- $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
- if (empty($provider)) {
- showMessage('通道信息有误');
- }
- $params = $_POST;
- unset($params['form_submit']);
- if (empty($params)) {
- showMessage('通道编辑成功', 'index.php?act=provider&op=index');
- }
- $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
- if ($result) {
- $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
- showMessage('通道编辑成功', 'index.php?act=provider&op=index');
- } else {
- showMessage('通道编辑失败', "index.php?act=merchant&op=provider_edit&id={$provider_id}");
- }
- }
- $provider_id = intval($_GET['id']) ?? '';
- $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
- if (empty($provider)) {
- showMessage('通道信息有误');
- }
- $type_text = ['油卡', '手机充值卡'];
- Tpl::output('type_text', $type_text);
- Tpl::output('provider', $provider);
- Tpl::showpage('provider.edit');
- }
- public function provider_delOp()
- {
- $provider_model = Model('refill_provider');
- $provider_id = intval($_GET['id']) ?? '';
- $provider = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
- if (empty($provider)) {
- showMessage('通道信息有误');
- }
- $result = $provider_model->delProvider(['provider_id' => $provider_id]);
- if ($result) {
- $this->log('删除通道:' . '[ ' . $provider['name'] . ']', 1);
- showMessage('通道删除成功', 'index.php?act=provider&op=index');
- } else {
- showMessage('通道删除失败', "index.php?act=provider&op=index");
- }
- }
- public function provider_amount_controlOp()
- {
- $type = $_GET['type'] ?? $_POST['type'];
- $form = $_GET['form'] ?? $_POST['form'];
- $rkey = $this->speed_key($type, $form);
- $quality = [
- 'common' => \refill\Quality::Normal, 'fast' => \refill\Quality::Quick, 'card' => \refill\Quality::CardKey,
- 'third' => \refill\Quality::ThirdShop, 'slow' => \refill\Quality::SlowTwentyFour, 'slow6' => \refill\Quality::SlowSix,
- 'slow2' => \refill\Quality::SlowTwo, 'slow48' => \refill\Quality::SlowFortyEight, 'slow72' => \refill\Quality::SlowSeventyTwo
- ];
- if (chksubmit()) {
- $provider_list = $this->providers();
- foreach ($provider_list as $provider) {
- $providers[$provider['provider_id']] = $provider;
- }
- $strs = $_POST['str'];
- $speeds = $_POST['speed'];
- $sorts = $_POST['sort'];
- $openeds = $_POST['opened'];
- foreach ($strs as $key => $str) {
- $item = explode('-', $str);
- $pid = $item[0];
- $type = $item[1];
- $amount = $item[2];
- $has = $item[3];
- if ($has == 0) {
- continue;
- }
- $data['pid'] = intval($pid);
- $data['name'] = $providers[$pid]['name'];
- $data['type'] = intval($type);
- $data['amount'] = intval($amount);
- $data['speed'] = intval($speeds[$key]);
- $data['sort'] = intval($sorts[$key]);
- $data['opened'] = intval($openeds[$key]);
- $index = "{$data['type']}-{$data['amount']}";
- $result[$index][] = $data;
- }
- // var_dump($result);die;
- // Log::record("provider amount data:".json_encode($result),Log::DEBUG);
- wcache($rkey, ['data' => serialize($result)], 'provider-');
- showMessage('编辑成功');
- } else {
- $speed_limit = rcache($rkey, 'provider-');
- if (empty($speed_limit)) {
- $speed_limit = [];
- } else {
- $speed_limit = unserialize($speed_limit['data']);
- }
- $initialiser = function ($provider) {
- $data['pid'] = $provider['provider_id'];
- $data['name'] = $provider['name'];
- $data['speed'] = -1;
- $data['sort'] = 1;
- $data['opened'] = 1;
- return $data;
- };
- $providers = Model('')->table('refill_provider,store')
- ->field('refill_provider.*,store.store_name')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where(['type' => $type, 'qualitys' => ['like', '%' . $quality[$form] . '%']])
- ->limit(1000)
- ->order('opened asc , sort desc')
- ->select();
- if (empty($providers)) {
- showMessage('暂无相关通道', 'index.php?act=provider&op=index');
- }
- $formData = $this->formData($type, $form);
- $amounts = $formData['amounts'];
- $cfgs = $formData['cfgs'];
- $types = $formData['types'];
- if (!empty($speed_limit)) {
- foreach ($speed_limit as $key => $speed) {
- foreach ($speed as $value) {
- $speed_limit[$key][$value['pid']] = $value;
- }
- }
- }
- $ProviderManager = new \refill\ProviderManager();
- $ProviderManager->load();
- $QPTA = $ProviderManager->getQPTA();
- $QPTA = $QPTA[$quality[$form]];
- foreach ($providers as $key => $provider) {
- $result = [];
- $pid = $provider['provider_id'];
- $name = $provider['name'];
- if (empty($cfgs) || !array_key_exists($name, $cfgs)) {
- unset($providers[$key]);
- continue;
- }
- foreach ($types as $type) {
- foreach ($amounts as $k => $amount) {
- $key = $type . '-' . $amount;
- if (is_array($speed_limit[$key]) && array_key_exists($pid, $speed_limit[$key])) {
- $speed = $speed_limit[$key][$pid];
- } else {
- $speed = $initialiser($provider);
- }
- if (is_array($QPTA["{$name}-{$type}-{$amount}"]) && array_key_exists("{$name}-{$type}-{$amount}", $QPTA)) {
- $speed['has'] = 1;
- } else {
- $speed['has'] = 0;
- }
- $result[] = $speed;
- }
- }
- $datas[$pid] = $result;
- }
- if (empty($datas)) {
- showMessage('暂无相关通道配置', 'index.php?act=provider&op=index');
- }
- Tpl::output('form', $formData);
- Tpl::output('datas', $datas);
- Tpl::output('providers', $providers);
- Tpl::showpage('provider.amount.control');
- }
- }
- private function speed_key($type, $form)
- {
- if ($type == 1) {
- $rkey = "channel-ctl-oil-{$form}-limit";
- } elseif ($type == 2) {
- $rkey = "channel-ctl-phone-{$form}-limit";
- } else {
- showMessage('类型有误', "index.php?act=provider&op=index");
- }
- Log::record($rkey, Log::DEBUG);
- return $rkey;
- }
- private function formData($type, $form)
- {
- global $config;
- $texts = [
- ["中石油", '中石化'], ['移动', '联通', '电信']
- ];
- $type_data = [[1, 2], [4, 5, 6]];
- $type_text = $texts[$type - 1];
- $type_data = $type_data[$type - 1];
- $amounts = [];
- if ($type == 1) {
- $amounts = $config['refill_oil_specs'];
- $cfgs = $config['oil_providers'];
- }
- if ($type == 2) {
- $amounts = $config['refill_phone_specs'];
- $cfgs = $config['phone_providers'];
- if ($form == 'fast') {
- //快充质量,加小面值
- $amounts = array_merge($config['refill_phone_small_specs'], $amounts);
- }
- }
- foreach ($type_text as $key => $value) {
- foreach ($amounts as $amount) {
- $data['text'] = $value . '-' . $amount . '元';
- $data['type'] = $type_data[$key];
- $data['amount'] = $amount;
- $amountData[] = $data;
- }
- }
- foreach ($cfgs as $cfg) {
- $pcfgs[$cfg['name']] = $cfg;
- }
- return ['amountData' => $amountData, 'form' => $form, 'amounts' => $amounts, 'types' => $type_data, 'cfgs' => $pcfgs];
- }
- public function OrderStatsCheckOp()
- {
- $stat_id = $_GET['stat_id'] ?? $_POST['stat_id'];
- $mod_stat = Model('refill_stats');
- $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
- if (empty($stats_data)) {
- showMessage('对应数据不存在', '');
- }
- $type = $stats_data['type'];
- if (chksubmit()) {
- $corder_success_count = $_POST['corder_success_count'] ?? 0;
- $corder_success_amounts = $_POST['corder_success_amounts'] ?? 0;
- $corder_success_refill_amounts = $_POST['corder_success_refill_amounts'] ?? 0;
- $refund = $_POST['refund'] ?? 0;
- $remark = $_POST['remark'];
- $gap_order_count = $gap_success_amounts = $gap_success_refill_amounts = 0;
- if ($type == 'provider') {
- if (!empty($corder_success_amounts)) {
- $gap_success_amounts = $corder_success_amounts - $stats_data['success_channel_amounts'];
- }
- if (!empty($corder_success_count)) {
- $gap_order_count = $corder_success_count - $stats_data['success_count'];
- }
- } elseif ($type == 'merchant') {
- if (!empty($corder_success_count)) {
- $gap_order_count = $stats_data['success_count'] - $corder_success_count;
- }
- if (!empty($corder_success_amounts)) {
- $gap_success_amounts = $stats_data['success_channel_amounts'] - $corder_success_amounts;
- }
- } else {
- showMessage('对账数据类型错误', 'index.php?act=OrderStats&op=index');
- }
- if (!empty($corder_success_refill_amounts)) {
- $gap_success_refill_amounts = $corder_success_refill_amounts - $stats_data['success_refill_amounts'];
- }
- $updata['corder_success_count'] = $corder_success_count;
- $updata['corder_success_amounts'] = $corder_success_amounts;
- $updata['corder_success_refill_amounts'] = $corder_success_refill_amounts;
- $updata['gap_order_count'] = $gap_order_count;
- $updata['gap_success_amounts'] = $gap_success_amounts;
- $updata['gap_success_refill_amounts'] = $gap_success_refill_amounts;
- $updata['remark'] = $remark;
- $updata['refund'] = $refund;
- if (!empty($corder_success_count) && !empty($corder_success_amounts) && !empty($corder_success_refill_amounts)) {
- if ($gap_order_count == 0 && $gap_success_amounts == 0 && $gap_success_refill_amounts == 0) {
- $updata['check_status'] = 1;
- } else {
- $updata['check_status'] = 2;
- }
- }
- $res = $mod_stat->edit($stat_id, $updata);
- if ($res) {
- showMessage('操作成功', "index.php?act=OrderStats&op=index&type={$type}&cid={$stats_data['cid']}&order_time_type={$stats_data['order_time_type']}");
- } else {
- showMessage('操作失败');
- }
- } else {
- $type_text = ['provider' => '上游', 'merchant' => '商户'];
- Tpl::output('stats_type', $type_text[$type]);
- Tpl::output('stats_data', $stats_data);
- Tpl::showpage('order.stats.check');
- }
- }
- public function OrderStatsReloadOp()
- {
- $stat_id = $_GET['stat_id'];
- $mod_stat = Model('refill_stats');
- $stats_data = $mod_stat->getStatsInfo(['stat_id' => $stat_id]);
- if (empty($stats_data)) {
- showMessage('对应数据不存在', '');
- }
- $refill = new statistics\stat_refill();
- try {
- $trans = new trans_wapper($mod_stat, __METHOD__);
- //更新新数据
- if ($stats_data['type'] == 'merchant') {
- $refill->merchant_stat($stats_data['time_stamp'], $stats_data['cid'], $stats_data['order_time_type']);
- } elseif ($stats_data['type'] == 'provider') {
- $refill->provider_stat($stats_data['time_stamp'], $stats_data['cid'], $stats_data['order_time_type']);
- }
- $trans->commit();
- showMessage('操作成功');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败');
- }
- }
- public function merchant_interceptOp()
- {
- $mchid = $_GET['mchid'] ?? $_POST['mchid'];
- $model_merchant = Model('merchant');
- $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
- if (empty($merchant)) {
- showMessage('机构信息有误');
- }
- if (chksubmit()) {
- $merchant_intercept['is_transfer'] = $_POST['is_transfer'];
- if (!empty($_POST['card_states'])) {
- $merchant_intercept['card_states'] = $_POST['card_states'];
- }
- $merchant_intercept = serialize($merchant_intercept);
- $resp = $model_merchant->editMerchant(['merchant_intercept' => $merchant_intercept], ['mchid' => $mchid]);
- if ($resp) {
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } else {
- showMessage('操作失败');
- }
- } else {
- $merchant_intercept = $merchant['merchant_intercept'];
- if (empty($merchant_intercept)) {
- $merchant_intercept = ['card_states' => [], 'is_transfer' => 0];
- } else {
- $merchant_intercept = unserialize($merchant_intercept);
- }
- Tpl::output('merchant', $merchant);
- Tpl::output('card_state', mtopcard\CardState);
- Tpl::output('merchant_intercept', $merchant_intercept);
- Tpl::showpage('merchant.intercept');
- }
- }
- public function merchant_retry_timesOp()
- {
- $mchid = $_GET['mchid'] ?? $_POST['mchid'];
- $model_merchant = Model('merchant');
- $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
- if (empty($merchant)) {
- showMessage('机构信息有误');
- }
- $qualitys = [
- \refill\Quality::Normal,\refill\Quality::Quick,\refill\Quality::CardKey,\refill\Quality::ThirdShop,
- \refill\Quality::SlowTwentyFour,\refill\Quality::SlowSix,\refill\Quality::SlowTwo,\refill\Quality::SlowFortyEight,
- \refill\Quality::SlowSeventyTwo
- ];
- if (chksubmit()) {
- $qualities = $merchant_retry_times = [];
- foreach ($qualitys as $quality) {
- $secs_key = "{$quality}-secs";
- $times_key = "{$quality}-times";
- if(!empty($_POST[$secs_key]) && !empty($_POST[$times_key])) {
- $qualities[$quality] = ['secs' => $_POST[$secs_key], 'times' => $_POST[$times_key]];
- }
- }
- $merchant_retry_times['qualities'] = $qualities;
- $ratio = $_POST['ratio'] ?? 0;
- $period = $_POST['period'] ?? 0;
- $merchant_retry_times['lower_ratio'] = ['ratio' => $ratio, 'period' => $period];
- $merchant_retry_times['opened'] = $_POST['opened'];
- $merchant_retry_times = serialize($merchant_retry_times);
- $resp = $model_merchant->editMerchant(['merchant_retry_times' => $merchant_retry_times], ['mchid' => $mchid]);
- if ($resp) {
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } else {
- showMessage('操作失败');
- }
- } else {
- foreach ($qualitys as $value) {
- $quality[$value] = $this->quality_format($value,4);
- }
- $merchant_retry_times = $merchant['merchant_retry_times'];
- if (empty($merchant_retry_times)) {
- $merchant_retry_times = [];
- } else {
- $merchant_retry_times = unserialize($merchant_retry_times);
- }
- Tpl::output('merchant', $merchant);
- Tpl::output('quality', $quality);
- Tpl::output('merchant_retry_times', $merchant_retry_times);
- Tpl::showpage('merchant.retry.times');
- }
- }
- }
|