field('UserId,sum(PaymentAmount) as money') ->where(['OrderState'=>['in',ProductOrderEnum::$PayComplete]]) ->group(['UserId']) ->order('money') ->fetchAll(); } /** * @description: 获取所有支付成功用户近一个月的支付总金额 * @param {*} * @return {*} */ public function getMonthCost($user_id){ $last_month = date("Y-m-d H:i:s", strtotime("-1 month")); $new_month = date("Y-m-d H:i:s", time()); return $this->field('UserId,sum(PaymentAmount) as money') ->where(['OrderState'=>['in',ProductOrderEnum::$PayComplete],'UpdateTime' => ['<', $new_month]]) ->where(['UpdateTime' => ['>', $last_month]]) ->where(['UserId' => ['in',$user_id]]) ->group(['UserId']) ->order('money') ->fetchAll(); } /** * @description: 获取所有支付成功用户近一个月在筛选范围的支付总金额 * @param {*} * @return {*} */ public function getScreenMonthCost($screen){ $last_month = date("Y-m-01", strtotime("-1 month")); $new_month = date("Y-m-t", strtotime("-1 month")); return $this->field('UserId,sum(PaymentAmount) as money') ->where(['OrderState'=>['in',ProductOrderEnum::$PayComplete],'UpdateTime' => ['<', $new_month]]) ->where(['UpdateTime' => ['>', $last_month]]) ->group(['UserId'],'having money>'.$screen['money1'].' and money<'.$screen['money2']) ->fetchAll(); } }