$time = time(); $endtime = strtotime(date('Y-m', strtotime('-6 month'))); $store_id = $_SESSION['admin_user']['store_id']; $where['pay_state'] = 2; //支付成功 $where['print_state'] = 4; //打印状态: 打印完成 $where['store_id'] = $store_id; $where['create_time'] = ['between', [$endtime, $time]]; $model = D('Order'); $list = $model->field("sum(pay_price) as price, count(1) as cnt,FROM_UNIXTIME(create_time, '%Y-%m') as create_time")->where($where)->group("FROM_UNIXTIME(create_time, '%Y-%m')")->order("create_time asc")->select(); var_dump($list);