model = new \app\admin\model\WalletLog; $this->view->assign('userTypeList', $this->model->getUserTypeList()); $this->view->assign('typeList', $this->model->getTypeList()); } /** * 流水总账列表(批量解析师傅/用户姓名手机及关联订单号,并计算汇总指标) */ public function index() { $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { $totalIncome = round((float)Db::name('wallet_log')->where('amount', '>', 0)->sum('amount'), 2); $totalOutflow = round(abs((float)Db::name('wallet_log')->where('amount', '<', 0)->sum('amount')), 2); $this->view->assign([ 'totalIncome' => $totalIncome, 'totalOutflow' => $totalOutflow, ]); return $this->view->fetch(); } if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->where($where) ->order($sort, $order) ->paginate($limit); $rows = $list->items(); $masterIds = []; $userIds = []; $orderIds = []; foreach ($rows as $r) { if ($r['user_type'] === 'master' && (int)$r['user_id'] > 0) { $masterIds[] = (int)$r['user_id']; } elseif ($r['user_type'] === 'user' && (int)$r['user_id'] > 0) { $userIds[] = (int)$r['user_id']; } if ((int)$r['order_id'] > 0) { $orderIds[] = (int)$r['order_id']; } } $masterMap = $masterIds ? Db::name('master')->where('id', 'in', array_unique($masterIds))->column('id,realname,mobile', 'id') : []; $userMap = $userIds ? Db::name('user')->where('id', 'in', array_unique($userIds))->column('id,nickname,username,mobile', 'id') : []; $orderMap = $orderIds ? Db::name('order')->where('id', 'in', array_unique($orderIds))->column('id,order_no,service_name', 'id') : []; foreach ($rows as &$item) { $uid = (int)$item['user_id']; if ($item['user_type'] === 'master') { $m = $masterMap[$uid] ?? null; $item['account_name'] = $m ? ($m['realname'] ?: ('师傅#' . $uid)) : ('师傅#' . $uid); $item['account_mobile'] = $m['mobile'] ?? ''; } else { $u = $userMap[$uid] ?? null; $item['account_name'] = $u ? ($u['nickname'] ?: ($u['username'] ?: ('用户#' . $uid))) : ('用户#' . $uid); $item['account_mobile'] = $u['mobile'] ?? ''; } $oid = (int)$item['order_id']; $ord = $oid > 0 ? ($orderMap[$oid] ?? null) : null; $item['order_no'] = $ord['order_no'] ?? ''; $item['service_name'] = $ord['service_name'] ?? ''; } unset($item); return json(['total' => $list->total(), 'rows' => $rows]); } /** * 资金流水溯源详情 */ public function detail($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $owner = []; if ($row['user_type'] === 'master' && (int)$row['user_id'] > 0) { $m = Db::name('master')->where('id', (int)$row['user_id'])->find(); if ($m) { $owner = [ 'role' => '认证师傅', 'name' => $m['realname'], 'mobile' => $m['mobile'], 'money' => $m['money'], 'frozen' => $m['frozen_money'], ]; } } elseif ((int)$row['user_id'] > 0) { $u = Db::name('user')->where('id', (int)$row['user_id'])->find(); if ($u) { $owner = [ 'role' => '平台注册用户', 'name' => $u['nickname'] ?: $u['username'], 'mobile' => $u['mobile'], 'money' => $u['money'], 'frozen' => '0.00', ]; } } $order = (int)$row['order_id'] > 0 ? Db::name('order')->where('id', (int)$row['order_id'])->find() : null; $settle = (int)$row['order_id'] > 0 ? Db::name('settle')->where('order_id', (int)$row['order_id'])->find() : null; $this->view->assign([ 'row' => $row, 'owner' => $owner, 'order' => $order ?: [], 'settle' => $settle ?: [], ]); return $this->view->fetch(); } public function add() { $this->error('财务资金流水由业务交易自动记账,禁止手工新增'); } public function edit($ids = null) { $this->error('财务资金流水属于不可篡改审计凭证,禁止编辑'); } public function del($ids = null) { $this->error('财务资金流水属于不可篡改审计凭证,禁止删除'); } public function multi($ids = null) { $this->error('财务资金流水禁止批量修改'); } }