$this->user_id]); $data['now_balance'] = $user_wallet['balance']??0; $data['today_income'] = 0; $data['withdraw_num'] = 0; $data['use_num'] = 0; $data['top_up_num'] = 0; $where = []; $where[] = ['mall_id' => $this->mall_id]; $where[] = ['user_id' => $this->user_id]; $params['order'] = 'id desc'; $params['select'] = 'type,balance_from_type,sum(money) as money'; $params['where'] = $where; $params['group'] = 'type,balance_from_type'; $list = BalanceLog::listPage($params); if (!empty($list['list'])) { $use_num_arr = [BalanceLog::getBalanceLogFrom('Pk支付'), BalanceLog::getBalanceLogFrom('云库存补货'), BalanceLog::getBalanceLogFrom('支付拿货款'), BalanceLog::getBalanceLogFrom('余额支付'),]; $top_up_num_arr = [BalanceLog::getBalanceLogFrom('后台充值'), BalanceLog::getBalanceLogFrom('前端会员充值')]; foreach ($list['list'] as $v) { if ($v['type'] == 2 && in_array($v['balance_from_type'], $use_num_arr)) $data['use_num'] += $v['money']; if ($v['balance_from_type'] == 17) $data['withdraw_num'] = $v['money']; if ($v['type'] == 1 && in_array($v['balance_from_type'], $top_up_num_arr)) $data['top_up_num'] += $v['money']; } } $where[] = ['type' => 1]; $where[] = ['>=', 'created_at', strtotime(date('Y-m-d', time()) . ' 00:00:00')]; $where[] = ['<=', 'created_at', strtotime(date('Y-m-d', time()) . ' 23:59:59')]; $result = BalanceLog::listPage(['where' => $where, 'select' => 'sum(money) as money']); if (!empty($result['list']) && !empty($result['list'][0]['money'])) $data['today_income'] = $result['list'][0]['money']; return $this->success('操作成功', $data); } /** * 余额充值/消费/提现记录 * @return mixed|void */ public function actionList() { $params = \Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['type'], 'required', 'message' => 'type,必传'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = []; $where[] = ['mall_id' => $this->mall_id]; $where[] = ['user_id' => $this->user_id]; if ($params['type'] == 3) { $use_num_arr = [BalanceLog::getBalanceLogFrom('Pk支付'), BalanceLog::getBalanceLogFrom('云库存补货'), BalanceLog::getBalanceLogFrom('支付拿货款'), BalanceLog::getBalanceLogFrom('余额支付')]; $where[] = ['type' => 2]; $where[] = ['balance_from_type' => $use_num_arr]; } if ($params['type'] == 2) { $where[] = ['type' => 2]; $where[] = ['balance_from_type' => [BalanceLog::getBalanceLogFrom('余额提现')]]; } if ($params['type'] == 1) { $where[] = ['type' => 1]; $where[] = ['balance_from_type' => [BalanceLog::getBalanceLogFrom('后台充值'), BalanceLog::getBalanceLogFrom('前端会员充值')]]; } $params['select'] = 'id,type,money,desc,balance,created_at'; $params['order'] = 'id desc'; $params['where'] = $where; $list = BalanceLog::listPage($params); return $this->success('操作成功', $list); } }