12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292 |
- <?php
- /**
- * 机构管理界面
- *
- **by 好商城V3 www.33hao.com 运营版*/
- defined('InShopNC') or exit('Access Invalid!');
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_HELPER_PATH . '/stat_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/refill/functional.php');
- require_once(BASE_HELPER_PATH . '/task/task_helper.php');
- require_once(BASE_HELPER_PATH . '/refill/functional.php');
- require_once(BASE_CORE_PATH . '/framework/function/http.php');
- use refill\quality_ploy;
- class merchantControl extends SystemControl
- {
- const EXPORT_SIZE = 1000;
- public function __construct()
- {
- parent::__construct();
- Language::read('merchant');
- }
- public function merchantOp()
- {
- global $config;
- $model_merchant = Model('merchant');
- $condition = [];
- if (trim($_GET['merchant_name']) != '') {
- $condition['company_name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
- }
- $debt_total = 0;
- $available_total = 0;
- $merchant_list = $model_merchant->getMerchantList($condition, 200, 'available_predeposit desc,merchant_state asc,mchid desc', true);
- foreach ($merchant_list as $key => $merchant) {
- $mchid = $merchant['mchid'];
- $available_predeposit = $merchant['available_predeposit'] - $merchant['credit_bonus'];
- $merchant_list[$key]['available_predeposit'] = number_format($available_predeposit,4,'.',',');;
- if(!in_array($mchid, $config['test_mchid']) && $merchant['merchant_state'] == 1) {
- if($available_predeposit >= 0) {
- $available_total += $available_predeposit;
- }else{
- $debt_total += $available_predeposit;
- }
- }
- }
- $stats = ['available_total' => $available_total, 'debt_total' => $debt_total];
- Tpl::output('merchant_state_text', self::STATE_TEXT);
- Tpl::output('merchant_list', $merchant_list);
- Tpl::output('stats', $stats);
- 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 AllCloseMerchantOp()
- {
- $model_merchant = Model('merchant');
- $resp = $model_merchant->editMerchant(['merchant_state' => 2], ['mchid' => ['gt',0]]);
- showMessage('操作成功');
- }
- 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
- {
- $model_merchant = Model('merchant');
- $model_member = Model('member');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- try
- {
- $name = trim($_POST['name']);
- $company_name = trim($_POST['company_name']);
- $pwd = trim($_POST['password']);
- $alarm_amount = $_POST['alarm_amount'] ?? 0;
- $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 > 0) {
- $helper = new refill\divert_account();
- $helper->init_member($insert_id);
- $ret = true;
- } else {
- $ret = false;
- }
- if($ret)
- {
- $trans->commit();
- $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 {
- $trans->rollback();
- showMessage('机构添加失败');
- }
- }
- 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']);
- $operatetype = $_POST['operatetype'];
- $credit_bonus_delta = false;
- if ($update_credit_bonus > 0)
- {
- if ($operatetype == 'add')
- {
- if ($merchant['credit_bonus'] + $update_credit_bonus < 0) {
- showMessage('授信金额调整后不能小于0');
- }
- $credit_bonus_delta = $update_credit_bonus;
- }
- elseif ($operatetype == 'del')
- {
- if ($merchant['credit_bonus'] - $update_credit_bonus < 0) {
- showMessage('授信金额调整后不能小于0');
- }
- $credit_bonus_delta = -$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['manual_recharge'] = $_POST['manual_recharge'];
- $day_timeout = intval($_POST['day_timeout']);
- $night_timeout = intval($_POST['night_timeout']);
- if($day_timeout <= 0) {
- $day_timeout = 180;
- }
- if($night_timeout <= 0) {
- $day_timeout = 180;
- }
- $update['day_timeout'] = $day_timeout;
- $update['night_timeout'] = $night_timeout;
- if(refill\functional::isDay()) {
- $update['time_out'] = intval($_POST['day_timeout']);
- } else {
- $update['time_out'] = intval($_POST['night_timeout']);
- }
- $member_id = $merchant['admin_id'];
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- try
- {
- if ($update_credit_bonus > 0 && $member_id > 0)
- {
- [$succ,$msg] = $this->credit_save_money($update_credit_bonus, $operatetype, $member_id);
- if (!$succ) {
- throw new Exception('调整预存款失败.');
- } else {
- $model_merchant->editMerchant(['credit_bonus' => ['exp', "credit_bonus+$credit_bonus_delta"]], ['admin_id' => $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']}]");
- 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');
- }
- 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'];
- $max_inprices = $_POST['max_inprice'];
- 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]);
- $data['max_inprice'] = ncPriceFormat($max_inprices[$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['max_inprice'] = $param['max_inprice'];
- $insert['card_types'] = $param['card_type'];
- $insert['quality'] = $quality;
- $inserts[] = $insert;
- }
- }
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- try {
- //删除旧费率
- $res = $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality]);
- if(!$res) {
- $trans->rollback();
- showMessage('删除旧费率失败');
- }
- $ret = true;
- //更新新费率
- if (!empty($inserts)) {
- $ret = $model_merchant->insertPrices($inserts);
- }
- if($ret) {
- $trans->commit();
- showMessage('操作成功');
- }else{
- $trans->rollback();
- showMessage('更新费率失败');
- }
- } catch (Exception $e) {
- $trans->rollback();
- Log::record("merchant_price update err: {$e->getMessage()}", Log::ERR);
- 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;
- }
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- try {
- 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'];
- }
- //删除旧费率
- $res = $model_merchant->delPrices(['mchid' => $mchid, 'quality' => $quality, 'pcode' => $param['pcode']]);
- if(!$res) {
- $trans->rollback();
- showMessage('删除旧费率失败');
- }
- $ret = true;
- //更新新费率
- if (!empty($insert)) {
- $ret = $model_merchant->table('merchant_price')->insert($insert);
- }
- if(!$ret) {
- $trans->rollback();
- showMessage('更新费率失败');
- }
- }
- $trans->commit();
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } catch (Exception $e) {
- $trans->rollback();
- Log::record("merchant_price pcode update err: {$e->getMessage()}", Log::ERR);
- showMessage('操作失败');
- }
- } else {
- $condition = [];
- if (!empty($_GET['system_code'])) {
- $condition['system_code'] = $_GET['system_code'];
- }
- if (!empty($_GET['product_type'])) {
- $condition['product_type'] = $_GET['product_type'];
- }
- if (trim($_GET['product_name']) != '') {
- $condition['product_name'] = ['like', '%' . $_GET['product_name'] . '%'];
- }
- $third_product = $mod->getProductList($condition, 50);
- $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_type', self::THIRD_PRODUCT_TYPE);
- 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) {
- $card_type = mtopcard\topcard_type($scard_type);
- 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'],
- 'max_inprice' => $item['max_inprice']
- ];
- }
- }
- 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'];
- $data['max_inprice'] = $mech_specs[$cardtype_spec]['max_inprice'];
- } else {
- $data['price'] = 0;
- $data['extra_price'] = 0;
- $data['max_inprice'] = 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';
- }
- break;
- /**
- * 验证机构是否存在
- */
- case 'check_merchant':
- $condition['mchid'] = intval($_GET['mchid']);
- $list = $model_merchant->getMerchantInfo($condition);
- if (!empty($list)) {
- echo 'true';
- } else {
- echo 'false';
- }
- }
- }
- 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('审核类型错误');
- }
- }
- 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', true);
- 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" => '预存金额不能为空']
- ];
- }
- $operatetype = $_POST['operatetype'];
- $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);
- }
- }
- $trans = new trans_wapper($model_merchant, __METHOD__);
- try {
- $member_id = $merchant_info['admin_id'];
- if ($operatetype == 'add') {
- $bz = "管理员{$add_type}操作,手动增加预存金额";
- $this->credit_save_money($money, 'add', $member_id, $bz);
- $_POST['pointsnum'] = $money;
- } elseif ($operatetype == 'del') {
- $bz = "管理员{$add_type}操作,手动减少预存金额";
- $this->credit_save_money($money, 'del', $member_id, $bz);
- $_POST['pointsnum'] = -($money);
- } 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'] == 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;
- }
- $trans = new trans_wapper($model_pd, __METHOD__);
- try {
- $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*', true,true);
- if ($evidence_info['is_operation'] == 2) {
- $trans->commit();
- showMessage('已经处理', 'index.php?act=refill_evidence&op=index', 'html', 'error');
- }
- //扣除冻结的预存款
- $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');
- }
- }
- 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, 'order_state' => ORDER_STATE_SEND]);
- $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0, 'is_retrying' => 0]);
- if (empty($refill_info) || empty($order_info)) {
- showMessage('订单不存在,或不符合条件');
- }
- $fetch_order_ids = $this->check_fetch_order($order_id);
- if (in_array($order_id, $fetch_order_ids)) {
- 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');
- }
- $this->manual_log_record($refill_info, $type);
- $this->log("手动处理,订单号:{$order_info['order_sn']}", 1);
- showMessage('操作成功');
- }
- private function manual_log_record($order, $oper_type)
- {
- $admininfo = $this->getAdminInfo();
- $cur_time = time();
- $bz = "手动处理订单,操作者:{$admininfo['name']}";
- $ins = [
- 'order_id' => $order['order_id'], 'order_sn' => $order['order_sn'],'order_time' => $order['order_time'], 'notify_time' => $order['notify_time'],
- 'manual_type' => $oper_type, 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'], 'act_time' => $cur_time, 'bz' => $bz
- ];
- Model('refill_buyback')->insert($ins);
- }
- 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 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('对应数据不存在', '');
- }
- $cond = [
- 'type' => $stats_data['type'],
- 'time_stamp' => $stats_data['time_stamp'],
- 'cid' => $stats_data['cid'],
- 'order_time_type' => $stats_data['order_time_type']
- ];
- $manager = new task\manager();
- $task = $manager->add_task('order_stat_reload',$cond,0,3600);
- if ($task->completed() && $task->success()) {
- showMessage('操作成功');
- } else {
- showMessage("操作成功,后台任务已开始重新统计,请稍后查看新数据");
- }
- }
- public function merchant_ctlOp()
- {
- $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, refill\Quality::Fastest
- ];
- if(chksubmit())
- {
- if(intval($_POST['transfer_opened']) === 1) {
- if($_POST['transfer_mchid'] == $mchid) {
- showMessage('预回调设置:转发通道不可为自身!');
- }
- $transfer_merchant = $model_merchant->getMerchantInfo(['mchid' => $_POST['transfer_mchid']], '*', true);
- if(empty($transfer_merchant)) {
- showMessage('预回调设置:转发通道不存在!');
- }
- }
- if(!empty($_POST['segment'])) {
- $segment = explode(',', $_POST['segment']);
- foreach ($segment as $str) {
- if (!preg_match('/^\d{3}$/',$str)){
- showMessage('拦截设置:号段拦截有误!');
- }
- }
- }
- $transfer_data = function (){
- $transfer_cfg['transfer_opened'] = intval($_POST['transfer_opened']) ?? 0;
- $transfer_cfg['transfer_mchid'] = intval($_POST['transfer_mchid']) ?? 0;
- $transfer_cfg['transfer_lowertime'] = intval($_POST['transfer_lowertime']) ?? 0;
- $transfer_cfg['transfer_uppertime'] = intval($_POST['transfer_uppertime']) ?? 0;
- return serialize($transfer_cfg);
- };
- $intercept_data = function (){
- $intercept_cfg['is_transfer'] = intval($_POST['is_transfer']) === 1;
- if (!empty($_POST['card_states'])) {
- foreach ($_POST['card_states'] as $card_state)
- {
- $card_states[] = intval($card_state);
- }
- $intercept_cfg['card_states'] = $card_states;
- }
- if (!empty($_POST['card_types'])) {
- foreach ($_POST['card_types'] as $card_type)
- {
- $card_types[] = intval($card_type);
- }
- $intercept_cfg['card_types'] = $card_types;
- }
- if(!empty($_POST['segment'])) {
- $intercept_cfg['segment'] = trim($_POST['segment']);
- }
- return serialize($intercept_cfg);
- };
- $retry_times_data = function ($qualitys){
- $qualities = [];
- foreach ($qualitys as $quality) {
- $quality = intval($quality);
- $day_secs_key = "{$quality}-day_secs";
- $night_secs_key = "{$quality}-night_secs";
- $times_key = "{$quality}-times";
- if(!empty($_POST[$day_secs_key]) && !empty($_POST[$night_secs_key]) && !empty($_POST[$times_key])) {
- $qualities[$quality] = ['day_secs' => intval($_POST[$day_secs_key]), 'night_secs' => intval($_POST[$night_secs_key]), 'times' => intval($_POST[$times_key])];
- }
- }
- $retry_times_cfg['qualities'] = $qualities;
- $ratio = floatval($_POST['ratio']) ?? 0;
- $period = intval($_POST['period']) ?? 0;
- $profit_ratio = floatval($_POST['profit_ratio']) ?? 0;
- $retry_times_cfg['lower_ratio'] = ['ratio' => $ratio, 'period' => $period];
- $retry_times_cfg['profit_ratio'] = $profit_ratio;
- $profit_formula = $_POST['profit_formula'] ?? '';
- $retry_times_cfg['profit_formula'] = $profit_formula;
- return serialize($retry_times_cfg);
- };
- $retry_times_cfg = $retry_times_data($qualitys);
- $update['quality'] = intval($_POST['quality']);
- $update['oil_quality'] = intval($_POST['oil_quality']);
- $update['intercept_cfg'] = $intercept_data();
- $update['retry_times_cfg'] = $retry_times_cfg;
- $update['transfer_cfg'] = $transfer_data();
- $resp = $model_merchant->editMerchant($update, ['mchid' => $mchid]);
- if ($resp) {
- $this->update_time_out($mchid);
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } else {
- showMessage('操作失败');
- }
- }
- else
- {
- foreach ($qualitys as $value) {
- $quality[$value] = $this->quality_format($value,mtopcard\ChinaMobileCard);
- }
- Tpl::output('intercept', $this->merchant_intercept($merchant));
- Tpl::output('retry_times', $this->merchant_retry_times($merchant));
- Tpl::output('transfer_cfg', $this->transfer_cfg($merchant));
- Tpl::output('merchant', $merchant);
- Tpl::output('quality', $quality);
- Tpl::output('card_state', mtopcard\CardState);
- Tpl::showpage('merchant.ctl');
- }
- }
- private function update_time_out($mchid)
- {
- $model_merchant = Model('merchant');
- $merchant = $model_merchant->getMerchantInfo(['mchid' => $mchid], '*', true);
- $org_quality = $merchant['quality'];
- $retry_times_cfg = $this->merchant_retry_times($merchant);
- $day_timeout = 0;
- $night_timeout = 0;
- $quality_ploy = new quality_ploy();
- $qualities = $quality_ploy->qualities($org_quality);
- foreach ($qualities as $quality) {
- $day_timeout += $retry_times_cfg['qualities'][$quality]['day_secs'];
- $night_timeout += $retry_times_cfg['qualities'][$quality]['night_secs'];
- }
- if (refill\functional::isDay()) {
- $time_out = $day_timeout;
- } else {
- $time_out = $night_timeout;
- }
- $update['day_timeout'] = $day_timeout;
- $update['night_timeout'] = $night_timeout;
- $update['time_out'] = $time_out;
- $model_merchant->editMerchant($update, ['mchid' => $mchid]);
- }
- private function merchant_intercept($merchant)
- {
- $intercept_cfg = $merchant['intercept_cfg'];
- if (empty($intercept_cfg)) {
- $intercept_cfg = ['card_states' => [], 'is_transfer' => 0, 'segment' => ''];
- } else {
- $intercept_cfg = unserialize($intercept_cfg);
- }
- return $intercept_cfg;
- }
- private function merchant_retry_times($merchant)
- {
- $retry_times_cfg = $merchant['retry_times_cfg'];
- if (empty($retry_times_cfg)) {
- $retry_times_cfg = [];
- } else {
- $retry_times_cfg = unserialize($retry_times_cfg);
- }
- return $retry_times_cfg;
- }
- private function transfer_cfg($merchant)
- {
- $transfer_cfg = $merchant['transfer_cfg'];
- if (empty($transfer_cfg)) {
- $transfer_cfg = ['transfer_opened' => 0, 'transfer_mchid' => 0, 'transfer_lowertime' => 0, 'transfer_uppertime' => 0];
- } else {
- $transfer_cfg = unserialize($transfer_cfg);
- }
- return $transfer_cfg;
- }
- }
|