12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517 |
- <?php
- /**
- * 机构管理界面
- *
- **by 好商城V3 www.33hao.com 运营版*/
- defined('InShopNC') or exit('Access Invalid!');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.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['name'] = ['like', '%' . $_GET['merchant_name'] . '%'];
- Tpl::output('merchant_name', $_GET['merchant_name']);
- }
- $merchant_list = $model_merchant->getMerchantList($condition, 25, 'available_predeposit desc');
- $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]);
- if(empty($merchant)){
- showMessage('机构信息有误');
- }
- if (chksubmit()) {
- $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['credit_bonus'] = ncPriceFormat($_POST['credit_bonus']);
- $update['time_out'] = intval($_POST['time_out'] * 60);
- $update['quality'] = intval($_POST['quality']);
- $member_id = $merchant['admin_id'];
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- if($merchant['credit_bonus'] == $update['credit_bonus']) {
- unset($update['credit_bonus']);
- } elseif ($merchant['credit_bonus'] > $update['credit_bonus']) {
- $credit_bonus = ncPriceFormat($merchant['credit_bonus'] - $update['credit_bonus']);
- $this->credit_save_money($credit_bonus , 2 , $member_id);
- } elseif ($merchant['credit_bonus'] < $update['credit_bonus']) {
- $credit_bonus = ncPriceFormat($update['credit_bonus'] - $merchant['credit_bonus']);
- $this->credit_save_money($credit_bonus , 1 , $member_id);
- }
- $result = $model_merchant->editMerchant($update,['mchid' => $mchid]);
- if(!$result) {
- $trans->rollback();
- showMessage('机构编辑失败', 'index.php?act=merchant&op=merchant');
- }
- $this->log('编辑机构:' . '[ ' . $merchant['name'] . ']', 1);
- $trans->commit();
- 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]);
- $admininfo = $this->getAdminInfo();
- switch ($operatetype) {
- case 1:
- $admin_act = "sys_add_money";
- $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】,预存款【增加】,金额为" . $money ;
- break;
- case 2:
- $admin_act = "sys_del_money";
- $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】,预存款【减少】,金额为" . $money;
- break;
- default:
- return [false , '调节类型错误'];
- break;
- }
- $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 ? $bz : '管理员操作客户授信,更改会员余额。';
- $model_pd->changePd($admin_act, $data);
- $this->log($log_msg, 1);
- return [true , 'success'];
- }
- public function orderStorgeOp()
- {
- if (chksubmit())
- {
- $mchids = $_POST['mchid'];
- $petrochinas = $_POST['petrochina'];
- $sinopecs = $_POST['sinopec'];
- foreach ($mchids as $pos => $mchid) {
- $mchid = intval($mchid);
- $data['mchid'] = $mchid;
- $data['petrochina'] = ['100' => intval($petrochinas[100][$pos]) , '200' => intval($petrochinas[200][$pos]) , '500' => intval($petrochinas[500][$pos]) , '1000' => intval($petrochinas[1000][$pos])];
- $data['sinopec'] = ['100' => intval($sinopecs[100][$pos]) , '200' => intval($sinopecs[200][$pos]) , '500' => intval($sinopecs[500][$pos]) , '1000' => intval($sinopecs[1000][$pos])];
- $data['time'] = time();
- $result[$mchid] = $data;
- }
- $this->cache_storge_limit($result);
- showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
- }
- else
- {
- $order_limit = rcache('storge_limit' , 'merchant-');
- if(empty($order_limit)){
- $order_limit = [];
- }else{
- $order_limit = unserialize($order_limit['data']);
- }
- $initialiser = function ($merchant) {
- $amount = [
- '100' => -1,
- '200' => -1,
- '500' => -1,
- '1000' => -1
- ];
- $data['mchid'] = $merchant['mchid'];
- $data['petrochina'] = $data['sinopec'] = $amount;
- $data['time'] = time();
- return $data;
- };
- $reader = function ($mchid,$time)
- {
- $cond['mchid'] = $mchid;
- $cond['inner_status'] = 0;
- $cond['order_state'] = ORDER_STATE_SUCCESS;
- $cond['refill_order.order_time'] = ['egt', $time];
- $items = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('refill_order.mchid,refill_order.card_type,refill_order.refill_amount,count(*) as num')
- ->group('refill_order.card_type,refill_order.refill_amount')
- ->where($cond)->select();
- return $items;
- };
- $type_map = [1 => 'petrochina' , 2 => 'sinopec'];
- $cur_limits = [];
- $model_merchant = model('merchant');
- $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc' , 'mchid,company_name');
- foreach ($merchant_list as $merchant)
- {
- $mchid = intval($merchant['mchid']);
- if(array_key_exists($mchid , $order_limit)) {
- $result[$mchid] = $order_limit[$mchid];
- }else{
- $result[$mchid] = $initialiser($merchant);
- }
- $start = $result[$mchid]['time'];
- $items = $reader($mchid,$start);
- $cur_limits[$mchid] = $result[$mchid];
- foreach ($items as $item) {
- $refill_amount = intval($item['refill_amount'] + 0.005);
- $card_type = $type_map[$item['card_type']];
- $cache_num = $result[$mchid][$card_type][$refill_amount];
- if ($cache_num == -1) {
- $new_num = -1;
- }else{
- $new_num = ($cache_num - $item['num']) >= 0 ? $cache_num - $item['num'] : 0;
- }
- $cur_limits[$mchid][$card_type][$refill_amount] = $new_num;
- }
- $cur_limits[$mchid]['company_name'] = $merchant['company_name'];
- }
- Tpl::output('data', $cur_limits);
- Tpl::showpage('merchant.orderlimit');
- }
- }
- private function cache_storge_limit($data)
- {
- Model('')->table('setting')->where(['name'=>'storge_limit'])->delete();
- Model('')->table('setting')->insert(['name'=>'storge_limit','value'=>serialize($data)]);
- wcache('storge_limit' , ['data' => serialize($data)] , 'merchant-');
- }
- public function priceOp()
- {
- $quality = $_GET['quality'] ? $_GET['quality'] : 1;
- if (chksubmit())
- {
- $mchid = $_POST['mchid'];
- //合并表单数据
- $card_types = $_POST['cardtype'];
- $specs = $_POST['spec'];
- $prices = $_POST['price'];
- foreach ($card_types as $key => $card_type) {
- $data['card_type'] = $card_type;
- $data['spec'] = intval($specs[$key]);
- $data['price'] = ncPriceFormat($prices[$key]);
- $params[] = $data;
- }
- foreach ($params as $param)
- {
- if($param['price'] > 0) {
- $insert['mchid'] = $mchid;
- $insert['spec'] = $param['spec'];
- $insert['price'] = $param['price'];
- $insert['card_types'] = $param['card_type'];
- $insert['quality'] = $quality;
- $inserts[] = $insert;
- }
- }
- if(empty($inserts)) {
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- }
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- //删除旧费率
- $model_merchant->delPrices($mchid,$quality);
- //更新新费率
- $model_merchant->insertPrices($inserts);
- $trans->commit();
- showMessage('操作成功', 'index.php?act=merchant&op=merchant');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=merchant&op=merchant', 'html', 'error');
- }
- }
- $mchid = $_GET['mchid'] ?? 0;
- $goods = $this->GoodsFormat($mchid,$quality);
- Tpl::output('goods', $goods);
- Tpl::showpage('merchant.price');
- }
- private function GoodsFormat($mchid,$quality)
- {
- $all_spector = function ()
- {
- 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;
- }
- $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']];
- }
- }
- return $result;
- };
- $all_cardtype_specs = $all_spector();
- $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'];
- } else {
- $data['price'] = 0;
- }
- $result[$value['card_type']][] = $data;
- }
- return $result;
- };
- $result = $merger($all_cardtype_specs,$merch_cardtype_specs);
- return $result;
- }
- 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 refill_evidenceOp()
- {
- $model_merchant = Model('merchant');
- $condition = [];
- if (trim($_GET['mch_name']) != '') {
- $condition['mch_name'] = ['like', '%' . $_GET['mch_name'] . '%'];
- Tpl::output('mch_name', $_GET['mch_name']);
- }
- $state_sel = intval($_REQUEST['state_sel']);
- if ($state_sel == 1) {
- $condition['check_time'] = 0;
- $condition['status'] = 1;
- } elseif ($state_sel == 2) {
- $condition['check_time'] = ['gt', 0];
- $condition['status'] = 2;
- } elseif ($state_sel == 3) {
- $condition['check_time'] = ['gt', 0];
- $condition['status'] = 3;
- } else {
- }
- //充值申请列表
- $evidence_list = $model_merchant->getRefillEvidence($condition, 20, '*,member.available_predeposit', 'refill_evidence.add_time desc');
- $status_text = ['申请中', '已通过', '已驳回'];
- $operation_text = ['未预存', '已预存'];
- Tpl::output('evidence_list', $evidence_list);
- Tpl::output('status_text', $status_text);
- Tpl::output('operation_text', $operation_text);
- Tpl::output('page', $model_merchant->showpage('2'));
- Tpl::showpage('merchant.refill.evidence_list');
- }
- 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], '*');
- 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('merchant', 'refill_evidence'));
- }
- 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=merchant&op=refill_evidence');
- } 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']);
- }
- Tpl::showpage('recharge.add');
- }
- }
- public function recharge_manualOp()
- {
- if (chksubmit()) {
- $obj_validate = new Validator();
- $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" => '预存金额不能为空']
- ];
- $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('预存金额错误');
- }
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- $member_id = $merchant_info['admin_id'];
- if($pointsnum > 0) {
- $bz = '管理员操作手动预存金额增加';
- $this->credit_save_money($money , 1 , $member_id , $bz);
- }elseif ($pointsnum < 0) {
- $bz = '管理员操作手动预存金额减少';
- $this->credit_save_money($money , 2 , $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=merchant&op=refill_evidence');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败', 'index.php?act=merchant&op=refill_evidence');
- }
- } else {
- Tpl::showpage('recharge.manual.add');
- }
- }
- 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'] = '/';
- $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'];
- $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')]
- ];
- $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');
- $evidence_info = $model_merchant->getRefillEvidenceInfo(['apply_id' => $apply_id], '*');
- 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]);
- $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=merchant&op=refill_evidence');
- 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;
- $model_pd->changePd($admin_act, $data);
- $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']]
- );
- $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=merchant&op=refill_evidence', '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 OrderQueryOp()
- {
- $model_vr_order = Model('vr_order');
- $condition['order_state'] = ORDER_STATE_SEND;
- $orders = $model_vr_order->getOrderList($condition);
- if(!empty($orders)) {
- foreach ($orders as $order) {
- $order_id = $order['order_id'];
- QueueClient::push("QueryRefillState",['order_id' => $order_id]);
- }
- }
- showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
- }
- public function mch_notifyOp()
- {
- $model_refill_order = Model('refill_order');
- $condition['mch_notify_state'] = 0;
- $condition['inner_status'] = 0;
- $orders = $model_refill_order->getMerchantOrderList($condition, 1000, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
- if(!empty($orders)) {
- foreach ($orders as $order) {
- $order_id = $order['order_id'];
- if($order['order_state'] == ORDER_STATE_SEND) {
- QueueClient::push("QueryRefillState",['order_id' => $order_id]);
- }else{
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true]);
- }
- }
- }
- showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
- }
- public function refill_orderOp()
- {
- $model_refill_order = Model('refill_order');
- $condition['inner_status'] = 0;
- $fSingle = false;
- if (!empty($_GET['order_sn'])) {
- $condition['refill_order.order_sn'] = $_GET['order_sn'];
- $fSingle = true;
- }
- if (!empty($_GET['mch_order'])) {
- $condition['refill_order.mch_order'] = $_GET['mch_order'];
- $fSingle = true;
- }
- if (!empty($_GET['ch_trade_no'])) {
- $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no'];
- $fSingle = true;
- }
- if (!empty($_GET['mchid'])) {
- $condition['refill_order.mchid'] = $_GET['mchid'];
- }
- if (!empty($_GET['channel_name'])) {
- $condition['refill_order.channel_name'] = $_GET['channel_name'];
- }
- if (!empty($_GET['store_id'])) {
- $condition['vr_order.store_id'] = $_GET['store_id'];
- }
- if (!empty($_GET['refill_amount'])) {
- $condition['refill_order.refill_amount'] = $_GET['refill_amount'];
- }
- if (!empty($_GET['card_no'])) {
- $condition['refill_order.card_no'] = $_GET['card_no'];
- }
- if (!empty($_GET['card_type']))
- {
- if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
- $condition['refill_order.card_type'] = $_GET['card_type'];
- }
- if($_GET['card_type'] == 'oil') {
- $condition['refill_order.card_type'] = ['in' , ['1' , '2']];
- }
- if($_GET['card_type'] == 'phone') {
- $condition['refill_order.card_type'] = ['in' , ['4' , '5' , '6']];
- }
- }
- $fToday = false;
- if(!$fSingle)
- {
- $start_unixtime = intval(strtotime($_GET['query_start_time']));
- $end_unixtime = intval(strtotime($_GET['query_end_time']));
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $condition['refill_order.order_time'] = [ ['egt', $start_unixtime] , ['lt', $end_unixtime] , 'and'];
- }
- elseif ($start_unixtime > 0) {
- $condition['refill_order.order_time'] = ['egt', $start_unixtime];
- }
- elseif ($end_unixtime > 0) {
- $condition['refill_order.order_time'] = ['lt', $end_unixtime];
- }
- else {
- $start = strtotime(date('Y-m-d',time()));
- $condition['refill_order.order_time'] = ['egt', $start];
- $fToday = true;
- }
- if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40']))
- {
- $condition['vr_order.order_state'] = $_GET['order_state'];
- if($_GET['order_state'] == ORDER_STATE_SEND)
- {
- if($_GET['time'] == 1){
- $condition['refill_order.order_time'] = ['between', [(time() - 3600) , (time() - 1800)]];
- }
- if($_GET['time'] == 2){
- $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
- }
- }
- }
- }
- $merchants = [];
- $merchant_list = Model('')->table('merchant')->limit(100)->select();
- foreach ($merchant_list as $key => $value) {
- $merchants[$value['mchid']] = $value;
- }
- $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
- $stat = $this->all_order_state_stat($condition);
- foreach ($order_list as $order_id => $order_info)
- {
- $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
- $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
- if ($order_info['notify_time'] > 0) {
- $diff_time = $order_info['notify_time'] - $order_info['order_time'];
- } else {
- $diff_time = time() - $order_info['order_time'];
- }
- $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
- $order_list[$order_id]['diff_time'] = $diff_time;
- }
- $provider_list = Model('')->table('refill_provider,store')
- ->field('refill_provider.*,store.store_name')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where(['refill_provider.opened' => 1])
- ->limit(100)
- ->select();
- Tpl::output('stat', $stat);
- Tpl::output('ftoday', $fToday);
- Tpl::output('order_list', $order_list);
- Tpl::output('provider_list', $provider_list);
- Tpl::output('merchant_list', $merchant_list);
- Tpl::output('show_page', $model_refill_order->showpage());
- Tpl::showpage('refill.order.index');
- }
- public function notify_merchantOp()
- {
- $order_id = $_GET['order_id'];
- $mod_order = Model('vr_order');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- 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('操作成功', 'index.php?act=merchant&op=refill_order');
- }
- 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]);
- if((time() - $order_info['order_time']) < 3600)
- {
- showMessage('订单时间未超过1小时', 'index.php?act=merchant&op=refill_order');
- }
- $logic_vr_order = Logic("vr_order");
- if($type == 'success') {
- if($order_info['order_state'] == ORDER_STATE_CANCEL){
- showMessage('此订单状态已为已取消,不可手动成功。', 'index.php?act=merchant&op=refill_order');
- }
- $logic_vr_order->changeOrderStateSuccess($order_id);
- }elseif ($type == 'cancel') {
- if($order_info['order_state'] == ORDER_STATE_SUCCESS){
- showMessage('此订单状态已为交易完成,不可手动失败。', 'index.php?act=merchant&op=refill_order');
- }
- $logic_vr_order->changeOrderStateCancel($order_info, '', "后台手动回调通知失败.");
- }else {
- showMessage('手动操作类型错误', 'index.php?act=merchant&op=refill_order');
- }
- $mod_refill = Model('refill_order');
- $mod_refill->edit($order_id, ['notify_time' => time(), 'notify_state' => 1]);
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
- showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
- }
- public function providerStatsOp()
- {
- $provider_model = Model('refill_provider');
- $condition = [];
- $provider_list = $provider_model->getProviderList($condition, 100);
- $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 providerOp()
- {
- $this->sync_cfgs();
- $provider_model = Model('refill_provider');
- $condition = [];
- if (trim($_GET['name']) != '') {
- $condition['name'] = ['like', '%' . $_GET['name'] . '%'];
- Tpl::output('name', $_GET['name']);
- }
- if (in_array($_GET['type'], [1, 2])) {
- $condition['type'] = $_GET['type'];
- }
- $provider_list = $provider_model->getProviderList($condition, 100);
- foreach ($provider_list as $key => $provider) {
- if(!empty($provider['start_period']) && !empty($provider['end_period'])){
- $provider_list[$key]['period'] = $provider['start_period'] . '~' . $provider['end_period'];
- }else{
- $provider_list[$key]['period'] = '全时间段';
- }
- }
- $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.index');
- }
- public function sync_cfgs()
- {
- $name_val = function ($items) {
- $result = [];
- foreach ($items as $item) {
- $name = $item['name'];
- $result[$name] = $item;
- }
- return $result;
- };
- $match = function ($all, $cur)
- {
- $inserts = $updates = [];
- foreach ($all as $key => $value)
- {
- if (!array_key_exists($key, $cur)) {
- $insert['name'] = $key;
- $insert['store_id'] = $value['cfg']['store_id'];
- $insert['qualitys'] = $value['cfg']['qualitys'];
- $inserts[] = $insert;
- } elseif ($value['cfg']['qualitys'] != $cur[$key]['qualitys']) {
- $update['provider_id'] = $cur[$key]['provider_id'];
- $update['qualitys'] = $value['cfg']['qualitys'];
- $updates[] = $update;
- }
- }
- return [$inserts, $updates];
- };
- $updater = function ($mod,$updates)
- {
- if(empty($updates)) return;
- foreach ($updates as $update) {
- $provider_id = $update['provider_id'];
- $data = ['qualitys' => $update['qualitys']];
- $mod->editProvider($data, ['provider_id' => $provider_id]);
- }
- };
- $inserter = function ($mod,$type,$names)
- {
- foreach ($names as $name) {
- $data = ['name' => $name['name'],'type' => $type,'store_id' => $name['store_id'] , 'qualitys' => $name['qualitys']];
- $mod->insert($data);
- }
- };
- global $config;
- $oil_configs = $config['oil_providers'];
- $pho_configs = $config['phone_providers'];
- $oils = $name_val($oil_configs);
- $phones = $name_val($pho_configs);
- $mod_prov = Model('refill_provider');
- $oil_items = $mod_prov->getProviderList(['type' => 1]);
- $oil_items = $name_val($oil_items);
- [$oil_inserts,$oil_updates] = $match($oils,$oil_items);
- $phone_items = $mod_prov->getProviderList(['type' => 2]);
- $phone_items = $name_val($phone_items);
- [$phone_inserts,$phone_updates] = $match($phones,$phone_items);
- $inserter($mod_prov,1,$oil_inserts);
- $inserter($mod_prov,2,$phone_inserts);
- $updater($mod_prov,$oil_updates);
- $updater($mod_prov,$phone_updates);
- }
- 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=merchant&op=provider');
- }
- $resp = $provider_model->editProvider(['opened' => $state], ['provider_id' => $provider_id]);
- if (!$resp) {
- showMessage('操作失败', 'index.php?act=merchant&op=provider', 'html', 'error');
- }
- showMessage('操作成功', 'index.php?act=merchant&op=provider');
- }
- /**
- * 新增通道
- */
- 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=merchant&op=provider',
- '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=merchant&op=provider');
- }
- $result = $provider_model->editProvider($params, ['provider_id' => $provider_id]);
- if ($result) {
- $this->log('编辑通道:' . '[ ' . $provider['name'] . ']', 1);
- showMessage('通道编辑成功', 'index.php?act=merchant&op=provider');
- } 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=merchant&op=provider');
- } else {
- showMessage('通道删除失败', "index.php?act=merchant&op=provider");
- }
- }
- public function provider_amount_controlOp()
- {
- global $config;
- $type = $_GET['type'] ?? $_POST['type'];
- $form = $_GET['form'] ?? $_POST['form'];
- $rkey = $this->speed_key($type , $form);
- $quality = [ 'common' => 1 , 'fast' => 2 , 'card' => 3 , 'third' => 4 , 'slow' => 5];
- if (chksubmit())
- {
- $pids = $_POST['pid'];
- $names = $_POST['name'];
- $types = $_POST['types'];
- $amounts = $_POST['amount'];
- $speeds = $_POST['speed'];
- $sorts = $_POST['sort'];
- $openeds = $_POST['opened'];
- $hass = $_POST['has'];
- foreach ($pids as $key => $pid) {
- if($hass[$key] == 0) {
- continue;
- }
- $data['pid'] = intval($pid);
- $data['name'] = $names[$key];
- $data['type'] = intval($types[$key]);
- $data['amount'] = intval($amounts[$key]);
- $data['speed'] = intval($speeds[$key]);
- $data['sort'] = intval($sorts[$key]);
- $data['opened'] = intval($openeds[$key]);
- $index = "{$data['type']}-{$data['amount']}";
- $result[$index][] = $data;
- }
- wcache($rkey , ['data' => serialize($result)] , 'provider-');
- showMessage('编辑成功', 'index.php?act=merchant&op=provider');
- }
- 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(100)
- ->order('opened asc , provider_id desc')
- ->select();
- if(empty($providers)) {
- showMessage('暂无相关通道', 'index.php?act=merchant&op=provider');
- }
- $formData = $this->formData($type , $form);
- $amounts = $formData['amounts'];
- $cfgs = $formData['cfgs'];
- $types = $formData['types'];
- 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=merchant&op=provider');
- }
- 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=merchant&op=provider");
- }
- 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'];
- }
- 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];
- }
- private function scard_type(int $card_type)
- {
- if ($card_type == 1) { //中石油
- return '中石油';
- } elseif ($card_type == 2) { //中石化
- return '中石化';
- } elseif ($card_type == 4) { //中国移动
- return '中国移动';
- } elseif ($card_type == 5) { //中国联通
- return '中国联通';
- } elseif ($card_type == 6) { //中国电信
- return '中国电信';
- } else {
- return 'unknown';
- }
- }
- private function elapse_time($seconds)
- {
- $minutes = intval($seconds / 60);
- $second = intval($seconds % 60);
- if($minutes >= 60) {
- $minute = $minutes % 60;
- $hours = intval($minutes / 60);
- $result = "{$minute}m{$second}s";
- }
- elseif($minutes > 0) {
- $result = "{$minutes}m{$second}s";
- } else {
- $result = "{$second}s";
- }
- if(isset($hours))
- {
- $result = "{$hours}h{$minute}m";
- }
- return $result;
- }
- private function refill_stat($condition , $times)
- {
- $stat_order = function ($condition) {
- $stat = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count ')
- ->where($condition)->find();
- return $stat['order_count'];
- };
- $result = [];
- $condition['order_state'] = ORDER_STATE_SEND;
- foreach ($times as $time) {
- $condition['refill_order.order_time'] = $time;
- $result[] = $stat_order($condition);
- }
- return $result;
- }
- private function all_order_state_stat($condition)
- {
- $counts = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts, order_state')
- ->where($condition)
- ->group('order_state')
- ->select();
- $all = [];
- $data['order_count'] = $data['refill_amounts'] = $data['channel_amounts'] = $data['mch_amounts'] = 0;
- $sending = $success = $cancel = $data;
- foreach ($counts as $count)
- {
- if ($count['order_state'] == ORDER_STATE_SEND) {
- $sending = $count;
- } elseif ($count['order_state'] == ORDER_STATE_SUCCESS) {
- $success = $count;
- } elseif ($count['order_state'] == ORDER_STATE_CANCEL) {
- $cancel = $count;
- }
- $all['order_count'] += $count['order_count'];
- $all['refill_amounts'] += ncPriceFormat($count['refill_amounts']);
- $all['channel_amounts'] += ncPriceFormat($count['channel_amounts']);
- $all['mch_amounts'] += ncPriceFormat($count['mch_amounts']);
- }
- return ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
- }
- public function OrderSendListOp()
- {
- $model_refill_order = Model('refill_order');
- $condition['refill_order.inner_status'] = 0;
- $condition['vr_order.order_state'] = ORDER_STATE_SEND;
- $condition['refill_order.order_time'] = ['lt', (time() - 1800)];
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- foreach ($merchant_list as $key =>$value) {
- $merchants[$value['mchid']] = $value;
- }
- $order_list = $model_refill_order->getMerchantOrderList($condition, 1000, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
- $stat = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
- ->where($condition)->find();
- $count = $this->refill_stat($condition ,
- [['between', [(time() - 3600) , (time() - 1800)]],
- ['lt', (time() - 3600)]]
- );
- foreach ($order_list as $order_id => $order_info) {
- $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
- $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
- $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
- $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
- }
- $provider_list = Model('')->table('refill_provider')->limit(100)->select();
- Tpl::output('stat', $stat);
- Tpl::output('count', $count);
- Tpl::output('order_list', $order_list);
- Tpl::output('provider_list', $provider_list);
- Tpl::output('show_page', $model_refill_order->showpage());
- Tpl::showpage('refill.order.send.index');
- }
- public function OrderStatsOp()
- {
- $type = $_GET['type'] ? $_GET['type'] : 'system';
- $page = "{$type}.order.stats";
- $model_refill_order = Model('refill_order');
- $condition['type'] = $type;
- if(!empty($_GET['cid'])) {
- $condition['cid'] = $_GET['cid'];
- }
- $start_unixtime = intval(strtotime($_GET['query_start_time']));
- $end_unixtime = intval(strtotime($_GET['query_end_time']));
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $condition['time_stamp'] = [ ['egt', $start_unixtime] , ['lt', $end_unixtime] , 'and'];
- }
- elseif ($start_unixtime > 0) {
- $condition['time_stamp'] = ['egt', $start_unixtime];
- }
- elseif ($end_unixtime > 0) {
- $condition['time_stamp'] = ['lt', $end_unixtime];
- }
- $stats_list = $model_refill_order->getOrderStatsList($condition);
- if($type == 'provider') {
- $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.store_id,store.store_name')->join('inner')
- ->on('store.store_id=refill_provider.store_id')->limit(100)->select();
- Tpl::output('provider_list', $provider_list);
- }elseif ($type == 'merchant') {
- $merchant_list = Model('')->table('merchant')->limit(100)->select();
- Tpl::output('merchant_list', $merchant_list);
- }
- Tpl::output('stats_list', $stats_list);
- Tpl::output('show_page', $model_refill_order->showpage());
- Tpl::showpage($page);
- }
- }
|