123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750 |
- <?php
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_HELPER_PATH . '/model/member_info.php');
- require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');
- class providerControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- global $config;
- $provider_model = Model('refill_provider');
- $condition = [];
- if (trim($_GET['name']) != '') {
- $condition['store_name'] = ['like', '%' . $_GET['name'] . '%'];
- Tpl::output('name', $_GET['name']);
- }
- if (in_array($_GET['type'], [mtopcard\OilCardPaper, mtopcard\PhoneCardPaper, mtopcard\ThirdCardPaper])) {
- $condition['type'] = $_GET['type'];
- }
- if(!empty($_GET['quality'])) {
- $condition['qualitys'] = ['like', '%' . $_GET['quality'] . '%'];
- }
- if(!empty($_GET['export'])) {
- $condition['opened'] = 1;
- }
- $refill_company = $this->refill_companys(['co_type' => refill_companyModel::co_type_provider]);
- $provider_items = $provider_model->table('refill_provider,store')
- ->field('refill_provider.*,store.store_name,store.member_id')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where($condition)
- ->order('opened asc, name asc')
- ->page(200)
- ->select();
- $providers = [];
- $mid_pids = [];
- $mids = [];
- foreach ($provider_items as $provider)
- {
- $pid = $provider['provider_id'];
- $providers[$pid] = $provider;
- $providers[$pid]['available_predeposit'] = 0;
- $quality_text = $provider['type'] == mtopcard\OilCardPaper ? $config['oil_quality_text'] : $config['phone_quality_text'];
- $providers[$pid]['quality_text'] = $quality_text[$provider['qualitys']];
- $providers[$pid]['co_name'] = $refill_company[$provider['co_id']]['co_name'] ?? '/';
- $account_id = intval($provider['account_id']);
- if($account_id > 0) {
- $mid_pids[$account_id] = $pid;
- $mids[] = $account_id;
- }
- }
- $debt_total = 0;
- $available_total = 0;
- if(!empty($mids))
- {
- $member_data = Model('member')->field('member_id,available_predeposit')->where(['member_id' => ['in',$mids]])->select();
- foreach ($member_data as $member)
- {
- $mid = intval($member['member_id']);
- if(array_key_exists($mid,$mid_pids)) {
- $pid = $mid_pids[$mid];
- $providers[$pid]['available_predeposit'] = $member['available_predeposit'];
- if($providers[$pid]['opened'] != 1) continue;
- if ($member['available_predeposit'] >= 0) {
- $available_total += $member['available_predeposit'];
- } else {
- $debt_total += $member['available_predeposit'];
- }
- }
- }
- }
- if(!empty($_GET['export']))
- {
- $this->provider_export($providers);
- return;
- }
- $stats = ['available_total' => $available_total, 'debt_total' => $debt_total];
- $opened_text = ['使用中', '已禁用'];
- $type_text = ['油卡', '手机充值卡', '增值业务'];
- Tpl::output('opened_text', $opened_text);
- Tpl::output('type_text', $type_text);
- Tpl::output('provider_list', $providers);
- Tpl::output('stats', $stats);
- Tpl::output('prices', $this->all_price());
- Tpl::output('show_page', $provider_model->showpage());
- Tpl::showpage('provider.index');
- }
- private function all_price()
- {
- $result = [];
- $mod_price = Model('provider_price');
- $prices = $mod_price->getPirces(['price_id' => ['gt', 0]]);
- foreach ($prices as $price)
- {
- $key = "{$price['provider_name']}-{$price['product_type']}";
- if(!empty($price['effect_time']))
- {
- $time = '<span style="color: #0bb20c">' . date("Y-m-d H:i:s", $price['effect_time']) . '</span>';
- }else{
- $time = date("Y-m-d H:i:s", $price['update_time']);
- }
- $result[$key] = $time;
- }
- return $result;
- }
- public function recharge_manualOp()
- {
- $provider_id = $_GET['provider_id'] ?? $_POST['provider_id'];
- $provider_model = Model('refill_provider');
- $provider_info = $provider_model->getProviderInfo(['provider_id' => $provider_id]);
- if (empty($provider_info)) {
- showMessage('通道信息有误');
- }
- if (chksubmit())
- {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => $_POST["operation"], "require" => "true", "message" => '操作人姓名不能为空'],
- ["input" => $_POST["pointsnum"], "require" => "true", "message" => '预存金额不能为空']
- ];
- $operatetype = $_POST['operatetype'];
- $pointsnum = $_POST['pointsnum'];
- $money = abs($pointsnum);
- if ($money == 0) {
- showMessage('金额错误');
- }
- if (!empty($_FILES['voucher']['name'])) {
- $upload = new UploadFile();
- $upload->set('default_dir', ATTACH_UPFILE);
- $result = $upload->upfile('voucher');
- if ($result) {
- $_POST['voucher_name'] = $upload->file_name;
- } else {
- showMessage($upload->error);
- }
- }
- try {
- $model_merchant = Model('merchant');
- $trans = new trans_wapper($model_merchant, __METHOD__);
- $member_id = $provider_info['account_id'];
- if ($operatetype == 'add') {
- $bz = "管理员调款操作,手动增加通道余额";
- $this->credit_save_money($money, 'add', $member_id, $bz);
- $_POST['pointsnum'] = $money;
- } elseif ($operatetype == 'del') {
- $bz = "管理员调款操作,手动减少通道余额";
- $this->credit_save_money($money, 'del', $member_id, $bz);
- $_POST['pointsnum'] = -($money);
- } else {
- showMessage('预存类型错误');
- }
- $result = $this->ct_provider_amount($_POST, $provider_info);
- if (!$result) {
- $trans->rollback();
- showMessage('操作失败');
- }
- $trans->commit();
- showMessage('操作成功', 'index.php?act=provider&op=index');
- } catch (Exception $e) {
- $trans->rollback();
- showMessage('操作失败');
- }
- }
- else
- {
- Tpl::output('provider', $provider_info);
- Tpl::showpage('provider.recharge');
- }
- }
- private function ct_provider_amount($params, $provider_info)
- {
- $input['provider_id'] = $provider_info['provider_id'];
- $input['memeber_id'] = $provider_info['account_id'];
- $input['amount'] = $params['pointsnum'];
- $input['operation'] = $params['operation'];
- $input['add_time'] = time();
- $input['bz'] = $params['bz'] ?? '';
- $input['voucher_name'] = $params['voucher_name'] ?? '';
- return Model('provider_amount')->addAmount($input);
- }
- public function provider_amountOp()
- {
- $condition = [];
- if(!empty($_GET['provider_id'])) {
- $condition['provider_amount.provider_id'] = $_GET['provider_id'];
- }
- $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['add_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $condition['add_time'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $condition['add_time'] = ['lt', $end_unixtime];
- }
- if (!empty($_GET['export'])) {
- $this->ProviderAmountExport($condition);
- return;
- }
- $provider_list = $this->providers();
- foreach ($provider_list as $provider) {
- $providers[$provider['provider_id']] = $provider;
- }
- $mod = Model('provider_amount');
- $list = $mod->getAmountList($condition,50,'provider_amount.*,refill_provider.name', 'provider_amount.add_time desc, refill_provider.name asc', '', true);
- foreach ($list as $key => $value) {
- $list[$key]['store_name'] = $providers[$value['provider_id']]['store_name'];
- }
- $stat = Model()->table('provider_amount,refill_provider')
- ->where($condition)
- ->join('inner')->on('provider_amount.provider_id=refill_provider.provider_id')
- ->field('sum(amount) as amounts')
- ->find();
- Tpl::output('stat', $stat);
- Tpl::output('provider_list', $providers);
- Tpl::output('show_page', $mod->showpage());
- Tpl::output('info_list', $list);
- Tpl::showpage('provider.amount');
- }
- 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)
- {
- $model_member = Model('member');
- foreach ($names as $name) {
- $insert_member = [];
- $insert_member['member_name'] = "{$name['name']}-refill";
- $insert_member['member_passwd'] = md5($name['name']);
- $insert_id = $model_member->addMember($insert_member);
- $helper = new refill\divert_account();
- $helper->init_member($insert_id);
- $data = ['name' => $name['name'], 'type' => $type, 'store_id' => $name['store_id'], 'qualitys' => $name['qualitys'], 'opened' => 2, 'account_id' => $insert_id];
- $mod->insert($data);
- }
- };
- global $config;
- $oil_configs = $config['oil_providers'];
- $pho_configs = $config['phone_providers'];
- $third_configs = $config['third_providers'];
- $oils = $name_val($oil_configs);
- $phones = $name_val($pho_configs);
- $third = $name_val($third_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);
- $third_items = $mod_prov->getProviderList(['type' => 3]);
- $third_items = $name_val($third_items);
- [$third_inserts, $third_updates] = $match($third, $third_items);
- $inserter($mod_prov, 1, $oil_inserts);
- $inserter($mod_prov, 2, $phone_inserts);
- $inserter($mod_prov, 3, $third_inserts);
- $updater($mod_prov, $oil_updates);
- $updater($mod_prov, $phone_updates);
- $updater($mod_prov, $third_updates);
- $chprice_helper = new refill\chprice_helper();
- $chprice_helper->update_from_file();
- }
- private function ProviderAmountExport($cond)
- {
- $result = Model('provider_amount')->getAllDatas($cond);
- $this->createExcel($result);
- }
- private function createExcel($data = [])
- {
- if(empty($data)) {
- showMessage('数据为空');
- }
- Language::read('export');
- import('libraries.excel');
- $provider_list = $this->providers();
- $providers = [];
- foreach ($provider_list as $provider) {
- $providers[$provider['provider_id']] = $provider;
- }
- $excel_obj = new Excel();
- $excel_data = [];
- //设置样式
- $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
- //header
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '序号'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '通道名称'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '调款金额'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '操作日期'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '操作人'];
- //data
- foreach ((array)$data as $k => $v) {
- $tmp = [];
- $provider_id = intval($v['provider_id']);
- $provider = $providers[$provider_id];
- $store_name = "{$provider['name']}({$provider['store_name']})";
- $tmp[] = ['data' => $k+1];
- $tmp[] = ['data' => $store_name];
- $tmp[] = ['data' => $v['amount']];
- if (empty($v['add_time'])) {
- $tmp[] = ['data' => ''];
- } else {
- $tmp[] = ['data' => date('Y-m-d H:i:s', $v['add_time'])];
- }
- $tmp[] = ['data' => $v['operation']];
- $excel_data[] = $tmp;
- }
- $excel_data = $excel_obj->charset($excel_data, CHARSET);
- $excel_obj->addArray($excel_data);
- $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
- $excel_obj->generateXML('通道调款记录导出-' . date('Y-m-d-H', time()));
- }
- public function file_syncOp()
- {
- $this->sync_cfgs();
- showMessage('操作完成');
- }
- public function refresh_priceOp()
- {
- $publisher = new message\publisher();
- $publisher->modify_refill_channel();
- showMessage('操作完成');
- }
- public function provider_priceOp()
- {
- $provider_id = $_GET['provider_id'];
- $mod_provider = Model('refill_provider');
- $mod_price = Model('provider_price');
- $provider = $mod_provider->getProviderInfo(['provider_id' => $provider_id]);
- $provider_name = $provider['name'];
- $type = $provider['type'];
- $price = $mod_price->getPirce(['provider_name' => $provider_name,'product_type' => $type]);
- $cfg = $this->price_cfg($price);
- if(empty($provider)) {
- showMessage('通道不存在');
- }
- if(chksubmit()){
- $admininfo = $this->getAdminInfo();
- $new_cfg = $this->cfg_format($_POST, $cfg);
- $effect_time = $_POST['effect_time'];
- if(!empty($effect_time))
- {
- $effect_time = strtotime($effect_time);
- if($effect_time < time()) {
- $effect_time = 0;
- }
- }
- else {
- $effect_time = 0;
- }
- $chprice_helper = new refill\chprice_helper();
- $ret = $chprice_helper->update($price['price_id'], $new_cfg, $effect_time, $admininfo['name']);
- if($effect_time > 0) {
- QueueClient::async_push('AysncChangePrice', ['price_id' => $price['price_id']], $effect_time - time());
- }
- if($ret) {
- showMessage('编辑成功');
- }else{
- showMessage('编辑失败');
- }
- }
- else
- {
- global $config;
- $all_specs = $this->all_specs($cfg['qualitys'], $type);
- $amounts = $this->map_cfg($cfg,$all_specs);
- $quality_text = $price['product_type'] == mtopcard\OilCardPaper ? $config['oil_quality_text'] : $config['phone_quality_text'];
- $quality_text = $quality_text[$cfg['qualitys']];
- Tpl::output('provider_name', $cfg['name']);
- Tpl::output('product_type', $price['product_type']);
- Tpl::output('quality_text', $quality_text);
- Tpl::output('quality', $cfg['qualitys']);
- Tpl::output('effect_time', $price['effect_time']);
- Tpl::output('amounts', $amounts);
- Tpl::output('all_specs', $all_specs);
- Tpl::showpage('provider.price.set');
- }
- }
- private function price_cfg($price)
- {
- $cfg = json_decode($price['cfg'], true);
- $new_cfg = $price['new_cfg'];
- if(!empty($new_cfg))
- {
- $cfg = json_decode($new_cfg, true);
- }
- return $cfg;
- }
- private function card_types($stypes)
- {
- $result = [];
- $types = explode(',',$stypes);
- foreach ($types as $stype) {
- $type = mtopcard\topcard_type($stype);
- $result[] = $type;
- }
- return $result;
- }
- private function map_cfg($cfg,$all_specs)
- {
- $amounts = $cfg['amount'] ?? [];
- $amount_list = [];
- foreach ($amounts as $spec => $goods)
- {
- foreach ($goods as $gitem)
- {
- $types = $this->card_types($gitem['card_type']);
- foreach ($types as $type) {
- $amount_list[$type][$spec] = $gitem['price'] ?? 0;
- }
- }
- }
- $result = [];
- foreach ($all_specs as $card_type => $val)
- {
- $specs = $val['specs'];
- foreach ($specs as $spec)
- {
- $result[$card_type][$spec] = ['price' => 0,'opened' => 0];
- }
- }
- foreach ($amount_list as $card_type => $prices)
- {
- foreach ($prices as $spec => $price)
- {
- if (array_key_exists($card_type, $result) && array_key_exists($spec, $result[$card_type])) {
- $result[$card_type][$spec]['price'] = $price;
- $result[$card_type][$spec]['opened'] = 1;
- }
- }
- }
- return $result;
- }
- private function all_specs($qualitys, $type): array
- {
- global $config;
- if ($type == mtopcard\OilCardPaper) {
- $refill_specs = [
- 'petrochina' => $config['refill_oil_specs'],
- 'sinopec' => $config['refill_oil_specs']
- ];
- } elseif ($type == mtopcard\PhoneCardPaper) {
- $refill_specs = [
- 'chinamobile' => $config['refill_phone_specs'],
- 'chinaunicom' => $config['refill_phone_specs'],
- 'chinatelecom' => $config['refill_phone_specs']
- ];
- } else {
- return [];
- }
- $all_type_specs = [];
- foreach ($refill_specs as $scard_type => $specs) {
- $data = [];
- $card_type = mtopcard\topcard_type($scard_type);
- if (in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
- if (in_array(refill\Quality::Quick, explode(',', $qualitys))) {
- $specs = array_merge($config['refill_phone_small_specs'], $specs);
- }
- }
- $data['goods_name'] = $this->scard_type($card_type);
- $data['specs'] = $specs;
- $all_type_specs[$card_type] = $data;
- }
- return $all_type_specs;
- }
- private function cfg_format($input, $cfg)
- {
- foreach ($cfg['amount'] as $amount => $amt_items)
- {
- $new_amount = [];
- foreach ($amt_items as $item){
- $goods_id = $item['goods_id'];
- $quality = $item['quality'];
- $card_types = $this->card_types($item['card_type']);
- foreach ($card_types as $card_type)
- {
- $key = "price-{$card_type}-{$amount}";
- $arr = [
- 'goods_id' => $goods_id,
- 'price' => floatval(ncPriceFormat($input[$key])),
- 'quality' => $quality,
- 'card_type' => mtopcard\scard_type($card_type)
- ];
- $new_amount[] = $arr;
- }
- }
- $cfg['amount'][$amount] = $new_amount;
- }
- return $cfg;
- }
- public function provider_amount_editOp()
- {
- $amount_id = $_GET['amount_id'];
- $mod = Model('provider_amount');
- $provider_amount = $mod->where(['id' => $amount_id])->find();
- if(empty($provider_amount)) {
- showMessage('记录不存在');
- }
- if(chksubmit())
- {
- $bz = $_POST['bz'];
- $resp = $mod->where(['id' => $amount_id])->update(['bz' => $bz]);
- if($resp) {
- showMessage('编辑成功');
- }else{
- showMessage('编辑失败');
- }
- }
- else
- {
- $provider = Model('')->table('refill_provider,store')
- ->field('refill_provider.*,store.store_name')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where(['provider_id' => $provider_amount['provider_id']])
- ->find();
- Tpl::output('provider', $provider);
- Tpl::output('provider_amount', $provider_amount);
- Tpl::showpage('provider.amount.edit');
- }
- }
- public function provider_export($providers)
- {
- Language::read('export');
- import('libraries.excel');
- $excel_obj = new Excel();
- $excel_data = [];
- //设置样式
- $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
- //header
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '通道ID'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '通道名称'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '订单成功后余额'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '接口查询余额'];
- //data
- foreach ($providers as $provider) {
- $tmp = [];
- $store_name = "{$provider['name']}({$provider['store_name']})";
- $tmp[] = ['data' => $provider['provider_id']];
- $tmp[] = ['data' => $store_name];
- $tmp[] = ['data' => $provider['available_predeposit']];
- $tmp[] = ['data' => $provider['balance']];
- $excel_data[] = $tmp;
- }
- $excel_data = $excel_obj->charset($excel_data, CHARSET);
- $excel_obj->addArray($excel_data);
- $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
- $excel_obj->generateXML('通道余额明细导出-' . date('Y-m-d-H', time()));
- }
- public function provider_remitOp()
- {
- $refill_company = $this->refill_companys(['co_type' => refill_companyModel::co_type_provider]);
- if (chksubmit())
- {
- $remits = $_POST['remits'];
- $strs = $_POST['strs'];
- $operation = $_POST['operation'];
- $title = '';
- $remit_total = 0;
- foreach ($strs as $key => $str)
- {
- $remit = $remits[$key];
- if(empty($remit)) continue;
- $item = explode('-', $str);
- $co_id = $item[0];
- $pid = $item[1];
- $data[$co_id][$pid] = $remit;
- $remit_total += $remit;
- }
- if(empty($data)) {
- showMessage('未提交数据');
- }
- if(ADMIN_NAME === 'YEZI') {
- $platform = '椰子';
- }else{
- $platform = '椰林';
- }
- foreach ($data as $co_id => $valuue)
- {
- $title .= "{$refill_company[$co_id]['co_name']}-";
- }
- $cur_time = time();
- $date = date("YmdHi", $cur_time);
- $title = "{$platform}-{$date}";
- $remit_record = [
- 'title' => $title,
- 'amount' => $remit_total,
- 'params' => json_encode($data),
- 'operation' => $operation,
- 'add_time' => $cur_time,
- 'oper_time' => $cur_time
- ];
- Model('refill_company_remit')->addRemit($remit_record);
- showMessage('操作成功', 'index.php?act=refill_company&op=remit_record');
- }
- else
- {
- $provider_items = $this->providers();
- $result = $this->remit_data($provider_items, $refill_company);
- Tpl::output('remit_data',$result);
- Tpl::showpage('provider.remit');
- }
- }
- private function remit_data($items, $refill_company): array
- {
- $providers = $mid_pids = $mids = $datas = $result =[];
- foreach ($items as $item)
- {
- $co_id = $item['co_id'];
- if(empty($co_id)) continue;
- $pid = $item['provider_id'];
- $account_id = intval($item['account_id']);
- if($account_id > 0) {
- $mid_pids[$account_id] = $pid;
- $mids[] = $account_id;
- }
- $item['available_predeposit'] = 0;
- $providers[$pid] = $item;
- }
- if(!empty($mids))
- {
- $member_data = Model('member')->field('member_id,available_predeposit')->where(['member_id' => ['in',$mids]])->select();
- foreach ($member_data as $member)
- {
- $mid = intval($member['member_id']);
- if(array_key_exists($mid,$mid_pids)) {
- $pid = $mid_pids[$mid];
- $providers[$pid]['available_predeposit'] = $member['available_predeposit'];
- }
- }
- }
- foreach ($providers as $provider)
- {
- $datas[$provider['co_id']][] = $provider;
- }
- $remit_cfg = $this->remit_cfg();
- foreach ($datas as $co_id => $data)
- {
- $available_total = 0;
- foreach ($data as $key => $value)
- {
- $remit = abs($value['available_predeposit'] - $remit_cfg['remit_money']);
- if ($remit > 1000 && $value['available_predeposit'] < $remit_cfg['remit_money']) {
- $data[$key]['remit'] = intval($remit - ($remit % 1000));
- } else {
- $data[$key]['remit'] = 0;
- }
- $available_total += $value['available_predeposit'];
- }
- if($available_total > $remit_cfg['remit_money'] || !array_key_exists($co_id, $refill_company)) continue;
- $result[] = [
- 'co_name' => $refill_company[$co_id]['co_name'],
- 'providers' => $data
- ];
- }
- return $result;
- }
- }
|