123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- <?php
- class refill_amount_statsControl extends SystemControl
- {
- private $setting_key;
- public function __construct()
- {
- parent::__construct();
- $this->setting_key = 'amount_stats_settings';
- }
- public function indexOp()
- {
- Tpl::showpage('refill_amount_stats.index');
- }
- public function stats_settingsOp()
- {
- $data = $this->get_stats_settings();
- exit(json_encode($data));
- }
- public function stats_settings_saveOp()
- {
- $writer = function ($key,$val) {
- $cache = rcache($this->setting_key, 'refill-');
- $data = unserialize($cache['data']) ?? [];
- $data[$key] = $val;
- wcache($this->setting_key, ['data' => serialize($data)], 'refill-');
- };
- $writer($_POST['key'], $_POST['value']);
- $data = $this->get_stats_settings();
- exit(json_encode($data));
- }
- private function get_stats_settings(): array
- {
- $settings = rcache($this->setting_key, 'refill-');
- $settings = unserialize($settings['data']);
- return [
- 'state' => true,
- 'channel_names' => $settings['channel_names'] ?? [],
- 'merchant_names' => $settings['merchant_names'] ?? [],
- 'channel_fast' => $settings['channel_fast'] ?? [],
- 'channel_normal' => $settings['channel_normal'] ?? [],
- 'merchant' => $settings['merchant'] ?? [],
- 'daily_channel' => $settings['daily_channel'] ?? [],
- 'daily_merchant' => $settings['daily_merchant'] ?? []
- ];
- }
- public function sys_channelsOp()
- {
- global $config;
- $provider_model = Model('refill_provider');
- $condition['opened'] = 1;
- $provider_items = $provider_model->table('refill_provider,store')
- ->field('refill_provider.name,refill_provider.qualitys,refill_provider.type,store.store_name,store.store_id')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where($condition)
- ->order('opened asc, name asc')
- ->select();
- $provider_items = array_map(function ($item) use($config) {
- $quality_text = $item['type'] == mtopcard\OilCardPaper ? $config['oil_quality_text'] : $config['phone_quality_text'];
- return [
- 'store_id' => $item['store_id'],
- 'name' => $item['name'],
- 'quality_text' => $quality_text[$item['qualitys']],
- 'store_name' => $item['store_name'],
- 'tag' => ADMIN_NAME
- ];
- }, $provider_items);
- $data = [
- 'state' => true,
- 'list' => $provider_items
- ];
- exit(json_encode($data));
- }
- public function channel_dataOp()
- {
- $store_ids = $_GET['store_ids'];
- if (empty($store_ids)) {
- $data = [
- 'state' => true,
- 'list' => []
- ];
- exit(json_encode($data));
- }
- $condition['refill_provider.store_id'] = ['in', $store_ids];
- $provider_model = Model('refill_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')
- ->select();
- $providers = [];
- foreach ($provider_items as $provider)
- {
- $pid = $provider['provider_id'];
- $providers[$pid] = $provider;
- $providers[$pid]['available_predeposit'] = 0;
- $account_id = intval($provider['account_id']);
- if($account_id > 0) {
- $mid_pids[$account_id] = $pid;
- $mids[] = $account_id;
- }
- }
- 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'];
- }
- }
- }
- $list = [];
- foreach ($providers as $val){
- $item = [
- 'tag' => ADMIN_NAME,
- 'store_name' => $val['store_name'],
- 'name' => $val['name'],
- 'balance' => $val['balance'] ?? 0,
- 'available_predeposit' => $val['available_predeposit'] ?? 0,
- ];
- $list[] = $item;
- }
- $data = [
- 'state' => true,
- 'list' => $list
- ];
- exit(json_encode($data));
- }
- public function sys_mchsOp()
- {
- $model_merchant = Model('merchant');
- $condition['merchant_state'] = 1;
- $merchant_list = $model_merchant->getMerchantList($condition, 200, 'available_predeposit desc,merchant_state asc,mchid desc', true);
- $merchant_list = array_map(function($item) {
- return [
- 'mch_id' => $item['mchid'],
- 'name' => $item['name'],
- 'mch_name' => $item['company_name'],
- 'tag' => ADMIN_NAME
- ];
- }, $merchant_list);
- $data = [
- 'state' => true,
- 'list' => $merchant_list
- ];
- exit(json_encode($data));
- }
- public function mch_dataOp()
- {
- $mch_ids = $_GET['mch_ids'];
- if (empty($mch_ids)) {
- $data = [
- 'state' => true,
- 'list' => []
- ];
- exit(json_encode($data));
- }
- $condition['merchant.mchid'] = ['in', $mch_ids];
- $model_merchant = Model('merchant');
- $merchant_list = $model_merchant->getMerchantList($condition, 200, 'available_predeposit desc,merchant_state asc,mchid desc', true);
- $merchant_debts = rcache("merchant-debts-detail", 'refill-');
- foreach ($merchant_list as $key => $merchant) {
- $mchid = $merchant['mchid'];
- $available_predeposit = $merchant['available_predeposit'] - $merchant['credit_bonus'];
- $merchant_list[$key]['available_predeposit'] = $available_predeposit;
- if (array_key_exists($mchid, $merchant_debts)) {
- $debt_detail = unserialize($merchant_debts[$mchid]);
- $merchant_list[$key]['debt'] = $debt_detail;
- } else {
- $merchant_list[$key]['debt'] = ['debt' => 0, 'send_amounts' => 0, 'lack_amounts' => 0];
- }
- }
- $list = [];
- foreach ($merchant_list as $val){
- $item = [
- 'tag' => ADMIN_NAME,
- 'mch_id' => $val['mchid'],
- 'mch_name' => $val['company_name'],
- 'name' => $val['name'],
- 'debt' => $val['debt']['debt'] ?? 0,
- 'available_predeposit' => $val['available_predeposit'] ?? 0,
- ];
- $list[] = $item;
- }
- $data = [
- 'state' => true,
- 'list' => $list
- ];
- exit(json_encode($data));
- }
- public function daily_statementOp()
- {
- Tpl::showpage('refill_amount_stats.daily_statement');
- }
- public function daily_provider_dataOp()
- {
- if (!$_GET['cid'] || !$_GET['query_day']) {
- $data = [
- 'state' => true,
- 'list' => []
- ];
- exit(json_encode($data));
- }
- $provider_model = Model('');
- $provider_condition['opened'] = 1;
- $provider_condition['store.store_id'] = ['in', $_GET['cid']];
- $provider_items = $provider_model->table('refill_provider,store')
- ->field('store.store_name,store.store_id,refill_provider.provider_id,refill_provider.name')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where($provider_condition)
- ->order('opened asc, name asc')
- ->select();
- $list = [];
- foreach ($provider_items as $item) {
- $store_id = $item['store_id'];
- $list[$store_id] = [
- 'day' => $_GET['query_day'],
- 'store_name' => $item['store_name'],
- 'name' => $item['name'],
- 'initial_balance' => 0,
- 'repayment_amount' => 0,
- 'tag' => ADMIN_NAME,
- 'store_id' => $store_id,
- 'notify_time' => [
- 'quantity' => 0,
- 'card_value' => 0,
- 'discounted_amount' => 0,
- ],
- 'order_time' => [
- 'quantity' => 0,
- 'card_value' => 0,
- 'discounted_amount' => 0,
- ]
- ];
- }
- $order_condition['type'] = 'provider';
- $order_condition['time_text'] = $_GET['query_day'];
- $order_condition['cid'] = ['in', $_GET['cid']];
- $model_refill_order = Model('refill_order');
- $stats_list = $model_refill_order->getOrderStatsListALl($order_condition);
- foreach ($stats_list as $item)
- {
- $store_id = $item['cid'];
- if (!array_key_exists($store_id, $list)) {
- continue;
- }
- $time_type = $item['order_time_type'];
- if (!in_array($time_type, ['notify_time', 'order_time'])) {
- continue;
- }
- $list[$store_id][$time_type]['quantity'] = $item['success_count'];
- $list[$store_id][$time_type]['card_value'] = $item['success_refill_amounts'];
- $list[$store_id][$time_type]['discounted_amount'] = $item['success_channel_amounts'];
- }
- $amount_condition['refill_provider.store_id'] = ['in', $_GET['cid']];
- $start_unixtime = intval(strtotime($_GET['query_day'] . '00:00:00'));
- $end_unixtime = $start_unixtime + 86400;
- $amount_condition['add_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- $amount_mod = Model('provider_amount');
- $amount_list = $amount_mod->getAmountList($amount_condition,200,'provider_amount.amount,refill_provider.store_id', 'provider_amount.add_time desc, refill_provider.name asc', '', true);
- foreach ($amount_list as $value) {
- $store_id = $value['store_id'];
- $list[$store_id]['repayment_amount'] += $value['amount'];
- }
- $data = [
- 'state' => true,
- 'list' => array_values($list)
- ];
- exit(json_encode($data));
- }
- public function daily_merchant_dataOp()
- {
- if (!$_GET['cid'] || !$_GET['query_day']) {
- $data = [
- 'state' => true,
- 'list' => []
- ];
- exit(json_encode($data));
- }
- $model_merchant = Model('merchant');
- $mch_ids = $_GET['cid'];
- $condition['merchant.mchid'] = ['in', $mch_ids];
- $merchant_list = $model_merchant->getMerchantList($condition, 200, 'available_predeposit desc,merchant_state asc,mchid desc', true);
- $list = [];
- foreach ($merchant_list as $item) {
- $mchid = $item['mchid'];
- $list[$mchid] = [
- 'day' => $_GET['query_day'],
- 'mch_name' => $item['company_name'],
- 'name' => $item['name'],
- 'initial_balance' => 0,
- 'repayment_amount' => 0,
- 'tag' => ADMIN_NAME,
- 'mch_id' => $mchid,
- 'notify_time' => [
- 'quantity' => 0,
- 'card_value' => 0,
- 'discounted_amount' => 0,
- ],
- 'order_time' => [
- 'quantity' => 0,
- 'card_value' => 0,
- 'discounted_amount' => 0,
- ]
- ];
- }
- $order_condition['type'] = 'merchant';
- $order_condition['time_text'] = $_GET['query_day'];
- $order_condition['cid'] = ['in', $_GET['cid']];
- $model_refill_order = Model('refill_order');
- $stats_list = $model_refill_order->getOrderStatsList($order_condition, 200, '*', 'time_stamp desc, cname asc');
- foreach ($stats_list as $item)
- {
- $store_id = $item['cid'];
- if (!array_key_exists($store_id, $list)) {
- continue;
- }
- $time_type = $item['order_time_type'];
- if (!in_array($time_type, ['notify_time', 'order_time'])) {
- continue;
- }
- $list[$store_id][$time_type]['quantity'] = $item['success_count'];
- $list[$store_id][$time_type]['card_value'] = $item['success_refill_amounts'];
- $list[$store_id][$time_type]['discounted_amount'] = $item['success_mch_amounts'];
- }
- $start_unixtime = intval(strtotime($_GET['query_day'] . '00:00:00'));
- $end_unixtime = $start_unixtime + 86400;
- $amount_condition['add_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- $amount_condition['mchid'] = ['in', $_GET['cid']];
- $amount_condition['check_time'] = ['gt', 0];
- $amount_condition['status'] = 2;
- $merchant_model = Model('merchant');
- $evidence_list = $merchant_model->getRefillEvidenceAll($amount_condition, 'refill_evidence.*,member.available_predeposit', 'refill_evidence.add_time desc');
- foreach ($evidence_list as $value)
- {
- $mchid = $value['mchid'];
- $list[$mchid]['repayment_amount'] += $value['amount'];
- }
- $data = [
- 'state' => true,
- 'list' => array_values($list)
- ];
- exit(json_encode($data));
- }
- }
|