123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace app\admin\controller\agent;
- use app\common\controller\Backend;
- use think\Db;
- class Moneylog extends Backend
- {
-
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Moneylog;
- }
- public function import()
- {
- parent::import();
- }
-
-
-
- public function index()
- {
-
- $this->relationSearch = true;
-
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
-
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-
- $gh_map = [];
-
- $map['moneylog.log_type'] = ['in', [21, 22, 23, 54, 60, 82]];
- if ($this->auth->id != 1 && $this->auth->id != 11) {
- if ($this->auth->user_id > 0) {
- $user_ids = Db::name('user')->where(['intro_uid' => $this->auth->user_id])->column('id');
- $user_ids = $user_ids ? : [];
- $map['moneylog.user_id'] = ['in', $user_ids];
- } else {
- $map['moneylog.user_id'] = -100;
- }
- }
- $list = $this->model
- ->with(['user', 'otheruser'])
- ->where($where)
- ->where($gh_map)
- ->where($map)
- ->order($sort, $order)
- ->paginate($limit);
- $wallet_logtype = config('wallet.logtype');
- $mt_user_match_video_log = Db::name('user_match_video_log');
- $mt_user_match_audio_log = Db::name('user_match_audio_log');
- foreach ($list as $row) {
- $row->getRelation('user')->visible(['username', 'nickname']);
- $row->getRelation('otheruser')->visible(['username', 'nickname']);
- $row['log_type_text'] = isset($wallet_logtype[$row['log_type']]) ? $wallet_logtype[$row['log_type']] : '';
- $row['call_minutes'] = '';
- if ($row['log_type'] == 21) {
- $row['call_minutes'] = $mt_user_match_video_log->where(['id' => $row['table_id']])->value('call_minutes');
- } elseif ($row['log_type'] == 22) {
- $row['call_minutes'] = $mt_user_match_audio_log->where(['id' => $row['table_id']])->value('call_minutes');
- }
- }
-
- $sum_money = db('user_money_log')->alias('moneylog')->join('user','moneylog.user_id = user.id','LEFT')->where($map)->where($gh_map)->field('sum(moneylog.change_value) as sum_money')->find();
-
- $today_time = strtotime(date('Y-m-d'));
- $today_sum_money = db('user_money_log')->alias('moneylog')->join('user','moneylog.user_id = user.id','LEFT')->where($map)->where($gh_map)->where(['moneylog.createtime' => ['egt', $today_time]])->field('sum(moneylog.change_value) as sum_money')->find();
-
- $week_time = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
- $week_sum_money = db('user_money_log')->alias('moneylog')->join('user','moneylog.user_id = user.id','LEFT')->where($map)->where($gh_map)->where(['moneylog.createtime' => ['between', [$today_time - 86400, $today_time - 1]]])->field('sum(moneylog.change_value) as sum_money')->find();
- $result = array("total" => $list->total(), "rows" => $list->items(),
- 'extend' => [
- 'sum_money' => $sum_money['sum_money'],
- 'today_sum_money' => $today_sum_money['sum_money'],
- 'week_sum_money' => $week_sum_money['sum_money'],
- ]
- );
- return json($result);
- }
- return $this->view->fetch();
- }
- }
|